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-2018 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 #include <config.h>
28 
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 // value for invalid queries
42 #define INVALID_DOUBLE_VALUE -1073741824
43 
44 #define LIBSUMO_SUBSCRIPTION_API \
45 static void subscribe(const std::string& objID, const std::vector<int>& vars = std::vector<int>(), double beginTime = INVALID_DOUBLE_VALUE, double endTime = INVALID_DOUBLE_VALUE); \
46 static void subscribeContext(const std::string& objID, int domain, double range, const std::vector<int>& vars = std::vector<int>(), double beginTime = INVALID_DOUBLE_VALUE, double endTime = INVALID_DOUBLE_VALUE); \
47 static const SubscriptionResults getAllSubscriptionResults(); \
48 static const TraCIResults getSubscriptionResults(const std::string& objID); \
49 static const ContextSubscriptionResults getAllContextSubscriptionResults(); \
50 static const SubscriptionResults getContextSubscriptionResults(const std::string& objID);
51 
52 #define LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(CLASS, DOMAIN) \
53 void \
54 CLASS::subscribe(const std::string& objID, const std::vector<int>& vars, double beginTime, double endTime) { \
55  libsumo::Helper::subscribe(CMD_SUBSCRIBE_##DOMAIN##_VARIABLE, objID, vars, beginTime, endTime); \
56 } \
57 void \
58 CLASS::subscribeContext(const std::string& objID, int domain, double range, const std::vector<int>& vars, double beginTime, double endTime) { \
59  libsumo::Helper::subscribe(CMD_SUBSCRIBE_##DOMAIN##_CONTEXT, objID, vars, beginTime, endTime, domain, range); \
60 } \
61 const SubscriptionResults \
62 CLASS::getAllSubscriptionResults() { \
63  return mySubscriptionResults; \
64 } \
65 const TraCIResults \
66 CLASS::getSubscriptionResults(const std::string& objID) { \
67  return mySubscriptionResults[objID]; \
68 } \
69 const ContextSubscriptionResults \
70 CLASS::getAllContextSubscriptionResults() { \
71  return myContextSubscriptionResults; \
72 } \
73 const SubscriptionResults \
74 CLASS::getContextSubscriptionResults(const std::string& objID) { \
75  return myContextSubscriptionResults[objID]; \
76 }
77 
78 
79 
80 // ===========================================================================
81 // class and type definitions
82 // ===========================================================================
83 namespace libsumo {
87 class TraCIException : public std::runtime_error {
88 public:
90  TraCIException(std::string what)
91  : std::runtime_error(what) {}
92 };
93 
96 
97 struct TraCIResult {
98  virtual ~TraCIResult() {}
99  virtual std::string getString() {
100  return "";
101  }
102 };
103 
108  std::string getString() {
109  std::ostringstream os;
110  os << "TraCIPosition(" << x << "," << y << "," << z << ")";
111  return os.str();
112  }
113  double x, y, z;
114 };
115 
120  std::string getString() {
121  std::ostringstream os;
122  os << "TraCIRoadPosition(" << edgeID << "_" << laneIndex << "," << pos << ")";
123  return os.str();
124  }
125  std::string edgeID;
126  double pos;
128 };
129 
134  std::string getString() {
135  std::ostringstream os;
136  os << "TraCIColor(" << (int)r << "," << (int)g << "," << (int)b << "," << (int)a << ")";
137  return os.str();
138  }
139  unsigned char r, g, b, a;
140 };
141 
145 typedef std::vector<TraCIPosition> TraCIPositionVector;
146 
147 
149  TraCIInt() : value(0) {}
150  TraCIInt(int v) : value(v) {}
151  std::string getString() {
152  std::ostringstream os;
153  os << value;
154  return os.str();
155  }
156  int value;
157 };
158 
159 
161  TraCIDouble() : value(0.) {}
162  TraCIDouble(double v) : value(v) {}
163  std::string getString() {
164  std::ostringstream os;
165  os << value;
166  return os.str();
167  }
168  double value;
169 };
170 
171 
173  TraCIString() : value("") {}
174  TraCIString(std::string v) : value(v) {}
175  std::string getString() {
176  return value;
177  }
178  std::string value;
179 };
180 
181 
183  std::string getString() {
184  std::ostringstream os;
185  os << "[";
186  for (std::string v : value) {
187  os << v << ",";
188  }
189  os << "]";
190  return os.str();
191  }
192  std::vector<std::string> value;
193 };
194 
195 
197 typedef std::map<int, std::shared_ptr<TraCIResult> > TraCIResults;
199 typedef std::map<std::string, TraCIResults> SubscriptionResults;
200 typedef std::map<std::string, SubscriptionResults> ContextSubscriptionResults;
201 
202 
203 class TraCIPhase {
204 public:
206  TraCIPhase(const double _duration, const std::string& _state, const double _minDur = INVALID_DOUBLE_VALUE, const double _maxDur = INVALID_DOUBLE_VALUE, const int _next = -1)
207  : duration(_duration), state(_state), minDur(_minDur), maxDur(_maxDur), next(_next) {}
209 
210  double duration;
211  std::string state;
212  double minDur, maxDur;
213  int next;
214 };
215 }
216 
217 
218 #ifdef SWIG
219 %template(TraCIPhaseVector) std::vector<libsumo::TraCIPhase>;
220 #endif
221 
222 
223 namespace libsumo {
224 class TraCILogic {
225 public:
227  TraCILogic(const std::string& _programID, const int _type, const int _currentPhaseIndex)
228  : programID(_programID), type(_type), currentPhaseIndex(_currentPhaseIndex) {}
230 
231  std::string programID;
232  int type;
234  std::vector<TraCIPhase> phases;
235  std::map<std::string, std::string> subParameter;
236 };
237 
238 
239 class TraCILink {
240 public:
241  TraCILink(const std::string& _from, const std::string& _via, const std::string& _to)
242  : fromLane(_from), viaLane(_via), toLane(_to) {}
244 
245  std::string fromLane;
246  std::string viaLane;
247  std::string toLane;
248 };
249 
250 
252 public:
253  TraCIConnection() {} // this is needed by SWIG when building a vector of this type, please don't use it
254  TraCIConnection(const std::string& _approachedLane, const bool _hasPrio, const bool _isOpen, const bool _hasFoe,
255  const std::string _approachedInternal, const std::string _state, const std::string _direction, const double _length)
256  : approachedLane(_approachedLane), hasPrio(_hasPrio), isOpen(_isOpen), hasFoe(_hasFoe),
257  approachedInternal(_approachedInternal), state(_state), direction(_direction), length(_length) {}
259 
260  std::string approachedLane;
261  bool hasPrio;
262  bool isOpen;
263  bool hasFoe;
264  std::string approachedInternal;
265  std::string state;
266  std::string direction;
267  double length;
268 };
269 
270 
274  std::string id;
276  double length;
278  double entryTime;
280  double leaveTime;
282  std::string typeID;
283 };
284 
285 
288  std::string id;
290  int tlIndex;
292  double dist;
294  char state;
295 };
296 
297 
300  std::string lane;
302  double endPos;
304  std::string stoppingPlaceID;
308  double duration;
310  double until;
311 };
312 
313 
316  std::string laneID;
318  double length;
320  double occupation;
326  std::vector<std::string> continuationLanes;
327 };
328 
329 
330 class TraCIStage {
331 public:
332  TraCIStage() {} // only to make swig happy
333  TraCIStage(int _type) : type(_type), depart(-1) {}
335  int type;
337  std::string vType;
339  std::string line;
341  std::string destStop;
343  std::vector<std::string> edges;
345  double travelTime;
347  double cost;
349  double length;
351  std::string intended;
353  double depart;
355  double departPos;
357  double arrivalPos;
359  std::string description;
360 };
361 }
362 
363 
364 #endif
365 
366 /****************************************************************************/
std::string value
Definition: TraCIDefs.h:178
std::string getString()
Definition: TraCIDefs.h:163
std::map< std::string, TraCIResults > SubscriptionResults
{object->{variable->value}}
Definition: TraCIDefs.h:199
std::string id
The id of the next tls.
Definition: TraCIDefs.h:288
int stopFlags
Stop flags.
Definition: TraCIDefs.h:306
int type
The type of stage (walking, driving, ...)
Definition: TraCIDefs.h:335
TraCILogic(const std::string &_programID, const int _type, const int _currentPhaseIndex)
Definition: TraCIDefs.h:227
double leaveTime
Leave-time of the vehicle in [s].
Definition: TraCIDefs.h:280
double dist
The distance to the tls.
Definition: TraCIDefs.h:292
bool allowsContinuation
Whether this lane allows continuing the route.
Definition: TraCIDefs.h:324
std::string line
The line or the id of the vehicle type.
Definition: TraCIDefs.h:339
std::string typeID
Type of the vehicle in.
Definition: TraCIDefs.h:282
double until
The time at which the vehicle may continue its journey.
Definition: TraCIDefs.h:310
An edgeId, position and laneIndex.
Definition: TraCIDefs.h:119
TraCIDouble(double v)
Definition: TraCIDefs.h:162
mirrors MSInductLoop::VehicleData
Definition: TraCIDefs.h:272
TraCIStage(int _type)
Definition: TraCIDefs.h:333
double arrivalPos
position on the lane when ending the stage
Definition: TraCIDefs.h:357
double length
length in m
Definition: TraCIDefs.h:349
std::string getString()
Definition: TraCIDefs.h:175
std::string destStop
The id of the destination stop.
Definition: TraCIDefs.h:341
std::map< int, std::shared_ptr< TraCIResult > > TraCIResults
{variable->value}
Definition: TraCIDefs.h:197
double occupation
The traffic density along length.
Definition: TraCIDefs.h:320
std::string laneID
The id of the lane.
Definition: TraCIDefs.h:316
virtual ~TraCIResult()
Definition: TraCIDefs.h:98
std::map< std::string, std::string > subParameter
Definition: TraCIDefs.h:235
std::map< std::string, SubscriptionResults > ContextSubscriptionResults
Definition: TraCIDefs.h:200
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:254
double depart
intended depart time for public transport ride or -1
Definition: TraCIDefs.h:353
std::vector< TraCIPhase > phases
Definition: TraCIDefs.h:234
double departPos
position on the lane when starting the stage
Definition: TraCIDefs.h:355
double cost
effort needed
Definition: TraCIDefs.h:347
std::string description
arbitrary description string
Definition: TraCIDefs.h:359
int bestLaneOffset
The offset of this lane from the best lane.
Definition: TraCIDefs.h:322
#define INVALID_DOUBLE_VALUE
Definition: TraCIDefs.h:42
virtual std::string getString()
Definition: TraCIDefs.h:99
std::string approachedInternal
Definition: TraCIDefs.h:264
std::string stoppingPlaceID
Id assigned to the stop.
Definition: TraCIDefs.h:304
std::vector< std::string > edges
The sequence of edges to travel.
Definition: TraCIDefs.h:343
double length
Length of the vehicle.
Definition: TraCIDefs.h:276
std::string id
The id of the vehicle.
Definition: TraCIDefs.h:274
unsigned char r
Definition: TraCIDefs.h:139
double endPos
The stopping position end.
Definition: TraCIDefs.h:302
std::string approachedLane
Definition: TraCIDefs.h:260
Definition: Edge.cpp:30
std::string vType
The vehicle type when using a private car or bike.
Definition: TraCIDefs.h:337
TraCIPhase(const double _duration, const std::string &_state, const double _minDur=INVALID_DOUBLE_VALUE, const double _maxDur=INVALID_DOUBLE_VALUE, const int _next=-1)
Definition: TraCIDefs.h:206
std::vector< std::string > value
Definition: TraCIDefs.h:192
std::string getString()
Definition: TraCIDefs.h:120
std::vector< TraCIPosition > TraCIPositionVector
Definition: TraCIDefs.h:145
std::string getString()
Definition: TraCIDefs.h:108
std::string programID
Definition: TraCIDefs.h:231
char state
The current state of the tls.
Definition: TraCIDefs.h:294
std::string getString()
Definition: TraCIDefs.h:151
double travelTime
duration of the stage in seconds
Definition: TraCIDefs.h:345
TraCIException(std::string what)
Definition: TraCIDefs.h:90
std::string getString()
Definition: TraCIDefs.h:183
double length
The length than can be driven from that lane without lane change.
Definition: TraCIDefs.h:318
std::string intended
id of the intended vehicle for public transport ride
Definition: TraCIDefs.h:351
double entryTime
Entry-time of the vehicle in [s].
Definition: TraCIDefs.h:278
TraCIString(std::string v)
Definition: TraCIDefs.h:174
A 3D-position.
Definition: TraCIDefs.h:107
std::string state
Definition: TraCIDefs.h:211
int tlIndex
The tls index of the controlled link.
Definition: TraCIDefs.h:290
double duration
The stopping duration.
Definition: TraCIDefs.h:308
std::vector< std::string > continuationLanes
The sequence of lanes that best allows continuing the route without lane change.
Definition: TraCIDefs.h:326
std::string getString()
Definition: TraCIDefs.h:134
std::string lane
The lane to stop at.
Definition: TraCIDefs.h:300