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 declarations
27// ===========================================================================
28#ifndef LIBTRACI
29class PositionVector;
30#endif
31
32
33// ===========================================================================
34// class definitions
35// ===========================================================================
36namespace LIBSUMO_NAMESPACE {
42public:
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 close(const std::string& reason = "Libsumo requested termination.");
76
78 static std::pair<int, std::string> getVersion();
79
81 static std::string getOption(const std::string& option);
82
83 static int getCurrentTime();
84 static double getTime();
85
87 static double getEndTime();
88
89 static int getLoadedNumber();
90 static std::vector<std::string> getLoadedIDList();
91 static int getDepartedNumber();
92 static std::vector<std::string> getDepartedIDList();
93 static int getArrivedNumber();
94 static std::vector<std::string> getArrivedIDList();
96 static std::vector<std::string> getParkingStartingVehiclesIDList();
98 static std::vector<std::string> getParkingEndingVehiclesIDList();
100 static std::vector<std::string> getStopStartingVehiclesIDList();
101 static int getStopEndingVehiclesNumber();
102 static std::vector<std::string> getStopEndingVehiclesIDList();
103 static int getCollidingVehiclesNumber();
104 static std::vector<std::string> getCollidingVehiclesIDList();
106 static std::vector<std::string> getEmergencyStoppingVehiclesIDList();
107 static int getStartingTeleportNumber();
108 static std::vector<std::string> getStartingTeleportIDList();
109 static int getEndingTeleportNumber();
110 static std::vector<std::string> getEndingTeleportIDList();
111
112 static int getDepartedPersonNumber();
113 static std::vector<std::string> getDepartedPersonIDList();
114 static int getArrivedPersonNumber();
115 static std::vector<std::string> getArrivedPersonIDList();
116
117 static std::vector<std::string> getBusStopIDList();
118 static int getBusStopWaiting(const std::string& stopID);
119
122 static std::vector<std::string> getBusStopWaitingIDList(const std::string& stopID);
123 static std::vector<std::string> getPendingVehicles();
124
125 static std::vector<libsumo::TraCICollision> getCollisions();
126
127 static double getScale();
128 static double getDeltaT();
129
131
132 static int getMinExpectedNumber();
133
134 static libsumo::TraCIPosition convert2D(const std::string& edgeID, double pos, int laneIndex = 0, bool toGeo = false);
135
136 static libsumo::TraCIPosition convert3D(const std::string& edgeID, double pos, int laneIndex = 0, bool toGeo = false);
137
138 static libsumo::TraCIRoadPosition convertRoad(double x, double y, bool isGeo = false, const std::string& vClass = "ignoring");
139
140 static libsumo::TraCIPosition convertGeo(double x, double y, bool fromGeo = false);
141
142 static double getDistance2D(double x1, double y1, double x2, double y2, bool isGeo = false, bool isDriving = false);
143 static double getDistanceRoad(const std::string& edgeID1, double pos1, const std::string& edgeID2, double pos2, bool isDriving = false);
144
145 static libsumo::TraCIStage findRoute(const std::string& fromEdge, const std::string& toEdge, const std::string& vType = "", const double depart = -1., const int routingMode = 0);
146
147 /* @note: default arrivalPos is not -1 because this would lead to very short walks when moving against the edge direction,
148 * instead the middle of the edge is used. DepartPos is treated differently so that 1-edge walks do not have length 0.
149 */
150 static std::vector<libsumo::TraCIStage> findIntermodalRoute(const std::string& fromEdge, const std::string& toEdge, const std::string& modes = "",
151 double depart = -1., const int routingMode = 0, double speed = -1., double walkFactor = -1.,
152 double departPos = 0, double arrivalPos = libsumo::INVALID_DOUBLE_VALUE, const double departPosLat = 0,
153 const std::string& pType = "", const std::string& vType = "", const std::string& destStop = "");
154
155 static std::string getParameter(const std::string& objectID, const std::string& key);
156 static const std::pair<std::string, std::string> getParameterWithKey(const std::string& objectID, const std::string& key);
157 static void setParameter(const std::string& objectID, const std::string& param, const std::string& value);
158
159 static void setScale(double value);
160 static void clearPending(const std::string& routeID = "");
161 static void saveState(const std::string& fileName);
163 static double loadState(const std::string& fileName);
164 static void writeMessage(const std::string& msg);
165
166 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());
168
170
171#ifndef LIBTRACI
172#ifndef SWIG
173 static void storeShape(PositionVector& shape);
174
175 static std::shared_ptr<VariableWrapper> makeWrapper();
176
177 static bool handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper, tcpip::Storage* paramData);
178#endif
179#endif
180
181private:
182#ifndef LIBTRACI
185#endif
186
188 Simulation() = delete;
189};
190
191
192}
#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:183
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 void setParameter(const std::string &objectID, const std::string &param, const std::string &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 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 const std::pair< std::string, std::string > getParameterWithKey(const std::string &objectID, const std::string &key)
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 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:184
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:301
TRACI_CONST int DEFAULT_NUM_RETRIES
std::map< std::string, libsumo::TraCIResults > SubscriptionResults
{object->{variable->value}}
Definition: TraCIDefs.h:300
std::map< int, std::shared_ptr< libsumo::TraCIResult > > TraCIResults
{variable->value}
Definition: TraCIDefs.h:298
A 3D-position.
Definition: TraCIDefs.h:172
A list of positions.
Definition: TraCIDefs.h:215
An edgeId, position and laneIndex.
Definition: TraCIDefs.h:184