edge_neighborhood¶
Syntax¶
edge_neighborhood(network, source_node_id, edge_limit)
edge_neighborhood(network, source_node_id, edge_limit, edge_list)
Parameters¶
network- The network to act upon.
source_node_id- The ID of the node in the network from which the edge distances will be calculated.
edge_limit- The maximum number of edges in the network that can be traversed to include a node's ID the returned list.
edge_list- Optional argument. If present, it is set the the distance in number of edges for each corresponding node ID in the list that this action returns.
Returns¶
Returns a list of node IDs that meet the criteria defined above.
Description¶
Returns a list of nodes whose shortest edge-paths have no more than
edge_limit edges in the network parameter. The nodes are sorted by ascending
edge-lengths of the their shortest edge-paths.
The last argument, edge_list is optional. If present it must be the name of a
shared or agent list variable. It is assigned shortest-path edge distance
values corresponding to each index in the returned list of nodes.
Examples¶
simulation {
locations = none
default_model = none
start_date = 2020-Jan-01
end_date = 2020-Jan-02
}
variables {
shared list weights
shared list n
}
network my_undirected_network {
is_directed = 0
}
startup {
add_edge(my_undirected_network, 1, 2)
add_edge(my_undirected_network, 2, 3)
add_edge(my_undirected_network, 1, 4)
add_edge(my_undirected_network, 2, 5)
add_edge(my_undirected_network, 3, 6)
add_edge(my_undirected_network, 5, 7)
add_edge(my_undirected_network, 7, 6)
set_weight(my_undirected_network, 1, 2, 2.0)
set_weight(my_undirected_network, 2, 3, 2.0)
set_weight(my_undirected_network, 1, 4, 2.0)
set_weight(my_undirected_network, 2, 5, 2.0)
set_weight(my_undirected_network, 3, 6, 2.0)
set_weight(my_undirected_network, 5, 7, 2.0)
set_weight(my_undirected_network, 7, 6, 2.0)
# 4th argument is optional
n = edge_neighborhood(my_undirected_network, 7, 2)
print(2, "-edge-neighborhood of ", 7, " : ", n)
n = edge_neighborhood(my_undirected_network, 7, 2, weights)
print(2, "-edge-neighborhood of ", 7, " : ", n)
print(weights)
n = edge_neighborhood(my_undirected_network, 2, 1, weights)
print(1, "-edge-neighborhood of ", 2, " : ", n)
print(weights)
n = edge_neighborhood(my_undirected_network, 3, 0, weights)
print(0, "-edge-neighborhood of ", 3, " : ", n)
print(weights)
n = edge_neighborhood(my_undirected_network, 4, 10, weights)
print(10, "-edge-neighborhood of ", 4, " : ", n)
print(weights)
}
2-edge-neighborhood of 7 : 7 5 6 2 3
2-edge-neighborhood of 7 : 7 5 6 2 3
0 1 1 2 2
1-edge-neighborhood of 2 : 2 1 3 5
0 1 1 1
0-edge-neighborhood of 3 : 3
0
10-edge-neighborhood of 4 : 4 1 2 3 5 6 7
0 1 2 3 3 4 4