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;
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 /****************************************************************************/
libsumo::TraCIInt::TraCIInt
TraCIInt()
Definition: TraCIDefs.h:154
libsumo::TraCILogic::getPhases
std::vector< TraCIPhase > getPhases()
Definition: TraCIDefs.h:242
libsumo::TraCIColor::TraCIColor
TraCIColor()
Definition: TraCIDefs.h:137
libsumo::TraCIString::TraCIString
TraCIString(std::string v)
Definition: TraCIDefs.h:179
libsumo::TraCINextStopData::duration
double duration
The stopping duration.
Definition: TraCIDefs.h:323
libsumo::INVALID_DOUBLE_VALUE
TRACI_CONST double INVALID_DOUBLE_VALUE
Definition: TraCIConstants.h:363
libsumo::TraCIInt::TraCIInt
TraCIInt(int v)
Definition: TraCIDefs.h:155
libsumo::TraCINextStopData::lane
std::string lane
The lane to stop at.
Definition: TraCIDefs.h:315
libsumo::TraCINextStopData::until
double until
The time at which the vehicle may continue its journey.
Definition: TraCIDefs.h:325
libsumo::TraCINextStopData::stopFlags
int stopFlags
Stop flags.
Definition: TraCIDefs.h:321
libsumo::TraCIResults
std::map< int, std::shared_ptr< TraCIResult > > TraCIResults
{variable->value}
Definition: TraCIDefs.h:202
libsumo::TraCIPosition
A 3D-position.
Definition: TraCIDefs.h:110
libsumo::TraCIConnection::approachedInternal
std::string approachedInternal
Definition: TraCIDefs.h:279
libsumo::TraCIPosition::x
double x
Definition: TraCIDefs.h:116
libsumo::TraCILogic::type
int type
Definition: TraCIDefs.h:247
libsumo::TraCIPhase::maxDur
double maxDur
Definition: TraCIDefs.h:220
libsumo::TraCIColor::a
int a
Definition: TraCIDefs.h:144
libsumo::TraCIBestLanesData::bestLaneOffset
int bestLaneOffset
The offset of this lane from the best lane.
Definition: TraCIDefs.h:337
libsumo::TraCIColor::g
int g
Definition: TraCIDefs.h:144
libsumo::TraCIVehicleData::leaveTime
double leaveTime
Leave-time of the vehicle in [s].
Definition: TraCIDefs.h:295
libsumo::ContextSubscriptionResults
std::map< std::string, SubscriptionResults > ContextSubscriptionResults
Definition: TraCIDefs.h:205
libsumo::TraCIString::TraCIString
TraCIString()
Definition: TraCIDefs.h:178
libsumo::TraCILogic::currentPhaseIndex
int currentPhaseIndex
Definition: TraCIDefs.h:248
libsumo::TraCINextTLSData::tlIndex
int tlIndex
The tls index of the controlled link.
Definition: TraCIDefs.h:305
libsumo::INVALID_INT_VALUE
TRACI_CONST int INVALID_INT_VALUE
Definition: TraCIConstants.h:365
libsumo::TraCIColor
A color.
Definition: TraCIDefs.h:136
libsumo::TraCIInt::value
int value
Definition: TraCIDefs.h:161
libsumo::TraCIVehicleData
mirrors MSInductLoop::VehicleData
Definition: TraCIDefs.h:287
libsumo::TraCIInt::getString
std::string getString()
Definition: TraCIDefs.h:156
libsumo::TraCIRoadPosition::edgeID
std::string edgeID
Definition: TraCIDefs.h:128
libsumo::TraCINextTLSData::dist
double dist
The distance to the tls.
Definition: TraCIDefs.h:307
libsumo::TraCIConnection::state
std::string state
Definition: TraCIDefs.h:280
libsumo::TraCIColor::b
int b
Definition: TraCIDefs.h:144
libsumo::TraCIString
Definition: TraCIDefs.h:177
libsumo::TraCINextStopData::stoppingPlaceID
std::string stoppingPlaceID
Id assigned to the stop.
Definition: TraCIDefs.h:319
libsumo::TraCIConnection::direction
std::string direction
Definition: TraCIDefs.h:281
libsumo::TraCIConnection::hasFoe
bool hasFoe
Definition: TraCIDefs.h:278
libsumo::TraCIResult::~TraCIResult
virtual ~TraCIResult()
Definition: TraCIDefs.h:101
libsumo::TraCIBestLanesData::allowsContinuation
bool allowsContinuation
Whether this lane allows continuing the route.
Definition: TraCIDefs.h:339
libsumo
Definition: Edge.cpp:30
libsumo::TraCIPhase::~TraCIPhase
~TraCIPhase()
Definition: TraCIDefs.h:216
libsumo::TraCIBestLanesData
Definition: TraCIDefs.h:329
libsumo::TraCILogic
Definition: TraCIDefs.h:233
libsumo::TraCINextTLSData::state
char state
The current state of the tls.
Definition: TraCIDefs.h:309
libsumo::TraCIStage::travelTime
double travelTime
duration of the stage in seconds
Definition: TraCIDefs.h:360
libsumo::TraCIStringList
Definition: TraCIDefs.h:187
libsumo::TraCIConnection::TraCIConnection
TraCIConnection()
Definition: TraCIDefs.h:268
libsumo::TraCIBestLanesData::occupation
double occupation
The traffic density along length.
Definition: TraCIDefs.h:335
libsumo::TraCIDouble::getString
std::string getString()
Definition: TraCIDefs.h:168
libsumo::TraCIPhase::TraCIPhase
TraCIPhase()
Definition: TraCIDefs.h:210
libsumo::TraCINextStopData::endPos
double endPos
The stopping position end.
Definition: TraCIDefs.h:317
libsumo::TraCIStage::TraCIStage
TraCIStage(int type)
Definition: TraCIDefs.h:348
TraCIConstants.h
libsumo::TraCIVehicleData::typeID
std::string typeID
Type of the vehicle in.
Definition: TraCIDefs.h:297
libsumo::TraCIBestLanesData::length
double length
The length than can be driven from that lane without lane change.
Definition: TraCIDefs.h:333
libsumo::TraCILogic::programID
std::string programID
Definition: TraCIDefs.h:246
libsumo::TraCIConnection::~TraCIConnection
~TraCIConnection()
Definition: TraCIDefs.h:273
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:236
libsumo::TraCIStage::line
std::string line
The line or the id of the vehicle type.
Definition: TraCIDefs.h:354
libsumo::TraCIConnection
Definition: TraCIDefs.h:266
libsumo::TraCIPhase::state
std::string state
Definition: TraCIDefs.h:219
libsumo::TraCIStage
Definition: TraCIDefs.h:345
libsumo::TraCIPosition::z
double z
Definition: TraCIDefs.h:116
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:269
libsumo::TraCIStringList::getString
std::string getString()
Definition: TraCIDefs.h:188
libsumo::TraCIString::value
std::string value
Definition: TraCIDefs.h:183
libsumo::TraCIString::getString
std::string getString()
Definition: TraCIDefs.h:180
libsumo::TraCIColor::getString
std::string getString()
Definition: TraCIDefs.h:139
libsumo::TraCIVehicleData::id
std::string id
The id of the vehicle.
Definition: TraCIDefs.h:289
libsumo::TraCIColor::r
int r
Definition: TraCIDefs.h:144
libsumo::TraCIBestLanesData::laneID
std::string laneID
The id of the lane.
Definition: TraCIDefs.h:331
libsumo::TraCIConnection::approachedLane
std::string approachedLane
Definition: TraCIDefs.h:275
libsumo::TraCIDouble::TraCIDouble
TraCIDouble(double v)
Definition: TraCIDefs.h:167
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:211
libsumo::TraCIPhase::minDur
double minDur
Definition: TraCIDefs.h:220
libsumo::TraCIResult
Definition: TraCIDefs.h:100
libsumo::TraCIPhase::duration
double duration
Definition: TraCIDefs.h:218
libsumo::TraCIInt
Definition: TraCIDefs.h:153
libsumo::TraCIDouble
Definition: TraCIDefs.h:165
libsumo::TraCIPhase::next
std::vector< int > next
Definition: TraCIDefs.h:221
libsumo::TraCIConnection::length
double length
Definition: TraCIDefs.h:282
libsumo::TraCIException
Definition: TraCIDefs.h:90
libsumo::TraCIDouble::value
double value
Definition: TraCIDefs.h:173
libsumo::TraCIVehicleData::length
double length
Length of the vehicle.
Definition: TraCIDefs.h:291
libsumo::TraCINextStopData
Definition: TraCIDefs.h:313
libsumo::TraCIColor::TraCIColor
TraCIColor(int r, int g, int b, int a=255)
Definition: TraCIDefs.h:138
libsumo::TraCINextTLSData::id
std::string id
The id of the next tls.
Definition: TraCIDefs.h:303
libsumo::TraCILogic::phases
std::vector< TraCIPhase > phases
Definition: TraCIDefs.h:249
libsumo::TraCIPhase
Definition: TraCIDefs.h:208
libsumo::TraCIConnection::hasPrio
bool hasPrio
Definition: TraCIDefs.h:276
libsumo::TraCIStage::type
int type
The type of stage (walking, driving, ...)
Definition: TraCIDefs.h:350
libsumo::TraCIStringList::value
std::vector< std::string > value
Definition: TraCIDefs.h:197
libsumo::TraCIDouble::TraCIDouble
TraCIDouble()
Definition: TraCIDefs.h:166
libsumo::TraCIStage::edges
std::vector< std::string > edges
The sequence of edges to travel.
Definition: TraCIDefs.h:358
libsumo::TraCIRoadPosition::pos
double pos
Definition: TraCIDefs.h:129
libsumo::TraCILogic::~TraCILogic
~TraCILogic()
Definition: TraCIDefs.h:239
libsumo::TraCIConnection::isOpen
bool isOpen
Definition: TraCIDefs.h:277
libsumo::TraCILogic::TraCILogic
TraCILogic()
Definition: TraCIDefs.h:235
libsumo::TraCINextTLSData
Definition: TraCIDefs.h:301
libsumo::TraCILogic::subParameter
std::map< std::string, std::string > subParameter
Definition: TraCIDefs.h:250
libsumo::TraCIRoadPosition
An edgeId, position and laneIndex.
Definition: TraCIDefs.h:122
libsumo::TraCIException::TraCIException
TraCIException(std::string what)
Definition: TraCIDefs.h:93
libsumo::TraCIPositionVector
std::vector< TraCIPosition > TraCIPositionVector
Definition: TraCIDefs.h:150
libsumo::TraCIBestLanesData::continuationLanes
std::vector< std::string > continuationLanes
The sequence of lanes that best allows continuing the route without lane change.
Definition: TraCIDefs.h:341
libsumo::TraCIPhase::name
std::string name
Definition: TraCIDefs.h:222
libsumo::TraCIStage::vType
std::string vType
The vehicle type when using a private car or bike.
Definition: TraCIDefs.h:352
libsumo::TraCIStage::destStop
std::string destStop
The id of the destination stop.
Definition: TraCIDefs.h:356
libsumo::TraCIPosition::getString
std::string getString()
Definition: TraCIDefs.h:111
libsumo::TraCIResult::getString
virtual std::string getString()
Definition: TraCIDefs.h:102
libsumo::TraCIStage::TraCIStage
TraCIStage()
Definition: TraCIDefs.h:347
libsumo::SubscriptionResults
std::map< std::string, TraCIResults > SubscriptionResults
{object->{variable->value}}
Definition: TraCIDefs.h:204
libsumo::TraCIRoadPosition::laneIndex
int laneIndex
Definition: TraCIDefs.h:130
libsumo::TraCIStage::cost
double cost
effort needed
Definition: TraCIDefs.h:362
libsumo::TraCIVehicleData::entryTime
double entryTime
Entry-time of the vehicle in [s].
Definition: TraCIDefs.h:293
libsumo::TraCIRoadPosition::getString
std::string getString()
Definition: TraCIDefs.h:123
libsumo::TraCIPosition::y
double y
Definition: TraCIDefs.h:116