C++ 在 OMNET ++ 中编码
C++ Coding in OMNET ++
谁能告诉我如何在OMNET++
中以不同的方式编写这段代码:
while(outGate==port){
outGate = intuniform(0, n-1);
}
另一个:
void Txc15::forwardMessage (TicTocMsg15 *msg, int port)
{
// Increment hop count.
msg->setHopCount(msg->getHopCount()+1);
int outGate, n = gateSize("gate");
if(port != -1){
//we enter here only if the message is forwarded
outGate=port;
//checking for more than one gate!
if (n>1)
{
/**
* It will exit from the while cycle only if the intuniform function
* will choose a port different from the incoming one.
*/
while(outGate==port){
outGate = intuniform(0, n-1);
}
}
EV << "Forwarding message " << msg << " on gate[" << outGate << "]n";
//forward the message provided following the conditions.
send(msg, "gate$o", outGate);
}else{
//port is equal to -1 if and only if the message in newly generated
outGate = intuniform(0, n-1); // Randomly choose a gate.
EV << "Forwarding message " << msg << " on gate[" << outGate << "]n";
send(msg, "gate$o", outGate);
}
}
这个运行时成本有限:
outGate = intuniform(0, n-2);
if (outgate >= port) outgate++;
请注意,均匀随机是从范围 0 到 n-2(而不是 n-1)绘制的。如果outgate
大于或等于port
,我们将其增加一。这有效地导致 0..n-1 范围内的随机均匀,只是它不能与端口相同。
相关文章:
- 如何确定我已使用非编码文件到达 EOF?
- 如何在OMNET++中指定与命令行参数组合的输出文件名
- 使用 MATLAB 编码器生成C++代码:编译错误"undefined reference to `rgb2gray_tbb_real64'"
- 在卡萨布兰卡形成编码参数的列表
- 使用C++进行游程编码
- 如何将不同的可执行文件合并到一个窗口框架中进行编码?像浏览器一样
- 使用已使用 java 编码的 openssl 解码数据
- boost 是否有按特殊类型值编码状态"compact optional"?
- 如何在CPP的给定目录中列出UTF编码的文件名?
- 如何使用 C++将 ISO-2022-KR 编码转换为 UTF-8 编码?
- 如何在OMNET++中添加专门的命令行参数?
- 绝对编码器十六进制输入
- 防止C++中的硬编码数字
- 无法为 X.radio 创建中等可视化,因为找不到网络节点可视化 - Omnet++
- 将C++ std::string 转换为 UTF-16-LE 编码的字符串
- OMNeT++:未定义对 'typeinfo for inet::IMobility' 的引用
- 使用文件内容作为硬编码字符串
- 运行长度编码程序 c++ 的问题
- OMNeT++ cPacket as std::bitset 以应用 Reed-Solomon 编码
- C++ 在 OMNET ++ 中编码