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 #define DEFAULT_VIEW "View #0"
42 #define PRECISION 2
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(" << r << "," << g << "," << b << "," << 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 double _duration1, const double _duration2, const std::string& _phase)
207  : duration(_duration), duration1(_duration1), duration2(_duration2), phase(_phase) {}
209 
210  double duration, duration1, duration2;
211  std::string phase;
212 };
213 
214 
215 class TraCILogic {
216 public:
218  TraCILogic(const std::string& _subID, int _type, int _currentPhaseIndex, const std::vector<TraCIPhase>& _phases = std::vector<TraCIPhase>())
219  : subID(_subID), type(_type), currentPhaseIndex(_currentPhaseIndex), phases(_phases) {}
221 
222  std::string subID;
223  int type;
225  std::vector<TraCIPhase> phases;
226  std::map<std::string, std::string> subParameter;
227 };
228 
229 
230 class TraCILink {
231 public:
232  TraCILink(const std::string& _from, const std::string& _via, const std::string& _to)
233  : fromLane(_from), viaLane(_via), toLane(_to) {}
235 
236  std::string fromLane;
237  std::string viaLane;
238  std::string toLane;
239 };
240 
241 
243 public:
244  TraCIConnection() {} // this is needed by SWIG when building a vector of this type, please don't use it
245  TraCIConnection(const std::string& _approachedLane, const bool _hasPrio, const bool _isOpen, const bool _hasFoe,
246  const std::string _approachedInternal, const std::string _state, const std::string _direction, const double _length)
247  : approachedLane(_approachedLane), hasPrio(_hasPrio), isOpen(_isOpen), hasFoe(_hasFoe),
248  approachedInternal(_approachedInternal), state(_state), direction(_direction), length(_length) {}
250 
251  std::string approachedLane;
252  bool hasPrio;
253  bool isOpen;
254  bool hasFoe;
255  std::string approachedInternal;
256  std::string state;
257  std::string direction;
258  double length;
259 };
260 
261 
265  std::string id;
267  double length;
269  double entryTime;
271  double leaveTime;
273  std::string typeID;
274 };
275 
276 
279  std::string id;
281  int tlIndex;
283  double dist;
285  char state;
286 };
287 
288 
291  std::string lane;
293  double endPos;
295  std::string stoppingPlaceID;
299  double duration;
301  double until;
302 };
303 
304 
307  std::string laneID;
309  double length;
311  double occupation;
317  std::vector<std::string> continuationLanes;
318 };
319 
320 
321 class TraCIStage {
322 public:
323  TraCIStage() {} // only to make swig happy
324  TraCIStage(int _type) : type(_type), depart(-1) {}
326  int type;
328  std::string line;
330  std::string destStop;
332  std::vector<std::string> edges;
334  double travelTime;
336  double cost;
338  std::string intended;
340  double depart;
342  double departPos;
344  double arrivalPos;
346  std::string description;
347 };
348 }
349 
350 
351 #endif
352 
353 /****************************************************************************/
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
TraCILogic(const std::string &_subID, int _type, int _currentPhaseIndex, const std::vector< TraCIPhase > &_phases=std::vector< TraCIPhase >())
Definition: TraCIDefs.h:218
std::string id
The id of the next tls.
Definition: TraCIDefs.h:279
int stopFlags
Stop flags.
Definition: TraCIDefs.h:297
std::string phase
Definition: TraCIDefs.h:211
int type
The type of stage (walking, driving, ...)
Definition: TraCIDefs.h:326
double leaveTime
Leave-time of the vehicle in [s].
Definition: TraCIDefs.h:271
double dist
The distance to the tls.
Definition: TraCIDefs.h:283
bool allowsContinuation
Whether this lane allows continuing the route.
Definition: TraCIDefs.h:315
std::string line
The line or the id of the vehicle type.
Definition: TraCIDefs.h:328
std::string typeID
Type of the vehicle in.
Definition: TraCIDefs.h:273
double until
The time at which the vehicle may continue its journey.
Definition: TraCIDefs.h:301
An edgeId, position and laneIndex.
Definition: TraCIDefs.h:119
TraCIDouble(double v)
Definition: TraCIDefs.h:162
mirrors MSInductLoop::VehicleData
Definition: TraCIDefs.h:263
TraCIStage(int _type)
Definition: TraCIDefs.h:324
double arrivalPos
position on the lane when ending the stage
Definition: TraCIDefs.h:344
std::string getString()
Definition: TraCIDefs.h:175
std::string destStop
The id of the destination stop.
Definition: TraCIDefs.h:330
std::map< int, std::shared_ptr< TraCIResult > > TraCIResults
{variable->value}
Definition: TraCIDefs.h:197
double occupation
The traffic density along length.
Definition: TraCIDefs.h:311
TraCIPhase(const double _duration, const double _duration1, const double _duration2, const std::string &_phase)
Definition: TraCIDefs.h:206
std::string laneID
The id of the lane.
Definition: TraCIDefs.h:307
virtual ~TraCIResult()
Definition: TraCIDefs.h:98
std::map< std::string, std::string > subParameter
Definition: TraCIDefs.h:226
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:245
double depart
intended depart time for public transport ride or -1
Definition: TraCIDefs.h:340
std::vector< TraCIPhase > phases
Definition: TraCIDefs.h:225
double departPos
position on the lane when starting the stage
Definition: TraCIDefs.h:342
double cost
effort needed
Definition: TraCIDefs.h:336
std::string description
arbitrary description string
Definition: TraCIDefs.h:346
int bestLaneOffset
The offset of this lane from the best lane.
Definition: TraCIDefs.h:313
virtual std::string getString()
Definition: TraCIDefs.h:99
std::string approachedInternal
Definition: TraCIDefs.h:255
std::string stoppingPlaceID
Id assigned to the stop.
Definition: TraCIDefs.h:295
std::vector< std::string > edges
The sequence of edges to travel.
Definition: TraCIDefs.h:332
double length
Length of the vehicle.
Definition: TraCIDefs.h:267
std::string id
The id of the vehicle.
Definition: TraCIDefs.h:265
unsigned char r
Definition: TraCIDefs.h:139
double endPos
The stopping position end.
Definition: TraCIDefs.h:293
std::string approachedLane
Definition: TraCIDefs.h:251
Definition: Edge.cpp:30
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
char state
The current state of the tls.
Definition: TraCIDefs.h:285
std::string getString()
Definition: TraCIDefs.h:151
double travelTime
duration of the stage
Definition: TraCIDefs.h:334
std::string subID
Definition: TraCIDefs.h:222
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:309
std::string intended
id of the intended vehicle for public transport ride
Definition: TraCIDefs.h:338
double entryTime
Entry-time of the vehicle in [s].
Definition: TraCIDefs.h:269
TraCIString(std::string v)
Definition: TraCIDefs.h:174
A 3D-position.
Definition: TraCIDefs.h:107
int tlIndex
The tls index of the controlled link.
Definition: TraCIDefs.h:281
double duration
The stopping duration.
Definition: TraCIDefs.h:299
std::vector< std::string > continuationLanes
The sequence of lanes that best allows continuing the route without lane change.
Definition: TraCIDefs.h:317
std::string getString()
Definition: TraCIDefs.h:134
std::string lane
The lane to stop at.
Definition: TraCIDefs.h:291