NS3仿真运行报错:ns3::UniformRandomRectanglePositionAllocator未找到求助
问题:NS3运行报错“ns3::UniformRandomRectanglePositionAllocator not found”
我运行一段NS3代码时触发断言错误,错误信息如下:
assert failed. cond="uid != 0", msg="Assert in TypeId::LookupByName: ns3::UniformRandomRectanglePositionAllocator not found", +0.000000000s -1 file=../src/core/model/type-id.cc, line=834
对应的代码:
#include "ns3/core-module.h" #include "ns3/network-module.h" #include "ns3/mobility-module.h" #include "ns3/csma-module.h" using namespace ns3; int main (int argc, char *argv[]) { // Create nodes uint32_t nNodes = 10; // Number of nodes NodeContainer nodes; nodes.Create (nNodes); // Create a 2D space for the nodes MobilityHelper mobility; mobility.SetPositionAllocator ("ns3::UniformRandomRectanglePositionAllocator", "X", DoubleValue (0.0), "Y", DoubleValue (0.0), "Width", DoubleValue (100.0), "Height", DoubleValue (100.0)); mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); mobility.Install (nodes); // Create the CSMA/CA protocol CsmaHelper csma; csma.SetChannelAttribute ("DataRate", DataRateValue (5000000)); csma.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (6560))); // Install the CSMA/CA protocol on the nodes NetDeviceContainer devices = csma.Install (nodes); // Run the simulation Simulator::Stop (Seconds (10.0)); Simulator::Run (); Simulator::Destroy (); return 0; }
解决方法
版本适配:替换位置分配器名称
UniformRandomRectanglePositionAllocator在NS3 3.35及以后的版本中已被重命名为UniformRandomBoxPositionAllocator,且需要新增Z轴相关参数。修改后的位置分配器代码如下:mobility.SetPositionAllocator ("ns3::UniformRandomBoxPositionAllocator", "X", DoubleValue (0.0), "Y", DoubleValue (0.0), "Z", DoubleValue (0.0), "Width", DoubleValue (100.0), "Height", DoubleValue (100.0), "Depth", DoubleValue (0.0));确认mobility模块已启用
如果使用旧版本NS3,需确保编译时已启用mobility模块。执行以下命令重新配置编译:./waf configure --enable-modules=mobility ./waf build检查编译依赖
手动编译时,确保链接阶段正确关联了mobility模块的库文件,避免因依赖缺失导致类型无法找到。
内容的提问来源于stack exchange,提问作者gushu
相关产品推荐
相关产品推荐

