weight_neighborhood¶
Syntax¶
Parameters¶
network- The network to act upon.
source_node_id- The ID of the node in the network from which the weight distances will be calculated.
weight_limit- The maximum amount of weight that can be traversed to include the ID of the node in the network in the returned list.
weight_list- Optional argument. If present, it is set the the distance in weight 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 node IDs whose shortest paths have weights less than or equal
to weight_limit. The nodes are sorted by ascending weight of the their
shortest paths.
The last argument, weight_list, is optional. If present, it must be the name
of a list variable. It is assigned shortest-path weight 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 path
shared list n
shared numeric i
shared numeric path_length
}
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)
path = shortest_path(my_undirected_network, 1, 6)
for(i, range(length(path)-1)) {
path_length = path_length + get_weight(my_undirected_network, path[i], path[i+1])
}
print(length(path), " : ", path, " :: length = ", path_length)
n = weight_neighborhood(my_undirected_network, 7, 4, weights)
print(4, "-neighborhood of ", 7, " : ", n)
print(weights)
n = weight_neighborhood(my_undirected_network, 2, 2, weights)
print(2, "-neighborhood of ", 2, " : ", n)
print(weights)
n = weight_neighborhood(my_undirected_network, 3, 0, weights)
print(0, "-neighborhood of ", 3, " : ", n)
print(weights)
n = weight_neighborhood(my_undirected_network, 4, 20, weights)
print(20, "-neighborhood of ", 4, " : ", n)
print(weights)
}
4 : 1 2 3 6 :: length = 6
4-neighborhood of 7 : 7 6 5 3 2
0 2 2 4 4
2-neighborhood of 2 : 2 5 3 1
0 2 2 2
0-neighborhood of 3 : 3
0
20-neighborhood of 4 : 4 1 2 5 3 7 6
0 2 4 6 6 8 8