A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
spectrum-model.cc
Go to the documentation of this file.
1
2/*
3 * Copyright (c) 2009 CTTC
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Nicola Baldo <nbaldo@cttc.es>
19 */
20
21#include "spectrum-model.h"
22
23#include <ns3/assert.h>
24#include <ns3/log.h>
25
26#include <cmath>
27#include <cstddef>
28
29namespace ns3
30{
31
32NS_LOG_COMPONENT_DEFINE("SpectrumModel");
33
34bool
35operator==(const SpectrumModel& lhs, const SpectrumModel& rhs)
36{
37 return (lhs.m_uid == rhs.m_uid);
38}
39
41
42SpectrumModel::SpectrumModel(const std::vector<double>& centerFreqs)
43{
44 NS_ASSERT(centerFreqs.size() > 1);
45 m_uid = ++m_uidCount;
46
47 for (auto it = centerFreqs.begin(); it != centerFreqs.end(); ++it)
48 {
49 BandInfo e;
50 e.fc = *it;
51 if (it == centerFreqs.begin())
52 {
53 double delta = ((*(it + 1)) - (*it)) / 2;
54 e.fl = *it - delta;
55 e.fh = *it + delta;
56 }
57 else if (it == centerFreqs.end() - 1)
58 {
59 double delta = ((*it) - (*(it - 1))) / 2;
60 e.fl = *it - delta;
61 e.fh = *it + delta;
62 }
63 else
64 {
65 e.fl = ((*it) + (*(it - 1))) / 2;
66 e.fh = ((*(it + 1)) + (*it)) / 2;
67 }
68 m_bands.push_back(e);
69 }
70}
71
73{
74 m_uid = ++m_uidCount;
75 NS_LOG_INFO("creating new SpectrumModel, m_uid=" << m_uid);
76 m_bands = bands;
77}
78
80 : m_bands(std::move(bands))
81{
82 m_uid = ++m_uidCount;
83 NS_LOG_INFO("creating new SpectrumModel, m_uid=" << m_uid);
84}
85
86Bands::const_iterator
88{
89 return m_bands.begin();
90}
91
92Bands::const_iterator
94{
95 return m_bands.end();
96}
97
98size_t
100{
101 return m_bands.size();
102}
103
106{
107 return m_uid;
108}
109
110bool
112{
113 for (auto myIt = Begin(); myIt != End(); ++myIt)
114 {
115 for (auto otherIt = other.Begin(); otherIt != other.End(); ++otherIt)
116 {
117 if (std::max(myIt->fl, otherIt->fl) < std::min(myIt->fh, otherIt->fh))
118 {
119 return false;
120 }
121 }
122 }
123 return true;
124}
125
126} // namespace ns3
Set of frequency values implementing the domain of the functions in the Function Space defined by Spe...
bool IsOrthogonal(const SpectrumModel &other) const
Check if another SpectrumModels has bands orthogonal to our bands.
static SpectrumModelUid_t m_uidCount
counter to assign m_uids
SpectrumModelUid_t m_uid
unique id for a given set of frequencies
SpectrumModel(const std::vector< double > &centerFreqs)
This constructs a SpectrumModel based on a given set of frequencies, which is assumed to be sorted by...
Bands::const_iterator End() const
Const Iterator to the model Bands container end.
size_t GetNumBands() const
Bands::const_iterator Begin() const
Const Iterator to the model Bands container start.
SpectrumModelUid_t GetUid() const
Bands m_bands
Actual definition of frequency bands within this SpectrumModel.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool operator==(const EventId &a, const EventId &b)
Definition: event-id.h:157
std::vector< BandInfo > Bands
Container of BandInfo.
uint32_t SpectrumModelUid_t
Uid for SpectrumModels.
STL namespace.
The building block of a SpectrumModel.
double fc
center frequency
double fl
lower limit of subband
double fh
upper limit of subband