question

Kim Jh avatar image
0 Likes"
Kim Jh asked Matthew Gillespie commented

How to list(write) all NetworkNodes between two NetworkNodes?

For example, in this situation, NN1 ↔ NN2 ↔ NN3 ↔ NN4 ↔ NN5. command1(NN1, NN5) writes as follows NN1, NN2, NN3, NN4, NN5

Choose One
network nodes
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

·
Matthew Gillespie avatar image
1 Like"
Matthew Gillespie answered Matthew Gillespie commented

The key here is to use the getnextnetnode() command. The tricky thing is that this command takes network node ranks as inputs and returns the rank of the next network node between the 2 you specify. So we will also have to use the rankfromnetnodeI() and netnodefromnode() commands to convert back and forth between the rank of the node and the node itself.

Here's the code:

treenode startNode = node("MODEL:/NN1");
treenode endNode = node("MODEL:/NN7");
int start = rankfromnetnode(startNode);
int end = rankfromnetnode(endNode);
int cur = start;

while(cur != end) {
	pt(getname(netnodefromrank(cur))); pr();
	cur = getnextnetnode(cur, end);
}

pt(getname(endNode));
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Matthew Gillespie avatar image Matthew Gillespie ♦♦ commented ·

And make sure you reset the model before running this script so that the network's distance table is up to date.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.