Dynamical system model
Loading...
Searching...
No Matches
dsm::FirstOrderDynamics< Delay > Class Template Reference
Inheritance diagram for dsm::FirstOrderDynamics< Delay >:
dsm::Dynamics< Delay >

Public Member Functions

 FirstOrderDynamics (Graph &graph)
 Construct a new First Order Dynamics object.
 
void setAgentSpeed (Size agentId) override
 Set the speed of an agent.
 
void setSpeedFluctuationSTD (double speedFluctuationSTD)
 Set the standard deviation of the speed fluctuation.
 
double streetMeanSpeed (Id streetId) const override
 Get the mean speed of a street in $m/s$.
 
Measurement< double > streetMeanSpeed () const override
 Get the mean speed of the streets in $m/s$.
 
Measurement< double > streetMeanSpeed (double threshold, bool above) const override
 Get the mean speed of the streets with density above or below a threshold in $m/s$.
 
- Public Member Functions inherited from dsm::Dynamics< Delay >
 Dynamics (Graph &graph)
 Construct a new Dynamics object.
 
void setItineraries (std::span< Itinerary > itineraries)
 Set the itineraries.
 
void setSeed (unsigned int seed)
 Set the seed for the graph's random number generator.
 
void setMinSpeedRateo (double minSpeedRateo)
 Set the minim speed rateo, i.e. the minim speed with respect to the speed limit.
 
void setErrorProbability (double errorProbability)
 Set the error probability.
 
void setMaxFlowPercentage (double maxFlowPercentage)
 Set the maximum flow percentage.
 
void setDestinationNodes (const std::span< Id > &destinationNodes, bool updatePaths=true)
 Set the dynamics destination nodes auto-generating itineraries.
 
void setForcePriorities (bool forcePriorities)
 Set the force priorities flag.
 
void setDataUpdatePeriod (Delay dataUpdatePeriod)
 Set the data update period.
 
virtual void updatePaths ()
 Update the paths of the itineraries based on the actual travel times.
 
virtual void evolve (bool reinsert_agents=false)
 Evolve the simulation.
 
void optimizeTrafficLights (Delay nCycles, double threshold=0., double densityTolerance=0.)
 Optimize the traffic lights by changing the green and red times.
 
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< Delay > > > & agents () const
 Get the agents.
 
TimePoint time () const
 Get the time.
 
void addAgent (const Agent< Delay > &agent)
 Add an agent to the simulation.
 
void addAgent (std::unique_ptr< Agent< Delay > > agent)
 Add an agent to the simulation.
 
void addAgent (Id srcNodeId, Id itineraryId)
 Add an agent with given source node and itinerary.
 
void addAgents (Id itineraryId, Size nAgents=1, std::optional< Id > srcNodeId=std::nullopt)
 Add a pack of agents to the simulation.
 
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< Delay > > agents)
 Add a set of agents to the simulation.
 
virtual void addAgentsUniformly (Size nAgents, std::optional< Id > itineraryId=std::nullopt)
 Add a set of agents to the simulation.
 
template<typename TContainer >
requires (std::is_same_v<TContainer, std::unordered_map<Id, double>> || std::is_same_v<TContainer, std::map<Id, double>>)
void addAgentsRandomly (Size nAgents, const TContainer &src_weights, const TContainer &dst_weights)
 
void removeAgent (Size agentId)
 Remove an agent from the simulation.
 
template<typename T1 , typename... Tn>
requires (std::is_convertible_v<T1, Size> && (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.
 
Measurement< double > agentMeanSpeed () const
 Get the mean speed of the agents in $m/s$.
 
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$.
 
const std::unordered_map< Id, std::array< unsigned long long, 4 > > & turnCounts () const
 Get the turn counts of the agents.
 
std::unordered_map< Id, std::array< double, 4 > > turnProbabilities (bool reset=true)
 Get the turn probabilities of the agents.
 
std::unordered_map< Id, std::array< long, 4 > > turnMapping () const
 

Additional Inherited Members

- Protected Member Functions inherited from dsm::Dynamics< Delay >
virtual Id m_nextStreetId (Id agentId, Id NodeId, std::optional< Id > streetId=std::nullopt)
 Get the next street id.
 
virtual void m_increaseTurnCounts (Id streetId, double delta)
 Increase the turn counts.
 
virtual void m_evolveStreet (const Id streetId, const std::unique_ptr< Street > &pStreet, bool reinsert_agents)
 Evolve a street.
 
virtual bool m_evolveNode (const std::unique_ptr< Node > &pNode)
 If possible, removes one agent from the node, putting it on the next street.
 
virtual void m_evolveAgents ()
 Evolve the agents.
 
void m_updatePath (const std::unique_ptr< Itinerary > &pItinerary)
 Update the path of a single itinerary.
 
- Protected Attributes inherited from dsm::Dynamics< Delay >
std::unordered_map< Id, std::unique_ptr< Itinerary > > m_itineraries
 
std::map< Id, std::unique_ptr< Agent< Delay > > > m_agents
 
TimePoint m_time
 
TimePoint m_previousSpireTime
 
Graph m_graph
 
double m_errorProbability
 
double m_minSpeedRateo
 
double m_maxFlowPercentage
 
std::mt19937_64 m_generator {std::random_device{}()}
 
std::uniform_real_distribution< double > m_uniformDist {0., 1.}
 
std::vector< unsigned int > m_travelTimes
 
std::unordered_map< Id, Id > m_agentNextStreetId
 
bool m_forcePriorities
 
std::optional< Delay > m_dataUpdatePeriod
 
std::unordered_map< Id, std::array< unsigned long long, 4 > > m_turnCounts
 
std::unordered_map< Id, std::array< long, 4 > > m_turnMapping
 
std::unordered_map< Id, unsigned long long > m_streetTails
 

Constructor & Destructor Documentation

◆ FirstOrderDynamics()

template<typename Delay >
dsm::FirstOrderDynamics< Delay >::FirstOrderDynamics ( Graph & graph)
inline

Construct a new First Order Dynamics object.

Parameters
graph,Thegraph representing the network

Member Function Documentation

◆ setAgentSpeed()

template<typename Delay >
requires (std::unsigned_integral<Delay>)
void dsm::FirstOrderDynamics< Delay >::setAgentSpeed ( Size agentId)
overridevirtual

Set the speed of an agent.

Parameters
agentIdThe id of the agent
Exceptions
std::invalid_argument,Ifthe agent is not found

Implements dsm::Dynamics< Delay >.

◆ setSpeedFluctuationSTD()

template<typename Delay >
requires (std::unsigned_integral<Delay>)
void dsm::FirstOrderDynamics< Delay >::setSpeedFluctuationSTD ( double speedFluctuationSTD)

Set the standard deviation of the speed fluctuation.

Parameters
speedFluctuationSTDThe standard deviation of the speed fluctuation
Exceptions
std::invalid_argument,Ifthe standard deviation is negative

◆ streetMeanSpeed() [1/3]

template<typename Delay >
requires (std::unsigned_integral<Delay>)
Measurement< double > dsm::FirstOrderDynamics< Delay >::streetMeanSpeed ( ) const
overridevirtual

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

Returns
Measurement The mean speed of the agents and the standard deviation

Implements dsm::Dynamics< Delay >.

◆ streetMeanSpeed() [2/3]

template<typename Delay >
requires (std::unsigned_integral<Delay>)
Measurement< double > dsm::FirstOrderDynamics< Delay >::streetMeanSpeed ( double threshold,
bool above ) const
overridevirtual

Get the mean speed of the streets with density above or below a threshold in $m/s$.

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

Implements dsm::Dynamics< Delay >.

◆ streetMeanSpeed() [3/3]

template<typename Delay >
requires (std::unsigned_integral<Delay>)
double dsm::FirstOrderDynamics< Delay >::streetMeanSpeed ( Id streetId) const
overridevirtual

Get the mean speed of a street in $m/s$.

Returns
double The mean speed of the street or street->maxSpeed() if the street is empty

The mean speed of a street is given by the formula: $ v_{\text{mean}} = v_{\text{max}} \left(1 - \frac{\alpha}{2} \left( n - 1\right)  \right) $ where $ v_{\text{max}} $ is the maximum speed of the street, $ \alpha $ is the minimum speed rateo divided by the capacity and $ n $ is the number of agents in the street

Implements dsm::Dynamics< Delay >.


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