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 // ===========================================================================
32 typedef long long int SUMOTime;
33 #define SUMOTime_MAX std::numeric_limits<SUMOTime>::max()
34 #define SUMOTime_MIN std::numeric_limits<SUMOTime>::min()
35 
36 // the step length in ms
37 extern SUMOTime DELTA_T;
38 
39 // the step length in seconds as double
40 #define TS (static_cast<double>(DELTA_T/1000.))
41 
42 // x*deltaT
43 #define SPEED2DIST(x) ((x)*TS)
44 // x/deltaT
45 #define DIST2SPEED(x) ((x)/TS)
46 // x*deltaT*deltaT
47 #define ACCEL2DIST(x) ((x)*TS*TS)
48 // x*deltaT
49 #define ACCEL2SPEED(x) ((x)*TS)
50 // x*deltaT
51 #define SPEED2ACCEL(x) ((x)/TS)
52 
53 #define STEPS2TIME(x) (static_cast<double>(x)/1000.)
54 // static cast to long long int truncates so we must pad away from 0 for correct rounding
55 #define TIME2STEPS(x) (static_cast<SUMOTime>((x) * 1000. + ((x) >= 0 ? 0.5 : -0.5)))
56 #define STEPFLOOR(x) (int(x/DELTA_T)*DELTA_T)
57 #define STEPS2MS(x) (x)
58 
59 #define SIMSTEP MSNet::getInstance()->getCurrentTimeStep()
60 #define SIMTIME STEPS2TIME(MSNet::getInstance()->getCurrentTimeStep())
61 
62 // ===========================================================================
63 // method declarations
64 // ===========================================================================
65 
67 SUMOTime string2time(const std::string& r);
68 
70 std::string time2string(SUMOTime t);
71 
73 std::string elapsedMs2string(long long int t);
74 
76 bool checkStepLengthMultiple(const SUMOTime t, const std::string& error = "", SUMOTime deltaT = DELTA_T);
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