Dynamical system model
Loading...
Searching...
No Matches
dsf::mobility::FirstOrderDynamics Class Reference
Inheritance diagram for dsf::mobility::FirstOrderDynamics:
dsf::mobility::RoadDynamics< Delay > dsf::Dynamics< RoadNetwork >

Public Member Functions

 FirstOrderDynamics (RoadNetwork &graph, bool useCache=false, std::optional< unsigned int > seed=std::nullopt, double alpha=0., PathWeight const weightFunction=PathWeight::TRAVELTIME, std::optional< double > weightTreshold=std::nullopt)
 Construct a new First Order Dynamics object.
void setAgentSpeed (std::unique_ptr< Agent > const &pAgent) override
 Set the speed of an agent.
void setSpeedFluctuationSTD (double speedFluctuationSTD)
 Set the standard deviation of the speed fluctuation.
Public Member Functions inherited from dsf::mobility::RoadDynamics< Delay >
 RoadDynamics (RoadNetwork &graph, bool useCache=false, std::optional< unsigned int > seed=std::nullopt, PathWeight const weightFunction=PathWeight::TRAVELTIME, std::optional< double > weightTreshold=std::nullopt)
 Construct a new RoadDynamics object.
void setErrorProbability (double errorProbability)
 Set the error probability.
void setPassageProbability (double passageProbability)
 Set the passage probability.
void killStagnantAgents (double timeToleranceFactor=3.)
 Set the time tolerance factor for killing stagnant agents. An agent will be considered stagnant if it has not moved for timeToleranceFactor * std::ceil(street_length / street_maxSpeed) time units.
void setWeightFunction (PathWeight const pathWeight, std::optional< double > weightThreshold=std::nullopt)
 Set the weight function.
void setForcePriorities (bool forcePriorities) noexcept
 Set the force priorities flag.
void setDataUpdatePeriod (Delay dataUpdatePeriod) noexcept
 Set the data update period.
void setMeanTravelDistance (double const meanTravelDistance)
 Set the mean distance travelled by a random agent. The distance will be sampled from an exponential distribution with this mean.
void setMeanTravelTime (std::time_t const meanTravelTime) noexcept
 Set the mean travel time for random agents. The travel time will be sampled from an exponential distribution with this mean.
void setOriginNodes (std::unordered_map< Id, double > const &originNodes={})
 Set the origin nodes. If the provided map is empty, the origin nodes are set using the streets' stationary weights. NOTE: the default stationary weights are 1.0 so, if not set, this is equivalent to setting uniform weights.
void setDestinationNodes (std::unordered_map< Id, double > const &destinationNodes)
 Set the destination nodes.
void initTurnCounts ()
 Initialize the turn counts map.
void resetTurnCounts ()
 Reset the turn counts map values to zero.
void saveData (std::time_t const savingInterval, bool const saveAverageStats=false, bool const saveStreetData=false, bool const saveTravelData=false)
void updatePaths (bool const throw_on_empty=true)
 Update the paths of the itineraries based on the given weight function.
void addAgentsUniformly (Size nAgents, std::optional< Id > itineraryId=std::nullopt)
 Add agents uniformly on the road network.
void addRandomAgents (std::size_t nAgents, TContainer const &spawnWeights)
void addAgentsRandomly (Size nAgents, const TContainer &src_weights, const TContainer &dst_weights)
 Add a set of agents to the simulation.
void addAgent (std::unique_ptr< Agent > agent)
 Add an agent to the simulation.
void addAgents (std::size_t const nAgents, TArgs &&... args)
void addItinerary (TArgs &&... args)
 Add an itinerary.
void evolve (bool reinsert_agents=false)
 Evolve the simulation.
void optimizeTrafficLights (TrafficLightOptimization optimizationType=TrafficLightOptimization::DOUBLE_TAIL, const std::string &logFile=std::string(), double const percentage=0.3, double const threshold=1.3)
 Optimize the traffic lights by changing the green and red times.
auto const & itineraries () const noexcept
 Get the itineraries.
std::unordered_map< Id, double > const & originNodes () const noexcept
 Get the origin nodes of the graph.
std::unordered_map< Id, double > const & destinationNodes () const noexcept
 Get the destination nodes of the graph.
const std::vector< std::unique_ptr< Agent > > & agents () const noexcept
 Get the agents.
Size nAgents () const
 Get the number of agents currently in the simulation.
Measurement< double > meanTravelTime (bool clearData=false)
 Get the mean travel time of the agents in \(s\).
Measurement< double > meanTravelDistance (bool clearData=false)
 Get the mean travel distance of the agents in \(m\).
Measurement< double > meanTravelSpeed (bool clearData=false)
 Get the mean travel speed of the agents in \(m/s\).
std::unordered_map< Id, std::unordered_map< Id, size_t > > const & turnCounts () const noexcept
 Get the turn counts of the agents.
std::unordered_map< Id, std::unordered_map< Id, double > > const normalizedTurnCounts () const noexcept
 Get the normalized turn counts of the agents.
std::unordered_map< Id, std::array< long, 4 > > turnMapping () const
tbb::concurrent_unordered_map< Id, std::size_t > originCounts (bool const bReset=true) noexcept
 Get the origin counts of the agents.
tbb::concurrent_unordered_map< Id, std::size_t > destinationCounts (bool const bReset=true) noexcept
 Get the destination counts of the agents.
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}\).
void summary (std::ostream &os=std::cout) const
 Print a summary of the dynamics to an output stream.
Public Member Functions inherited from dsf::Dynamics< RoadNetwork >
 Dynamics (RoadNetwork &graph, std::optional< unsigned int > seed=std::nullopt)
 Construct a new Dynamics object.
void setName (const std::string &name)
 Set the name of the simulation.
void setInitTime (std::time_t timeEpoch)
 Set the initial time as epoch time.
void connectDataBase (std::string const &dbPath)
auto const & graph () const
 Get the graph.
auto const & id () const
 Get the id of the simulation.
auto const & name () const
 Get the name of the simulation.
auto const & database () const
 Get the database connection (const version).
auto time () const
 Get the current simulation time as epoch time.
auto time_step () const
 Get the current simulation time-step.
auto strDateTime () const
 Get the current simulation time as formatted string (YYYY-MM-DD HH:MM:SS).

Additional Inherited Members

Protected Member Functions inherited from dsf::Dynamics< RoadNetwork >
void m_evolve ()
auto m_safeDateTime () const
 Get a safe date-time string for filenames (YYYYMMDD_HHMMSS).
auto m_safeName () const
 Get a safe name string for filenames (spaces replaced by underscores).
Protected Attributes inherited from dsf::mobility::RoadDynamics< Delay >
std::unordered_map< Id, std::unordered_map< Id, size_t > > m_turnCounts
std::unordered_map< Id, std::array< long, 4 > > m_turnMapping
tbb::concurrent_unordered_map< Id, std::unordered_map< Direction, double > > m_queuesAtTrafficLights
tbb::concurrent_vector< std::pair< double, double > > m_travelDTs
std::time_t m_previousOptimizationTime
std::function< double(std::unique_ptr< Street > const &)> m_weightFunction
std::optional< double > m_errorProbability
std::optional< double > m_passageProbability
std::optional< double > m_meanTravelDistance
std::optional< std::time_t > m_meanTravelTime
std::optional< Delay > m_dataUpdatePeriod
bool m_bCacheEnabled
PathWeight m_pathWeight
double m_weightTreshold
std::optional< double > m_timeToleranceFactor
bool m_forcePriorities
std::time_t m_savingInterval
bool m_bSaveStreetData
bool m_bSaveTravelData
bool m_bSaveAverageStats
Protected Attributes inherited from dsf::Dynamics< RoadNetwork >
tbb::task_arena m_taskArena
std::mt19937_64 m_generator

Constructor & Destructor Documentation

◆ FirstOrderDynamics()

dsf::mobility::FirstOrderDynamics::FirstOrderDynamics ( RoadNetwork & graph,
bool useCache = false,
std::optional< unsigned int > seed = std::nullopt,
double alpha = 0.,
PathWeight const weightFunction = PathWeight::TRAVELTIME,
std::optional< double > weightTreshold = std::nullopt )

Construct a new First Order Dynamics object.

Parameters
graphThe graph representing the network
useCacheIf true, the cache is used (default is false)
seedThe seed for the random number generator (default is std::nullopt)
alphaThe minimum speed rate (default is 0)
weightFunctionThe dsf::PathWeight function to use for the pathfinding (default is dsf::PathWeight::TRAVELTIME)
weightTresholdThe weight threshold for the pathfinding (default is std::nullopt)

Member Function Documentation

◆ setAgentSpeed()

void dsf::mobility::FirstOrderDynamics::setAgentSpeed ( std::unique_ptr< Agent > const & pAgent)
overridevirtual

Set the speed of an agent.

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

Implements dsf::mobility::RoadDynamics< Delay >.

◆ setSpeedFluctuationSTD()

void dsf::mobility::FirstOrderDynamics::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

The documentation for this class was generated from the following files:
  • src/dsf/mobility/FirstOrderDynamics.hpp
  • src/dsf/mobility/FirstOrderDynamics.cpp