Eclipse SUMO - Simulation of Urban MObility
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-2024 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
29 class PositionVector;
30 #endif
31 
32 
33 // ===========================================================================
34 // class definitions
35 // ===========================================================================
36 namespace LIBSUMO_NAMESPACE {
41 class Simulation {
42 public:
43 #ifdef LIBTRACI
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 bool isLibsumo();
48 
49  // we cannot call this switch because it is a reserved word in C++
50  static void switchConnection(const std::string& label);
51 
52  static const std::string& getLabel();
53 
54  static void setOrder(int order);
55 
56 #endif
57 
58  static std::pair<int, std::string> start(const std::vector<std::string>& cmd, int port = -1, int numRetries = libsumo::DEFAULT_NUM_RETRIES,
59  const std::string& label = "default", const bool verbose = false,
60  const std::string& traceFile = "", bool traceGetters = true, void* _stdout = nullptr);
61 
63  static void load(const std::vector<std::string>& args);
64 
66  static bool hasGUI();
67 
69  static bool isLoaded();
70 
72  static void step(const double time = 0.);
73 
75  static void executeMove();
76 
78  static void close(const std::string& reason = "Libsumo requested termination.");
79 
81  static std::pair<int, std::string> getVersion();
82 
84  static std::string getOption(const std::string& option);
85 
86  static int getCurrentTime();
87  static double getTime();
88 
90  static double getEndTime();
91 
92  static int getLoadedNumber();
93  static std::vector<std::string> getLoadedIDList();
94  static int getDepartedNumber();
95  static std::vector<std::string> getDepartedIDList();
96  static int getArrivedNumber();
97  static std::vector<std::string> getArrivedIDList();
99  static std::vector<std::string> getParkingStartingVehiclesIDList();
100  static int getParkingEndingVehiclesNumber();
101  static std::vector<std::string> getParkingEndingVehiclesIDList();
102  static int getStopStartingVehiclesNumber();
103  static std::vector<std::string> getStopStartingVehiclesIDList();
104  static int getStopEndingVehiclesNumber();
105  static std::vector<std::string> getStopEndingVehiclesIDList();
106  static int getCollidingVehiclesNumber();
107  static std::vector<std::string> getCollidingVehiclesIDList();
109  static std::vector<std::string> getEmergencyStoppingVehiclesIDList();
110  static int getStartingTeleportNumber();
111  static std::vector<std::string> getStartingTeleportIDList();
112  static int getEndingTeleportNumber();
113  static std::vector<std::string> getEndingTeleportIDList();
114 
115  static int getDepartedPersonNumber();
116  static std::vector<std::string> getDepartedPersonIDList();
117  static int getArrivedPersonNumber();
118  static std::vector<std::string> getArrivedPersonIDList();
119 
120  static std::vector<std::string> getBusStopIDList();
121  static int getBusStopWaiting(const std::string& stopID);
122 
125  static std::vector<std::string> getBusStopWaitingIDList(const std::string& stopID);
126  static std::vector<std::string> getPendingVehicles();
127 
128  static std::vector<libsumo::TraCICollision> getCollisions();
129 
130  static double getScale();
131  static double getDeltaT();
132 
134 
135  static int getMinExpectedNumber();
136 
137  static libsumo::TraCIPosition convert2D(const std::string& edgeID, double pos, int laneIndex = 0, bool toGeo = false);
138 
139  static libsumo::TraCIPosition convert3D(const std::string& edgeID, double pos, int laneIndex = 0, bool toGeo = false);
140 
141  static libsumo::TraCIRoadPosition convertRoad(double x, double y, bool isGeo = false, const std::string& vClass = "ignoring");
142 
143  static libsumo::TraCIPosition convertGeo(double x, double y, bool fromGeo = false);
144 
145  static double getDistance2D(double x1, double y1, double x2, double y2, bool isGeo = false, bool isDriving = false);
146  static double getDistanceRoad(const std::string& edgeID1, double pos1, const std::string& edgeID2, double pos2, bool isDriving = false);
147 
148  static libsumo::TraCIStage findRoute(const std::string& fromEdge, const std::string& toEdge, const std::string& vType = "", const double depart = -1., const int routingMode = 0);
149 
150  /* @note: default arrivalPos is not -1 because this would lead to very short walks when moving against the edge direction,
151  * instead the middle of the edge is used. DepartPos is treated differently so that 1-edge walks do not have length 0.
152  */
153  static std::vector<libsumo::TraCIStage> findIntermodalRoute(const std::string& fromEdge, const std::string& toEdge, const std::string& modes = "",
154  double depart = -1., const int routingMode = 0, double speed = -1., double walkFactor = -1.,
155  double departPos = 0, double arrivalPos = libsumo::INVALID_DOUBLE_VALUE, const double departPosLat = 0,
156  const std::string& pType = "", const std::string& vType = "", const std::string& destStop = "");
157 
158  static std::string getParameter(const std::string& objectID, const std::string& key);
159  static const std::pair<std::string, std::string> getParameterWithKey(const std::string& objectID, const std::string& key);
160  static void setParameter(const std::string& objectID, const std::string& key, const std::string& value);
161 
162  static void setScale(double value);
163  static void clearPending(const std::string& routeID = "");
164  static void saveState(const std::string& fileName);
166  static double loadState(const std::string& fileName);
167  static void writeMessage(const std::string& msg);
168 
169  static void subscribe(const std::vector<int>& varIDs = std::vector<int>(), double begin = libsumo::INVALID_DOUBLE_VALUE, double end = libsumo::INVALID_DOUBLE_VALUE, const libsumo::TraCIResults& params = libsumo::TraCIResults());
171 
173 
174 #ifndef LIBTRACI
175 #ifndef SWIG
176  static void storeShape(PositionVector& shape);
177 
178  static std::shared_ptr<VariableWrapper> makeWrapper();
179 
180  static bool handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper, tcpip::Storage* paramData);
181 #endif
182 #endif
183 
184 private:
185 #ifndef LIBTRACI
188 #endif
189 
191  Simulation() = delete;
192 };
193 
194 
195 }
#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:186
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::shared_ptr< VariableWrapper > makeWrapper()
static std::vector< std::string > getArrivedPersonIDList()
static bool handleVariable(const std::string &objID, const int variable, VariableWrapper *wrapper, tcpip::Storage *paramData)
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 void subscribe(const std::vector< int > &varIDs=std::vector< int >(), double begin=libsumo::INVALID_DOUBLE_VALUE, double end=libsumo::INVALID_DOUBLE_VALUE, const libsumo::TraCIResults &params=libsumo::TraCIResults())
static bool isLoaded()
return whether a simulation (network) is present
static const std::pair< std::string, std::string > getParameterWithKey(const std::string &objectID, const std::string &key)
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 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 storeShape(PositionVector &shape)
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:187
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 const libsumo::TraCIResults getSubscriptionResults()
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 std::string getOption(const std::string &option)
return the SUMO option value
A list of positions.
TRACI_CONST double INVALID_DOUBLE_VALUE
std::map< std::string, libsumo::SubscriptionResults > ContextSubscriptionResults
Definition: TraCIDefs.h:338
TRACI_CONST int DEFAULT_NUM_RETRIES
std::map< std::string, libsumo::TraCIResults > SubscriptionResults
{object->{variable->value}}
Definition: TraCIDefs.h:337
std::map< int, std::shared_ptr< libsumo::TraCIResult > > TraCIResults
{variable->value}
Definition: TraCIDefs.h:335
A 2D or 3D-position, for 2D positions z == INVALID_DOUBLE_VALUE.
Definition: TraCIDefs.h:178
A list of positions.
Definition: TraCIDefs.h:234
An edgeId, position and laneIndex.
Definition: TraCIDefs.h:197