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