|
<< Click to Display Table of Contents >> Navigation: Using SMILE Wrappers > Networks, nodes and arcs > Nodes > Iterating over nodes |
To iterate over nodes in the network, use Network.get_first_node and Network.get_next_node. Note the loop exit condition: iteration continues only while the returned handle is greater than or equal to zero.
Python
h = net.get_first_node()
while (h >= 0):
# do something with net and node identified by h
h = net.get_next_node(h)
Java
for (int h = net.getFirstNode(); h >= 0; h = net.getNextNode(h)) {
// do something with net and node identified by h
}
C#
for (int h = net.GetFirstNode(); h >= 0; h = net.GetNextNode(h))
{
// do something with net and node identified by h
}
// alternatively, iterate directly via IEnumerable implemented by Network
foreach (int h in net)
{
// do something with net and node identified by h
}
R
h <- net$getFirstNode()
while (h >= 0) {
# do something with net and node identified by h
h <- net$getNextNode(h)
}
The following methods allow you to obtain an array of all node handles, an array of all node identifiers, or the number of nodes in the network:
Python
get_all_nodes() -> List[int]
get_all_node_ids() -> List[str]
get_node_count() -> int
Java
int[] getAllNodes()
String[] getAllNodeIds()
int getNodeCount()
C#
int[] GetAllNodes()
string[] GetAllNodeIds()
int NodeCount { get; }
R
allNodeHandles <- getAllNodes()
allNodeIds <- getAllNodeIds()
nodeCount <- getNodeCount()