Dynamical system model
Loading...
Searching...
No Matches
dsm::RoadNetwork Class Reference

The RoadNetwork class represents a graph in the network. More...

#include <RoadNetwork.hpp>

Inheritance diagram for dsm::RoadNetwork:
dsm::Network< Node, Street >

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)
 
RoadNetworkoperator= (const RoadNetwork &other)
 
 RoadNetwork (RoadNetwork &&)=default
 
RoadNetworkoperator= (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)
 
TrafficLightmakeTrafficLight (Id const nodeId, Delay const cycleTime, Delay const counter=0)
 Convert an existing node to a traffic light.
 
RoundaboutmakeRoundabout (Id nodeId)
 Convert an existing node into a roundabout.
 
StochasticStreetmakeStochasticStreet (Id streetId, double const flowRate)
 
void makeSpireStreet (Id streetId)
 Convert an existing street into a spire street.
 
StationmakeStation (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.
 
- Public Member Functions inherited from dsm::Network< Node, Street >
 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

- Protected Attributes inherited from dsm::Network< Node, Street >
AdjacencyMatrix m_adjacencyMatrix
 
std::unordered_map< Id, std::unique_ptr< Node > > m_nodes
 
std::unordered_map< Id, std::unique_ptr< Street > > m_edges
 

Detailed Description

The RoadNetwork class represents a graph in the network.

Template Parameters
Id,Thetype of the graph's id. It must be an unsigned integral type.
Size,Thetype of the graph's capacity. It must be an unsigned integral type.

Constructor & Destructor Documentation

◆ RoadNetwork() [1/2]

dsm::RoadNetwork::RoadNetwork ( AdjacencyMatrix const & adj)

Construct a new RoadNetwork object.

Parameters
adjAn adjacency matrix made by a SparseMatrix representing the graph's adjacency matrix

◆ RoadNetwork() [2/2]

dsm::RoadNetwork::RoadNetwork ( const std::unordered_map< Id, std::unique_ptr< Street > > & streetSet)

Construct a new RoadNetwork object.

Parameters
streetSetA map of streets representing the graph's streets

Member Function Documentation

◆ addStreet()

void dsm::RoadNetwork::addStreet ( const Street & street)

Add a street to the graph.

Parameters
streetA reference to the street to add

◆ adjustNodeCapacities()

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.

◆ buildAdj()

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.

◆ exportEdges()

void dsm::RoadNetwork::exportEdges ( const std::string & fileName)

Export the graph's edges to a csv-like file separated with ';'.

Parameters
pathThe 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

◆ exportMatrix()

void dsm::RoadNetwork::exportMatrix ( std::string path = "./matrix.dsm",
bool isAdj = true )

Export the graph's adjacency matrix to a file.

Parameters
pathThe path to the file to export the adjacency matrix to (default: ./matrix.dsm)
isAdjA boolean value indicating if the file contains the adjacency matrix or the distance matrix.
Exceptions
std::invalid_argumentif the file is not found or invalid

◆ exportNodes()

void dsm::RoadNetwork::exportNodes ( const std::string & fileName)

Export the graph's nodes to a csv-like file separated with ';'.

Parameters
pathThe 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

◆ importCoordinates()

void dsm::RoadNetwork::importCoordinates ( const std::string & fileName)

Import the graph's nodes from a file.

Parameters
fileNameThe name of the file to import the nodes from.
Exceptions
std::invalid_argumentif 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.

◆ importMatrix()

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.

Parameters
fileNameThe name of the file to import the adjacency matrix from.
isAdjA boolean value indicating if the file contains the adjacency matrix or the distance matrix.
defaultSpeedThe default speed limit for the streets
Exceptions
std::invalid_argumentif the file is not found or invalid The matrix format is deduced from the file extension. Currently only .dsm files are supported.

◆ importOSMEdges()

void dsm::RoadNetwork::importOSMEdges ( const std::string & fileName)

Import the graph's streets from a file.

Parameters
fileNameThe name of the file to import the streets from.
Exceptions
std::invalid_argumentif the file is not found, invalid or the format is not supported

◆ importOSMNodes()

void dsm::RoadNetwork::importOSMNodes ( const std::string & fileName)

Import the graph's nodes from a file.

Parameters
fileNameThe name of the file to import the nodes from.
Exceptions
std::invalid_argumentif the file is not found, invalid or the format is not supported

◆ inputNodes() [1/2]

std::vector< Id > & dsm::RoadNetwork::inputNodes ( )
inline

Get the input nodes of the graph.

Returns
std::vector<Id>& The input nodes of the graph

◆ inputNodes() [2/2]

std::vector< Id > const & dsm::RoadNetwork::inputNodes ( ) const
inline

Get the input nodes of the graph.

Returns
std::vector<Id> const& The input nodes of the graph

◆ makeRoundabout()

Roundabout & dsm::RoadNetwork::makeRoundabout ( Id nodeId)

Convert an existing node into a roundabout.

Parameters
nodeIdThe id of the node to convert to a roundabout
Returns
A reference to the roundabout
Exceptions
std::invalid_argumentif the node does not exist

◆ makeSpireStreet()

void dsm::RoadNetwork::makeSpireStreet ( Id streetId)

Convert an existing street into a spire street.

Parameters
streetIdThe id of the street to convert to a spire street
Exceptions
std::invalid_argumentif the street does not exist

◆ makeStation()

Station & dsm::RoadNetwork::makeStation ( Id nodeId,
const unsigned int managementTime )

Convert an existing node into a station.

Parameters
nodeIdThe id of the node to convert to a station
managementTimeThe station's management time
Returns
A reference to the station
Exceptions
std::invalid_argumentif the node does not exist

◆ makeTrafficLight()

TrafficLight & dsm::RoadNetwork::makeTrafficLight ( Id const nodeId,
Delay const cycleTime,
Delay const counter = 0 )

Convert an existing node to a traffic light.

Parameters
nodeIdThe id of the node to convert to a traffic light
cycleTimeThe traffic light's cycle time
counterThe traffic light's counter initial value. Default is 0
Returns
A reference to the traffic light
Exceptions
std::invalid_argumentif the node does not exist

◆ maxCapacity()

unsigned long long dsm::RoadNetwork::maxCapacity ( ) const
inline

Get the maximum agent capacity.

Returns
unsigned long long The maximum agent capacity of the graph

◆ oppositeStreet()

const std::unique_ptr< Street > * dsm::RoadNetwork::oppositeStreet ( Id streetId) const

Get the opposite street of a street in the graph.

Parameters
streetIdThe id of the street
Exceptions
std::invalid_argumentif the street does not exist
Returns
A std::unique_ptr to the street if it exists, nullptr otherwise

◆ outputNodes() [1/2]

std::vector< Id > & dsm::RoadNetwork::outputNodes ( )
inline

Get the output nodes of the graph.

Returns
std::vector<Id>& The output nodes of the graph

◆ outputNodes() [2/2]

std::vector< Id > const & dsm::RoadNetwork::outputNodes ( ) const
inline

Get the output nodes of the graph.

Returns
std::vector<Id> const& The output nodes of the graph

◆ shortestPath() [1/2]

template<typename Func>
requires ( std::is_same_v<std::invoke_result_t<Func, const RoadNetwork*, Id, Id>, double>)
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.

Parameters
sourceThe source node
destinationThe destination node
Returns
A DijkstraResult object containing the path and the distance

◆ shortestPath() [2/2]

template<typename Func>
requires ( std::is_same_v<std::invoke_result_t<Func, const RoadNetwork*, Id, Id>, double>)
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.

Parameters
sourceThe source node id
destinationThe destination node id
Returns
A DijkstraResult object containing the path and the distance

◆ street()

const std::unique_ptr< Street > * dsm::RoadNetwork::street ( Id source,
Id destination ) const

Get a street from the graph.

Parameters
sourceThe source node
destinationThe destination node
Returns
A std::unique_ptr to the street if it exists, nullptr otherwise

The documentation for this class was generated from the following file: