How to set up the position allocator when using Ra

2019-08-02 21:05发布

问题:

I tried to alter the example code(third.cc) by replacing the mobility model name(RandomWalk2dMobilityModel) with RandomWaypointMobilityModel. After running the code, it turned out to be an output like

assert failed. cond="m_position", msg="No position allocator added before using this model"

So basically this is the most relevant code with the error msg

MobilityHelper mobility;

mobility.SetPositionAllocator ("ns3::GridPositionAllocator",

"MinX", DoubleValue (0.0),

"MinY", DoubleValue (0.0),

"DeltaX", DoubleValue (5.0),

"DeltaY", DoubleValue (10.0),

"GridWidth", UintegerValue (3),

"LayoutType", StringValue ("RowFirst"));

// mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel", // "Bounds", RectangleValue (Rectangle (-50, 50, -50, 50)));

mobility.SetMobilityModel ("ns3::RandomWaypointMobilityModel");
mobility.Install (wifiStaNodes);

mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");

mobility.Install (wifiApNode);

What I am confused about is before setting mobility model, there has already set up the position allocator it worked for randomwalk2d, however, obviously it does not work for randomwaypoint model. So how to deal with it? I'll appreciate if there is someone who can help me to figure it out.

Many thanks.

回答1:

There should be actually TWO position allocators when you are using RandomWayPointModel.

  • The first, the one you have already used, is for the initial position of the nodes.

  • The second though, is an attribute to the RandomWayPointModel and it is used to pick a destination point. Please refer to the documentation for more details.



标签: c++ ns-3