|
Dynamical system model
|
The RoadNetwork class represents a graph in the network. More...
#include <RoadNetwork.hpp>
Public Member Functions | |
| RoadNetwork (AdjacencyMatrix const &adj) | |
| Construct a new RoadNetwork object. | |
| RoadNetwork (const RoadNetwork &)=delete | |
| RoadNetwork & | operator= (const RoadNetwork &)=delete |
| RoadNetwork (RoadNetwork &&)=default | |
| RoadNetwork & | operator= (RoadNetwork &&)=default |
| std::size_t | nCoils () const |
| Get the graph's number of coil streets. | |
| std::size_t | nIntersections () const |
| Get the graph's number of intersections. | |
| std::size_t | nRoundabouts () const |
| Get the graph's number of roundabouts. | |
| std::size_t | nTrafficLights () const |
| Get the graph's number of traffic lights. | |
| void | adjustNodeCapacities () |
| Adjust the nodes' transport capacity. | |
| void | autoInitTrafficLights (double const mainRoadPercentage=0.6) |
| Initialize the traffic lights with random parameters. | |
| void | autoMapStreetLanes () |
| Automatically re-maps street lanes basing on network's topology. | |
| void | autoAssignRoadPriorities () |
| Automatically assigns road priorities at intersections, basing on road types. | |
| void | describe (std::ostream &os=std::cout) const |
| Describe the RoadNetwork. | |
| template<typename... TArgs> | |
| void | importEdges (const std::string &fileName, TArgs &&... args) |
| Import the graph's streets from a file. | |
| template<typename... TArgs> | |
| void | importNodeProperties (const std::string &fileName, TArgs &&... args) |
| Import the graph's nodes properties from a file. | |
| void | importTrafficLights (const std::string &fileName) |
| Import the graph's traffic lights from a file. | |
|
template<typename T1, typename... Tn> requires is_node_v<std::remove_reference_t<T1>> && (is_node_v<std::remove_reference_t<Tn>> && ...) | |
| void | addNodes (T1 &&node, Tn &&... nodes) |
| TrafficLight & | makeTrafficLight (Id const nodeId, Delay const cycleTime, Delay const counter=0) |
| Convert an existing node to a traffic light. | |
| Roundabout & | makeRoundabout (Id nodeId) |
| Convert an existing node into a roundabout. | |
| void | addCoil (Id streetId, std::string const &name=std::string()) |
| Add a coil (dsf::Counter sensor) on the street with streetId. | |
| Station & | makeStation (Id nodeId, const unsigned int managementTime) |
| Convert an existing node into a station. | |
| void | addStreet (Street &&street) |
| Add a street to the graph. | |
|
template<typename T1> requires is_street_v<std::remove_reference_t<T1>> | |
| void | addStreets (T1 &&street) |
|
template<typename T1, typename... Tn> requires is_street_v<std::remove_reference_t<T1>> && (is_street_v<std::remove_reference_t<Tn>> && ...) | |
| void | addStreets (T1 &&street, Tn &&... streets) |
| void | setStreetStatusById (Id const streetId, RoadStatus const status) |
| Set the street's status by its id. | |
| void | setStreetStatusByName (std::string const &name, RoadStatus const status) |
| Set the street's status of all streets with the given name. | |
| void | changeStreetNLanesById (Id const streetId, int const nLanes, std::optional< double > const speedFactor=std::nullopt) |
| Change the street's number of lanes by its id. | |
| void | changeStreetNLanesByName (std::string const &name, int const nLanes, std::optional< double > const speedFactor=std::nullopt) |
| Change the street's number of lanes of all streets with the given name. | |
| void | changeStreetCapacityById (Id const streetId, double const factor) |
| Change the street's capacity by its id. | |
| void | changeStreetCapacityByName (std::string const &name, double const factor) |
| Change the street's capacity of all streets with the given name. | |
| void | setStreetStationaryWeights (std::unordered_map< Id, double > const &streetWeights) |
| Set the streets' stationary weights. | |
| const std::unique_ptr< Street > * | street (Id source, Id destination) const |
| Get a street from the graph. | |
| auto | capacity () const noexcept |
| Get the maximum agent capacity. | |
| template<typename DynamicsFunc> requires (std::is_invocable_r_v<double, DynamicsFunc, std::unique_ptr<Street> const&>) | |
| PathCollection | allPathsTo (Id const targetId, DynamicsFunc getEdgeWeight, double const threshold=1e-9) const |
| Perform a global Dijkstra search to a target node from all other nodes in the graph. | |
| template<typename DynamicsFunc> requires (std::is_invocable_r_v<double, DynamicsFunc, std::unique_ptr<Street> const&>) | |
| PathCollection | shortestPath (Id const sourceId, Id const targetId, DynamicsFunc getEdgeWeight, double const threshold=1e-9) const |
| Find the shortest path between two nodes using Dijkstra's algorithm. | |
Public Member Functions inherited from dsf::Network< RoadJunction, Street > | |
| Network ()=default | |
| Construct a new empty Network object. | |
| Network (AdjacencyMatrix const &adj) | |
| Construct a new Network object. | |
| std::unordered_map< Id, std::unique_ptr< RoadJunction > > const & | nodes () const |
| Get the nodes as an unordered map. | |
| std::unordered_map< Id, std::unique_ptr< Street > > const & | edges () const |
| Get the edges as an unordered map. | |
| size_t | nNodes () const |
| Get the number of nodes. | |
| size_t | nEdges () const |
| Get the number of edges. | |
| void | addNode (TArgs &&... args) |
| Add a node to the network. | |
| void | addNDefaultNodes (size_t n) |
| void | addEdge (TArgs &&... args) |
| Add an edge to the network. | |
| std::unique_ptr< RoadJunction > const & | node (Id nodeId) const |
| Get a node by id. | |
| std::unique_ptr< RoadJunction > & | node (Id nodeId) |
| Get a node by id. | |
| TNode & | node (Id nodeId) |
| Get a node by id. | |
| std::unique_ptr< Street > const & | edge (Id edgeId) const |
| Get an edge by id. | |
| std::unique_ptr< Street > & | edge (Id edgeId) |
| Get an edge by id. | |
| std::unique_ptr< Street > const & | edge (Id source, Id target) const |
| TEdge & | edge (Id edgeId) |
| Get an edge by id. | |
Additional Inherited Members | |
Protected Member Functions inherited from dsf::Network< RoadJunction, Street > | |
| Id | m_cantorHash (Id u, Id v) const |
| Id | m_cantorHash (std::pair< Id, Id > const &idPair) const |
Protected Attributes inherited from dsf::Network< RoadJunction, Street > | |
| std::unordered_map< Id, std::unique_ptr< RoadJunction > > | m_nodes |
| std::unordered_map< Id, std::unique_ptr< Street > > | m_edges |
The RoadNetwork class represents a graph in the network.
| Id,The | type of the graph's id. It must be an unsigned integral type. |
| Size,The | type of the graph's capacity. It must be an unsigned integral type. |
| dsf::mobility::RoadNetwork::RoadNetwork | ( | AdjacencyMatrix const & | adj | ) |
Construct a new RoadNetwork object.
| adj | An adjacency matrix made by a SparseMatrix representing the graph's adjacency matrix |
| void dsf::mobility::RoadNetwork::addCoil | ( | Id | streetId, |
| std::string const & | name = std::string() ) |
Add a coil (dsf::Counter sensor) on the street with streetId.
| streetId | The id of the street to add the coil to |
| name | The coil name |
| std::invalid_argument | if the street does not exist |
| void dsf::mobility::RoadNetwork::addStreet | ( | Street && | street | ) |
Add a street to the graph.
| street | A reference to the street to add |
| void dsf::mobility::RoadNetwork::adjustNodeCapacities | ( | ) |
Adjust the nodes' transport capacity.
The nodes' capacity is adjusted using the graph's streets transport capacity, which may vary basing on the number of lanes. The node capacity will be set to the sum of the incoming streets' transport capacity.
| PathCollection dsf::mobility::RoadNetwork::allPathsTo | ( | Id const | targetId, |
| DynamicsFunc | getEdgeWeight, | ||
| double const | threshold = 1e-9 ) const |
Perform a global Dijkstra search to a target node from all other nodes in the graph.
| DynamicsFunc | A callable type that takes a const reference to a Street and returns a double representing the edge weight |
| targetId | The id of the target node |
| getEdgeWeight | A callable that takes a const reference to a Street and returns a double representing the edge weight |
| threshold | A threshold value to consider alternative paths |
| std::out_of_range | if the target node does not exist |
| void dsf::mobility::RoadNetwork::autoInitTrafficLights | ( | double const | mainRoadPercentage = 0.6 | ) |
Initialize the traffic lights with random parameters.
| mainRoadPercentage | The percentage of main roads for the traffic lights cycles (default is 0.6) |
Traffic Lights with no parameters set are initialized with random parameters. Street priorities are assigned considering the number of lanes and the speed limit. Traffic Lights with an input degree lower than 3 are converted to standard intersections.
| void dsf::mobility::RoadNetwork::autoMapStreetLanes | ( | ) |
Automatically re-maps street lanes basing on network's topology.
For example, if one street has the right turn forbidden, then the right lane becomes a straight one
|
inlinenoexcept |
Get the maximum agent capacity.
| void dsf::mobility::RoadNetwork::changeStreetCapacityById | ( | Id const | streetId, |
| double const | factor ) |
Change the street's capacity by its id.
| streetId | The id of the street |
| factor | The factor to multiply the capacity by |
| void dsf::mobility::RoadNetwork::changeStreetCapacityByName | ( | std::string const & | name, |
| double const | factor ) |
Change the street's capacity of all streets with the given name.
| name | The name to match |
| factor | The factor to multiply the capacity by |
| void dsf::mobility::RoadNetwork::changeStreetNLanesById | ( | Id const | streetId, |
| int const | nLanes, | ||
| std::optional< double > const | speedFactor = std::nullopt ) |
Change the street's number of lanes by its id.
| streetId | The id of the street |
| nLanes | The new number of lanes |
| speedFactor | Optional, The factor to multiply the max speed of the street |
| void dsf::mobility::RoadNetwork::changeStreetNLanesByName | ( | std::string const & | name, |
| int const | nLanes, | ||
| std::optional< double > const | speedFactor = std::nullopt ) |
Change the street's number of lanes of all streets with the given name.
| name | The name to match |
| nLanes | The new number of lanes |
| speedFactor | Optional, The factor to multiply the max speed of the street |
| void dsf::mobility::RoadNetwork::describe | ( | std::ostream & | os = std::cout | ) | const |
Describe the RoadNetwork.
| os | The output stream to write the description to (default is std::cout) |
| void dsf::mobility::RoadNetwork::importEdges | ( | const std::string & | fileName, |
| TArgs &&... | args ) |
Import the graph's streets from a file.
| fileName | The name of the file to import the streets from. |
Supports csv, json and geojson file formats. The file format is deduced from the file extension. Supported fields:
geometry: The geometry of the street, as a LINESTRING
Next columns are optional (meaning that their absence will not -hopefully- cause any pain):
weight parameter of the Edge class. You can use it for the shortest path via dsf::weight_functions::customWeight. | args | Additional arguments |
| void dsf::mobility::RoadNetwork::importNodeProperties | ( | const std::string & | fileName, |
| TArgs &&... | args ) |
Import the graph's nodes properties from a file.
| fileName | The name of the file to import the nodes properties from. |
| args | Additional arguments |
Supports csv file format. Please specify the separator as second parameter. Supported fields:
| void dsf::mobility::RoadNetwork::importTrafficLights | ( | const std::string & | fileName | ) |
Import the graph's traffic lights from a file.
| fileName | The name of the file to import the traffic lights from. |
The file format is csv-like with the ';' separator. Supported columns (in order):
| std::invalid_argument | if the file is not found, invalid or the format is not supported |
| Roundabout & dsf::mobility::RoadNetwork::makeRoundabout | ( | Id | nodeId | ) |
Convert an existing node into a roundabout.
| nodeId | The id of the node to convert to a roundabout |
| std::invalid_argument | if the node does not exist |
| Station & dsf::mobility::RoadNetwork::makeStation | ( | Id | nodeId, |
| const unsigned int | managementTime ) |
Convert an existing node into a station.
| nodeId | The id of the node to convert to a station |
| managementTime | The station's management time |
| std::invalid_argument | if the node does not exist |
| TrafficLight & dsf::mobility::RoadNetwork::makeTrafficLight | ( | Id const | nodeId, |
| Delay const | cycleTime, | ||
| Delay const | counter = 0 ) |
Convert an existing node to a traffic light.
| nodeId | The id of the node to convert to a traffic light |
| cycleTime | The traffic light's cycle time |
| counter | The traffic light's counter initial value. Default is 0 |
| std::invalid_argument | if the node does not exist |
| std::size_t dsf::mobility::RoadNetwork::nCoils | ( | ) | const |
Get the graph's number of coil streets.
| std::size_t dsf::mobility::RoadNetwork::nIntersections | ( | ) | const |
Get the graph's number of intersections.
| std::size_t dsf::mobility::RoadNetwork::nRoundabouts | ( | ) | const |
Get the graph's number of roundabouts.
| std::size_t dsf::mobility::RoadNetwork::nTrafficLights | ( | ) | const |
Get the graph's number of traffic lights.
| void dsf::mobility::RoadNetwork::setStreetStationaryWeights | ( | std::unordered_map< Id, double > const & | streetWeights | ) |
Set the streets' stationary weights.
| streetWeights | A map where the key is the street id and the value is the street stationary weight. If a street id is not present in the map, its stationary weight is set to 1.0. |
| void dsf::mobility::RoadNetwork::setStreetStatusById | ( | Id const | streetId, |
| RoadStatus const | status ) |
Set the street's status by its id.
| streetId | The id of the street |
| status | The status to set |
| void dsf::mobility::RoadNetwork::setStreetStatusByName | ( | std::string const & | name, |
| RoadStatus const | status ) |
Set the street's status of all streets with the given name.
| name | The name to match |
| status | The status to set |
| PathCollection dsf::mobility::RoadNetwork::shortestPath | ( | Id const | sourceId, |
| Id const | targetId, | ||
| DynamicsFunc | getEdgeWeight, | ||
| double const | threshold = 1e-9 ) const |
Find the shortest path between two nodes using Dijkstra's algorithm.
| DynamicsFunc | A callable type that takes a const reference to a Street and returns a double representing the edge weight |
| sourceId | The id of the source node |
| targetId | The id of the target node |
| getEdgeWeight | A callable that takes a const reference to a Street and returns a double representing the edge weight |
| threshold | A threshold value to consider alternative paths |
| std::out_of_range | if the source or target node does not exist |
Uses Dijkstra's algorithm to find shortest paths from source to target. Like allPathsTo, this method tracks all equivalent paths within the threshold, allowing for multiple next hops per node.
| const std::unique_ptr< Street > * dsf::mobility::RoadNetwork::street | ( | Id | source, |
| Id | destination ) const |
Get a street from the graph.
| source | The source node |
| destination | The destination node |