Eclipse SUMO - Simulation of Urban MObility
SUMOTime.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2001-2022 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/****************************************************************************/
20// Variables, methods, and tools for internal time representation
21/****************************************************************************/
22#pragma once
23#include <config.h>
24#include <limits>
25#include <string>
26#include "UtilExceptions.h"
27
28
29// ===========================================================================
30// type definitions
31// ===========================================================================
32typedef long long int SUMOTime;
33#define SUMOTime_MAX std::numeric_limits<SUMOTime>::max()
34#define SUMOTime_MIN std::numeric_limits<SUMOTime>::min()
35#define SUMOTime_MAX_PERIOD (SUMOTime_MAX - SUMOTime_MAX % DELTA_T)
36
37// the step length in ms
38extern SUMOTime DELTA_T;
39
40// the step length in seconds as double
41#define TS (static_cast<double>(DELTA_T)/1000.)
42
43// x*deltaT
44#define SPEED2DIST(x) ((x)*TS)
45// x/deltaT
46#define DIST2SPEED(x) ((x)/TS)
47// x*deltaT*deltaT
48#define ACCEL2DIST(x) ((x)*TS*TS)
49// x*deltaT
50#define ACCEL2SPEED(x) ((x)*TS)
51// x*deltaT
52#define SPEED2ACCEL(x) ((x)/TS)
53
54#define STEPS2TIME(x) (static_cast<double>(x)/1000.)
55// static cast to long long int truncates so we must pad away from 0 for correct rounding
56#define TIME2STEPS(x) (static_cast<SUMOTime>((x) * 1000. + ((x) >= 0 ? 0.5 : -0.5)))
57#define STEPFLOOR(x) (int(x/DELTA_T)*DELTA_T)
58#define STEPS2MS(x) (x)
59
60#define SIMSTEP MSNet::getInstance()->getCurrentTimeStep()
61#define SIMTIME STEPS2TIME(MSNet::getInstance()->getCurrentTimeStep())
62
63// ===========================================================================
64// method declarations
65// ===========================================================================
66
68SUMOTime string2time(const std::string& r);
69
71std::string time2string(SUMOTime t);
72
74std::string elapsedMs2string(long long int t);
75
77bool checkStepLengthMultiple(const SUMOTime t, const std::string& error = "", SUMOTime deltaT = DELTA_T);
long long int SUMOTime
Definition: GUI.h:36
bool checkStepLengthMultiple(const SUMOTime t, const std::string &error="", SUMOTime deltaT=DELTA_T)
check if given SUMOTime is multiple of the step length
Definition: SUMOTime.cpp:123
std::string elapsedMs2string(long long int t)
convert ms to string for log output
Definition: SUMOTime.cpp:110
SUMOTime DELTA_T
Definition: SUMOTime.cpp:37
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition: SUMOTime.cpp:45
long long int SUMOTime
Definition: SUMOTime.h:32