1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
10 /// @file    SUMOTime.h
11 /// @author  Daniel Krajzewicz
12 /// @author  Jakob Erdmann
13 /// @author  Michael Behrisch
14 /// @date    Fri, 29.04.2005
15 /// @version $Id$
16 ///
17 // Variables, methods, and tools for internal time representation
18 /****************************************************************************/
19 #ifndef SUMOTime_h
20 #define SUMOTime_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 
27 #include <limits>
28 #include <string>
29 #include "UtilExceptions.h"
30 
31 
32 // ===========================================================================
33 // type definitions
34 // ===========================================================================
35 typedef long long int SUMOTime;
36 #define SUMOTime_MAX std::numeric_limits<SUMOTime>::max()
37 #define SUMOTime_MIN std::numeric_limits<SUMOTime>::min()
38 #define SUMOTIME_MAXSTRING "9223372036854774" // SUMOTime_MAX / 1000 - 1 (because of rounding errors)
39 
40 // the step length in ms
41 extern SUMOTime DELTA_T;
42 
43 // the step length in seconds as double
44 #define TS (static_cast<double>(DELTA_T/1000.))
45 
46 // x*deltaT
47 #define SPEED2DIST(x) ((x)*TS)
48 // x/deltaT
49 #define DIST2SPEED(x) ((x)/TS)
50 // x*deltaT*deltaT
51 #define ACCEL2DIST(x) ((x)*TS*TS)
52 // x*deltaT
53 #define ACCEL2SPEED(x) ((x)*TS)
54 // x*deltaT
55 #define SPEED2ACCEL(x) ((x)/TS)
56 
57 #define STEPS2TIME(x) (static_cast<double>((x)/1000.))
58 // static cast to long long int truncates so we must pad away from 0 for correct rounding
59 #define TIME2STEPS(x) (static_cast<SUMOTime>((x)*1000 + ((x) >= 0 ? 0.5 : -0.5)))
60 #define STEPFLOOR(x) (int(x/DELTA_T)*DELTA_T)
61 #define STEPS2MS(x) (x)
62 
63 #define SIMSTEP MSNet::getInstance()->getCurrentTimeStep()
64 #define SIMTIME STEPS2TIME(MSNet::getInstance()->getCurrentTimeStep())
65 
66 // ===========================================================================
67 // method declarations
68 // ===========================================================================
69 SUMOTime string2time(const std::string& r);
70 std::string time2string(SUMOTime t);
71 
72 
73 #endif
74 
75 /****************************************************************************/
76 
77