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 /****************************************************************************/
17 // C++ TraCI client API implementation
18 /****************************************************************************/
19 #ifndef TraCIDefs_h
20 #define TraCIDefs_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 // we do not include config.h here, since we should be independent of a special sumo build
27 #include <libsumo/TraCIConstants.h>
28 #include <vector>
29 #include <limits>
30 #include <map>
31 #include <string>
32 #include <stdexcept>
33 #include <sstream>
34 #include <memory>
35 
36 
37 // ===========================================================================
38 // global definitions
39 // ===========================================================================
40 
41 #define LIBSUMO_SUBSCRIPTION_API \
42 static void subscribe(const std::string& objectID, const std::vector<int>& varIDs = std::vector<int>(), double begin = libsumo::INVALID_DOUBLE_VALUE, double end = libsumo::INVALID_DOUBLE_VALUE); \
43 static void subscribeContext(const std::string& objectID, int domain, double range, const std::vector<int>& varIDs = std::vector<int>(), double begin = libsumo::INVALID_DOUBLE_VALUE, double end = libsumo::INVALID_DOUBLE_VALUE); \
44 static void unsubscribeContext(const std::string& objectID, int domain, double range); \
45 static const SubscriptionResults getAllSubscriptionResults(); \
46 static const TraCIResults getSubscriptionResults(const std::string& objectID); \
47 static const ContextSubscriptionResults getAllContextSubscriptionResults(); \
48 static const SubscriptionResults getContextSubscriptionResults(const std::string& objectID);
49 
50 #define LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(CLASS, DOMAIN) \
51 void \
52 CLASS::subscribe(const std::string& objectID, const std::vector<int>& varIDs, double begin, double end) { \
53  libsumo::Helper::subscribe(CMD_SUBSCRIBE_##DOMAIN##_VARIABLE, objectID, varIDs, begin, end); \
54 } \
55 void \
56 CLASS::subscribeContext(const std::string& objectID, int domain, double range, const std::vector<int>& varIDs, double begin, double end) { \
57  libsumo::Helper::subscribe(CMD_SUBSCRIBE_##DOMAIN##_CONTEXT, objectID, varIDs, begin, end, domain, range); \
58 } \
59 void \
60 CLASS::unsubscribeContext(const std::string& objectID, int domain, double range) { \
61  libsumo::Helper::subscribe(CMD_SUBSCRIBE_##DOMAIN##_CONTEXT, objectID, std::vector<int>(), libsumo::INVALID_DOUBLE_VALUE, libsumo::INVALID_DOUBLE_VALUE, domain, range); \
62 } \
63 const SubscriptionResults \
64 CLASS::getAllSubscriptionResults() { \
65  return mySubscriptionResults; \
66 } \
67 const TraCIResults \
68 CLASS::getSubscriptionResults(const std::string& objectID) { \
69  return mySubscriptionResults[objectID]; \
70 } \
71 const ContextSubscriptionResults \
72 CLASS::getAllContextSubscriptionResults() { \
73  return myContextSubscriptionResults; \
74 } \
75 const SubscriptionResults \
76 CLASS::getContextSubscriptionResults(const std::string& objectID) { \
77  return myContextSubscriptionResults[objectID]; \
78 }
79 
80 
81 
82 // ===========================================================================
83 // class and type definitions
84 // ===========================================================================
85 namespace libsumo {
89 class TraCIException : public std::runtime_error {
90 public:
92  TraCIException(std::string what)
93  : std::runtime_error(what) {}
94 };
95 
98 
99 struct TraCIResult {
100  virtual ~TraCIResult() {}
101  virtual std::string getString() {
102  return "";
103  }
104 };
105 
110  std::string getString() {
111  std::ostringstream os;
112  os << "TraCIPosition(" << x << "," << y << "," << z << ")";
113  return os.str();
114  }
116 };
117 
122  std::string getString() {
123  std::ostringstream os;
124  os << "TraCIRoadPosition(" << edgeID << "_" << laneIndex << "," << pos << ")";
125  return os.str();
126  }
127  std::string edgeID;
128  double pos;
130 };
131 
136  TraCIColor() : r(0), g(0), b(0), a(255) {}
137  TraCIColor(int r, int g, int b, int a = 255) : r(r), g(g), b(b), a(a) {}
138  std::string getString() {
139  std::ostringstream os;
140  os << "TraCIColor(" << r << "," << g << "," << b << "," << a << ")";
141  return os.str();
142  }
143  int r, g, b, a;
144 };
145 
149 typedef std::vector<TraCIPosition> TraCIPositionVector;
150 
151 
153  TraCIInt() : value(0) {}
154  TraCIInt(int v) : value(v) {}
155  std::string getString() {
156  std::ostringstream os;
157  os << value;
158  return os.str();
159  }
160  int value;
161 };
162 
163 
165  TraCIDouble() : value(0.) {}
166  TraCIDouble(double v) : value(v) {}
167  std::string getString() {
168  std::ostringstream os;
169  os << value;
170  return os.str();
171  }
172  double value;
173 };
174 
175 
177  TraCIString() : value("") {}
178  TraCIString(std::string v) : value(v) {}
179  std::string getString() {
180  return value;
181  }
182  std::string value;
183 };
184 
185 
187  std::string getString() {
188  std::ostringstream os;
189  os << "[";
190  for (std::string v : value) {
191  os << v << ",";
192  }
193  os << "]";
194  return os.str();
195  }
196  std::vector<std::string> value;
197 };
198 
199 
201 typedef std::map<int, std::shared_ptr<TraCIResult> > TraCIResults;
203 typedef std::map<std::string, TraCIResults> SubscriptionResults;
204 typedef std::map<std::string, SubscriptionResults> ContextSubscriptionResults;
205 
206 
207 class TraCIPhase {
208 public:
210  TraCIPhase(const double _duration, const std::string& _state, const double _minDur = libsumo::INVALID_DOUBLE_VALUE,
211  const double _maxDur = libsumo::INVALID_DOUBLE_VALUE,
212  const std::vector<int>& _next = std::vector<int>(),
213  const std::string& _name = "") :
214  duration(_duration), state(_state), minDur(_minDur), maxDur(_maxDur), next(_next), name(_name) {}
216 
217  double duration;
218  std::string state;
219  double minDur, maxDur;
220  std::vector<int> next;
221  std::string name;
222 };
223 }
224 
225 
226 #ifdef SWIG
227 %template(TraCIPhaseVector) std::vector<libsumo::TraCIPhase>; // *NOPAD*
228 #endif
229 
230 
231 namespace libsumo {
232 class TraCILogic {
233 public:
235  TraCILogic(const std::string& _programID, const int _type, const int _currentPhaseIndex,
236  const std::vector<libsumo::TraCIPhase>& _phases = std::vector<libsumo::TraCIPhase>())
237  : programID(_programID), type(_type), currentPhaseIndex(_currentPhaseIndex), phases(_phases) {}
239 
240 #ifndef SWIGJAVA
241  std::vector<TraCIPhase> getPhases() {
242  return phases;
243  }
244 #endif
245  std::string programID;
246  int type;
248  std::vector<TraCIPhase> phases;
249  std::map<std::string, std::string> subParameter;
250 };
251 
252 
253 class TraCILink {
254 public:
255  TraCILink(const std::string& _from, const std::string& _via, const std::string& _to)
256  : fromLane(_from), viaLane(_via), toLane(_to) {}
258 
259  std::string fromLane;
260  std::string viaLane;
261  std::string toLane;
262 };
263 
264 
266 public:
267  TraCIConnection() {} // this is needed by SWIG when building a vector of this type, please don't use it
268  TraCIConnection(const std::string& _approachedLane, const bool _hasPrio, const bool _isOpen, const bool _hasFoe,
269  const std::string _approachedInternal, const std::string _state, const std::string _direction, const double _length)
270  : approachedLane(_approachedLane), hasPrio(_hasPrio), isOpen(_isOpen), hasFoe(_hasFoe),
271  approachedInternal(_approachedInternal), state(_state), direction(_direction), length(_length) {}
273 
274  std::string approachedLane;
275  bool hasPrio;
276  bool isOpen;
277  bool hasFoe;
278  std::string approachedInternal;
279  std::string state;
280  std::string direction;
281  double length;
282 };
283 
284 
288  std::string id;
290  double length;
292  double entryTime;
294  double leaveTime;
296  std::string typeID;
297 };
298 
299 
302  std::string id;
304  int tlIndex;
306  double dist;
308  char state;
309 };
310 
311 
314  std::string lane;
316  double endPos;
318  std::string stoppingPlaceID;
322  double duration;
324  double until;
325 };
326 
327 
330  std::string laneID;
332  double length;
334  double occupation;
340  std::vector<std::string> continuationLanes;
341 };
342 
343 
344 class TraCIStage {
345 public:
346  TraCIStage() {} // only to make swig happy
347  TraCIStage(int type) : type(type) {}
349  int type;
351  std::string vType;
353  std::string line;
355  std::string destStop;
357  std::vector<std::string> edges;
359  double travelTime;
361  double cost;
363  double length = INVALID_DOUBLE_VALUE;
365  std::string intended = "";
367  double depart = INVALID_DOUBLE_VALUE;
369  double departPos = INVALID_DOUBLE_VALUE;
371  double arrivalPos = INVALID_DOUBLE_VALUE;
373  std::string description = "";
374 };
375 }
376 
377 
378 #endif
379 
380 /****************************************************************************/
libsumo::TraCIInt::TraCIInt
TraCIInt()
Definition: TraCIDefs.h:153
libsumo::TraCILogic::getPhases
std::vector< TraCIPhase > getPhases()
Definition: TraCIDefs.h:241
libsumo::TraCIColor::TraCIColor
TraCIColor()
Definition: TraCIDefs.h:136
libsumo::TraCIString::TraCIString
TraCIString(std::string v)
Definition: TraCIDefs.h:178
libsumo::TraCINextStopData::duration
double duration
The stopping duration.
Definition: TraCIDefs.h:322
libsumo::INVALID_DOUBLE_VALUE
TRACI_CONST double INVALID_DOUBLE_VALUE
Definition: TraCIConstants.h:362
libsumo::TraCIInt::TraCIInt
TraCIInt(int v)
Definition: TraCIDefs.h:154
libsumo::TraCINextStopData::lane
std::string lane
The lane to stop at.
Definition: TraCIDefs.h:314
libsumo::TraCINextStopData::until
double until
The time at which the vehicle may continue its journey.
Definition: TraCIDefs.h:324
libsumo::TraCINextStopData::stopFlags
int stopFlags
Stop flags.
Definition: TraCIDefs.h:320
libsumo::TraCIResults
std::map< int, std::shared_ptr< TraCIResult > > TraCIResults
{variable->value}
Definition: TraCIDefs.h:201
libsumo::TraCIPosition
A 3D-position.
Definition: TraCIDefs.h:109
libsumo::TraCIConnection::approachedInternal
std::string approachedInternal
Definition: TraCIDefs.h:278
libsumo::TraCIPosition::x
double x
Definition: TraCIDefs.h:115
libsumo::TraCILogic::type
int type
Definition: TraCIDefs.h:246
libsumo::TraCIPhase::maxDur
double maxDur
Definition: TraCIDefs.h:219
libsumo::TraCIColor::a
int a
Definition: TraCIDefs.h:143
libsumo::TraCIBestLanesData::bestLaneOffset
int bestLaneOffset
The offset of this lane from the best lane.
Definition: TraCIDefs.h:336
libsumo::TraCIColor::g
int g
Definition: TraCIDefs.h:143
libsumo::TraCIVehicleData::leaveTime
double leaveTime
Leave-time of the vehicle in [s].
Definition: TraCIDefs.h:294
libsumo::ContextSubscriptionResults
std::map< std::string, SubscriptionResults > ContextSubscriptionResults
Definition: TraCIDefs.h:204
libsumo::TraCIString::TraCIString
TraCIString()
Definition: TraCIDefs.h:177
libsumo::TraCILogic::currentPhaseIndex
int currentPhaseIndex
Definition: TraCIDefs.h:247
libsumo::TraCINextTLSData::tlIndex
int tlIndex
The tls index of the controlled link.
Definition: TraCIDefs.h:304
libsumo::INVALID_INT_VALUE
TRACI_CONST int INVALID_INT_VALUE
Definition: TraCIConstants.h:364
libsumo::TraCIColor
A color.
Definition: TraCIDefs.h:135
libsumo::TraCIInt::value
int value
Definition: TraCIDefs.h:160
libsumo::TraCIVehicleData
mirrors MSInductLoop::VehicleData
Definition: TraCIDefs.h:286
libsumo::TraCIInt::getString
std::string getString()
Definition: TraCIDefs.h:155
libsumo::TraCIRoadPosition::edgeID
std::string edgeID
Definition: TraCIDefs.h:127
libsumo::TraCINextTLSData::dist
double dist
The distance to the tls.
Definition: TraCIDefs.h:306
libsumo::TraCIConnection::state
std::string state
Definition: TraCIDefs.h:279
libsumo::TraCIColor::b
int b
Definition: TraCIDefs.h:143
libsumo::TraCIString
Definition: TraCIDefs.h:176
libsumo::TraCINextStopData::stoppingPlaceID
std::string stoppingPlaceID
Id assigned to the stop.
Definition: TraCIDefs.h:318
libsumo::TraCIConnection::direction
std::string direction
Definition: TraCIDefs.h:280
libsumo::TraCIConnection::hasFoe
bool hasFoe
Definition: TraCIDefs.h:277
libsumo::TraCIResult::~TraCIResult
virtual ~TraCIResult()
Definition: TraCIDefs.h:100
libsumo::TraCIBestLanesData::allowsContinuation
bool allowsContinuation
Whether this lane allows continuing the route.
Definition: TraCIDefs.h:338
libsumo
Definition: Edge.cpp:29
libsumo::TraCIPhase::~TraCIPhase
~TraCIPhase()
Definition: TraCIDefs.h:215
libsumo::TraCIBestLanesData
Definition: TraCIDefs.h:328
libsumo::TraCILogic
Definition: TraCIDefs.h:232
libsumo::TraCINextTLSData::state
char state
The current state of the tls.
Definition: TraCIDefs.h:308
libsumo::TraCIStage::travelTime
double travelTime
duration of the stage in seconds
Definition: TraCIDefs.h:359
libsumo::TraCIStringList
Definition: TraCIDefs.h:186
libsumo::TraCIConnection::TraCIConnection
TraCIConnection()
Definition: TraCIDefs.h:267
libsumo::TraCIBestLanesData::occupation
double occupation
The traffic density along length.
Definition: TraCIDefs.h:334
libsumo::TraCIDouble::getString
std::string getString()
Definition: TraCIDefs.h:167
libsumo::TraCIPhase::TraCIPhase
TraCIPhase()
Definition: TraCIDefs.h:209
libsumo::TraCINextStopData::endPos
double endPos
The stopping position end.
Definition: TraCIDefs.h:316
libsumo::TraCIStage::TraCIStage
TraCIStage(int type)
Definition: TraCIDefs.h:347
TraCIConstants.h
libsumo::TraCIVehicleData::typeID
std::string typeID
Type of the vehicle in.
Definition: TraCIDefs.h:296
libsumo::TraCIBestLanesData::length
double length
The length than can be driven from that lane without lane change.
Definition: TraCIDefs.h:332
libsumo::TraCILogic::programID
std::string programID
Definition: TraCIDefs.h:245
libsumo::TraCIConnection::~TraCIConnection
~TraCIConnection()
Definition: TraCIDefs.h:272
libsumo::TraCILogic::TraCILogic
TraCILogic(const std::string &_programID, const int _type, const int _currentPhaseIndex, const std::vector< libsumo::TraCIPhase > &_phases=std::vector< libsumo::TraCIPhase >())
Definition: TraCIDefs.h:235
libsumo::TraCIStage::line
std::string line
The line or the id of the vehicle type.
Definition: TraCIDefs.h:353
libsumo::TraCIConnection
Definition: TraCIDefs.h:265
libsumo::TraCIPhase::state
std::string state
Definition: TraCIDefs.h:218
libsumo::TraCIStage
Definition: TraCIDefs.h:344
libsumo::TraCIPosition::z
double z
Definition: TraCIDefs.h:115
libsumo::TraCIConnection::TraCIConnection
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:268
libsumo::TraCIStringList::getString
std::string getString()
Definition: TraCIDefs.h:187
libsumo::TraCIString::value
std::string value
Definition: TraCIDefs.h:182
libsumo::TraCIString::getString
std::string getString()
Definition: TraCIDefs.h:179
libsumo::TraCIColor::getString
std::string getString()
Definition: TraCIDefs.h:138
libsumo::TraCIVehicleData::id
std::string id
The id of the vehicle.
Definition: TraCIDefs.h:288
libsumo::TraCIColor::r
int r
Definition: TraCIDefs.h:143
libsumo::TraCIBestLanesData::laneID
std::string laneID
The id of the lane.
Definition: TraCIDefs.h:330
libsumo::TraCIConnection::approachedLane
std::string approachedLane
Definition: TraCIDefs.h:274
libsumo::TraCIDouble::TraCIDouble
TraCIDouble(double v)
Definition: TraCIDefs.h:166
libsumo::TraCIPhase::TraCIPhase
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:210
libsumo::TraCIPhase::minDur
double minDur
Definition: TraCIDefs.h:219
libsumo::TraCIResult
Definition: TraCIDefs.h:99
libsumo::TraCIPhase::duration
double duration
Definition: TraCIDefs.h:217
libsumo::TraCIInt
Definition: TraCIDefs.h:152
libsumo::TraCIDouble
Definition: TraCIDefs.h:164
libsumo::TraCIPhase::next
std::vector< int > next
Definition: TraCIDefs.h:220
libsumo::TraCIConnection::length
double length
Definition: TraCIDefs.h:281
libsumo::TraCIException
Definition: TraCIDefs.h:89
libsumo::TraCIDouble::value
double value
Definition: TraCIDefs.h:172
libsumo::TraCIVehicleData::length
double length
Length of the vehicle.
Definition: TraCIDefs.h:290
libsumo::TraCINextStopData
Definition: TraCIDefs.h:312
libsumo::TraCIColor::TraCIColor
TraCIColor(int r, int g, int b, int a=255)
Definition: TraCIDefs.h:137
libsumo::TraCINextTLSData::id
std::string id
The id of the next tls.
Definition: TraCIDefs.h:302
libsumo::TraCILogic::phases
std::vector< TraCIPhase > phases
Definition: TraCIDefs.h:248
libsumo::TraCIPhase
Definition: TraCIDefs.h:207
libsumo::TraCIConnection::hasPrio
bool hasPrio
Definition: TraCIDefs.h:275
libsumo::TraCIStage::type
int type
The type of stage (walking, driving, ...)
Definition: TraCIDefs.h:349
libsumo::TraCIStringList::value
std::vector< std::string > value
Definition: TraCIDefs.h:196
libsumo::TraCIDouble::TraCIDouble
TraCIDouble()
Definition: TraCIDefs.h:165
libsumo::TraCIStage::edges
std::vector< std::string > edges
The sequence of edges to travel.
Definition: TraCIDefs.h:357
libsumo::TraCIRoadPosition::pos
double pos
Definition: TraCIDefs.h:128
libsumo::TraCILogic::~TraCILogic
~TraCILogic()
Definition: TraCIDefs.h:238
libsumo::TraCIConnection::isOpen
bool isOpen
Definition: TraCIDefs.h:276
libsumo::TraCILogic::TraCILogic
TraCILogic()
Definition: TraCIDefs.h:234
libsumo::TraCINextTLSData
Definition: TraCIDefs.h:300
libsumo::TraCILogic::subParameter
std::map< std::string, std::string > subParameter
Definition: TraCIDefs.h:249
libsumo::TraCIRoadPosition
An edgeId, position and laneIndex.
Definition: TraCIDefs.h:121
libsumo::TraCIException::TraCIException
TraCIException(std::string what)
Definition: TraCIDefs.h:92
libsumo::TraCIPositionVector
std::vector< TraCIPosition > TraCIPositionVector
Definition: TraCIDefs.h:149
libsumo::TraCIBestLanesData::continuationLanes
std::vector< std::string > continuationLanes
The sequence of lanes that best allows continuing the route without lane change.
Definition: TraCIDefs.h:340
libsumo::TraCIPhase::name
std::string name
Definition: TraCIDefs.h:221
libsumo::TraCIStage::vType
std::string vType
The vehicle type when using a private car or bike.
Definition: TraCIDefs.h:351
libsumo::TraCIStage::destStop
std::string destStop
The id of the destination stop.
Definition: TraCIDefs.h:355
libsumo::TraCIPosition::getString
std::string getString()
Definition: TraCIDefs.h:110
libsumo::TraCIResult::getString
virtual std::string getString()
Definition: TraCIDefs.h:101
libsumo::TraCIStage::TraCIStage
TraCIStage()
Definition: TraCIDefs.h:346
libsumo::SubscriptionResults
std::map< std::string, TraCIResults > SubscriptionResults
{object->{variable->value}}
Definition: TraCIDefs.h:203
libsumo::TraCIRoadPosition::laneIndex
int laneIndex
Definition: TraCIDefs.h:129
libsumo::TraCIStage::cost
double cost
effort needed
Definition: TraCIDefs.h:361
libsumo::TraCIVehicleData::entryTime
double entryTime
Entry-time of the vehicle in [s].
Definition: TraCIDefs.h:292
libsumo::TraCIRoadPosition::getString
std::string getString()
Definition: TraCIDefs.h:122
libsumo::TraCIPosition::y
double y
Definition: TraCIDefs.h:115