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-2020 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 <config.h>
22 
23 #include <vector>
24 #include <libsumo/TraCIDefs.h>
25 
26 
27 // ===========================================================================
28 // class declarations
29 // ===========================================================================
30 #ifndef LIBTRACI
31 namespace libsumo {
32 class VariableWrapper;
33 }
34 #endif
35 
36 
37 // ===========================================================================
38 // class definitions
39 // ===========================================================================
40 namespace LIBSUMO_NAMESPACE {
45 class Simulation {
46 public:
47 #ifdef LIBTRACI
48  static std::pair<int, std::string> init(int port = 8813, int numRetries = 10, const std::string& host = "localhost", const std::string& label = "default", FILE* const pipe = nullptr);
49 
50  static std::pair<int, std::string> start(const std::vector<std::string>& cmd, int port = -1, int numRetries = 10, const std::string& label = "default", const bool verbose = false);
51 
52  static bool isLibsumo();
53 
54  static bool hasGUI();
55 
56  // we cannot call this switch because it is a reserved word in C++
57  static void switchConnection(const std::string& label);
58 
59  static const std::string& getLabel();
60 
61  static void setOrder(int order);
62 
63 #endif
64 
66  static void load(const std::vector<std::string>& args);
67 
69  static bool isLoaded();
70 
72  static void step(const double time = 0.);
73 
75  static void close(const std::string& reason = "Libsumo requested termination.");
76 
78  static std::pair<int, std::string> getVersion();
79 
80  static int getCurrentTime();
81  static double getTime();
82 
83  static int getLoadedNumber();
84  static std::vector<std::string> getLoadedIDList();
85  static int getDepartedNumber();
86  static std::vector<std::string> getDepartedIDList();
87  static int getArrivedNumber();
88  static std::vector<std::string> getArrivedIDList();
90  static std::vector<std::string> getParkingStartingVehiclesIDList();
91  static int getParkingEndingVehiclesNumber();
92  static std::vector<std::string> getParkingEndingVehiclesIDList();
93  static int getStopStartingVehiclesNumber();
94  static std::vector<std::string> getStopStartingVehiclesIDList();
95  static int getStopEndingVehiclesNumber();
96  static std::vector<std::string> getStopEndingVehiclesIDList();
97  static int getCollidingVehiclesNumber();
98  static std::vector<std::string> getCollidingVehiclesIDList();
100  static std::vector<std::string> getEmergencyStoppingVehiclesIDList();
101  static int getStartingTeleportNumber();
102  static std::vector<std::string> getStartingTeleportIDList();
103  static int getEndingTeleportNumber();
104  static std::vector<std::string> getEndingTeleportIDList();
105 
106  static std::vector<std::string> getBusStopIDList();
107  static int getBusStopWaiting(const std::string& stopID);
108 
111  static std::vector<std::string> getBusStopWaitingIDList(const std::string& stopID);
112 
113 
114  static double getDeltaT();
115 
117 
118  static int getMinExpectedNumber();
119 
120 #ifndef LIBTRACI
121 // the following functions are not implemented in libtraci, yet
122 
123  static libsumo::TraCIPosition convert2D(const std::string& edgeID, double pos, int laneIndex = 0, bool toGeo = false);
124 
125  static libsumo::TraCIPosition convert3D(const std::string& edgeID, double pos, int laneIndex = 0, bool toGeo = false);
126 
127  static libsumo::TraCIRoadPosition convertRoad(double x, double y, bool isGeo = false, const std::string& vClass = "ignoring");
128 
129  static libsumo::TraCIPosition convertGeo(double x, double y, bool fromGeo = false);
130 
131  static double getDistance2D(double x1, double y1, double x2, double y2, bool isGeo = false, bool isDriving = false);
132  static double getDistanceRoad(const std::string& edgeID1, double pos1, const std::string& edgeID2, double pos2, bool isDriving = false);
133 
134  static libsumo::TraCIStage findRoute(const std::string& fromEdge, const std::string& toEdge, const std::string& vType = "", const double depart = -1., const int routingMode = 0);
135 
136  /* @note: default arrivalPos is not -1 because this would lead to very short walks when moving against the edge direction,
137  * instead the middle of the edge is used. DepartPos is treated differently so that 1-edge walks do not have length 0.
138  */
139  static std::vector<libsumo::TraCIStage> findIntermodalRoute(const std::string& fromEdge, const std::string& toEdge, const std::string& modes = "",
140  double depart = -1., const int routingMode = 0, double speed = -1., double walkFactor = -1.,
141  double departPos = 0, double arrivalPos = libsumo::INVALID_DOUBLE_VALUE, const double departPosLat = 0,
142  const std::string& pType = "", const std::string& vType = "", const std::string& destStop = "");
143 
144  static std::string getParameter(const std::string& objectID, const std::string& key);
145 #endif
146 
147  static void clearPending(const std::string& routeID = "");
148  static void saveState(const std::string& fileName);
150  static double loadState(const std::string& fileName);
151  static void writeMessage(const std::string& msg);
152 
153 #ifndef LIBTRACI
154  static void subscribe(const std::vector<int>& varIDs = std::vector<int>(), double begin = libsumo::INVALID_DOUBLE_VALUE, double end = libsumo::INVALID_DOUBLE_VALUE);
158 
159  static std::shared_ptr<VariableWrapper> makeWrapper();
160 
161  static bool handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper);
162 #endif
163 
164 private:
165 #ifndef LIBTRACI
168 #endif
169 
171  Simulation() = delete;
172 };
173 
174 
175 }
C++ TraCI client API implementation.
Definition: Simulation.h:45
static std::vector< std::string > getDepartedIDList()
static libsumo::TraCIPosition convert2D(const std::string &edgeID, double pos, int laneIndex=0, bool toGeo=false)
static std::vector< std::string > getParkingEndingVehiclesIDList()
static SubscriptionResults mySubscriptionResults
Definition: Simulation.h:166
static void saveState(const std::string &fileName)
static void close(const std::string &reason="Libsumo requested termination.")
close simulation
static std::shared_ptr< VariableWrapper > makeWrapper()
static double getDistanceRoad(const std::string &edgeID1, double pos1, const std::string &edgeID2, double pos2, bool isDriving=false)
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 bool isLoaded()
return whether a simulation (network) is present
static const SubscriptionResults getAllSubscriptionResults()
static libsumo::TraCIPositionVector getNetBoundary()
static std::vector< std::string > getCollidingVehiclesIDList()
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 int getBusStopWaiting(const std::string &stopID)
static void subscribe(const std::vector< int > &varIDs=std::vector< int >(), double begin=libsumo::INVALID_DOUBLE_VALUE, double end=libsumo::INVALID_DOUBLE_VALUE)
static std::vector< std::string > getBusStopIDList()
static libsumo::TraCIPosition convert3D(const std::string &edgeID, double pos, int laneIndex=0, bool toGeo=false)
static std::vector< std::string > getStartingTeleportIDList()
static void step(const double time=0.)
Advances by one step (or up to the given time)
static const ContextSubscriptionResults getAllContextSubscriptionResults()
static libsumo::TraCIRoadPosition convertRoad(double x, double y, bool isGeo=false, const std::string &vClass="ignoring")
static const libsumo::TraCIResults getSubscriptionResults()
Simulation()=delete
invalidated standard constructor
static std::vector< std::string > getArrivedIDList()
static std::vector< std::string > getParkingStartingVehiclesIDList()
static std::vector< std::string > getEndingTeleportIDList()
static ContextSubscriptionResults myContextSubscriptionResults
Definition: Simulation.h:167
static std::pair< int, std::string > getVersion()
return TraCI API and SUMO version
static libsumo::TraCIPosition convertGeo(double x, double y, bool fromGeo=false)
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 void writeMessage(const std::string &msg)
static std::string getParameter(const std::string &objectID, const std::string &key)
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 bool handleVariable(const std::string &objID, const int variable, VariableWrapper *wrapper)
static std::vector< std::string > getStopStartingVehiclesIDList()
static double getDistance2D(double x1, double y1, double x2, double y2, bool isGeo=false, bool isDriving=false)
TRACI_CONST double INVALID_DOUBLE_VALUE
std::map< int, std::shared_ptr< TraCIResult > > TraCIResults
{variable->value}
Definition: TraCIDefs.h:248
std::vector< TraCIPosition > TraCIPositionVector
Definition: TraCIDefs.h:196
std::map< std::string, TraCIResults > SubscriptionResults
{object->{variable->value}}
Definition: TraCIDefs.h:250
std::map< std::string, SubscriptionResults > ContextSubscriptionResults
Definition: TraCIDefs.h:251
A 3D-position.
Definition: TraCIDefs.h:141
An edgeId, position and laneIndex.
Definition: TraCIDefs.h:153