uxsim.Utilities.Utilities¶
Submodule for general utilities. This contains functions that are not essential for simulation but useful to specific analysis.
Functions
|
Enumerate the k shortest routes between two nodes in a network. |
|
Enumerate the k shortest routes between two nodes in a network. |
|
Generate a grid network with imax x jmax nodes. |
- uxsim.Utilities.Utilities.enumerate_k_shortest_routes(W, source, target, k=1, cost_function=<function <lambda>>, print_stats=0, return_cost=False)[source]¶
Enumerate the k shortest routes between two nodes in a network. By default, enumerate_k_shortest_routes(W, “O”, “D”) returns the shortest path from node “O” to “D” based on the free-flow travel time.
- Parameters:
W (World) – The world object containing the network.
source (str | Node) – The source node.
target (str | Node) – The target node.
k (int) – The number of shortest routes to enumerate. Default is 1.
cost_function (function) – A link cost function to compute shortest path. The argument is Link object. Default is the free-flow travel time, lambda l: l.length/l.u.
print_stats (bool) – Print the statistics of the paths.
return_cost (bool) – Return the cost of the paths.
- Returns:
routes (list) – A list of k shortest routes. Each route is a list of link names.
costs (list) – A list of costs of the routes if return_cost is True.
- uxsim.Utilities.Utilities.enumerate_k_shortest_routes_on_t(W, source, target, t, k=1, cost_function=<function <lambda>>, print_stats=0, return_cost=False)[source]¶
Enumerate the k shortest routes between two nodes in a network. By default, enumerate_k_shortest_routes_on_t(W, “O”, “D”, t=t) returns the shortest path from node “O” to “D” based on instantanious travel time on time t.
- Parameters:
W (World) – The world object containing the network.
source (str | Node) – The source node.
target (str | Node) – The target node.
t (float) – The time point to compute shortest routes.
k (int) – The number of shortest routes to enumerate. Default is 1.
cost_function (function) – A link cost function to compute shortest path. The argument is Link object and time t. Default is the instantaneous travel time, lambda l, t: l.instant_travel_time(t).
print_stats (bool) – Print the statistics of the paths.
return_cost (bool) – Return the cost of the paths.
- Returns:
routes (list) – A list of k shortest routes. Each route is a list of link names.
costs (list) – A list of costs of the routes if return_cost is True.
- uxsim.Utilities.Utilities.generate_grid_network(W, imax, jmax, **kwargs)[source]¶
Generate a grid network with imax x jmax nodes.
- Parameters:
W (World) – The world object to which the network will be added.
imax (int) – The number of nodes in the x direction.
jmax (int) – The number of nodes in the y direction.
**kwargs (dict) – Additional keyword arguments to be passed to the addLink function.