Dynamical system model
|
The Dynamics class represents the dynamics of the network. More...
#include <Dynamics.hpp>
Public Member Functions | |
Dynamics (Graph &graph, bool useCache=false, std::optional< unsigned int > seed=std::nullopt) | |
Construct a new Dynamics object. | |
virtual void | setAgentSpeed (Size agentId)=0 |
virtual void | evolve (bool reinsert_agents=false)=0 |
virtual void | updatePaths () |
Update the paths of the itineraries based on the actual travel times. | |
void | setDestinationNodes (const std::span< Id > &destinationNodes, bool updatePaths=true) |
Set the dynamics destination nodes auto-generating itineraries. | |
void | addAgent (std::unique_ptr< agent_t > agent) |
Add an agent to the simulation. | |
template<typename... TArgs> requires (std::is_constructible_v<agent_t, TArgs...>) | |
void | addAgent (TArgs &&... args) |
template<typename... TArgs> requires (std::is_constructible_v<agent_t, Id, TArgs...>) | |
void | addAgents (Size nAgents, TArgs &&... args) |
template<typename... Tn> requires (is_agent_v<Tn> && ...) | |
void | addAgents (Tn... agents) |
Add a pack of agents to the simulation. | |
template<typename T1, typename... Tn> requires (is_agent_v<T1> && (is_agent_v<Tn> && ...)) | |
void | addAgents (T1 agent, Tn... agents) |
Add a pack of agents to the simulation. | |
void | addAgents (std::span< agent_t > agents) |
Add a set of agents to the simulation. | |
void | removeAgent (Size agentId) |
Remove an agent from the simulation. | |
template<typename T1, typename... Tn> requires (std::is_convertible_v<T1, Id> && (std::is_convertible_v<Tn, Size> && ...)) | |
void | removeAgents (T1 id, Tn... ids) |
void | addItinerary (const Itinerary &itinerary) |
Add an itinerary. | |
void | addItinerary (std::unique_ptr< Itinerary > itinerary) |
Add an itinerary. | |
template<typename... Tn> requires (is_itinerary_v<Tn> && ...) | |
void | addItineraries (Tn... itineraries) |
template<typename T1, typename... Tn> requires (is_itinerary_v<T1> && (is_itinerary_v<Tn> && ...)) | |
void | addItineraries (T1 itinerary, Tn... itineraries) |
Add a pack of itineraries. | |
void | addItineraries (std::span< Itinerary > itineraries) |
Add a set of itineraries. | |
void | resetTime () |
Reset the simulation time. | |
const Graph & | graph () const |
Get the graph. | |
const std::unordered_map< Id, std::unique_ptr< Itinerary > > & | itineraries () const |
Get the itineraries. | |
const std::map< Id, std::unique_ptr< agent_t > > & | agents () const |
Get the agents. | |
Size | nAgents () const |
Get the number of agents currently in the simulation. | |
Time | time () const |
Get the time. | |
Measurement< double > | agentMeanSpeed () const |
Get the mean speed of the agents in . | |
virtual double | streetMeanSpeed (Id streetId) const |
virtual Measurement< double > | streetMeanSpeed () const |
virtual Measurement< double > | streetMeanSpeed (double, bool) const |
Measurement< double > | streetMeanDensity (bool normalized=false) const |
Get the mean density of the streets in . | |
Measurement< double > | streetMeanFlow () const |
Get the mean flow of the streets in . | |
Measurement< double > | streetMeanFlow (double threshold, bool above) const |
Get the mean flow of the streets in . | |
Measurement< double > | meanSpireInputFlow (bool resetValue=true) |
Get the mean spire input flow of the streets in . | |
Measurement< double > | meanSpireOutputFlow (bool resetValue=true) |
Get the mean spire output flow of the streets in . | |
Measurement< double > | meanTravelTime (bool clearData=false) |
Get the mean travel time of the agents in . | |
void | saveStreetDensities (const std::string &filename, bool normalized=true) const |
Save the street densities in csv format. | |
void | saveInputStreetCounts (const std::string &filename, bool reset=false) |
Save the street input counts in csv format. | |
void | saveOutputStreetCounts (const std::string &filename, bool reset=false) |
Save the street output counts in csv format. | |
Protected Member Functions | |
virtual void | m_evolveStreet (const std::unique_ptr< Street > &pStreet, bool reinsert_agents)=0 |
virtual bool | m_evolveNode (const std::unique_ptr< Node > &pNode)=0 |
virtual void | m_evolveAgents ()=0 |
void | m_updatePath (const std::unique_ptr< Itinerary > &pItinerary) |
Update the path of a single itinerary using Dijsktra's algorithm. | |
Protected Attributes | |
Graph | m_graph |
Time | m_time |
Time | m_previousSpireTime |
std::mt19937_64 | m_generator |
The Dynamics class represents the dynamics of 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::Dynamics< agent_t >::Dynamics | ( | Graph & | graph, |
bool | useCache = false, | ||
std::optional< unsigned int > | seed = std::nullopt ) |
Construct a new Dynamics object.
graph | The graph representing the network |
useCache | If true, the paths are cached (default is false) |
seed | The seed for the random number generator (default is std::nullopt) |
void dsm::Dynamics< agent_t >::addAgent | ( | std::unique_ptr< agent_t > | agent | ) |
Add an agent to the simulation.
agent | std::unique_ptr to the agent |
void dsm::Dynamics< agent_t >::addAgents | ( | std::span< agent_t > | agents | ) |
Add a set of agents to the simulation.
agents | Generic container of agents, represented by an std::span |
void dsm::Dynamics< agent_t >::addAgents | ( | T1 | agent, |
Tn... | agents ) |
Add a pack of agents to the simulation.
agent | An agent |
agents | Parameter pack of agents |
void dsm::Dynamics< agent_t >::addAgents | ( | Tn... | agents | ) |
Add a pack of agents to the simulation.
agents | Parameter pack of agents |
void dsm::Dynamics< agent_t >::addItineraries | ( | std::span< Itinerary > | itineraries | ) |
Add a set of itineraries.
itineraries | Generic container of itineraries, represented by an std::span |
void dsm::Dynamics< agent_t >::addItineraries | ( | T1 | itinerary, |
Tn... | itineraries ) |
Add a pack of itineraries.
T1 | |
...Tn |
itinerary | |
...itineraries |
void dsm::Dynamics< agent_t >::addItinerary | ( | const Itinerary & | itinerary | ) |
Add an itinerary.
itinerary | The itinerary |
void dsm::Dynamics< agent_t >::addItinerary | ( | std::unique_ptr< Itinerary > | itinerary | ) |
Add an itinerary.
itinerary | std::unique_ptr to the itinerary |
Measurement< double > dsm::Dynamics< agent_t >::agentMeanSpeed | ( | ) | const |
Get the mean speed of the agents in .
|
inline |
Get the agents.
|
pure virtual |
Implemented in dsm::RoadDynamics< delay_t >, and dsm::RoadDynamics< Delay >.
|
inline |
Get the graph.
|
inline |
Get the itineraries.
|
protectedpure virtual |
Implemented in dsm::RoadDynamics< delay_t >, and dsm::RoadDynamics< Delay >.
|
protectedpure virtual |
Implemented in dsm::RoadDynamics< delay_t >, and dsm::RoadDynamics< Delay >.
|
protectedpure virtual |
Implemented in dsm::RoadDynamics< delay_t >, and dsm::RoadDynamics< Delay >.
|
inlineprotected |
Update the path of a single itinerary using Dijsktra's algorithm.
pItinerary | An std::unique_prt to the itinerary |
Measurement< double > dsm::Dynamics< agent_t >::meanSpireInputFlow | ( | bool | resetValue = true | ) |
Get the mean spire input flow of the streets in .
resetValue | If true, the spire input/output flows are cleared after the computation |
The spire input flow is computed as the sum of counts over the product of the number of spires and the time delta
Measurement< double > dsm::Dynamics< agent_t >::meanSpireOutputFlow | ( | bool | resetValue = true | ) |
Get the mean spire output flow of the streets in .
resetValue | If true, the spire output/input flows are cleared after the computation |
The spire output flow is computed as the sum of counts over the product of the number of spires and the time delta
Measurement< double > dsm::Dynamics< agent_t >::meanTravelTime | ( | bool | clearData = false | ) |
Get the mean travel time of the agents in .
clearData | If true, the travel times are cleared after the computation |
|
inline |
Get the number of agents currently in the simulation.
void dsm::Dynamics< agent_t >::removeAgent | ( | Size | agentId | ) |
Remove an agent from the simulation.
agentId | the id of the agent to remove |
void dsm::Dynamics< agent_t >::saveInputStreetCounts | ( | const std::string & | filename, |
bool | reset = false ) |
Save the street input counts in csv format.
filename | The name of the file |
reset | If true, the input counts are cleared after the computation |
NOTE: counts are printed only if the street is a spire
void dsm::Dynamics< agent_t >::saveOutputStreetCounts | ( | const std::string & | filename, |
bool | reset = false ) |
Save the street output counts in csv format.
filename | The name of the file |
reset | If true, the output counts are cleared after the computation |
NOTE: counts are printed only if the street is a spire
void dsm::Dynamics< agent_t >::saveStreetDensities | ( | const std::string & | filename, |
bool | normalized = true ) const |
Save the street densities in csv format.
filename | The name of the file |
normalized | If true, the densities are normalized in [0, 1] |
|
pure virtual |
Implemented in dsm::FirstOrderDynamics.
void dsm::Dynamics< agent_t >::setDestinationNodes | ( | const std::span< Id > & | destinationNodes, |
bool | updatePaths = true ) |
Set the dynamics destination nodes auto-generating itineraries.
destinationNodes | The destination nodes |
updatePaths | If true, the paths are updated |
std::invalid_argument | Ifone or more destination nodes do not exist |
Measurement< double > dsm::Dynamics< agent_t >::streetMeanDensity | ( | bool | normalized = false | ) | const |
Get the mean density of the streets in .
Measurement< double > dsm::Dynamics< agent_t >::streetMeanFlow | ( | ) | const |
Get the mean flow of the streets in .
Measurement< double > dsm::Dynamics< agent_t >::streetMeanFlow | ( | double | threshold, |
bool | above ) const |
Get the mean flow of the streets in .
threshold | The density threshold to consider |
above | If true, the function returns the mean flow of the streets with a density above the threshold, otherwise below |
|
virtual |
Reimplemented in dsm::FirstOrderDynamics.
|
virtual |
Reimplemented in dsm::FirstOrderDynamics.
|
virtual |
Reimplemented in dsm::FirstOrderDynamics.
|
inline |
Get the time.