重复连接基于omnet ++中欧氏距离的节点 [英] Connect, repetitively, nodes based at their euclidean distance in omnet++

查看:206
本文介绍了重复连接基于omnet ++中欧氏距离的节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ned文件中创建了一个随机拓扑.在该拓扑中,每个节点都具有相同的弧度连接距离.我想为rc距离内的每个节点建立连接.

I have created a random topology in ned file. In that topology, every node has the same radian connection distance. I want to make connections for every node that is in the rc distance.

据我所知:

network ranTop
{
    parameters:
        int n = 100;
        int rc = 5;
        volatile int posX = intuniform (0,100);
        volatile int posY = intuniform (0,100);

    submodules:
        node[n] : Node {
            parameters:
                @display("p=$posX,$posY");
        }

}

推荐答案

您应该为每个节点设置(非易失性)posXposY参数,然后在所有节点上创建循环如果距离小于range,则仅可能连接并仅连接节点.您也可以在循环中以及在if条件中访问节点参数:

You should have (non volatile!) posX, posY parameter for each node and then create a loop over all possible connections and connect the nodes only if the distance is less than range. You can access the node parameters in the loop and in the if condition too:

simple MeshNode extends Node
{
    parameters:
        int posX = default(intuniform(0,100));
        int posY = default(intuniform(0,100));

        @display("i=misc/node_vs;p=$posX,$posY");
    gates:
        inout g[];
}


//
// A network of nodes randomly placed where nodes 
// closer than 'range' are connected.
//
network MeshNetwork
{
    parameters:
        int num @prompt("Number of nodes") = default(100);
        int range = 15;  // nodes closer than this should be connected

    submodules:
        node[num] : MeshNode;

    connections allowunconnected:
        for i=0..(num-2), for j=(i+1)..(num-1) {
            node[i].g++ <--> node[j].g++ if pow(node[i].posX-node[j].posX, 2)+pow(node[i].posY-node[j].posY, 2) < range*range;
        }
}

这篇关于重复连接基于omnet ++中欧氏距离的节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆