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-2024 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
38// the step length in ms
39extern SUMOTime DELTA_T;
40
41// the step length in seconds as double
42#define TS (static_cast<double>(DELTA_T)/1000.)
43
44// x*deltaT
45#define SPEED2DIST(x) ((x)*TS)
46// x/deltaT
47#define DIST2SPEED(x) ((x)/TS)
48// x*deltaT*deltaT
49#define ACCEL2DIST(x) ((x)*TS*TS)
50// x*deltaT
51#define ACCEL2SPEED(x) ((x)*TS)
52// x*deltaT
53#define SPEED2ACCEL(x) ((x)/TS)
54
55#define STEPS2TIME(x) (static_cast<double>(x)/1000.)
56// static cast to long long int truncates so we must pad away from 0 for correct rounding
57#define TIME2STEPS(x) (static_cast<SUMOTime>((x) * 1000. + ((x) >= 0 ? 0.5 : -0.5)))
58#define STEPFLOOR(x) (static_cast<SUMOTime>((x)/DELTA_T)*DELTA_T)
59#define STEPS2MS(x) (x)
60
61#define SIMSTEP MSNet::getInstance()->getCurrentTimeStep()
62#define SIMTIME STEPS2TIME(MSNet::getInstance()->getCurrentTimeStep())
63
64// ===========================================================================
65// method declarations
66// ===========================================================================
67
69SUMOTime string2time(const std::string& r);
70
72std::string time2string(SUMOTime t, bool humanReadable);
73
75std::string time2string(SUMOTime t);
76
78std::string elapsedMs2string(long long int t);
79
81bool checkStepLengthMultiple(const SUMOTime t, const std::string& error = "", SUMOTime deltaT = DELTA_T, SUMOTime begin = 0);
82
84void 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:150
std::string elapsedMs2string(long long int t)
convert ms to string for log output
Definition SUMOTime.cpp:122
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:135
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:69
long long int SUMOTime
Definition SUMOTime.h:33