|
Dynamical System Framework
|
The RoadNetwork class represents a graph in the network. More...
#include <RoadNetwork.hpp>
Public Member Functions | |
| 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, dsf::Delay const defaultCycleDuration=90) |
| Auto-initialise traffic light phases from street geometry. | |
| 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 traffic light phases from a legacy CSV 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) |
| 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. | |
| template<typename... TArgs> | |
| Street & | addStreet (Id const streetId, std::pair< Id, Id > const nodeIds, TArgs &&... args) |
| Add a street to the graph, creating its missing nodes as intersections. | |
| void | setStreetStatusById (Id const streetId, RoadStatus const status) |
| Set the street's status by its id. | |
| void | setStreetStatusById (std::span< Id const > streetIds, RoadStatus const status) |
| Set the status of several streets by their ids. | |
| 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. | |
| Street const * | street (Id source, Id destination) const |
| Get a street from the graph. | |
| auto | capacity () const noexcept |
| Get the maximum agent capacity. | |
| void | exportTrafficLights (std::string_view const fileName) const |
| void | exportCSV (std::string_view const folder) const |
| Export the graph's edges and nodes to two CSV files in the specified folder. | |
| Public Member Functions inherited from dsf::Network< RoadJunction, Street > | |
| Network ()=default | |
| Construct a new empty Network object. | |
| auto | nodes () const noexcept |
| Get the nodes as a view of (id, pointer to const node) pairs. | |
| auto | edges () const noexcept |
| Get the edges as a view of (id, pointer to const edge) pairs. | |
| auto | nNodes () const noexcept |
| Get the number of nodes. | |
| auto | nEdges () const noexcept |
| Get the number of edges. | |
| void | addNode (TArgs &&... args) |
| void | addNDefaultNodes (std::size_t const n) |
| TEdge & | addEdge (Id const edgeId, std::pair< Id, Id > const nodeIds, TArgs &&... args) |
| Add an edge between two nodes, creating the missing ones. | |
| const auto & | node (Id const nodeId) const |
| Get a node by id. | |
| const auto & | edge (Id const edgeId) const |
| Get an edge by id. | |
| void | computeBetweennessCentralities (EdgeWeight const &weight) |
| Compute node weighted betweenness centralities using Brandes' algorithm. | |
| void | computeEdgeBetweennessCentralities (EdgeWeight const &weight) |
| Compute edge weighted betweenness centralities using Brandes' algorithm. | |
| void | computeEdgeKBetweennessCentralities (EdgeWeight const &weight, std::size_t const K) |
| Compute edge betweenness centralities using Yen's K-shortest paths. | |
Static Public Member Functions | |
| static bool | isTurnAllowed (Street const &from, Street const &to) |
| Check whether an agent travelling a street may turn into another one. | |
Additional Inherited Members | |
| Public Types inherited from dsf::Network< RoadJunction, Street > | |
| using | EdgeWeight |
| An edge cost function. | |
| Protected Member Functions inherited from dsf::Network< RoadJunction, Street > | |
| Street * | m_findEdge (Id const source, Id const target) const |
| Find the edge going from source to target. | |
| TNode & | m_replaceNode (std::unique_ptr< RoadJunction > &pNode, TArgs &&... args) |
| Replace a node with a new object of type TNode, built from the old one. | |
| Static Protected Member Functions inherited from dsf::Network< RoadJunction, Street > | |
| static constexpr auto | m_cantorHash (Id u, Id v) noexcept |
| static auto | m_inEdges (RoadJunction const &node) noexcept |
| static auto | m_outEdges (RoadJunction const &node) noexcept |
| static RoadJunction * | m_targetOf (Street const &edge) noexcept |
| 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.
| 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 |
| Street & dsf::mobility::RoadNetwork::addStreet | ( | Id const | streetId, |
| std::pair< Id, Id > const | nodeIds, | ||
| TArgs &&... | args ) |
Add a street to the graph, creating its missing nodes as intersections.
| streetId | The street's id |
| nodeIds | The ids of the street's (source, target) nodes |
| args | The other arguments of Street's constructor (length, max speed, ...) |
| std::invalid_argument | if a street with the same id already exists |
| void dsf::mobility::RoadNetwork::adjustNodeCapacities | ( | ) |
Adjust the nodes' transport capacity.
Each street contributes its number of lanes times its transport capacity, i.e. the agents per time step it can deliver.
| void dsf::mobility::RoadNetwork::autoInitTrafficLights | ( | double const | mainRoadPercentage = 0.6, |
| dsf::Delay const | defaultCycleDuration = 90 ) |
Auto-initialise traffic light phases from street geometry.
| mainRoadPercentage | Fraction of the cycle time allocated to priority streets (default 0.6). |
| defaultCycleDuration | The default cycle duration in ticks (default 90). |
| std::invalid_argument | If mainRoadPercentage is not in the range (0, 1). |
For each TrafficLight node that has no phases yet:
| 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::exportCSV | ( | std::string_view const | folder | ) | const |
Export the graph's edges and nodes to two CSV files in the specified folder.
| folder | The folder to export the files to |
| 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):
| 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 traffic light phases from a legacy CSV file.
| fileName | The path to the CSV file. |
The file uses ';' as separator. Expected columns (in order):
The importer reconstructs a two-phase TrafficLight from each node's entries:
All streets are added with Direction::ANY. Use the JSON config block under road_network.traffic_lights for direction-level control.
| std::runtime_error | if the file cannot be opened. |
|
inlinestatic |
Check whether an agent travelling a street may turn into another one.
| from | The street the agent is travelling |
| to | An outgoing street of the target node of from |
The status of the two streets is not checked, but closed streets are not legal alternatives to a U-turn
| 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 | ) |
Convert an existing node to a traffic light.
| nodeId | The id of the node to convert. |
| 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::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::setStreetStatusById | ( | std::span< Id const > | streetIds, |
| RoadStatus const | status ) |
Set the status of several streets by their ids.
| streetIds | The ids of the streets |
| status | The status to set |
| std::out_of_range | if an id is not found, in which case no status is changed |
During a run, agents plan again (from the street they are on) when they find their next street closed, including those already queued at its end. Agents already inside a node, or on the closed street, still enter or finish it
| 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 |
| Street const * dsf::mobility::RoadNetwork::street | ( | Id | source, |
| Id | destination ) const |
Get a street from the graph.
| source | The source node |
| destination | The destination node |