Dynamical system model
|
The Graph class represents a graph in the network. More...
#include <Graph.hpp>
Public Member Functions | |
Graph (const SparseMatrix< Id, bool > &adj) | |
Construct a new Graph object. | |
Graph (const std::unordered_map< Id, std::unique_ptr< Street< Id, Size > > > &streetSet) | |
Construct a new Graph object. | |
Graph (const Graph< Id, Size > &other) | |
Graph & | operator= (const Graph< Id, Size > &other) |
Graph (Graph< Id, Size > &&)=default | |
Graph & | operator= (Graph< Id, Size > &&)=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 | 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 | addNode (std::unique_ptr< NodeConcept< Id, Size > > node) |
Add a node to the graph. | |
void | addNode (const Node< Id, Size > &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>) | |
void | makeTrafficLight (Id nodeId) |
Convert an existing node to a traffic light. | |
void | makeRoundabout (Id nodeId) |
Convert an existing node into a roundabout. | |
void | makeSpireStreet (Id streetId) |
Convert an existing street into a spire street. | |
void | addStreet (std::shared_ptr< Street< Id, Size > > street) |
Add a street to the graph. | |
void | addStreet (const Street< Id, Size > &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< Id, bool > & | adjMatrix () const |
Get the graph's adjacency matrix. | |
const std::unordered_map< Id, std::unique_ptr< NodeConcept< Id, Size > > > & | nodeSet () const |
Get the graph's node map. | |
std::unordered_map< Id, std::unique_ptr< NodeConcept< Id, Size > > > & | nodeSet () |
Get the graph's node map. | |
const std::unordered_map< Id, std::unique_ptr< Street< Id, Size > > > & | streetSet () const |
Get the graph's street map. | |
std::unordered_map< Id, std::unique_ptr< Street< Id, Size > > > & | streetSet () |
Get the graph's street map. | |
const std::unique_ptr< Street< Id, Size > > * | street (Id source, Id destination) const |
Get a street from the graph. | |
unsigned long long | maxCapacity () const |
Get the maximum agent capacity. | |
std::optional< DijkstraResult< Id > > | shortestPath (const Node< Id, Size > &source, const Node< Id, Size > &destination) const |
Get the shortest path between two nodes using dijkstra algorithm. | |
std::optional< DijkstraResult< Id > > | 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< Id, Size >::Graph | ( | const SparseMatrix< Id, bool > & | adj | ) |
Construct a new Graph object.
adj | An adjacency matrix made by a SparseMatrix representing the graph's adjacency matrix |
dsm::Graph< Id, Size >::Graph | ( | const std::unordered_map< Id, std::unique_ptr< Street< Id, Size > > > & | streetSet | ) |
Construct a new Graph object.
streetSet | A map of streets representing the graph's streets |
void dsm::Graph< Id, Size >::addNode | ( | const Node< Id, Size > & | node | ) |
Add a node to the graph.
node | A reference to the node to add |
void dsm::Graph< Id, Size >::addNode | ( | std::unique_ptr< NodeConcept< Id, Size > > | node | ) |
Add a node to the graph.
node | A std::shared_ptr to the node to add |
void dsm::Graph< Id, Size >::addStreet | ( | const Street< Id, Size > & | street | ) |
Add a street to the graph.
street | A reference to the street to add |
void dsm::Graph< Id, Size >::addStreet | ( | std::shared_ptr< Street< Id, Size > > | 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< Id, Size >::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< Id, Size >::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. |
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< Id, Size >::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< Id, Size >::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< Id, Size >::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< Id, Size >::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 |
void dsm::Graph< Id, Size >::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::Graph< Id, Size >::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 |
void dsm::Graph< Id, Size >::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.
std::optional< DijkstraResult< Id > > dsm::Graph< Id, Size >::shortestPath | ( | const Node< Id, Size > & | source, |
const Node< Id, Size > & | destination ) const |
Get the shortest path between two nodes using dijkstra algorithm.
source | The source node |
destination | The destination node |
std::optional< DijkstraResult< Id > > dsm::Graph< Id, Size >::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< Id, Size > > * dsm::Graph< Id, Size >::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.