Dynamical system model
|
The Graph class represents a graph in the network. More...
#include <Graph.hpp>
Public Member Functions | |
Graph (const SparseMatrix< bool > &adj) | |
Construct a new Graph object. | |
Graph (const std::unordered_map< Id, std::unique_ptr< Street > > &streetSet) | |
Construct a new Graph object. | |
Graph (const Graph &other) | |
Graph & | operator= (const Graph &other) |
Graph (Graph &&)=default | |
Graph & | operator= (Graph &&)=default |
void | buildAdj () |
Build the graph's adjacency matrix and computes max capacity. | |
void | buildStreetAngles () |
Build the graph's street angles using the node's coordinates. | |
void | adjustNodeCapacities () |
Adjust the nodes' transport capacity. | |
void | normalizeStreetCapacities (double meanVehicleLength=5.) |
Normalize the streets' capacities. | |
void | importMatrix (const std::string &fileName, bool isAdj=true) |
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 | exportMatrix (std::string path="./matrix.dsm", bool isAdj=true) |
Export the graph's adjacency matrix to a file. | |
void | exportCoordinates (std::string const &path="./coordinates.csv") |
Export the nodes' coordinates to a file. | |
void | addNode (std::unique_ptr< Node > node) |
Add a node to the graph. | |
void | addNode (const Intersection &node) |
Add a node to the graph. | |
template<typename... Tn> requires (is_node_v<std::remove_reference_t<Tn>> && ...) | |
void | addNodes (Tn &&... nodes) |
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) |
template<typename Delay > requires (std::unsigned_integral<Delay>) | |
TrafficLight< Delay > & | makeTrafficLight (Id nodeId) |
Convert an existing node to a traffic light. | |
Roundabout & | makeRoundabout (Id nodeId) |
Convert an existing node into a roundabout. | |
SpireStreet & | makeSpireStreet (Id streetId) |
Convert an existing street into a spire street. | |
void | addStreet (std::shared_ptr< Street > street) |
Add a street to the graph. | |
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 SparseMatrix< bool > & | adjMatrix () const |
Get the graph's adjacency matrix. | |
const std::unordered_map< Id, std::unique_ptr< Node > > & | nodeSet () const |
Get the graph's node map. | |
std::unordered_map< Id, std::unique_ptr< Node > > & | nodeSet () |
Get the graph's node map. | |
const std::unordered_map< Id, std::unique_ptr< Street > > & | streetSet () const |
Get the graph's street map. | |
std::unordered_map< Id, std::unique_ptr< Street > > & | streetSet () |
Get the graph's street map. | |
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::optional< DijkstraResult > | shortestPath (const Intersection &source, const Intersection &destination) const |
Get the shortest path between two nodes using dijkstra algorithm. | |
std::optional< DijkstraResult > | shortestPath (Id source, Id destination) const |
Get the shortest path between two nodes using dijkstra algorithm. | |
The Graph 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::Graph::Graph | ( | const SparseMatrix< bool > & | adj | ) |
Construct a new Graph object.
adj | An adjacency matrix made by a SparseMatrix representing the graph's adjacency matrix |
dsm::Graph::Graph | ( | const std::unordered_map< Id, std::unique_ptr< Street > > & | streetSet | ) |
Construct a new Graph object.
streetSet | A map of streets representing the graph's streets |
void dsm::Graph::addNode | ( | const Intersection & | node | ) |
Add a node to the graph.
node | A reference to the node to add |
void dsm::Graph::addNode | ( | std::unique_ptr< Node > | node | ) |
Add a node to the graph.
node | A std::unique_ptr to the node to add |
void dsm::Graph::addStreet | ( | const Street & | street | ) |
Add a street to the graph.
street | A reference to the street to add |
void dsm::Graph::addStreet | ( | std::shared_ptr< Street > | street | ) |
Add a street to the graph.
street | A std::shared_ptr to the street to add |
|
inline |
Get the graph's adjacency matrix.
void dsm::Graph::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::Graph::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.
void dsm::Graph::exportCoordinates | ( | std::string const & | path = "./coordinates.csv" | ) |
Export the nodes' coordinates to a file.
path | The path to the file to export the nodes' coordinates to (default: ./nodes.dsm) |
void dsm::Graph::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::Graph::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::Graph::importMatrix | ( | const std::string & | fileName, |
bool | isAdj = true ) |
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. |
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::Graph::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::Graph::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 |
Roundabout & dsm::Graph::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 |
SpireStreet & dsm::Graph::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 |
TrafficLight< Delay > & dsm::Graph::makeTrafficLight | ( | Id | nodeId | ) |
Convert an existing node to a traffic light.
Delay | The type of the traffic light's delay |
nodeId | The id of the node to convert to a traffic light |
std::invalid_argument | if the node does not exist |
|
inline |
Get the maximum agent capacity.
|
inline |
Get the graph's node map.
|
inline |
Get the graph's node map.
void dsm::Graph::normalizeStreetCapacities | ( | double | meanVehicleLength = 5. | ) |
Normalize the streets' capacities.
meanVehicleLength | The mean vehicle length |
The streets' capacities are normalized using the mean vehicle length following the formula:
const std::unique_ptr< Street > * dsm::Graph::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 |
std::optional< DijkstraResult > dsm::Graph::shortestPath | ( | const Intersection & | source, |
const Intersection & | destination ) const |
Get the shortest path between two nodes using dijkstra algorithm.
source | The source node |
destination | The destination node |
std::optional< DijkstraResult > dsm::Graph::shortestPath | ( | Id | source, |
Id | destination ) 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::Graph::street | ( | Id | source, |
Id | destination ) const |
Get a street from the graph.
source | The source node |
destination | The destination node |
|
inline |
Get the graph's street map.
|
inline |
Get the graph's street map.