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.org/sumo
3 // Copyright (C) 2012-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 /****************************************************************************/
18 // C++ TraCI client API implementation
19 /****************************************************************************/
20 #pragma once
21 #include <vector>
22 #include <libsumo/TraCIDefs.h>
23 
24 
25 // ===========================================================================
26 // class definitions
27 // ===========================================================================
28 namespace LIBSUMO_NAMESPACE {
33 class Simulation {
34 public:
35 #ifdef LIBTRACI
36  static std::pair<int, std::string> init(int port = 8813, int numRetries = libsumo::DEFAULT_NUM_RETRIES,
37  const std::string& host = "localhost", const std::string& label = "default", FILE* const pipe = nullptr);
38 
39  static bool isLibsumo();
40 
41  static bool hasGUI();
42 
43  // we cannot call this switch because it is a reserved word in C++
44  static void switchConnection(const std::string& label);
45 
46  static const std::string& getLabel();
47 
48  static void setOrder(int order);
49 
50 #endif
51 
52  static std::pair<int, std::string> start(const std::vector<std::string>& cmd, int port = -1, int numRetries = libsumo::DEFAULT_NUM_RETRIES,
53  const std::string& label = "default", const bool verbose = false,
54  const std::string& traceFile = "", bool traceGetters = true, void* _stdout = nullptr);
55 
57  static void load(const std::vector<std::string>& args);
58 
60  static bool isLoaded();
61 
63  static void step(const double time = 0.);
64 
66  static void close(const std::string& reason = "Libsumo requested termination.");
67 
69  static std::pair<int, std::string> getVersion();
70 
71  static int getCurrentTime();
72  static double getTime();
73 
75  static double getEndTime();
76 
77  static int getLoadedNumber();
78  static std::vector<std::string> getLoadedIDList();
79  static int getDepartedNumber();
80  static std::vector<std::string> getDepartedIDList();
81  static int getArrivedNumber();
82  static std::vector<std::string> getArrivedIDList();
84  static std::vector<std::string> getParkingStartingVehiclesIDList();
85  static int getParkingEndingVehiclesNumber();
86  static std::vector<std::string> getParkingEndingVehiclesIDList();
87  static int getStopStartingVehiclesNumber();
88  static std::vector<std::string> getStopStartingVehiclesIDList();
89  static int getStopEndingVehiclesNumber();
90  static std::vector<std::string> getStopEndingVehiclesIDList();
91  static int getCollidingVehiclesNumber();
92  static std::vector<std::string> getCollidingVehiclesIDList();
94  static std::vector<std::string> getEmergencyStoppingVehiclesIDList();
95  static int getStartingTeleportNumber();
96  static std::vector<std::string> getStartingTeleportIDList();
97  static int getEndingTeleportNumber();
98  static std::vector<std::string> getEndingTeleportIDList();
99 
100  static int getDepartedPersonNumber();
101  static std::vector<std::string> getDepartedPersonIDList();
102  static int getArrivedPersonNumber();
103  static std::vector<std::string> getArrivedPersonIDList();
104 
105  static std::vector<std::string> getBusStopIDList();
106  static int getBusStopWaiting(const std::string& stopID);
107 
110  static std::vector<std::string> getBusStopWaitingIDList(const std::string& stopID);
111  static std::vector<std::string> getPendingVehicles();
112 
113  static std::vector<libsumo::TraCICollision> getCollisions();
114 
115  static double getDeltaT();
116 
118 
119  static int getMinExpectedNumber();
120 
121  static libsumo::TraCIPosition convert2D(const std::string& edgeID, double pos, int laneIndex = 0, bool toGeo = false);
122 
123  static libsumo::TraCIPosition convert3D(const std::string& edgeID, double pos, int laneIndex = 0, bool toGeo = false);
124 
125  static libsumo::TraCIRoadPosition convertRoad(double x, double y, bool isGeo = false, const std::string& vClass = "ignoring");
126 
127  static libsumo::TraCIPosition convertGeo(double x, double y, bool fromGeo = false);
128 
129  static double getDistance2D(double x1, double y1, double x2, double y2, bool isGeo = false, bool isDriving = false);
130  static double getDistanceRoad(const std::string& edgeID1, double pos1, const std::string& edgeID2, double pos2, bool isDriving = false);
131 
132  static libsumo::TraCIStage findRoute(const std::string& fromEdge, const std::string& toEdge, const std::string& vType = "", const double depart = -1., const int routingMode = 0);
133 
134  /* @note: default arrivalPos is not -1 because this would lead to very short walks when moving against the edge direction,
135  * instead the middle of the edge is used. DepartPos is treated differently so that 1-edge walks do not have length 0.
136  */
137  static std::vector<libsumo::TraCIStage> findIntermodalRoute(const std::string& fromEdge, const std::string& toEdge, const std::string& modes = "",
138  double depart = -1., const int routingMode = 0, double speed = -1., double walkFactor = -1.,
139  double departPos = 0, double arrivalPos = libsumo::INVALID_DOUBLE_VALUE, const double departPosLat = 0,
140  const std::string& pType = "", const std::string& vType = "", const std::string& destStop = "");
141 
142  static std::string getParameter(const std::string& objectID, const std::string& key);
143  static const std::pair<std::string, std::string> getParameterWithKey(const std::string& objectID, const std::string& key);
144  static void setParameter(const std::string& objectID, const std::string& param, const std::string& value);
145 
146  static void clearPending(const std::string& routeID = "");
147  static void saveState(const std::string& fileName);
149  static double loadState(const std::string& fileName);
150  static void writeMessage(const std::string& msg);
151 
152  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());
154 
156 
157 #ifndef LIBTRACI
158 #ifndef SWIG
159  static std::shared_ptr<VariableWrapper> makeWrapper();
160 
161  static bool handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper, tcpip::Storage* paramData);
162 #endif
163 #endif
164 
165 private:
166 #ifndef LIBTRACI
169 #endif
170 
172  Simulation() = delete;
173 };
174 
175 
176 }
#define LIBSUMO_SUBSCRIPTION_API
Definition: TraCIDefs.h:56
C++ TraCI client API implementation.
Definition: Simulation.h:33
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:167
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 setParameter(const std::string &objectID, const std::string &param, const std::string &value)
static LIBSUMO_SUBSCRIPTION_API 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 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 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::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:168
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()
TRACI_CONST double INVALID_DOUBLE_VALUE
std::map< std::string, libsumo::SubscriptionResults > ContextSubscriptionResults
Definition: TraCIDefs.h:279
TRACI_CONST int DEFAULT_NUM_RETRIES
std::map< std::string, libsumo::TraCIResults > SubscriptionResults
{object->{variable->value}}
Definition: TraCIDefs.h:278
std::map< int, std::shared_ptr< libsumo::TraCIResult > > TraCIResults
{variable->value}
Definition: TraCIDefs.h:276
A 3D-position.
Definition: TraCIDefs.h:164
A list of positions.
Definition: TraCIDefs.h:207
An edgeId, position and laneIndex.
Definition: TraCIDefs.h:176