c++ - 为连接的 OMNeT++ 门分配随机选择但匹配的参数?

标签 c++ omnet++

我正在 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/

相关文章:

c++ - &lt;!&gt; 启动时出错 : Cannot load library in OMNET++ project while using sqlite3

java - Omnet++ 中的模拟时间

c++ - Omnet++ 错误在子类中设置参数并在另一个子类中调用它

c++ - Wt 从 http 响应回调添加新的小部件

c++ - 在 C 函数中创建的对象的存在

c++ - 文件何时加载到内存中 - 用于 fread、fopen 和 fwrite 调用?

c++ - std::shared_ptr 在空指针上调用非默认删除器

c++ - 模拟真实的 UDP 应用程序并测量 OMNeT++ 上的流量负载

c++ - 如何在 omnet++ 中的模块上单独调用 finish()

c++ - 在 QGraphicsScene 中使用自定义坐标