20 #include "ns3/boolean.h"
21 #include "ns3/command-line.h"
22 #include "ns3/config.h"
23 #include "ns3/constant-position-mobility-model.h"
24 #include "ns3/double.h"
25 #include "ns3/gnuplot.h"
26 #include "ns3/jakes-propagation-loss-model.h"
27 #include "ns3/pointer.h"
28 #include "ns3/propagation-loss-model.h"
29 #include "ns3/simulator.h"
30 #include "ns3/string.h"
45 dround(
double number,
double precision)
50 number = floor(number + 0.5);
54 number = ceil(number - 0.5);
80 double txPowerDbm = +20;
87 a->SetPosition(Vector(0.0, 0.0, 0.0));
89 for (
double distance = 0.0; distance < targetDistance; distance += step)
91 b->SetPosition(Vector(distance, 0.0, 0.0));
94 double rxPowerDbm = model->
CalcRxPower(txPowerDbm, a, b);
96 dataset.
Add(distance, rxPowerDbm);
103 std::ostringstream os;
104 os <<
"txPower " << txPowerDbm <<
"dBm";
125 double targetDistance,
127 unsigned int samples)
136 plot.
AppendExtra(
"set zlabel 'Probability' offset 0,+10");
145 double txPowerDbm = +20;
149 dataset.
SetStyle(
"with linespoints");
150 dataset.
SetExtra(
"pointtype 3 pointsize 0.5");
152 typedef std::map<double, unsigned int> rxPowerMapType;
157 a->SetPosition(Vector(0.0, 0.0, 0.0));
159 for (
double distance = 100.0; distance < targetDistance; distance += step)
161 b->SetPosition(Vector(distance, 0.0, 0.0));
163 rxPowerMapType rxPowerMap;
165 for (
unsigned int samp = 0; samp < samples; ++samp)
168 double rxPowerDbm = model->
CalcRxPower(txPowerDbm, a, b);
169 rxPowerDbm =
dround(rxPowerDbm, 1.0);
171 rxPowerMap[rxPowerDbm]++;
177 for (
auto i = rxPowerMap.begin(); i != rxPowerMap.end(); ++i)
179 dataset.
Add(distance, i->first, (
double)i->second / (
double)samples);
185 std::ostringstream os;
186 os <<
"txPower " << txPowerDbm <<
"dBm";
218 double txPowerDbm = +20;
225 a->SetPosition(Vector(0.0, 0.0, 0.0));
226 b->SetPosition(Vector(distance, 0.0, 0.0));
232 double rxPowerDbm = model->
CalcRxPower(txPowerDbm, a, b);
242 std::ostringstream os;
243 os <<
"txPower " << txPowerDbm <<
"dBm";
254 main(
int argc,
char* argv[])
258 cmd.AddValue(
"test",
"Run as a test, sample the models only once", test);
259 cmd.Parse(argc, argv);
261 double testDeterministicDistance = 2500.0;
262 double testProbabilisticDistance = 2500.0;
263 unsigned int testProbabilisticSamples = 100000;
269 testDeterministicDistance = 10;
270 testProbabilisticDistance = 200;
271 testProbabilisticSamples = 1;
272 testJakesTimeOneMsRes =
Seconds(0.001);
273 testJakesTimeZeroDotOneMsRes =
Seconds(0.0001);
282 plot.
SetTitle(
"ns3::FriisPropagationLossModel (Default Parameters)");
283 gnuplots.AddPlot(plot);
291 plot.
SetTitle(
"ns3::LogDistancePropagationLossModel (Exponent = 2.5)");
292 gnuplots.AddPlot(plot);
298 CreateObjectWithAttributes<ExponentialRandomVariable>(
"Mean",
DoubleValue(50.0));
302 plot.
SetTitle(
"ns3::RandomPropagationLossModel with Exponential Distribution");
303 gnuplots.AddPlot(plot);
314 "ns3::JakesPropagationLossModel (with 477.9 Hz shift and 1 millisec resolution)");
315 gnuplots.AddPlot(plot);
331 "ns3::JakesPropagationLossModel (with 477.9 Hz shift and 0.1 millisec resolution)");
332 gnuplots.AddPlot(plot);
341 CreateObject<ThreeLogDistancePropagationLossModel>();
344 plot.
SetTitle(
"ns3::ThreeLogDistancePropagationLossModel (Defaults)");
345 gnuplots.AddPlot(plot);
350 CreateObject<ThreeLogDistancePropagationLossModel>();
354 log3->SetAttribute(
"Exponent2",
DoubleValue(10.0));
357 plot.
SetTitle(
"ns3::ThreeLogDistancePropagationLossModel (Exponents 1.0, 3.0 and 10.0)");
358 gnuplots.AddPlot(plot);
365 TestProbabilistic(nak, testProbabilisticDistance, 100.0, testProbabilisticSamples);
366 plot.
SetTitle(
"ns3::NakagamiPropagationLossModel (Default Parameters)");
367 gnuplots.AddPlot(plot);
372 CreateObject<ThreeLogDistancePropagationLossModel>();
378 TestProbabilistic(log3, testProbabilisticDistance, 100.0, testProbabilisticSamples);
379 plot.
SetTitle(
"ns3::ThreeLogDistancePropagationLossModel and "
380 "ns3::NakagamiPropagationLossModel (Default Parameters)");
381 gnuplots.AddPlot(plot);
384 gnuplots.GenerateOutput(std::cout);
Parse command-line arguments.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Class to represent a 2D points plot.
void SetStyle(enum Style style)
void Add(double x, double y)
Class to represent a 2D function expression plot.
Class to represent a 3D points plot.
void AddEmptyLine()
Add an empty line in the data output sequence.
void Add(double x, double y, double z)
void SetStyle(const std::string &style)
a simple class to group together multiple gnuplots into one file, e.g.
void SetExtra(const std::string &extra)
Add extra formatting parameters to this dataset.
void SetTitle(const std::string &title)
Change line title.
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
void AddDataset(const GnuplotDataset &dataset)
void AppendExtra(const std::string &extra)
void SetTitle(const std::string &title)
Hold objects of type Ptr<T>.
double CalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
Returns the Rx Power taking into account all the PropagationLossModel(s) chained to the current one.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
static Time Now()
Return the current simulation virtual time.
static void Run()
Run the simulation.
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Simulation virtual time values and global simulation resolution.
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
void SetDefault(std::string name, const AttributeValue &value)
Time Seconds(double value)
Construct a Time in the indicated unit.
static double dround(double number, double precision)
Round a double number to the given precision.
static Gnuplot TestDeterministicByTime(Ptr< PropagationLossModel > model, Time timeStep, Time timeTotal, double distance)
Test the model by sampling over time.
static Gnuplot TestDeterministic(Ptr< PropagationLossModel > model, double targetDistance, double step)
Test the model by sampling over a distance.
static Gnuplot TestProbabilistic(Ptr< PropagationLossModel > model, double targetDistance, double step, unsigned int samples)
Test the model by sampling over a distance.
Every class exported by the ns3 library is enclosed in the ns3 namespace.