我在ned文件中创建了一个随机拓扑。在该拓扑中,每个节点都具有相同的弧度连接距离。我想为rc距离内的每个节点建立连接。
据我所知:
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");
}
}
答案 0 :(得分:2)
您应该为每个节点设置(非易失性)posX
,posY
参数,然后在所有可能的连接上创建循环并仅连接节点 (如果距离小于range
。您也可以在循环中以及在if条件中访问节点参数:
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;
}
}