Dynamical System Framework
Loading...
Searching...
No Matches
dsf::mobility::TrafficSimulator Class Reference

Public Member Functions

 TrafficSimulator ()
 Construct a new TrafficSimulator with a generated simulation id.
 TrafficSimulator (std::string_view const jsonConfigFile)
 Construct a new TrafficSimulator and import its configuration from JSON.
void importConfig (std::string_view const jsonConfigFile)
 Import a JSON configuration file and apply it to the simulator.
void connectDataBase (std::string_view const dbPath, std::string_view const queries="PRAGMA busy_timeout = 5000;PRAGMA journal_mode = WAL;PRAGMA " "synchronous=NORMAL;PRAGMA temp_store=MEMORY;PRAGMA cache_size=-20000;")
 Connect to a SQLite database, creating it if it doesn't exist, and executing optional initialization queries.
void importRoadNetwork (std::string_view const edgesFile, std::string_view const nodePropertiesFile=std::string_view())
 Import a road network and build the simulation dynamics.
void saveData (std::time_t const savingInterval, bool const saveAverageStats=false, bool const saveStreetData=false, bool const saveTravelData=false, bool const saveAgentData=false, bool const saveTurnCounts=false)
 Configure the data-saving behavior.
void setName (std::string_view const name)
 Set the name of the simulation.
void setId (Id const id)
 Set the id of the simulation.
void setOutputPrefix (std::string_view const prefix)
 Set the output prefix used for generated CSV files and database paths.
void setTimeFrame (std::time_t const initTime, std::optional< std::time_t > const endTime=std::nullopt)
 Set the simulation time frame.
void setAgentInsertionMethod (AgentInsertionMethod const insertionMethod) noexcept
 Set the strategy used when inserting new agents.
void scheduleStreetStatusById (std::time_t const time, std::vector< Id > streetIds, RoadStatus const status)
 Schedule a change of the status of some streets during the runs.
void scheduleStreetStatusByName (std::time_t const time, std::string streetName, RoadStatus const status)
 Schedule a change of the status of the streets whose name contains the given one (see RoadNetwork::setStreetStatusByName).
void run (std::vector< std::size_t > const &nAgentsPerTimeStep, std::optional< std::time_t > const deltaT=std::nullopt)
 Run the simulation until the configured end time.
void run (std::size_t const nInitialAgents, std::time_t const agentInsertionDeltaT, std::time_t const checkDeltaT, std::size_t const agentIncrement=1)
 Run a slow charge: agents are added at a growing rate until the end time, or until the network is saturated.
auto * database () const
 Get the database connection (const version).
auto const * dynamics () const
 Get the dynamics engine managed by this simulator.
auto * dynamics ()
 Get the mutable dynamics engine managed by this simulator.
auto id () const
 Get the id of the simulation.
auto initTime () const
 Get the simulation start time.
auto strInitTime () const
 Get the formatted simulation start time.
auto endTime () const
 Get the simulation end time.
auto strEndTime () const
 Get the formatted simulation end time.
auto const & name () const
 Get the name of the simulation.
auto const & safeName () const
 Get a safe name string for filenames (spaces replaced by underscores).

Constructor & Destructor Documentation

◆ TrafficSimulator()

dsf::mobility::TrafficSimulator::TrafficSimulator ( std::string_view const jsonConfigFile)
explicit

Construct a new TrafficSimulator and import its configuration from JSON.

Parameters
jsonConfigFileThe path to the JSON configuration file.

Member Function Documentation

◆ connectDataBase()

void dsf::mobility::TrafficSimulator::connectDataBase ( std::string_view const dbPath,
std::string_view const queries = "PRAGMA busy_timeout = 5000;PRAGMA journal_mode = WAL;PRAGMA " "synchronous=NORMAL;PRAGMA temp_store=MEMORY;PRAGMA cache_size=-20000;" )

Connect to a SQLite database, creating it if it doesn't exist, and executing optional initialization queries.

Parameters
dbPathThe path to the SQLite database file
queriesOptional SQL queries to execute upon connecting to the database (default is a set of pragmas for performance optimization : "PRAGMA busy_timeout = 5000;PRAGMA journal_mode = WAL;PRAGMA synchronous=NORMAL;PRAGMA temp_store=MEMORY;PRAGMA cache_size=-20000;")

◆ database()

auto * dsf::mobility::TrafficSimulator::database ( ) const
inline

Get the database connection (const version).

Returns
const SQLite::Database const*, The database connection

◆ id()

auto dsf::mobility::TrafficSimulator::id ( ) const
inline

Get the id of the simulation.

Returns
Id, The id of the simulation

◆ importConfig()

void dsf::mobility::TrafficSimulator::importConfig ( std::string_view const jsonConfigFile)

Import a JSON configuration file and apply it to the simulator.

Parameters
jsonConfigFileThe path to the JSON configuration file.

◆ importRoadNetwork()

void dsf::mobility::TrafficSimulator::importRoadNetwork ( std::string_view const edgesFile,
std::string_view const nodePropertiesFile = std::string_view() )

Import a road network and build the simulation dynamics.

Parameters
edgesFileThe edges CSV file.
nodePropertiesFileOptional node-properties CSV file.

◆ name()

auto const & dsf::mobility::TrafficSimulator::name ( ) const
inline

Get the name of the simulation.

Returns
const std::string&, The name of the simulation

◆ run()

void dsf::mobility::TrafficSimulator::run ( std::size_t const nInitialAgents,
std::time_t const agentInsertionDeltaT,
std::time_t const checkDeltaT,
std::size_t const agentIncrement = 1 )
inline

Run a slow charge: agents are added at a growing rate until the end time, or until the network is saturated.

Parameters
nInitialAgentsThe number of agents added at each insertion, at first
agentInsertionDeltaTThe time steps between two insertions
checkDeltaTThe time steps between two checks: the number of agents added at each insertion grows by agentIncrement if the agents decreased since the last check
agentIncrementThe growth of the agents added at each insertion

When the network has no room left for an insertion, the run stops there, logging an error, and its summary is logged as usual

◆ safeName()

auto const & dsf::mobility::TrafficSimulator::safeName ( ) const
inline

Get a safe name string for filenames (spaces replaced by underscores).

Returns
std::string, The safe name string

◆ scheduleStreetStatusById()

void dsf::mobility::TrafficSimulator::scheduleStreetStatusById ( std::time_t const time,
std::vector< Id > streetIds,
RoadStatus const status )

Schedule a change of the status of some streets during the runs.

Parameters
timeThe time step of the run, counted from its start, at which the change is made (before the agents of that step are added)
streetIdsThe ids of the streets, checked when a run starts
statusThe status to set

Agents react to a closure as described in RoadNetwork::setStreetStatusById. Changes not made yet when a run ends are kept for the next run (with a warning), whose steps are counted from its own start

◆ scheduleStreetStatusByName()

void dsf::mobility::TrafficSimulator::scheduleStreetStatusByName ( std::time_t const time,
std::string streetName,
RoadStatus const status )

Schedule a change of the status of the streets whose name contains the given one (see RoadNetwork::setStreetStatusByName).

Parameters
timeThe time step of the run, counted from its start, at which the change is made (before the agents of that step are added)
streetNameThe name to match
statusThe status to set

◆ setAgentInsertionMethod()

void dsf::mobility::TrafficSimulator::setAgentInsertionMethod ( AgentInsertionMethod const insertionMethod)
inlinenoexcept

Set the strategy used when inserting new agents.

Parameters
insertionMethodThe insertion method to use.

◆ setId()

void dsf::mobility::TrafficSimulator::setId ( Id const id)

Set the id of the simulation.

Parameters
idThe id of the simulation

The default id is the creation time (YYYYMMDDHHMMSS)

Exceptions
std::invalid_argumentif the id does not fit in a SQLite INTEGER (64-bit signed)

◆ setName()

void dsf::mobility::TrafficSimulator::setName ( std::string_view const name)

Set the name of the simulation.

Parameters
nameThe name of the simulation

◆ setOutputPrefix()

void dsf::mobility::TrafficSimulator::setOutputPrefix ( std::string_view const prefix)

Set the output prefix used for generated CSV files and database paths.

Parameters
prefixThe prefix or directory path.

◆ setTimeFrame()

void dsf::mobility::TrafficSimulator::setTimeFrame ( std::time_t const initTime,
std::optional< std::time_t > const endTime = std::nullopt )

Set the simulation time frame.

Parameters
initTimeThe simulation start time.
endTimeOptional simulation end time.

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