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 std::unordered_map< Id, std::unique_ptr< Street > > &streetSet) | |
Construct a new RoadNetwork object. | |
RoadNetwork (const RoadNetwork &other) | |
RoadNetwork & | operator= (const RoadNetwork &other) |
RoadNetwork (RoadNetwork &&)=default | |
RoadNetwork & | operator= (RoadNetwork &&)=default |
void | buildAdj () |
Build the graph's adjacency matrix and computes max capacity. | |
void | adjustNodeCapacities () |
Adjust the nodes' transport capacity. | |
void | importMatrix (const std::string &fileName, bool isAdj=true, double defaultSpeed=13.8888888889) |
Import the graph's adjacency matrix from a file. If the file is not of a supported format, it will read the file as a matrix with the first two elements being the number of rows and columns and the following elements being the matrix elements. | |
void | importCoordinates (const std::string &fileName) |
Import the graph's nodes from a file. | |
void | importOSMNodes (const std::string &fileName) |
Import the graph's nodes from a file. | |
void | importOSMEdges (const std::string &fileName) |
Import the graph's streets from a file. | |
void | exportNodes (const std::string &fileName) |
Export the graph's nodes to a csv-like file separated with ';'. | |
void | exportEdges (const std::string &fileName) |
Export the graph's edges to a csv-like file separated with ';'. | |
void | exportMatrix (std::string path="./matrix.dsm", bool isAdj=true) |
Export the graph's adjacency matrix to 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. | |
StochasticStreet & | makeStochasticStreet (Id streetId, double const flowRate) |
void | makeSpireStreet (Id streetId) |
Convert an existing street into a spire street. | |
Station & | makeStation (Id nodeId, const unsigned int managementTime) |
Convert an existing node into a station. | |
void | addStreet (const 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) |
const std::unique_ptr< Street > * | street (Id source, Id destination) const |
Get a street from the graph. | |
const std::unique_ptr< Street > * | oppositeStreet (Id streetId) const |
Get the opposite street of a street in the graph. | |
unsigned long long | maxCapacity () const |
Get the maximum agent capacity. | |
std::vector< Id > const & | inputNodes () const |
Get the input nodes of the graph. | |
std::vector< Id > & | inputNodes () |
Get the input nodes of the graph. | |
std::vector< Id > const & | outputNodes () const |
Get the output nodes of the graph. | |
std::vector< Id > & | outputNodes () |
Get the output nodes of the graph. | |
template<typename Func = std::function<double(const RoadNetwork*, Id, Id)>> requires ( std::is_same_v<std::invoke_result_t<Func, const RoadNetwork*, Id, Id>, double>) | |
std::optional< DijkstraResult > | shortestPath (const Node &source, const Node &destination, Func f=weight_functions::streetLength) const |
Get the shortest path between two nodes using dijkstra algorithm. | |
template<typename Func = std::function<double(const RoadNetwork*, Id, Id)>> requires ( std::is_same_v<std::invoke_result_t<Func, const RoadNetwork*, Id, Id>, double>) | |
std::optional< DijkstraResult > | shortestPath (Id source, Id destination, Func f=weight_functions::streetLength) const |
Get the shortest path between two nodes using dijkstra algorithm. | |
![]() | |
Network (AdjacencyMatrix const &adj) | |
Construct a new Network object. | |
AdjacencyMatrix const & | adjacencyMatrix () const |
Get the adjacency matrix. | |
std::unordered_map< Id, std::unique_ptr< Node > > 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 (Id nodeId, TArgs &&... args) |
Add a node to the network. | |
void | addEdge (Id edgeId, TArgs &&... args) |
Add an edge to the network. | |
std::unique_ptr< Node > const & | node (Id nodeId) const |
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. | |
TEdge & | edge (Id edgeId) |
Get an edge by id. | |
Additional Inherited Members | |
![]() | |
AdjacencyMatrix | m_adjacencyMatrix |
std::unordered_map< Id, std::unique_ptr< Node > > | 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. |
dsm::RoadNetwork::RoadNetwork | ( | AdjacencyMatrix const & | adj | ) |
Construct a new RoadNetwork object.
adj | An adjacency matrix made by a SparseMatrix representing the graph's adjacency matrix |
dsm::RoadNetwork::RoadNetwork | ( | const std::unordered_map< Id, std::unique_ptr< Street > > & | streetSet | ) |
Construct a new RoadNetwork object.
streetSet | A map of streets representing the graph's streets |
void dsm::RoadNetwork::addStreet | ( | const Street & | street | ) |
Add a street to the graph.
street | A reference to the street to add |
void dsm::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.
void dsm::RoadNetwork::buildAdj | ( | ) |
Build the graph's adjacency matrix and computes max capacity.
The adjacency matrix is built using the graph's streets and nodes. N.B.: The street ids are reassigned using the max node id, i.e. newStreetId = srcId * n + dstId, where n is the max node id. Moreover, street angles and geometries are set using the nodes' coordinates.
void dsm::RoadNetwork::exportEdges | ( | const std::string & | fileName | ) |
Export the graph's edges to a csv-like file separated with ';'.
path | The path to the file to export the edges to |
The file format is csv-like, with the first line being the column names: id;source_id;target_id;name;geometry
void dsm::RoadNetwork::exportMatrix | ( | std::string | path = "./matrix.dsm", |
bool | isAdj = true ) |
Export the graph's adjacency matrix to a file.
path | The path to the file to export the adjacency matrix to (default: ./matrix.dsm) |
isAdj | A boolean value indicating if the file contains the adjacency matrix or the distance matrix. |
std::invalid_argument | if the file is not found or invalid |
void dsm::RoadNetwork::exportNodes | ( | const std::string & | fileName | ) |
Export the graph's nodes to a csv-like file separated with ';'.
path | The path to the file to export the nodes to |
The file format is csv-like, with the first line being the column names: id;lon;lat
void dsm::RoadNetwork::importCoordinates | ( | const std::string & | fileName | ) |
Import the graph's nodes from a file.
fileName | The name of the file to import the nodes from. |
std::invalid_argument | if the file is not found, invalid or the format is not supported |
The file format is deduced from the file extension. Currently only .dsm files are supported. The first input number is the number of nodes, followed by the coordinates of each node. In the i-th row of the file, the (i - 1)-th node's coordinates are expected.
void dsm::RoadNetwork::importMatrix | ( | const std::string & | fileName, |
bool | isAdj = true, | ||
double | defaultSpeed = 13.8888888889 ) |
Import the graph's adjacency matrix from a file. If the file is not of a supported format, it will read the file as a matrix with the first two elements being the number of rows and columns and the following elements being the matrix elements.
fileName | The name of the file to import the adjacency matrix from. |
isAdj | A boolean value indicating if the file contains the adjacency matrix or the distance matrix. |
defaultSpeed | The default speed limit for the streets |
std::invalid_argument | if the file is not found or invalid The matrix format is deduced from the file extension. Currently only .dsm files are supported. |
void dsm::RoadNetwork::importOSMEdges | ( | const std::string & | fileName | ) |
Import the graph's streets from a file.
fileName | The name of the file to import the streets from. |
std::invalid_argument | if the file is not found, invalid or the format is not supported |
void dsm::RoadNetwork::importOSMNodes | ( | const std::string & | fileName | ) |
Import the graph's nodes from a file.
fileName | The name of the file to import the nodes from. |
std::invalid_argument | if the file is not found, invalid or the format is not supported |
|
inline |
Get the input nodes of the graph.
|
inline |
Get the input nodes of the graph.
Roundabout & dsm::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 |
void dsm::RoadNetwork::makeSpireStreet | ( | Id | streetId | ) |
Convert an existing street into a spire street.
streetId | The id of the street to convert to a spire street |
std::invalid_argument | if the street does not exist |
Station & dsm::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 & dsm::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 |
|
inline |
Get the maximum agent capacity.
const std::unique_ptr< Street > * dsm::RoadNetwork::oppositeStreet | ( | Id | streetId | ) | const |
Get the opposite street of a street in the graph.
streetId | The id of the street |
std::invalid_argument | if the street does not exist |
|
inline |
Get the output nodes of the graph.
|
inline |
Get the output nodes of the graph.
std::optional< DijkstraResult > dsm::RoadNetwork::shortestPath | ( | const Node & | source, |
const Node & | destination, | ||
Func | f = weight_functions::streetLength ) const |
Get the shortest path between two nodes using dijkstra algorithm.
source | The source node |
destination | The destination node |
std::optional< DijkstraResult > dsm::RoadNetwork::shortestPath | ( | Id | source, |
Id | destination, | ||
Func | f = weight_functions::streetLength ) const |
Get the shortest path between two nodes using dijkstra algorithm.
source | The source node id |
destination | The destination node id |
const std::unique_ptr< Street > * dsm::RoadNetwork::street | ( | Id | source, |
Id | destination ) const |
Get a street from the graph.
source | The source node |
destination | The destination node |