我正在 OMNeT++ 中开发一个网络模型,我在其中引入了一个自定义 channel 类型来表示我的网络中的链接。对于此 channel 类型实例的一个属性,我想分配一个随机参数。但是,连接门的随机数应该相同。
我的节点定义具有以下门定义:
simple GridAgent
{
/* ... other paramters/definitions omitted ... */
gates:
inout agentConnections[];
}
在我的网络配置中,我使用简单的 <-->
连接节点语法,例如:
someSwitchyard.agentConnections++ <--> AgentConnectionChannel <--> someWindfarm.agentConnections++;
现在,这个 AgentConnectionChannel 有一个名为 impedance 的属性,我想随机分配它。此阻抗 属性对于 A -> B 和 B -> A 应该相同。我尝试添加 { impedance = default(unitform(1, 10)) }
网络定义,以及 **.agentConnections$o[*].channel.impedance = uniform(1, 10)
进入omnetpp.ini
.然而,在这两种情况下,A -> B 的赋值与 B -> A 的赋值不同。
如 OMNet++ mailing list 所示,这是因为 <-->
语法实际上是创建两个不同连接的简写,因此会发生随机数分布中的两个绘图。
如何将随机参数分配给连接的属性并且在两个连接的门的两个方向上具有相同的值?有没有办法在 omnetpp.ini
中做到这一点?文件,或者我是否需要在 Perl、Ruby 或 Python 中创建一个脚本来生成 omnetpp.ini
为了我的运行?
最佳答案
您的问题没有简单的解决方案,仅通过操作omnetpp.ini
文件无法解决。
我建议手动重写第二个方向的参数值。它需要为 channel 准备一个 C++ 类(您可能已经完成了)。
假设您在 NED 中的 channel 定义如下:
channel AgentConnectionChannel extends ned.DatarateChannel {
@class(AgentConnectionChannel);
double impedance;
}
在 omnetpp.ini
中你有:
**.agentConnections$o[*].channel.impedance = uniform(1, 10)
你应该准备C++
类AgentConnectionChannel
:
class AgentConnectionChannel: public cDatarateChannel {
public:
AgentConnectionChannel() : parAlreadyRewritten(false) {}
void setParAlreadyRewritten() {parAlreadyRewritten=true;}
protected:
virtual void initialize();
private:
bool parAlreadyRewritten;
private:
double impedance;
};
Define_Channel(AgentConnectionChannel);
void AgentConnectionChannel::initialize() {
if (parAlreadyRewritten == false) {
parAlreadyRewritten = true;
cGate * srcOut = this->getSourceGate();
cModule *owner = srcOut->getOwnerModule();
int index = srcOut->isVector() ? srcOut->getIndex() : -1;
cGate *srcIn = owner->gateHalf(srcOut->getBaseName(), cGate::INPUT,
index);
cChannel * channel = srcIn->findIncomingTransmissionChannel();
AgentConnectionChannel * reverseChan =
dynamic_cast<AgentConnectionChannel*>(channel);
if (reverseChan) {
reverseChan->setParAlreadyRewritten();
// assigning a value from forward direction channel
reverseChan->par("impedance") = this->par("impedance");
}
}
// and now read a parameter as usual
impedance = par("impedance").doubleValue();
EV << getFullPath() << ", impedance=" << impedance << endl;
}
关于c++ - 为连接的 OMNeT++ 门分配随机选择但匹配的参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36487357/