Eclipse SUMO - Simulation of Urban MObility
TraCIDefs.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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
18 // C++ TraCI client API implementation
19 /****************************************************************************/
20 #ifndef TraCIDefs_h
21 #define TraCIDefs_h
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 // we do not include config.h here, since we should be independent of a special sumo build
28 #include <libsumo/TraCIConstants.h>
29 #include <vector>
30 #include <limits>
31 #include <map>
32 #include <string>
33 #include <stdexcept>
34 #include <sstream>
35 #include <memory>
36 
37 
38 // ===========================================================================
39 // global definitions
40 // ===========================================================================
41 
42 #define LIBSUMO_SUBSCRIPTION_API \
43 static void subscribe(const std::string& objID, const std::vector<int>& vars = std::vector<int>(), double beginTime = libsumo::INVALID_DOUBLE_VALUE, double endTime = libsumo::INVALID_DOUBLE_VALUE); \
44 static void subscribeContext(const std::string& objID, int domain, double range, const std::vector<int>& vars = std::vector<int>(), double beginTime = libsumo::INVALID_DOUBLE_VALUE, double endTime = libsumo::INVALID_DOUBLE_VALUE); \
45 static void unsubscribeContext(const std::string& objID, int domain, double range); \
46 static const SubscriptionResults getAllSubscriptionResults(); \
47 static const TraCIResults getSubscriptionResults(const std::string& objID); \
48 static const ContextSubscriptionResults getAllContextSubscriptionResults(); \
49 static const SubscriptionResults getContextSubscriptionResults(const std::string& objID);
50 
51 #define LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(CLASS, DOMAIN) \
52 void \
53 CLASS::subscribe(const std::string& objID, const std::vector<int>& vars, double beginTime, double endTime) { \
54  libsumo::Helper::subscribe(CMD_SUBSCRIBE_##DOMAIN##_VARIABLE, objID, vars, beginTime, endTime); \
55 } \
56 void \
57 CLASS::subscribeContext(const std::string& objID, int domain, double range, const std::vector<int>& vars, double beginTime, double endTime) { \
58  libsumo::Helper::subscribe(CMD_SUBSCRIBE_##DOMAIN##_CONTEXT, objID, vars, beginTime, endTime, domain, range); \
59 } \
60 void \
61 CLASS::unsubscribeContext(const std::string& objID, int domain, double range) { \
62  libsumo::Helper::subscribe(CMD_SUBSCRIBE_##DOMAIN##_CONTEXT, objID, std::vector<int>(), libsumo::INVALID_DOUBLE_VALUE, libsumo::INVALID_DOUBLE_VALUE, domain, range); \
63 } \
64 const SubscriptionResults \
65 CLASS::getAllSubscriptionResults() { \
66  return mySubscriptionResults; \
67 } \
68 const TraCIResults \
69 CLASS::getSubscriptionResults(const std::string& objID) { \
70  return mySubscriptionResults[objID]; \
71 } \
72 const ContextSubscriptionResults \
73 CLASS::getAllContextSubscriptionResults() { \
74  return myContextSubscriptionResults; \
75 } \
76 const SubscriptionResults \
77 CLASS::getContextSubscriptionResults(const std::string& objID) { \
78  return myContextSubscriptionResults[objID]; \
79 }
80 
81 
82 
83 // ===========================================================================
84 // class and type definitions
85 // ===========================================================================
86 namespace libsumo {
90 class TraCIException : public std::runtime_error {
91 public:
93  TraCIException(std::string what)
94  : std::runtime_error(what) {}
95 };
96 
99 
100 struct TraCIResult {
101  virtual ~TraCIResult() {}
102  virtual std::string getString() {
103  return "";
104  }
105 };
106 
111  std::string getString() {
112  std::ostringstream os;
113  os << "TraCIPosition(" << x << "," << y << "," << z << ")";
114  return os.str();
115  }
117 };
118 
123  std::string getString() {
124  std::ostringstream os;
125  os << "TraCIRoadPosition(" << edgeID << "_" << laneIndex << "," << pos << ")";
126  return os.str();
127  }
128  std::string edgeID;
129  double pos;
130  int laneIndex = INVALID_INT_VALUE;
131 };
132 
137  TraCIColor() : r(0), g(0), b(0), a(255) {}
138  TraCIColor(int r, int g, int b, int a = 255) : r(r), g(g), b(b), a(a) {}
139  std::string getString() {
140  std::ostringstream os;
141  os << "TraCIColor(" << r << "," << g << "," << b << "," << a << ")";
142  return os.str();
143  }
144  int r, g, b, a;
145 };
146 
150 typedef std::vector<TraCIPosition> TraCIPositionVector;
151 
152 
154  TraCIInt() : value(0) {}
155  TraCIInt(int v) : value(v) {}
156  std::string getString() {
157  std::ostringstream os;
158  os << value;
159  return os.str();
160  }
161  int value;
162 };
163 
164 
166  TraCIDouble() : value(0.) {}
167  TraCIDouble(double v) : value(v) {}
168  std::string getString() {
169  std::ostringstream os;
170  os << value;
171  return os.str();
172  }
173  double value;
174 };
175 
176 
178  TraCIString() : value("") {}
179  TraCIString(std::string v) : value(v) {}
180  std::string getString() {
181  return value;
182  }
183  std::string value;
184 };
185 
186 
188  std::string getString() {
189  std::ostringstream os;
190  os << "[";
191  for (std::string v : value) {
192  os << v << ",";
193  }
194  os << "]";
195  return os.str();
196  }
197  std::vector<std::string> value;
198 };
199 
200 
202 typedef std::map<int, std::shared_ptr<TraCIResult> > TraCIResults;
204 typedef std::map<std::string, TraCIResults> SubscriptionResults;
205 typedef std::map<std::string, SubscriptionResults> ContextSubscriptionResults;
206 
207 
208 class TraCIPhase {
209 public:
211  TraCIPhase(const double _duration, const std::string& _state, const double _minDur = libsumo::INVALID_DOUBLE_VALUE,
212  const double _maxDur = libsumo::INVALID_DOUBLE_VALUE,
213  const std::vector<int>& _next = std::vector<int>(),
214  const std::string& _name = "") :
215  duration(_duration), state(_state), minDur(_minDur), maxDur(_maxDur), next(_next), name(_name) {}
217 
218  double duration;
219  std::string state;
220  double minDur, maxDur;
221  std::vector<int> next;
222  std::string name;
223 };
224 }
225 
226 
227 #ifdef SWIG
228 %template(TraCIPhaseVector) std::vector<libsumo::TraCIPhase>; // *NOPAD*
229 #endif
230 
231 
232 namespace libsumo {
233 class TraCILogic {
234 public:
236  TraCILogic(const std::string& _programID, const int _type, const int _currentPhaseIndex,
237  const std::vector<libsumo::TraCIPhase>& _phases = std::vector<libsumo::TraCIPhase>())
238  : programID(_programID), type(_type), currentPhaseIndex(_currentPhaseIndex), phases(_phases) {}
240 
241 #ifndef SWIGJAVA
242  std::vector<TraCIPhase> getPhases() {
243  return phases;
244  }
245 #endif
246  std::string programID;
247  int type;
249  std::vector<TraCIPhase> phases;
250  std::map<std::string, std::string> subParameter;
251 };
252 
253 
254 class TraCILink {
255 public:
256  TraCILink(const std::string& _from, const std::string& _via, const std::string& _to)
257  : fromLane(_from), viaLane(_via), toLane(_to) {}
259 
260  std::string fromLane;
261  std::string viaLane;
262  std::string toLane;
263 };
264 
265 
267 public:
268  TraCIConnection() {} // this is needed by SWIG when building a vector of this type, please don't use it
269  TraCIConnection(const std::string& _approachedLane, const bool _hasPrio, const bool _isOpen, const bool _hasFoe,
270  const std::string _approachedInternal, const std::string _state, const std::string _direction, const double _length)
271  : approachedLane(_approachedLane), hasPrio(_hasPrio), isOpen(_isOpen), hasFoe(_hasFoe),
272  approachedInternal(_approachedInternal), state(_state), direction(_direction), length(_length) {}
274 
275  std::string approachedLane;
276  bool hasPrio;
277  bool isOpen;
278  bool hasFoe;
279  std::string approachedInternal;
280  std::string state;
281  std::string direction;
282  double length;
283 };
284 
285 
289  std::string id;
291  double length;
293  double entryTime;
295  double leaveTime;
297  std::string typeID;
298 };
299 
300 
303  std::string id;
305  int tlIndex;
307  double dist;
309  char state;
310 };
311 
312 
315  std::string lane;
317  double endPos;
319  std::string stoppingPlaceID;
323  double duration;
325  double until;
326 };
327 
328 
331  std::string laneID;
333  double length;
335  double occupation;
341  std::vector<std::string> continuationLanes;
342 };
343 
344 
345 class TraCIStage {
346 public:
347  TraCIStage() {} // only to make swig happy
348  TraCIStage(int type) : type(type) {}
350  int type;
352  std::string vType;
354  std::string line;
356  std::string destStop;
358  std::vector<std::string> edges;
360  double travelTime;
362  double cost;
364  double length = INVALID_DOUBLE_VALUE;
366  std::string intended = "";
368  double depart = INVALID_DOUBLE_VALUE;
370  double departPos = INVALID_DOUBLE_VALUE;
372  double arrivalPos = INVALID_DOUBLE_VALUE;
374  std::string description = "";
375 };
376 }
377 
378 
379 #endif
380 
381 /****************************************************************************/
std::string value
Definition: TraCIDefs.h:183
std::string getString()
Definition: TraCIDefs.h:168
std::map< std::string, TraCIResults > SubscriptionResults
{object->{variable->value}}
Definition: TraCIDefs.h:204
std::string id
The id of the next tls.
Definition: TraCIDefs.h:303
int stopFlags
Stop flags.
Definition: TraCIDefs.h:321
int type
The type of stage (walking, driving, ...)
Definition: TraCIDefs.h:350
double leaveTime
Leave-time of the vehicle in [s].
Definition: TraCIDefs.h:295
double dist
The distance to the tls.
Definition: TraCIDefs.h:307
bool allowsContinuation
Whether this lane allows continuing the route.
Definition: TraCIDefs.h:339
std::string line
The line or the id of the vehicle type.
Definition: TraCIDefs.h:354
std::string typeID
Type of the vehicle in.
Definition: TraCIDefs.h:297
double until
The time at which the vehicle may continue its journey.
Definition: TraCIDefs.h:325
An edgeId, position and laneIndex.
Definition: TraCIDefs.h:122
TraCIDouble(double v)
Definition: TraCIDefs.h:167
mirrors MSInductLoop::VehicleData
Definition: TraCIDefs.h:287
std::string getString()
Definition: TraCIDefs.h:180
std::string destStop
The id of the destination stop.
Definition: TraCIDefs.h:356
TraCILogic(const std::string &_programID, const int _type, const int _currentPhaseIndex, const std::vector< libsumo::TraCIPhase > &_phases=std::vector< libsumo::TraCIPhase >())
Definition: TraCIDefs.h:236
std::map< int, std::shared_ptr< TraCIResult > > TraCIResults
{variable->value}
Definition: TraCIDefs.h:202
TraCIColor(int r, int g, int b, int a=255)
Definition: TraCIDefs.h:138
std::string name
Definition: TraCIDefs.h:222
double occupation
The traffic density along length.
Definition: TraCIDefs.h:335
std::string laneID
The id of the lane.
Definition: TraCIDefs.h:331
virtual ~TraCIResult()
Definition: TraCIDefs.h:101
std::map< std::string, std::string > subParameter
Definition: TraCIDefs.h:250
std::map< std::string, SubscriptionResults > ContextSubscriptionResults
Definition: TraCIDefs.h:205
TraCIConnection(const std::string &_approachedLane, const bool _hasPrio, const bool _isOpen, const bool _hasFoe, const std::string _approachedInternal, const std::string _state, const std::string _direction, const double _length)
Definition: TraCIDefs.h:269
std::vector< TraCIPhase > phases
Definition: TraCIDefs.h:249
double cost
effort needed
Definition: TraCIDefs.h:362
int bestLaneOffset
The offset of this lane from the best lane.
Definition: TraCIDefs.h:337
virtual std::string getString()
Definition: TraCIDefs.h:102
TRACI_CONST int INVALID_INT_VALUE
std::string approachedInternal
Definition: TraCIDefs.h:279
std::vector< TraCIPhase > getPhases()
Definition: TraCIDefs.h:242
std::string stoppingPlaceID
Id assigned to the stop.
Definition: TraCIDefs.h:319
std::vector< std::string > edges
The sequence of edges to travel.
Definition: TraCIDefs.h:358
double length
Length of the vehicle.
Definition: TraCIDefs.h:291
std::string id
The id of the vehicle.
Definition: TraCIDefs.h:289
double endPos
The stopping position end.
Definition: TraCIDefs.h:317
TraCIStage(int type)
Definition: TraCIDefs.h:348
std::string approachedLane
Definition: TraCIDefs.h:275
Definition: Edge.cpp:30
std::string vType
The vehicle type when using a private car or bike.
Definition: TraCIDefs.h:352
std::vector< std::string > value
Definition: TraCIDefs.h:197
std::string getString()
Definition: TraCIDefs.h:123
std::vector< TraCIPosition > TraCIPositionVector
Definition: TraCIDefs.h:150
std::string getString()
Definition: TraCIDefs.h:111
std::string programID
Definition: TraCIDefs.h:246
char state
The current state of the tls.
Definition: TraCIDefs.h:309
std::string getString()
Definition: TraCIDefs.h:156
double travelTime
duration of the stage in seconds
Definition: TraCIDefs.h:360
std::vector< int > next
Definition: TraCIDefs.h:221
TraCIException(std::string what)
Definition: TraCIDefs.h:93
std::string getString()
Definition: TraCIDefs.h:188
double length
The length than can be driven from that lane without lane change.
Definition: TraCIDefs.h:333
double entryTime
Entry-time of the vehicle in [s].
Definition: TraCIDefs.h:293
TraCIPhase(const double _duration, const std::string &_state, const double _minDur=libsumo::INVALID_DOUBLE_VALUE, const double _maxDur=libsumo::INVALID_DOUBLE_VALUE, const std::vector< int > &_next=std::vector< int >(), const std::string &_name="")
Definition: TraCIDefs.h:211
TraCIString(std::string v)
Definition: TraCIDefs.h:179
A 3D-position.
Definition: TraCIDefs.h:110
TRACI_CONST double INVALID_DOUBLE_VALUE
std::string state
Definition: TraCIDefs.h:219
int tlIndex
The tls index of the controlled link.
Definition: TraCIDefs.h:305
double duration
The stopping duration.
Definition: TraCIDefs.h:323
std::vector< std::string > continuationLanes
The sequence of lanes that best allows continuing the route without lane change.
Definition: TraCIDefs.h:341
std::string getString()
Definition: TraCIDefs.h:139
std::string lane
The lane to stop at.
Definition: TraCIDefs.h:315