Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
SUMOTime.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2026 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
21// Variables, methods, and tools for internal time representation
22/****************************************************************************/
23#pragma once
24#include <config.h>
25#include <limits>
26#include <string>
27#include "UtilExceptions.h"
28
29
30// ===========================================================================
31// type definitions
32// ===========================================================================
33typedef long long int SUMOTime;
34#define SUMOTime_MAX (std::numeric_limits<SUMOTime>::max() - 1000)
35#define SUMOTime_MIN std::numeric_limits<SUMOTime>::min()
36#define SUMOTime_MAX_PERIOD (SUMOTime_MAX - SUMOTime_MAX % DELTA_T)
37#define SUMOTime_DAY 86400000
38#define SUMOTime_HOUR 3600000
39#define SUMOTime_MINUTE 60000
40
41// the step length in ms
42extern SUMOTime DELTA_T;
43
44// the step length in seconds as double
45#define TS (static_cast<double>(DELTA_T)/1000.)
46
47// x*deltaT
48#define SPEED2DIST(x) ((x)*TS)
49// x/deltaT
50#define DIST2SPEED(x) ((x)/TS)
51// x*deltaT*deltaT
52#define ACCEL2DIST(x) ((x)*TS*TS)
53// x*deltaT
54#define ACCEL2SPEED(x) ((x)*TS)
55// x*deltaT
56#define SPEED2ACCEL(x) ((x)/TS)
57
58#define STEPS2TIME(x) (static_cast<double>(x)/1000.)
59// static cast to long long int truncates so we must pad away from 0 for correct rounding
60#define TIME2STEPS(x) (static_cast<SUMOTime>((x) * 1000. + ((x) >= 0 ? 0.5 : -0.5)))
61#define STEPFLOOR(x) (static_cast<SUMOTime>((x)/DELTA_T)*DELTA_T)
62#define STEPS2MS(x) (x)
63
64#define SIMSTEP MSNet::getInstance()->getCurrentTimeStep()
65#define SIMTIME STEPS2TIME(MSNet::getInstance()->getCurrentTimeStep())
66
67// ===========================================================================
68// method declarations
69// ===========================================================================
70
72SUMOTime string2time(const std::string& r);
73
75bool isTime(const std::string& r);
76
78std::string time2string(SUMOTime t, bool humanReadable);
79
81std::string time2string(SUMOTime t);
82
84std::string elapsedMs2string(long long int t);
85
87bool checkStepLengthMultiple(const SUMOTime t, const std::string& error = "", SUMOTime deltaT = DELTA_T, SUMOTime begin = 0);
88
90void checkTimeBounds(const double time);
long long int SUMOTime
Definition GUI.h:36
void checkTimeBounds(const double time)
check the valid SUMOTime range of double input and throw an error if out of bounds
Definition SUMOTime.cpp:173
std::string elapsedMs2string(long long int t)
convert ms to string for log output
Definition SUMOTime.cpp:145
SUMOTime DELTA_T
Definition SUMOTime.cpp:38
bool checkStepLengthMultiple(const SUMOTime t, const std::string &error="", SUMOTime deltaT=DELTA_T, SUMOTime begin=0)
check if given SUMOTime is multiple of the step length
Definition SUMOTime.cpp:158
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition SUMOTime.cpp:46
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:91
bool isTime(const std::string &r)
check if the given string is a valid time
Definition SUMOTime.cpp:69
long long int SUMOTime
Definition SUMOTime.h:33