starling_sim.basemodel.topology.topology
Module Contents
Classes
This abstract class describes a network of the simulation. |
Attributes
- starling_sim.basemodel.topology.topology.NETWORK_WEIGHT_CLASSES
- class starling_sim.basemodel.topology.topology.Topology(transport_mode, weight_class=None, store_paths=False)
Bases:
abc.ABC
This abstract class describes a network of the simulation.
Networks are stored as NetworkX graphs.
- TIME_ATTRIBUTE = 'time'
- LENGTH_ATTRIBUTE = 'length'
- init_weight(weight_class)
Initialise the weight class.
- Parameters:
weight_class – weight class key
- setup()
Prepare the topology for the simulation run.
Initialise the network graph, set relevant attributes and compute weight values for path evaluation.
- abstract init_graph()
Initialise the network graph from any data source.
- abstract add_time_and_length(u, v, d)
Set the TIME_ATTRIBUTE and LENGTH_ATTRIBUTE attributes on the graph edge.
- Parameters:
u – edge origin
v – edge destination
d – edge data
- compute_weights(u, v, d)
For each edge, set a value for each weight hash.
- Parameters:
u –
v –
d –
- shortest_path_length(origin, destination, parameters)
- dijkstra_shortest_path_and_length(origin, destination, parameters, return_weight=False)
Find the path from origin to destination with minimum the total weight.
Get the hash corresponding to the parameters and call Dijkstra’s algorithm on the corresponding weight values.
Raises an exception if origin or destination is None, instead of computing all shortest path (which is what NetworkX would do)
- Parameters:
origin – origin position
destination – destination position
parameters – parameters defining the utility
return_weight – also return the total weight
- Returns:
path (list of positions), duration, length
- compute_dijkstra_path(origin, destination, weight)
- evaluate_path_duration_and_length(path)
- get_positions()
Return the list of all topology positions
- Returns:
list of positions
- get_edge_data(node1, node2, data)
Return the corresponding edge information
- Parameters:
node1 – node of the topology
node2 – node of the topology
data – requested attribute
- Returns:
data information of the edge
- abstract position_localisation(position)
Return the localisation [lat, lon] of the position
- Parameters:
position – position in the topology
- Returns:
list [lat, lon]
- abstract nearest_position(localisation)
Return the nearest position to given localisation (lat, lon)
- Parameters:
localisation – (lat, lon) tuple
- Returns:
position
- abstract localisations_nearest_nodes(x_coordinates, y_coordinates, return_dist=False)
Return the graph nodes nearest to a list of points.
This method should allow a faster computation than multiple nearest_position calls.
- Parameters:
x_coordinates – list of X coordinates of the localisations (lon in GPS)
y_coordinates – list of Y coordinates of the localisations (lat in GPS)
return_dist – optionally also return distance between points and nearest nodes
- Returns:
list of nearest nodes