Dynamical system model
Loading...
Searching...
No Matches
dsm::Dynamics< agent_t > Class Template Referenceabstract

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 Graphgraph () 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 $m/s$.
 
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 $m^{-1}$.
 
Measurement< double > streetMeanFlow () const
 Get the mean flow of the streets in $s^{-1}$.
 
Measurement< double > streetMeanFlow (double threshold, bool above) const
 Get the mean flow of the streets in $s^{-1}$.
 
Measurement< double > meanSpireInputFlow (bool resetValue=true)
 Get the mean spire input flow of the streets in $s^{-1}$.
 
Measurement< double > meanSpireOutputFlow (bool resetValue=true)
 Get the mean spire output flow of the streets in $s^{-1}$.
 
Measurement< double > meanTravelTime (bool clearData=false)
 Get the mean travel time of the agents in $s$.
 
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
 

Detailed Description

template<typename agent_t>
class dsm::Dynamics< agent_t >

The Dynamics class represents the dynamics of 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

◆ Dynamics()

template<typename agent_t>
dsm::Dynamics< agent_t >::Dynamics ( Graph & graph,
bool useCache = false,
std::optional< unsigned int > seed = std::nullopt )

Construct a new Dynamics object.

Parameters
graphThe graph representing the network
useCacheIf true, the paths are cached (default is false)
seedThe seed for the random number generator (default is std::nullopt)

Member Function Documentation

◆ addAgent()

template<typename agent_t>
void dsm::Dynamics< agent_t >::addAgent ( std::unique_ptr< agent_t > agent)

Add an agent to the simulation.

Parameters
agentstd::unique_ptr to the agent

◆ addAgents() [1/3]

template<typename agent_t>
void dsm::Dynamics< agent_t >::addAgents ( std::span< agent_t > agents)

Add a set of agents to the simulation.

Parameters
agentsGeneric container of agents, represented by an std::span

◆ addAgents() [2/3]

template<typename agent_t>
requires (is_agent_v<T1> && (is_agent_v<Tn> && ...))
template<typename T1, typename... Tn>
requires (is_agent_v<T1> && (is_agent_v<Tn> && ...))
void dsm::Dynamics< agent_t >::addAgents ( T1 agent,
Tn... agents )

Add a pack of agents to the simulation.

Parameters
agentAn agent
agentsParameter pack of agents

◆ addAgents() [3/3]

template<typename agent_t>
requires (is_agent_v<Tn> && ...)
template<typename... Tn>
requires (is_agent_v<Tn> && ...)
void dsm::Dynamics< agent_t >::addAgents ( Tn... agents)

Add a pack of agents to the simulation.

Parameters
agentsParameter pack of agents

◆ addItineraries() [1/2]

template<typename agent_t>
void dsm::Dynamics< agent_t >::addItineraries ( std::span< Itinerary > itineraries)

Add a set of itineraries.

Parameters
itinerariesGeneric container of itineraries, represented by an std::span

◆ addItineraries() [2/2]

template<typename agent_t>
template<typename T1, typename... Tn>
requires (is_itinerary_v<T1> && (is_itinerary_v<Tn> && ...))
void dsm::Dynamics< agent_t >::addItineraries ( T1 itinerary,
Tn... itineraries )

Add a pack of itineraries.

Template Parameters
T1
...Tn
Parameters
itinerary
...itineraries

◆ addItinerary() [1/2]

template<typename agent_t>
void dsm::Dynamics< agent_t >::addItinerary ( const Itinerary & itinerary)

Add an itinerary.

Parameters
itineraryThe itinerary

◆ addItinerary() [2/2]

template<typename agent_t>
void dsm::Dynamics< agent_t >::addItinerary ( std::unique_ptr< Itinerary > itinerary)

Add an itinerary.

Parameters
itinerarystd::unique_ptr to the itinerary

◆ agentMeanSpeed()

template<typename agent_t>
Measurement< double > dsm::Dynamics< agent_t >::agentMeanSpeed ( ) const

Get the mean speed of the agents in $m/s$.

Returns
Measurement<double> The mean speed of the agents and the standard deviation

◆ agents()

template<typename agent_t>
const std::map< Id, std::unique_ptr< agent_t > > & dsm::Dynamics< agent_t >::agents ( ) const
inline

Get the agents.

Returns
const std::unordered_map<Id, Agent<Id>>&, The agents

◆ evolve()

template<typename agent_t>
virtual void dsm::Dynamics< agent_t >::evolve ( bool reinsert_agents = false)
pure virtual

◆ graph()

template<typename agent_t>
const Graph & dsm::Dynamics< agent_t >::graph ( ) const
inline

Get the graph.

Returns
const Graph&, The graph

◆ itineraries()

template<typename agent_t>
const std::unordered_map< Id, std::unique_ptr< Itinerary > > & dsm::Dynamics< agent_t >::itineraries ( ) const
inline

Get the itineraries.

Returns
const std::unordered_map<Id, Itinerary>&, The itineraries

◆ m_evolveAgents()

template<typename agent_t>
virtual void dsm::Dynamics< agent_t >::m_evolveAgents ( )
protectedpure virtual

◆ m_evolveNode()

template<typename agent_t>
virtual bool dsm::Dynamics< agent_t >::m_evolveNode ( const std::unique_ptr< Node > & pNode)
protectedpure virtual

◆ m_evolveStreet()

template<typename agent_t>
virtual void dsm::Dynamics< agent_t >::m_evolveStreet ( const std::unique_ptr< Street > & pStreet,
bool reinsert_agents )
protectedpure virtual

◆ m_updatePath()

template<typename agent_t>
void dsm::Dynamics< agent_t >::m_updatePath ( const std::unique_ptr< Itinerary > & pItinerary)
inlineprotected

Update the path of a single itinerary using Dijsktra's algorithm.

Parameters
pItineraryAn std::unique_prt to the itinerary

◆ meanSpireInputFlow()

template<typename agent_t>
Measurement< double > dsm::Dynamics< agent_t >::meanSpireInputFlow ( bool resetValue = true)

Get the mean spire input flow of the streets in $s^{-1}$.

Parameters
resetValueIf true, the spire input/output flows are cleared after the computation
Returns
Measurement<double> The mean spire input flow of the streets and the standard deviation

The spire input flow is computed as the sum of counts over the product of the number of spires and the time delta

◆ meanSpireOutputFlow()

template<typename agent_t>
Measurement< double > dsm::Dynamics< agent_t >::meanSpireOutputFlow ( bool resetValue = true)

Get the mean spire output flow of the streets in $s^{-1}$.

Parameters
resetValueIf true, the spire output/input flows are cleared after the computation
Returns
Measurement<double> The mean spire output flow of the streets and the standard deviation

The spire output flow is computed as the sum of counts over the product of the number of spires and the time delta

◆ meanTravelTime()

template<typename agent_t>
Measurement< double > dsm::Dynamics< agent_t >::meanTravelTime ( bool clearData = false)

Get the mean travel time of the agents in $s$.

Parameters
clearDataIf true, the travel times are cleared after the computation
Returns
Measurement<double> The mean travel time of the agents and the standard

◆ nAgents()

template<typename agent_t>
Size dsm::Dynamics< agent_t >::nAgents ( ) const
inline

Get the number of agents currently in the simulation.

Returns
Size The number of agents

◆ removeAgent()

template<typename agent_t>
void dsm::Dynamics< agent_t >::removeAgent ( Size agentId)

Remove an agent from the simulation.

Parameters
agentIdthe id of the agent to remove

◆ saveInputStreetCounts()

template<typename agent_t>
void dsm::Dynamics< agent_t >::saveInputStreetCounts ( const std::string & filename,
bool reset = false )

Save the street input counts in csv format.

Parameters
filenameThe name of the file
resetIf true, the input counts are cleared after the computation

NOTE: counts are printed only if the street is a spire

◆ saveOutputStreetCounts()

template<typename agent_t>
void dsm::Dynamics< agent_t >::saveOutputStreetCounts ( const std::string & filename,
bool reset = false )

Save the street output counts in csv format.

Parameters
filenameThe name of the file
resetIf true, the output counts are cleared after the computation

NOTE: counts are printed only if the street is a spire

◆ saveStreetDensities()

template<typename agent_t>
void dsm::Dynamics< agent_t >::saveStreetDensities ( const std::string & filename,
bool normalized = true ) const

Save the street densities in csv format.

Parameters
filenameThe name of the file
normalizedIf true, the densities are normalized in [0, 1]

◆ setAgentSpeed()

template<typename agent_t>
virtual void dsm::Dynamics< agent_t >::setAgentSpeed ( Size agentId)
pure virtual

Implemented in dsm::FirstOrderDynamics.

◆ setDestinationNodes()

template<typename agent_t>
void dsm::Dynamics< agent_t >::setDestinationNodes ( const std::span< Id > & destinationNodes,
bool updatePaths = true )

Set the dynamics destination nodes auto-generating itineraries.

Parameters
destinationNodesThe destination nodes
updatePathsIf true, the paths are updated
Exceptions
std::invalid_argumentIfone or more destination nodes do not exist

◆ streetMeanDensity()

template<typename agent_t>
Measurement< double > dsm::Dynamics< agent_t >::streetMeanDensity ( bool normalized = false) const

Get the mean density of the streets in $m^{-1}$.

Returns
Measurement<double> The mean density of the streets and the standard deviation

◆ streetMeanFlow() [1/2]

template<typename agent_t>
Measurement< double > dsm::Dynamics< agent_t >::streetMeanFlow ( ) const

Get the mean flow of the streets in $s^{-1}$.

Returns
Measurement<double> The mean flow of the streets and the standard deviation

◆ streetMeanFlow() [2/2]

template<typename agent_t>
Measurement< double > dsm::Dynamics< agent_t >::streetMeanFlow ( double threshold,
bool above ) const

Get the mean flow of the streets in $s^{-1}$.

Parameters
thresholdThe density threshold to consider
aboveIf true, the function returns the mean flow of the streets with a density above the threshold, otherwise below
Returns
Measurement<double> The mean flow of the streets and the standard deviation

◆ streetMeanSpeed() [1/3]

template<typename agent_t>
Measurement< double > dsm::Dynamics< agent_t >::streetMeanSpeed ( ) const
virtual

Reimplemented in dsm::FirstOrderDynamics.

◆ streetMeanSpeed() [2/3]

template<typename agent_t>
Measurement< double > dsm::Dynamics< agent_t >::streetMeanSpeed ( double threshold,
bool above ) const
virtual

Reimplemented in dsm::FirstOrderDynamics.

◆ streetMeanSpeed() [3/3]

template<typename agent_t>
double dsm::Dynamics< agent_t >::streetMeanSpeed ( Id streetId) const
virtual

Reimplemented in dsm::FirstOrderDynamics.

◆ time()

template<typename agent_t>
Time dsm::Dynamics< agent_t >::time ( ) const
inline

Get the time.

Returns
Time The time

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