RandomRectanglePositionAllocator

73 views
Skip to first unread message

13634...@qq.com

unread,
Jun 18, 2018, 10:41:04 PM6/18/18
to ns-3-users
  1. Dear all,
can you teach me how to use   RandomRectanglePositionAllocator?I want to randomly allocate 100 nodes in a rectangular area.
 I modified the src/mobility/examples/main-topology.cc script in order to test RandomRectanglePositionAllocator.

在此输入#include "ns3/core-module.h"
#include "ns3/mobility-module.h"

using namespace ns3;

static void
CourseChange (std::string context, Ptr<const MobilityModel> position)
{
 
Vector pos = position->GetPosition ();
  std
::cout << Simulator::Now () << ", pos=" << position << ", x=" << pos.x << ", y=" << pos.y
           
<< ", z=" << pos.z << std::endl;
}

int main (int argc, char *argv[])
{
 
CommandLine cmd;
  cmd
.Parse (argc, argv);


  NodeContainer c;
  c
.Create (10000);

  MobilityHelper mobility;
  mobility
.SetPositionAllocator ("ns3::RandomDiscPositionAllocator",
                                 
"X", StringValue ("100.0"),
                                 
"Y", StringValue ("100.0"),
                                 
"Rho", StringValue ("ns3::UniformRandomVariable[Min=0|Max=30]"));
  mobility
.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
  mobility
.Install (c);

  Config::Connect ("/NodeList/*/$ns3::MobilityModel/CourseChange",
                   
MakeCallback (&CourseChange));

  Simulator::Stop (Seconds (100.0));

  Simulator::Run ();

  1.   Simulator::Destroy ();
  2.   return 0;
  3. }
and this is what I changed
在此输mobility.SetPositionAllocator ("ns3::RandomRectanglePositionAllocator",
                                 "X", StringValue ("100.0"),
                                 "Y", StringValue ("100.0"));

but it didnt work:

 ./waf --run scratch/main-random-topology
Waf: Entering directory `/home/d/repos/ns-3-allinone/ns-3.28/build'
Waf: Leaving directory `/home/d/repos/ns-3-allinone/ns-3.28/build'
Build commands will be stored in build/compile_commands.json
'build' finished successfully (17.336s)
assert failed. cond="uid != 0", msg="Assert in TypeId::LookupByName: 100.0 not found", file=../src/core/model/type-id.cc, line=827
terminate called without an active exception



13634...@qq.com

unread,
Jun 18, 2018, 11:16:13 PM6/18/18
to ns-3-users


在 2018年6月19日星期二 UTC+8上午10:41:04,13634...@qq.com写道:
  1. Dear all,
can you teach me how to use   RandomRectanglePositionAllocator?I want to randomly allocate 100 nodes in a rectangular area.
 I modified the src/mobility/examples/main-topology.cc script in order to test RandomRectanglePositionAllocator.

mobility.SetPositionAllocator ("ns3::RandomRectanglePositionAllocator",
                                 "X", StringValue ("100.0"),
                                 "Y", StringValue ("100.0"));

pdbarnes

unread,
Jun 18, 2018, 11:20:13 PM6/18/18
to ns-3-users
RandomRectanglePositionAllicator takes different attribute. See the API docs:

https://www.nsnam.org/doxygen/classns3_1_1_random_rectangle_position_allocator.html#details

Peter

13634...@qq.com

unread,
Jun 19, 2018, 12:44:26 AM6/19/18
to ns-3-users
having help me twice,you are really kind and patient.
wish you a happy life!

在 2018年6月19日星期二 UTC+8上午11:20:13,pdbarnes写道:
Reply all
Reply to author
Forward
0 new messages