Eclipse SUMO - Simulation of Urban MObility
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Simulation.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2012-2025 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/****************************************************************************/
18// C++ TraCI client API implementation
19/****************************************************************************/
20#pragma once
21#include <vector>
22#include <libsumo/TraCIDefs.h>
23
24
25// ===========================================================================
26// class declarations
27// ===========================================================================
28#ifndef LIBTRACI
29class PositionVector;
30#endif
31
32
33// ===========================================================================
34// class definitions
35// ===========================================================================
36namespace LIBSUMO_NAMESPACE {
42public:
43 // not implemented in libsumo
44 static std::pair<int, std::string> init(int port = 8813, int numRetries = libsumo::DEFAULT_NUM_RETRIES,
45 const std::string& host = "localhost", const std::string& label = "default", FILE* const pipe = nullptr);
46
47 static std::pair<int, std::string> start(const std::vector<std::string>& cmd, int port = -1, int numRetries = libsumo::DEFAULT_NUM_RETRIES,
48 const std::string& label = "default", const bool verbose = false,
49 const std::string& traceFile = "", bool traceGetters = true, void* _stdout = nullptr);
50
51 static bool isLibsumo();
52
53 // we cannot call this switch because it is a reserved word in C++
54 // not implemented in libsumo
55 static void switchConnection(const std::string& label);
56
57 // not implemented in libsumo
58 static const std::string& getLabel();
59
60 // not implemented in libsumo
61 static void setOrder(int order);
62
64 static void load(const std::vector<std::string>& args);
65
67 static bool hasGUI();
68
70 static bool isLoaded();
71
73 static void step(const double time = 0.);
74
76 static void executeMove();
77
79 static void close(const std::string& reason = "Libsumo requested termination.");
80
82 static std::pair<int, std::string> getVersion();
83
85 static std::string getOption(const std::string& option);
86
87 static int getCurrentTime();
88 static double getTime();
89
91 static double getEndTime();
92
93 static int getLoadedNumber();
94 static std::vector<std::string> getLoadedIDList();
95 static int getDepartedNumber();
96 static std::vector<std::string> getDepartedIDList();
97 static int getArrivedNumber();
98 static std::vector<std::string> getArrivedIDList();
100 static std::vector<std::string> getParkingStartingVehiclesIDList();
102 static std::vector<std::string> getParkingEndingVehiclesIDList();
104 static std::vector<std::string> getStopStartingVehiclesIDList();
105 static int getStopEndingVehiclesNumber();
106 static std::vector<std::string> getStopEndingVehiclesIDList();
107 static int getCollidingVehiclesNumber();
108 static std::vector<std::string> getCollidingVehiclesIDList();
110 static std::vector<std::string> getEmergencyStoppingVehiclesIDList();
111 static int getStartingTeleportNumber();
112 static std::vector<std::string> getStartingTeleportIDList();
113 static int getEndingTeleportNumber();
114 static std::vector<std::string> getEndingTeleportIDList();
115
116 static int getDepartedPersonNumber();
117 static std::vector<std::string> getDepartedPersonIDList();
118 static int getArrivedPersonNumber();
119 static std::vector<std::string> getArrivedPersonIDList();
120
121 static std::vector<std::string> getBusStopIDList();
122 static int getBusStopWaiting(const std::string& stopID);
123
126 static std::vector<std::string> getBusStopWaitingIDList(const std::string& stopID);
127 static std::vector<std::string> getPendingVehicles();
128
129 static std::vector<libsumo::TraCICollision> getCollisions();
130
131 static double getScale();
132 static double getDeltaT();
133
135
136 static int getMinExpectedNumber();
137
138 static libsumo::TraCIPosition convert2D(const std::string& edgeID, double pos, int laneIndex = 0, bool toGeo = false);
139
140 static libsumo::TraCIPosition convert3D(const std::string& edgeID, double pos, int laneIndex = 0, bool toGeo = false);
141
142 static libsumo::TraCIRoadPosition convertRoad(double x, double y, bool isGeo = false, const std::string& vClass = "ignoring");
143
144 static libsumo::TraCIPosition convertGeo(double x, double y, bool fromGeo = false);
145
146 static double getDistance2D(double x1, double y1, double x2, double y2, bool isGeo = false, bool isDriving = false);
147 static double getDistanceRoad(const std::string& edgeID1, double pos1, const std::string& edgeID2, double pos2, bool isDriving = false);
148
149 static libsumo::TraCIStage findRoute(const std::string& fromEdge, const std::string& toEdge, const std::string& vType = "", const double depart = -1., const int routingMode = 0);
150
151 /* @note: default arrivalPos is not -1 because this would lead to very short walks when moving against the edge direction,
152 * instead the middle of the edge is used. DepartPos is treated differently so that 1-edge walks do not have length 0.
153 */
154 static std::vector<libsumo::TraCIStage> findIntermodalRoute(const std::string& fromEdge, const std::string& toEdge, const std::string& modes = "",
155 double depart = -1., const int routingMode = 0, double speed = -1., double walkFactor = -1.,
156 double departPos = 0, double arrivalPos = libsumo::INVALID_DOUBLE_VALUE, const double departPosLat = 0,
157 const std::string& pType = "", const std::string& vType = "", const std::string& destStop = "");
158
159 static std::string getParameter(const std::string& objectID, const std::string& key);
160 static const std::pair<std::string, std::string> getParameterWithKey(const std::string& objectID, const std::string& key);
161 static void setParameter(const std::string& objectID, const std::string& key, const std::string& value);
162
163 static void setScale(double value);
164 static void clearPending(const std::string& routeID = "");
165 static void saveState(const std::string& fileName);
167 static double loadState(const std::string& fileName);
168 static void writeMessage(const std::string& msg);
169
171
172 static void subscribe(const std::vector<int>& varIDs = std::vector<int>({-1}), double begin = libsumo::INVALID_DOUBLE_VALUE, double end = libsumo::INVALID_DOUBLE_VALUE, const libsumo::TraCIResults& parameters = libsumo::TraCIResults());
173 static const libsumo::TraCIResults getSubscriptionResults();
174
175#ifndef LIBTRACI
176#ifndef SWIG
177 static void storeShape(PositionVector& shape);
178
179 static std::shared_ptr<VariableWrapper> makeWrapper();
180
181 static bool handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper, tcpip::Storage* paramData);
182#endif
183#endif
184
185private:
186#ifndef LIBTRACI
187 static SubscriptionResults mySubscriptionResults;
188 static ContextSubscriptionResults myContextSubscriptionResults;
189#ifdef HAVE_FOX
191 static FXMutex myStepMutex;
192#endif
193#endif
194
196 Simulation() = delete;
197};
198
199
200}
#define LIBSUMO_SUBSCRIPTION_API
Definition TraCIDefs.h:62
C++ TraCI client API implementation.
Definition Simulation.h:41
static std::vector< std::string > getDepartedIDList()
static std::vector< libsumo::TraCIStage > findIntermodalRoute(const std::string &fromEdge, const std::string &toEdge, const std::string &modes="", double depart=-1., const int routingMode=0, double speed=-1., double walkFactor=-1., double departPos=0, double arrivalPos=libsumo::INVALID_DOUBLE_VALUE, const double departPosLat=0, const std::string &pType="", const std::string &vType="", const std::string &destStop="")
static std::vector< std::string > getParkingEndingVehiclesIDList()
static libsumo::TraCIRoadPosition convertRoad(double x, double y, bool isGeo=false, const std::string &vClass="ignoring")
static SubscriptionResults mySubscriptionResults
Definition Simulation.h:187
static double getEndTime()
return configured end time
static void saveState(const std::string &fileName)
static void close(const std::string &reason="Libsumo requested termination.")
close simulation
static void setScale(double value)
static std::vector< std::string > getArrivedPersonIDList()
static void clearPending(const std::string &routeID="")
static void executeMove()
Advances a "half" step.
static bool hasGUI()
whether we run with graphical user interface (sumo-gui)
static void load(const std::vector< std::string > &args)
load a simulation with the given arguments
static double loadState(const std::string &fileName)
quick-load simulation state from file and return the state time
static std::vector< std::string > getEmergencyStoppingVehiclesIDList()
static std::vector< std::string > getLoadedIDList()
static const std::pair< std::string, std::string > getParameterWithKey(const std::string &objectID, const std::string &key)
static const std::string & getLabel()
static bool isLoaded()
return whether a simulation (network) is present
static libsumo::TraCIStage findRoute(const std::string &fromEdge, const std::string &toEdge, const std::string &vType="", const double depart=-1., const int routingMode=0)
static double getDistance2D(double x1, double y1, double x2, double y2, bool isGeo=false, bool isDriving=false)
static void setParameter(const std::string &objectID, const std::string &key, const std::string &value)
static libsumo::TraCIPositionVector getNetBoundary()
static std::vector< std::string > getCollidingVehiclesIDList()
static std::pair< int, std::string > init(int port=8813, int numRetries=libsumo::DEFAULT_NUM_RETRIES, const std::string &host="localhost", const std::string &label="default", FILE *const pipe=nullptr)
static int getBusStopWaiting(const std::string &stopID)
static std::pair< int, std::string > start(const std::vector< std::string > &cmd, int port=-1, int numRetries=libsumo::DEFAULT_NUM_RETRIES, const std::string &label="default", const bool verbose=false, const std::string &traceFile="", bool traceGetters=true, void *_stdout=nullptr)
static std::vector< std::string > getBusStopIDList()
static libsumo::TraCIPosition convert3D(const std::string &edgeID, double pos, int laneIndex=0, bool toGeo=false)
static LIBSUMO_SUBSCRIPTION_API void subscribe(const std::vector< int > &varIDs=std::vector< int >({-1}), double begin=libsumo::INVALID_DOUBLE_VALUE, double end=libsumo::INVALID_DOUBLE_VALUE, const libsumo::TraCIResults &parameters=libsumo::TraCIResults())
static libsumo::TraCIPosition convertGeo(double x, double y, bool fromGeo=false)
static std::vector< std::string > getStartingTeleportIDList()
static void step(const double time=0.)
Advances by one step (or up to the given time)
Simulation()=delete
invalidated standard constructor
static std::vector< std::string > getArrivedIDList()
static double getDistanceRoad(const std::string &edgeID1, double pos1, const std::string &edgeID2, double pos2, bool isDriving=false)
static std::vector< std::string > getParkingStartingVehiclesIDList()
static std::vector< std::string > getEndingTeleportIDList()
static ContextSubscriptionResults myContextSubscriptionResults
Definition Simulation.h:188
static std::pair< int, std::string > getVersion()
return TraCI API and SUMO version
static std::vector< std::string > getPendingVehicles()
static void writeMessage(const std::string &msg)
static std::string getParameter(const std::string &objectID, const std::string &key)
static std::vector< std::string > getDepartedPersonIDList()
static std::vector< std::string > getBusStopWaitingIDList(const std::string &stopID)
Returns the IDs of the transportables on a given bus stop.
static std::vector< std::string > getStopEndingVehiclesIDList()
static std::vector< std::string > getStopStartingVehiclesIDList()
static libsumo::TraCIPosition convert2D(const std::string &edgeID, double pos, int laneIndex=0, bool toGeo=false)
static std::vector< libsumo::TraCICollision > getCollisions()
static void switchConnection(const std::string &label)
static std::string getOption(const std::string &option)
return the SUMO option value
A list of positions.
TRACI_CONST double INVALID_DOUBLE_VALUE
TRACI_CONST int DEFAULT_NUM_RETRIES
std::map< int, std::shared_ptr< libsumo::TraCIResult > > TraCIResults
{variable->value}
Definition TraCIDefs.h:376
A 2D or 3D-position, for 2D positions z == INVALID_DOUBLE_VALUE.
Definition TraCIDefs.h:179
A list of positions.
Definition TraCIDefs.h:240
An edgeId, position and laneIndex.
Definition TraCIDefs.h:201