Dynamical system model
|
The RoadDynamics class represents the dynamics of the network. More...
#include <RoadDynamics.hpp>
Public Member Functions | |
RoadDynamics (Graph &graph, bool useCache=false, std::optional< unsigned int > seed=std::nullopt) | |
Construct a new RoadDynamics object. | |
void | setErrorProbability (double errorProbability) |
Set the error probability. | |
void | setPassageProbability (double passageProbability) |
void | setForcePriorities (bool forcePriorities) |
Set the force priorities flag. | |
void | setDataUpdatePeriod (delay_t dataUpdatePeriod) |
Set the data update period. | |
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, const size_t minNodeDistance=0) |
Add a set of agents to the simulation. | |
void | evolve (bool reinsert_agents=false) override |
Evolve the simulation. | |
void | optimizeTrafficLights (double const threshold=0., TrafficLightOptimization optimizationType=TrafficLightOptimization::DOUBLE_TAIL) |
Optimize the traffic lights by changing the green and red times. | |
Measurement< double > | meanTravelTime (bool clearData=false) |
Get the mean travel time of the agents in . | |
Measurement< double > | meanTravelDistance (bool clearData=false) |
Get the mean travel distance of the agents in . | |
Measurement< double > | meanTravelSpeed (bool clearData=false) |
Get the mean travel speed of the agents in . | |
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 |
void | saveTravelSpeeds (const std::string &filename, bool reset=false) |
Save the travel speeds of the agents in csv format. | |
Public Member Functions inherited from dsm::Dynamics< Agent< delay_t > > | |
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 | 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< delay_t > > agent) |
Add an agent to the simulation. | |
void | addAgent (TArgs &&... args) |
void | addAgents (Size nAgents, TArgs &&... args) |
void | addAgents (Tn... agents) |
Add a pack of agents to the simulation. | |
void | addAgents (T1 agent, Tn... agents) |
Add a pack of agents to the simulation. | |
void | addAgents (std::span< Agent< delay_t > > agents) |
Add a set of agents to the simulation. | |
void | removeAgent (Size agentId) |
Remove an agent from the simulation. | |
void | removeAgents (T1 id, Tn... ids) |
void | addItinerary (const Itinerary &itinerary) |
Add an itinerary. | |
void | addItinerary (std::unique_ptr< Itinerary > itinerary) |
Add an itinerary. | |
void | addItineraries (Tn... itineraries) |
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< delay_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 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. | |
void | m_evolveStreet (const std::unique_ptr< Street > &pStreet, bool reinsert_agents) override |
Evolve a street. | |
bool | m_evolveNode (const std::unique_ptr< Node > &pNode) override |
If possible, removes one agent from the node, putting it on the next street. | |
void | m_evolveAgents () override |
Evolve the agents. | |
Protected Member Functions inherited from dsm::Dynamics< Agent< delay_t > > | |
void | m_updatePath (const std::unique_ptr< Itinerary > &pItinerary) |
Update the path of a single itinerary using Dijsktra's algorithm. | |
Protected Attributes | |
Time | m_previousOptimizationTime |
std::vector< std::pair< double, double > > | m_travelDTs |
std::unordered_map< Id, Id > | m_agentNextStreetId |
bool | m_forcePriorities |
std::optional< delay_t > | 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, double > | m_streetTails |
Protected Attributes inherited from dsm::Dynamics< Agent< delay_t > > | |
Graph | m_graph |
Time | m_time |
Time | m_previousSpireTime |
std::mt19937_64 | m_generator |
The RoadDynamics 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::RoadDynamics< delay_t >::RoadDynamics | ( | Graph & | graph, |
bool | useCache = false, | ||
std::optional< unsigned int > | seed = std::nullopt ) |
Construct a new RoadDynamics object.
graph | The graph representing the network |
useCache | If true, the cache is used (default is false) |
seed | The seed for the random number generator (default is std::nullopt) |
void dsm::RoadDynamics< delay_t >::addAgentsRandomly | ( | Size | nAgents, |
const TContainer & | src_weights, | ||
const TContainer & | dst_weights, | ||
const size_t | minNodeDistance = 0 ) |
Add a set of agents to the simulation.
nAgents | The number of agents to add |
src_weights | The weights of the source nodes |
dst_weights | The weights of the destination nodes |
std::invalid_argument | If the source and destination nodes are the same |
void dsm::RoadDynamics< delay_t >::addAgentsUniformly | ( | Size | nAgents, |
std::optional< Id > | itineraryId = std::nullopt ) |
Add a set of agents to the simulation.
nAgents | The number of agents to add |
uniformly | If true, the agents are added uniformly on the streets |
std::runtime_error | If there are no itineraries |
|
overridevirtual |
Evolve the simulation.
Evolve the simulation by moving the agents and updating the travel times. In particular:
reinsert_agents | If true, the agents are reinserted in the simulation after they reach their destination |
Implements dsm::Dynamics< Agent< delay_t > >.
|
overrideprotectedvirtual |
Evolve the agents.
Puts all new agents on a street, if possible, decrements all delays and increments all travel times.
Implements dsm::Dynamics< Agent< delay_t > >.
|
overrideprotectedvirtual |
If possible, removes one agent from the node, putting it on the next street.
pNode | A std::unique_ptr to the node |
Implements dsm::Dynamics< Agent< delay_t > >.
|
overrideprotectedvirtual |
Evolve a street.
pStreet | A std::unique_ptr to the street |
reinsert_agents | If true, the agents are reinserted in the simulation after they reach their destination |
If possible, removes the first agent of the street's queue, putting it in the destination node. If the agent is going into the destination node, it is removed from the simulation (and then reinserted if reinsert_agents is true)
Implements dsm::Dynamics< Agent< delay_t > >.
|
protectedvirtual |
Get the next street id.
agentId | The id of the agent |
NodeId | The id of the node |
streetId | The id of the incoming street |
Measurement< double > dsm::RoadDynamics< delay_t >::meanTravelDistance | ( | bool | clearData = false | ) |
Get the mean travel distance of the agents in .
clearData | If true, the travel distances are cleared after the computation |
Measurement< double > dsm::RoadDynamics< delay_t >::meanTravelSpeed | ( | bool | clearData = false | ) |
Get the mean travel speed of the agents in .
clearData | If true, the travel times and distances are cleared after the computation |
Measurement< double > dsm::RoadDynamics< delay_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 |
void dsm::RoadDynamics< delay_t >::optimizeTrafficLights | ( | double const | threshold = 0., |
TrafficLightOptimization | optimizationType = TrafficLightOptimization::DOUBLE_TAIL ) |
Optimize the traffic lights by changing the green and red times.
threshold | double, The minimum difference between green and red queues to trigger the optimization (n agents - default is 0) |
optimizationType | TrafficLightOptimization, The type of optimization. Default is DOUBLE_TAIL |
The function cycles over the traffic lights and, if the difference between the two tails is greater than the threshold multiplied by the mean capacity of the streets, it changes the green and red times of the traffic light, keeping the total cycle time constant. The optimizationType parameter can be set to SINGLE_TAIL to use an algorith which looks only at the incoming street tails or to DOUBLE_TAIL to consider both incoming and outgoing street tails.
void dsm::RoadDynamics< delay_t >::saveTravelSpeeds | ( | const std::string & | filename, |
bool | reset = false ) |
Save the travel speeds of the agents in csv format.
filename | The name of the file |
reset | If true, the travel speeds are cleared after the computation |
|
inline |
Set the data update period.
dataUpdatePeriod | delay_t, The period |
Some data, i.e. the street queue lengths, are stored only after a fixed amount of time which is represented by this variable.
void dsm::RoadDynamics< delay_t >::setErrorProbability | ( | double | errorProbability | ) |
Set the error probability.
errorProbability | The error probability |
std::invalid_argument | If the error probability is not between 0 and 1 |
|
inline |
Set the force priorities flag.
forcePriorities | The flag |
If true, if an agent cannot move to the next street, the whole node is skipped
|
inline |
Get the turn counts of the agents.
The array contains the counts of left (0), straight (1), right (2) and U (3) turns
std::unordered_map< Id, std::array< double, 4 > > dsm::RoadDynamics< delay_t >::turnProbabilities | ( | bool | reset = true | ) |
Get the turn probabilities of the agents.
The array contains the probabilities of left (0), straight (1), right (2) and U (3) turns