"Cannot cast from integer to double" 错误 运行 Castalia3.3 上使用 Omnet 5.3 的示例

"Cannot cast from integer to double" error when running an example on Castalia3.3 using Omnet 5.3

当我 运行 在 ubuntu 上使用 Omnet5.3 的任何 Castalia 3.3 示例时,例如 connectivityMap 一个,我收到此错误:

"无法评估参数 'packetSpacing':(omnetpp::cIntParImpl)packetSpacing:无法从类型整数转换为双精度 -- 在模块 (ConnectivityMap) SN.node[1] 中.Application (id=25),在 t=0.003536244016s,事件 #13" .

当我查看 SensorNetwork.ned 文件时,我发现参数是双精度类型

参数:

double field_x = default (30);          // the length of the deployment field
double field_y = default (30);          // the width of the deployment field
double field_z = default (0);           // the height of the deployment field (2-D field by default)

int numNodes;                       // the number of nodes

string deployment = default ("");

int numPhysicalProcesses = default (1);
string physicalProcessName = default ("CustomizablePhysicalProcess");
string wirelessChannelName = default ("WirelessChannel");
string debugInfoFileName = default ("Castalia-Trace.txt");

是bug问题吗?新版 omnet 的参数转换问题? 请帮助我,我还不是 Omnet 的专家

不,这不是错误,这是自 OMNeT++ 5.3 以来的有意更改。
表达式:

(double) par("packetSpacing")

调用 doubleValue() 的结果。 cPar.h中对该方法有如下描述:

Returns value as double. The cPar type must be DOUBLE.
Note: Implicit conversion from INT is intentionally missing.


有两种方法可以解决这个问题:

  1. packetSpacing 表单 int 的类型更改为 ConnectivityMap.ned 中的 double

  1. 通过添加intValue()强制将参数读取为int,例如ConnectivityMap.cc:

    packetSpacing = (double) par("packetSpacing").intValue() / 1000.0;