/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file SUMOTime.h14/// @author Daniel Krajzewicz15/// @author Jakob Erdmann16/// @author Michael Behrisch17/// @author Mirko Barthauer18/// @date Fri, 29.04.200519///20// Variables, methods, and tools for internal time representation21/****************************************************************************/22#pragma once23#include <config.h>24#include <limits>25#include <string>26#include "UtilExceptions.h"272829// ===========================================================================30// type definitions31// ===========================================================================32typedef long long int SUMOTime;33#define SUMOTime_MAX (std::numeric_limits<SUMOTime>::max() - 1000)34#define SUMOTime_MIN std::numeric_limits<SUMOTime>::min()35#define SUMOTime_MAX_PERIOD (SUMOTime_MAX - SUMOTime_MAX % DELTA_T)3637// the step length in ms38extern SUMOTime DELTA_T;3940// the step length in seconds as double41#define TS (static_cast<double>(DELTA_T)/1000.)4243// x*deltaT44#define SPEED2DIST(x) ((x)*TS)45// x/deltaT46#define DIST2SPEED(x) ((x)/TS)47// x*deltaT*deltaT48#define ACCEL2DIST(x) ((x)*TS*TS)49// x*deltaT50#define ACCEL2SPEED(x) ((x)*TS)51// x*deltaT52#define SPEED2ACCEL(x) ((x)/TS)5354#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 rounding56#define TIME2STEPS(x) (static_cast<SUMOTime>((x) * 1000. + ((x) >= 0 ? 0.5 : -0.5)))57#define STEPFLOOR(x) (static_cast<SUMOTime>((x)/DELTA_T)*DELTA_T)58#define STEPS2MS(x) (x)5960#define SIMSTEP MSNet::getInstance()->getCurrentTimeStep()61#define SIMTIME STEPS2TIME(MSNet::getInstance()->getCurrentTimeStep())6263// ===========================================================================64// method declarations65// ===========================================================================6667/// @brief convert string to SUMOTime68SUMOTime string2time(const std::string& r);6970/// @brief check if the given string is a valid time71bool isTime(const std::string& r);7273/// @brief convert SUMOTime to string (independently of global format setting)74std::string time2string(SUMOTime t, bool humanReadable);7576/// @brief convert SUMOTime to string (using the global format setting)77std::string time2string(SUMOTime t);7879/// @brief convert ms to string for log output80std::string elapsedMs2string(long long int t);8182/// @brief check if given SUMOTime is multiple of the step length83bool checkStepLengthMultiple(const SUMOTime t, const std::string& error = "", SUMOTime deltaT = DELTA_T, SUMOTime begin = 0);8485/// @brief check the valid SUMOTime range of double input and throw an error if out of bounds86void checkTimeBounds(const double time);878889