omnet++ - 模块错误中的 Omnet++ 未知参数
问题描述
我正在创建一个随机生成的网络,在询问其他节点是否已经知道更新后,节点将发送更新消息。目前更新状态仍然是预定义的。运行模拟时收到此错误消息:
"(omnetpp::cModule)Simplegossip1: Unknown parameter 'updated' -- in module (Sg1) Simplegossip1.node[0] (id=2), at t=0s, event #1"
这是我的代码:
simplegossip1.ned (我在这里使用代码How to create a random connected graph in OMNeT++?)
simple Sg1
{
parameters:
@display("i=block/routing");
bool updated;
gates:
input in[]; // declare in[] and out[] to be vector gates
output out[];
}
network Simplegossip1
{
parameters:
int count;
double connectedness; // 0.0<x<1.0
submodules:
node[count]: Sg1 {
gates:
in[]; // removed the size of gate
out[];
}
connections allowunconnected:
for i=0..count-2, for j=i+1..count-1, if uniform(0,1)<connectedness {
node[i].out++ --> node[j].in++;
node[i].in++ <-- node[j].out++;
}
}
sg1.cc
#include <stdio.h>
#include <string.h>
#include <omnetpp.h>
using namespace omnetpp;
/**
* First attempt for gossip protocol
*/
class Sg1 : public cSimpleModule
{
public:
cMessage *askupdated = new cMessage("Ask Update");
cMessage *updated = new cMessage("Updated");
cMessage *unupdated = new cMessage("Unupdated");
cMessage *update = new cMessage("Here is the update");
protected:
virtual void forwardMessage(cMessage *msg, int dest);
virtual void initialize() override;
virtual void handleMessage(cMessage *msg) override;
};
Define_Module(Sg1);
void Sg1::initialize()
{
if (getIndex() == 0) {
// Boot the process scheduling the initial message as a self-message.
char msgname[20];
sprintf(msgname, "tic-%d", getIndex());
cMessage *msg = new cMessage(msgname);
scheduleAt(0.0, msg);
}
}
void Sg1::handleMessage(cMessage *msg)
{
int n = gateSize("out");
int k = intuniform(0, n-1);
int sid = msg->getArrivalGateId();
bool updatestatus = getParentModule()->par("updated");
if (msg == askupdated) {
if (updatestatus == true){
forwardMessage(updated,sid);
}
else {
forwardMessage(unupdated,sid);
}
}
else if (msg == unupdated) {
forwardMessage(update,sid);
}
else {
forwardMessage(askupdated,k);
}
}
void Sg1::forwardMessage(cMessage *msg, int dest)
{
// In this example, we just pick a random gate to send it on.
// We draw a random number between 0 and the size of gate `out[]'.
EV << "Forwarding message " << msg << " on port out[" << dest << "]\n";
send(msg, "out", dest);
}
还有一个只调用 Simplegossip1 网络的 omnet.ini 文件。
我该如何解决这个问题?提前致谢。
解决方案
你必须换行
bool updatestatus = getParentModule()->par("updated");
进入
bool updatestatus = par("updated");
因为updated
是Sg1
not 的父级的参数Sg1
。
推荐阅读
- regex - VS代码正则表达式替换部分字符串并保留其他
- spring-boot - 在边缘浏览器的头部添加访问令牌
- python - 仅当没有此类任务正在运行或计划时才创建 celery 任务
- c# - 无法从他人创建的共享链接 URL 中获取信息
- regex - 如果匹配 7 个字符,则正则表达式 (-) 之前的所有内容
- flutter - 是否可以在颤动中使用 localhost woocommerce rest api 发布数据
- powershell - PowerShell 在源文件夹和目标文件夹之间同步文件并替换目标文件夹中的最新文件
- c# - 如何在WPF的情节提要动画中将宽度值作为百分比
- mysql - SQL SELF JOIN 如果不存在则返回 null
- oracle - Oracle Sql Developer 应用程序中的隐藏双引号