Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2012-2025 German Aerospace Center (DLR) and others.
4 : // This program and the accompanying materials are made available under the
5 : // terms of the Eclipse Public License 2.0 which is available at
6 : // https://www.eclipse.org/legal/epl-2.0/
7 : // This Source Code may also be made available under the following Secondary
8 : // Licenses when the conditions for such availability set forth in the Eclipse
9 : // Public License 2.0 are satisfied: GNU General Public License, version 2
10 : // or later which is available at
11 : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 : /****************************************************************************/
14 : /// @file TraCIDefs.h
15 : /// @author Daniel Krajzewicz
16 : /// @author Mario Krumnow
17 : /// @author Michael Behrisch
18 : /// @author Robert Hilbrich
19 : /// @date 30.05.2012
20 : ///
21 : // C++ TraCI client API implementation
22 : /****************************************************************************/
23 : #pragma once
24 : // we do not include config.h here, since we should be independent of a special sumo build
25 : // but we want to avoid certain warnings in MSVC see config.h.cmake for details
26 : #ifdef _MSC_VER
27 : #pragma warning(push)
28 : #pragma warning(disable: 4514 4820)
29 : #endif
30 :
31 : #include <libsumo/TraCIConstants.h>
32 : #include <vector>
33 : #include <limits>
34 : #include <map>
35 : #include <string>
36 : #include <stdexcept>
37 : #include <sstream>
38 : #include <memory>
39 : #include <cstring>
40 :
41 :
42 : // ===========================================================================
43 : // common declarations
44 : // ===========================================================================
45 : namespace libsumo {
46 : class VariableWrapper;
47 : }
48 : namespace tcpip {
49 : class Storage;
50 : }
51 :
52 :
53 : // ===========================================================================
54 : // global definitions
55 : // ===========================================================================
56 : #ifdef LIBTRACI
57 : #define LIBSUMO_NAMESPACE libtraci
58 : #else
59 : #define LIBSUMO_NAMESPACE libsumo
60 : #endif
61 :
62 : #define LIBSUMO_SUBSCRIPTION_API \
63 : static void subscribe(const std::string& objectID, const std::vector<int>& varIDs = std::vector<int>({-1}), \
64 : double begin = libsumo::INVALID_DOUBLE_VALUE, double end = libsumo::INVALID_DOUBLE_VALUE, const libsumo::TraCIResults& parameters = libsumo::TraCIResults()); \
65 : static void unsubscribe(const std::string& objectID); \
66 : static void subscribeContext(const std::string& objectID, int domain, double dist, const std::vector<int>& varIDs = std::vector<int>({-1}), \
67 : double begin = libsumo::INVALID_DOUBLE_VALUE, double end = libsumo::INVALID_DOUBLE_VALUE, const libsumo::TraCIResults& parameters = libsumo::TraCIResults()); \
68 : static void unsubscribeContext(const std::string& objectID, int domain, double dist); \
69 : static const libsumo::SubscriptionResults getAllSubscriptionResults(); \
70 : static const libsumo::TraCIResults getSubscriptionResults(const std::string& objectID); \
71 : static const libsumo::ContextSubscriptionResults getAllContextSubscriptionResults(); \
72 : static const libsumo::SubscriptionResults getContextSubscriptionResults(const std::string& objectID); \
73 : static void subscribeParameterWithKey(const std::string& objectID, const std::string& key, double beginTime = libsumo::INVALID_DOUBLE_VALUE, double endTime = libsumo::INVALID_DOUBLE_VALUE); \
74 : static const int DOMAIN_ID; \
75 : static int domainID() { return DOMAIN_ID; }
76 :
77 : #define LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(CLASS, DOM) \
78 : const int CLASS::DOMAIN_ID(libsumo::CMD_GET_##DOM##_VARIABLE); \
79 : void \
80 : CLASS::subscribe(const std::string& objectID, const std::vector<int>& varIDs, double begin, double end, const libsumo::TraCIResults& parameters) { \
81 : libsumo::Helper::subscribe(libsumo::CMD_SUBSCRIBE_##DOM##_VARIABLE, objectID, varIDs, begin, end, parameters); \
82 : } \
83 : void \
84 : CLASS::unsubscribe(const std::string& objectID) { \
85 : libsumo::Helper::subscribe(libsumo::CMD_SUBSCRIBE_##DOM##_VARIABLE, objectID, std::vector<int>(), libsumo::INVALID_DOUBLE_VALUE, libsumo::INVALID_DOUBLE_VALUE, libsumo::TraCIResults()); \
86 : } \
87 : void \
88 : CLASS::subscribeContext(const std::string& objectID, int domain, double dist, const std::vector<int>& varIDs, double begin, double end, const TraCIResults& parameters) { \
89 : libsumo::Helper::subscribe(libsumo::CMD_SUBSCRIBE_##DOM##_CONTEXT, objectID, varIDs, begin, end, parameters, domain, dist); \
90 : } \
91 : void \
92 : CLASS::unsubscribeContext(const std::string& objectID, int domain, double dist) { \
93 : libsumo::Helper::subscribe(libsumo::CMD_SUBSCRIBE_##DOM##_CONTEXT, objectID, std::vector<int>(), libsumo::INVALID_DOUBLE_VALUE, libsumo::INVALID_DOUBLE_VALUE, libsumo::TraCIResults(), domain, dist); \
94 : } \
95 : const libsumo::SubscriptionResults \
96 : CLASS::getAllSubscriptionResults() { \
97 : return mySubscriptionResults; \
98 : } \
99 : const libsumo::TraCIResults \
100 : CLASS::getSubscriptionResults(const std::string& objectID) { \
101 : return mySubscriptionResults[objectID]; \
102 : } \
103 : const libsumo::ContextSubscriptionResults \
104 : CLASS::getAllContextSubscriptionResults() { \
105 : return myContextSubscriptionResults; \
106 : } \
107 : const libsumo::SubscriptionResults \
108 : CLASS::getContextSubscriptionResults(const std::string& objectID) { \
109 : return myContextSubscriptionResults[objectID]; \
110 : } \
111 : void \
112 : CLASS::subscribeParameterWithKey(const std::string& objectID, const std::string& key, double beginTime, double endTime) { \
113 : libsumo::Helper::subscribe(libsumo::CMD_SUBSCRIBE_##DOM##_VARIABLE, objectID, std::vector<int>({libsumo::VAR_PARAMETER_WITH_KEY}), beginTime, endTime, libsumo::TraCIResults {{libsumo::VAR_PARAMETER_WITH_KEY, std::make_shared<libsumo::TraCIString>(key)}}); \
114 : }
115 :
116 :
117 : #define LIBSUMO_ID_PARAMETER_API \
118 : static std::vector<std::string> getIDList(); \
119 : static int getIDCount(); \
120 : static std::string getParameter(const std::string& objectID, const std::string& key); \
121 : static const std::pair<std::string, std::string> getParameterWithKey(const std::string& objectID, const std::string& key); \
122 : static void setParameter(const std::string& objectID, const std::string& key, const std::string& value);
123 :
124 : #define LIBSUMO_GET_PARAMETER_WITH_KEY_IMPLEMENTATION(CLASS) \
125 : const std::pair<std::string, std::string> \
126 : CLASS::getParameterWithKey(const std::string& objectID, const std::string& key) { \
127 : return std::make_pair(key, getParameter(objectID, key)); \
128 : }
129 :
130 :
131 : #define SWIGJAVA_CAST(CLASS) \
132 : static std::shared_ptr<CLASS> cast(std::shared_ptr<TraCIResult> res) { \
133 : return std::dynamic_pointer_cast<CLASS>(res); \
134 : }
135 :
136 :
137 : // ===========================================================================
138 : // class and type definitions
139 : // ===========================================================================
140 : namespace libsumo {
141 : /**
142 : * @class TraCIException
143 : * @brief An error which allows to continue
144 : */
145 : class TraCIException : public std::runtime_error {
146 : public:
147 : /** constructor */
148 : TraCIException(std::string what)
149 6789 : : std::runtime_error(what) {}
150 : };
151 :
152 : /**
153 : * @class FatalTraCIError
154 : * @brief An error which is not recoverable
155 : */
156 : class FatalTraCIError : public std::runtime_error {
157 : public:
158 : /** constructor */
159 : FatalTraCIError(std::string what)
160 104 : : std::runtime_error(what) {}
161 : };
162 :
163 : /// @name Structures definitions
164 : /// @{
165 :
166 314085 : struct TraCIResult {
167 0 : virtual ~TraCIResult() {}
168 0 : virtual std::string getString() const {
169 0 : return "";
170 : }
171 96 : virtual int getType() const {
172 96 : return -1;
173 : }
174 : };
175 :
176 : /** @struct TraCIPosition
177 : * @brief A 2D or 3D-position, for 2D positions z == INVALID_DOUBLE_VALUE
178 : */
179 2414022 : struct TraCIPosition : TraCIResult {
180 138 : std::string getString() const override {
181 138 : std::ostringstream os;
182 276 : os << "TraCIPosition(" << x << "," << y;
183 138 : if (z != INVALID_DOUBLE_VALUE) {
184 5 : os << "," << z;
185 : }
186 138 : os << ")";
187 138 : return os.str();
188 138 : }
189 28 : int getType() const override {
190 28 : return z != INVALID_DOUBLE_VALUE ? POSITION_3D : POSITION_2D;
191 : }
192 : double x = INVALID_DOUBLE_VALUE, y = INVALID_DOUBLE_VALUE, z = INVALID_DOUBLE_VALUE;
193 : #ifdef SWIGJAVA
194 0 : SWIGJAVA_CAST(TraCIPosition)
195 : #endif
196 : };
197 :
198 : /** @struct TraCIRoadPosition
199 : * @brief An edgeId, position and laneIndex
200 : */
201 2000 : struct TraCIRoadPosition : TraCIResult {
202 15614 : TraCIRoadPosition(const std::string e = "", const double p = INVALID_DOUBLE_VALUE, const int li = INVALID_INT_VALUE) : edgeID(e), pos(p), laneIndex(li) {}
203 2 : std::string getString() const override {
204 2 : std::ostringstream os;
205 4 : os << "TraCIRoadPosition(" << edgeID << "_" << laneIndex << "," << pos << ")";
206 2 : return os.str();
207 2 : }
208 20 : int getType() const override {
209 20 : return POSITION_ROADMAP;
210 : }
211 : std::string edgeID;
212 : double pos;
213 : int laneIndex;
214 : #ifdef SWIGJAVA
215 0 : SWIGJAVA_CAST(TraCIRoadPosition)
216 : #endif
217 : };
218 :
219 : /** @struct TraCIColor
220 : * @brief A color
221 : */
222 1743 : struct TraCIColor : TraCIResult {
223 1539 : TraCIColor() : r(0), g(0), b(0), a(255) {}
224 86 : TraCIColor(int r, int g, int b, int a = 255) : r(r), g(g), b(b), a(a) {}
225 3 : std::string getString() const override {
226 3 : std::ostringstream os;
227 12 : os << "TraCIColor(" << r << "," << g << "," << b << "," << a << ")";
228 3 : return os.str();
229 3 : }
230 : int r, g, b, a;
231 : #ifdef SWIGJAVA
232 0 : SWIGJAVA_CAST(TraCIColor)
233 : #endif
234 : };
235 :
236 :
237 : /** @struct TraCIPositionVector
238 : * @brief A list of positions
239 : */
240 97022 : struct TraCIPositionVector : TraCIResult {
241 3 : std::string getString() const override {
242 3 : std::ostringstream os;
243 3 : os << "[";
244 20 : for (const TraCIPosition& v : value) {
245 51 : os << "(" << v.x << "," << v.y << "," << v.z << ")";
246 : }
247 3 : os << "]";
248 3 : return os.str();
249 3 : }
250 : std::vector<TraCIPosition> value;
251 : #ifdef SWIGJAVA
252 0 : SWIGJAVA_CAST(TraCIPositionVector)
253 : #endif
254 : };
255 :
256 :
257 : struct TraCIInt : TraCIResult {
258 17303 : TraCIInt(int v = 0, int t = libsumo::TYPE_INTEGER) : value(v), traciType(t) {}
259 0 : std::string getString() const override {
260 0 : std::ostringstream os;
261 0 : os << value;
262 0 : return os.str();
263 0 : }
264 216 : int getType() const override {
265 216 : return traciType;
266 : }
267 : int value;
268 : int traciType;
269 : #ifdef SWIGJAVA
270 0 : SWIGJAVA_CAST(TraCIInt)
271 : #endif
272 : };
273 :
274 :
275 : struct TraCIDouble : TraCIResult {
276 47210 : TraCIDouble(double v = 0.) : value(v) {}
277 132 : std::string getString() const override {
278 132 : std::ostringstream os;
279 132 : os << value;
280 132 : return os.str();
281 132 : }
282 639 : int getType() const override {
283 639 : return libsumo::TYPE_DOUBLE;
284 : }
285 : double value;
286 : #ifdef SWIGJAVA
287 0 : SWIGJAVA_CAST(TraCIDouble)
288 : #endif
289 : };
290 :
291 :
292 : struct TraCIString : TraCIResult {
293 33883 : TraCIString(std::string v = "") : value(v) {}
294 141 : std::string getString() const override {
295 141 : return value;
296 : }
297 1260 : int getType() const override {
298 1260 : return libsumo::TYPE_STRING;
299 : }
300 : std::string value;
301 : #ifdef SWIGJAVA
302 0 : SWIGJAVA_CAST(TraCIString)
303 : #endif
304 : };
305 :
306 :
307 1855 : struct TraCIStringList : TraCIResult {
308 0 : std::string getString() const override {
309 0 : std::ostringstream os;
310 0 : os << "[";
311 0 : for (std::string v : value) {
312 0 : os << v << ",";
313 : }
314 0 : os << "]";
315 0 : return os.str();
316 0 : }
317 : std::vector<std::string> value;
318 : #ifdef SWIGJAVA
319 30 : SWIGJAVA_CAST(TraCIStringList)
320 : #endif
321 : };
322 :
323 :
324 8 : struct TraCIDoubleList : TraCIResult {
325 0 : std::string getString() const override {
326 0 : std::ostringstream os;
327 0 : os << "[";
328 0 : for (double v : value) {
329 0 : os << v << ",";
330 : }
331 0 : os << "]";
332 0 : return os.str();
333 0 : }
334 : std::vector<double> value;
335 : #ifdef SWIGJAVA
336 0 : SWIGJAVA_CAST(TraCIDoubleList)
337 : #endif
338 : };
339 :
340 :
341 4 : struct TraCIIntList : TraCIResult {
342 0 : std::string getString() const override {
343 0 : std::ostringstream os;
344 0 : os << "[";
345 0 : for (int v : value) {
346 0 : os << v << ",";
347 : }
348 0 : os << "]";
349 0 : return os.str();
350 0 : }
351 : std::vector<int> value;
352 : #ifdef SWIGJAVA
353 0 : SWIGJAVA_CAST(TraCIIntList)
354 : #endif
355 : };
356 :
357 :
358 40 : struct TraCIStringDoublePairList : TraCIResult {
359 0 : std::string getString() const override {
360 0 : std::ostringstream os;
361 0 : os << "[";
362 0 : for (const auto& v : value) {
363 0 : os << "(" << v.first << "," << v.second << "),";
364 : }
365 0 : os << "]";
366 0 : return os.str();
367 0 : }
368 : std::vector<std::pair<std::string, double> > value;
369 : #ifdef SWIGJAVA
370 0 : SWIGJAVA_CAST(TraCIStringDoublePairList)
371 : #endif
372 : };
373 :
374 :
375 : /// @brief {variable->value}
376 : typedef std::map<int, std::shared_ptr<libsumo::TraCIResult> > TraCIResults;
377 : /// @brief {object->{variable->value}}
378 : typedef std::map<std::string, libsumo::TraCIResults> SubscriptionResults;
379 : typedef std::map<std::string, libsumo::SubscriptionResults> ContextSubscriptionResults;
380 :
381 :
382 : struct TraCIPhase {
383 240 : TraCIPhase() {}
384 1433 : TraCIPhase(const double _duration, const std::string& _state, const double _minDur = libsumo::INVALID_DOUBLE_VALUE,
385 : const double _maxDur = libsumo::INVALID_DOUBLE_VALUE,
386 : const std::vector<int>& _next = std::vector<int>(),
387 : const std::string& _name = "",
388 1433 : const std::string& _earlyTarget = "") :
389 4299 : duration(_duration), state(_state), minDur(_minDur), maxDur(_maxDur), next(_next), name(_name), earlyTarget(_earlyTarget) {}
390 1637 : ~TraCIPhase() {}
391 :
392 : double duration;
393 : std::string state;
394 : double minDur, maxDur;
395 : std::vector<int> next;
396 : std::string name;
397 : std::string earlyTarget;
398 : };
399 : }
400 :
401 :
402 : #ifdef SWIG
403 : %template(TraCIPhaseVector) std::vector<std::shared_ptr<libsumo::TraCIPhase> >; // *NOPAD*
404 : #endif
405 :
406 :
407 : namespace libsumo {
408 : struct TraCILogic {
409 79 : TraCILogic() {}
410 191 : TraCILogic(const std::string& _programID, const int _type, const int _currentPhaseIndex,
411 : const std::vector<std::shared_ptr<libsumo::TraCIPhase> >& _phases = std::vector<std::shared_ptr<libsumo::TraCIPhase> >())
412 191 : : programID(_programID), type(_type), currentPhaseIndex(_currentPhaseIndex), phases(_phases) {}
413 754 : ~TraCILogic() {}
414 :
415 0 : std::string getString() const {
416 0 : std::ostringstream os;
417 0 : os << "TraCILink(" << programID << "," << type << "," << currentPhaseIndex << ")";
418 0 : return os.str();
419 0 : }
420 :
421 : std::string programID;
422 : int type;
423 : int currentPhaseIndex;
424 : std::vector<std::shared_ptr<libsumo::TraCIPhase> > phases;
425 : std::map<std::string, std::string> subParameter;
426 : };
427 :
428 :
429 6 : struct TraCILogicVectorWrapped : TraCIResult {
430 0 : std::string getString() const override {
431 0 : std::ostringstream os;
432 0 : os << "TraCILogicVectorWrapped[";
433 0 : for (const TraCILogic& v : value) {
434 0 : os << v.getString() << ",";
435 : }
436 0 : os << "]";
437 0 : return os.str();
438 0 : }
439 :
440 : std::vector<TraCILogic> value;
441 : };
442 :
443 :
444 : struct TraCILink {
445 0 : TraCILink() {}
446 1046 : TraCILink(const std::string& _from, const std::string& _via, const std::string& _to)
447 3138 : : fromLane(_from), viaLane(_via), toLane(_to) {}
448 2986 : ~TraCILink() {}
449 :
450 0 : std::string getString() const {
451 0 : std::ostringstream os;
452 0 : os << "TraCILink(" << fromLane << "," << viaLane << "," << toLane << ")";
453 0 : return os.str();
454 0 : }
455 :
456 : std::string fromLane;
457 : std::string viaLane;
458 : std::string toLane;
459 : };
460 :
461 :
462 4 : struct TraCILinkVectorVectorWrapped : TraCIResult {
463 0 : std::string getString() const override {
464 0 : std::ostringstream os;
465 0 : os << "TraCILinkVectorVectorWrapped[";
466 0 : for (const std::vector<TraCILink>& v : value) {
467 0 : os << "[";
468 0 : for (const TraCILink& tl : v) {
469 0 : os << tl.getString() << ",";
470 : }
471 : }
472 0 : os << "]";
473 0 : return os.str();
474 0 : }
475 :
476 : std::vector<std::vector<TraCILink> > value;
477 : };
478 :
479 :
480 : struct TraCIConnection {
481 33 : TraCIConnection() {} // this is needed by SWIG when building a vector of this type, please don't use it
482 152 : TraCIConnection(const std::string& _approachedLane, const bool _hasPrio, const bool _isOpen, const bool _hasFoe,
483 : const std::string _approachedInternal, const std::string _state, const std::string _direction, const double _length)
484 152 : : approachedLane(_approachedLane), hasPrio(_hasPrio), isOpen(_isOpen), hasFoe(_hasFoe),
485 608 : approachedInternal(_approachedInternal), state(_state), direction(_direction), length(_length) {}
486 514 : ~TraCIConnection() {}
487 :
488 0 : std::string getString() const {
489 0 : std::ostringstream os;
490 0 : os << "TraCIConnection(" << approachedLane << "," << hasPrio << "," << isOpen
491 0 : << "," << hasFoe << "," << approachedInternal << "," << state << "," << direction << "," << length << ")";
492 0 : return os.str();
493 0 : }
494 :
495 : std::string approachedLane;
496 : bool hasPrio;
497 : bool isOpen;
498 : bool hasFoe;
499 : std::string approachedInternal;
500 : std::string state;
501 : std::string direction;
502 : double length;
503 : };
504 :
505 :
506 26 : struct TraCIConnectionVectorWrapped : TraCIResult {
507 0 : std::string getString() const override {
508 0 : std::ostringstream os;
509 0 : os << "TraCIConnectionVectorWrapped[";
510 0 : for (const TraCIConnection& v : value) {
511 0 : os << v.getString() << ",";
512 : }
513 0 : os << "]";
514 0 : return os.str();
515 0 : }
516 :
517 : std::vector<TraCIConnection> value;
518 : };
519 :
520 :
521 : /// @brief mirrors MSInductLoop::VehicleData
522 17228 : struct TraCIVehicleData {
523 0 : std::string getString() const {
524 0 : std::ostringstream os;
525 0 : os << "TraCIVehicleData(" << id << "," << length << "," << entryTime
526 0 : << "," << leaveTime << "," << typeID << ")";
527 0 : return os.str();
528 0 : }
529 :
530 : /// @brief The id of the vehicle
531 : std::string id;
532 : /// @brief Length of the vehicle
533 : double length;
534 : /// @brief Entry-time of the vehicle in [s]
535 : double entryTime;
536 : /// @brief Leave-time of the vehicle in [s]
537 : double leaveTime;
538 : /// @brief Type of the vehicle in
539 : std::string typeID;
540 : };
541 :
542 :
543 4 : struct TraCIVehicleDataVectorWrapped : TraCIResult {
544 0 : std::string getString() const override {
545 0 : std::ostringstream os;
546 0 : os << "TraCIVehicleDataVectorWrapped[";
547 0 : for (const TraCIVehicleData& v : value) {
548 0 : os << v.getString() << ",";
549 : }
550 0 : os << "]";
551 0 : return os.str();
552 0 : }
553 :
554 : std::vector<TraCIVehicleData> value;
555 : };
556 :
557 :
558 2394 : struct TraCINextTLSData {
559 0 : std::string getString() const {
560 0 : std::ostringstream os;
561 0 : os << "TraCINextTLSData(" << id << "," << tlIndex << "," << dist
562 0 : << "," << state << ")";
563 0 : return os.str();
564 0 : }
565 :
566 : /// @brief The id of the next tls
567 : std::string id;
568 : /// @brief The tls index of the controlled link
569 : int tlIndex;
570 : /// @brief The distance to the tls
571 : double dist;
572 : /// @brief The current state of the tls
573 : char state;
574 : };
575 :
576 :
577 4 : struct TraCINextTLSDataVectorWrapped : TraCIResult {
578 0 : std::string getString() const override {
579 0 : std::ostringstream os;
580 0 : os << "TraCINextTLSDataVectorWrapped[";
581 0 : for (const TraCINextTLSData& v : value) {
582 0 : os << v.getString() << ",";
583 : }
584 0 : os << "]";
585 0 : return os.str();
586 0 : }
587 :
588 : std::vector<TraCINextTLSData> value;
589 : };
590 :
591 :
592 : struct TraCINextStopData {
593 :
594 10878 : TraCINextStopData(const std::string& lane = "",
595 : double startPos = INVALID_DOUBLE_VALUE,
596 : double endPos = INVALID_DOUBLE_VALUE,
597 : const std::string& stoppingPlaceID = "",
598 : int stopFlags = 0,
599 : double duration = INVALID_DOUBLE_VALUE,
600 : double until = INVALID_DOUBLE_VALUE,
601 : double intendedArrival = INVALID_DOUBLE_VALUE,
602 : double arrival = INVALID_DOUBLE_VALUE,
603 : double depart = INVALID_DOUBLE_VALUE,
604 : const std::string& split = "",
605 : const std::string& join = "",
606 : const std::string& actType = "",
607 : const std::string& tripId = "",
608 : const std::string& line = "",
609 10878 : double speed = 0):
610 10878 : lane(lane),
611 10878 : startPos(startPos),
612 10878 : endPos(endPos),
613 10878 : stoppingPlaceID(stoppingPlaceID),
614 10878 : stopFlags(stopFlags),
615 10878 : duration(duration),
616 10878 : until(until),
617 10878 : intendedArrival(intendedArrival),
618 10878 : arrival(arrival),
619 10878 : depart(depart),
620 10878 : split(split),
621 10878 : join(join),
622 10878 : actType(actType),
623 10878 : tripId(tripId),
624 10878 : line(line),
625 10878 : speed(speed)
626 10878 : {}
627 :
628 0 : std::string getString() const {
629 0 : std::ostringstream os;
630 0 : os << "TraCINextStopData(" << lane << "," << endPos << "," << stoppingPlaceID
631 0 : << "," << stopFlags << "," << duration << "," << until
632 0 : << "," << arrival << ")";
633 0 : return os.str();
634 0 : }
635 :
636 : /// @brief The lane to stop at
637 : std::string lane;
638 : /// @brief The stopping position start
639 : double startPos;
640 : /// @brief The stopping position end
641 : double endPos;
642 : /// @brief Id assigned to the stop
643 : std::string stoppingPlaceID;
644 : /// @brief Stop flags
645 : int stopFlags;
646 : /// @brief The intended (minimum) stopping duration
647 : double duration;
648 : /// @brief The time at which the vehicle may continue its journey
649 : double until;
650 : /// @brief The intended arrival time
651 : double intendedArrival;
652 : /// @brief The actual arrival time (only for past stops)
653 : double arrival;
654 : /// @brief The time at which this stop was ended
655 : double depart;
656 : /// @brief the id of the vehicle (train portion) that splits of upon reaching this stop
657 : std::string split;
658 : /// @brief the id of the vehicle (train portion) to which this vehicle shall be joined
659 : std::string join;
660 : /// @brief additional information for this stop
661 : std::string actType;
662 : /// @brief id of the trip within a cyclical public transport route
663 : std::string tripId;
664 : /// @brief the new line id of the trip within a cyclical public transport route
665 : std::string line;
666 : /// @brief the speed at which this stop counts as reached (waypoint mode)
667 : double speed;
668 : };
669 :
670 :
671 : /** @struct TraCINextStopDataVectorWrapped
672 : * @brief A list of vehicle stops
673 : * @see TraCINextStopData
674 : */
675 6 : struct TraCINextStopDataVectorWrapped : TraCIResult {
676 0 : std::string getString() const override {
677 0 : std::ostringstream os;
678 0 : os << "TraCINextStopDataVectorWrapped[";
679 0 : for (const TraCINextStopData& v : value) {
680 0 : os << v.getString() << ",";
681 : }
682 0 : os << "]";
683 0 : return os.str();
684 0 : }
685 :
686 : std::vector<TraCINextStopData> value;
687 : };
688 :
689 :
690 387 : struct TraCIBestLanesData {
691 0 : std::string getString() const {
692 0 : std::ostringstream os;
693 0 : os << "TraCIBestLanesData(" << laneID << "," << length << "," << occupation
694 0 : << "," << bestLaneOffset << "," << allowsContinuation << ",[";
695 0 : for (const std::string& s : continuationLanes) {
696 0 : os << s << ",";
697 : }
698 0 : os << "])";
699 0 : return os.str();
700 0 : }
701 :
702 : /// @brief The id of the lane
703 : std::string laneID;
704 : /// @brief The length than can be driven from that lane without lane change
705 : double length;
706 : /// @brief The traffic density along length
707 : double occupation;
708 : /// @brief The offset of this lane from the best lane
709 : int bestLaneOffset;
710 : /// @brief Whether this lane allows continuing the route
711 : bool allowsContinuation;
712 : /// @brief The sequence of lanes that best allows continuing the route without lane change
713 : std::vector<std::string> continuationLanes;
714 : };
715 :
716 :
717 4 : struct TraCIBestLanesDataVectorWrapped : TraCIResult {
718 0 : std::string getString() const override {
719 0 : std::ostringstream os;
720 0 : os << "TraCIBestLanesDataVectorWrapped[";
721 0 : for (const TraCIBestLanesData& v : value) {
722 0 : os << v.getString() << ",";
723 : }
724 0 : os << "]";
725 0 : return os.str();
726 0 : }
727 :
728 : std::vector<TraCIBestLanesData> value;
729 : };
730 :
731 :
732 : struct TraCIStage : TraCIResult {
733 : public:
734 8423 : TraCIStage(int type = INVALID_INT_VALUE, const std::string& vType = "", const std::string& line = "", const std::string& destStop = "",
735 : const std::vector<std::string>& edges = std::vector<std::string>(),
736 : double travelTime = INVALID_DOUBLE_VALUE, double cost = INVALID_DOUBLE_VALUE, double length = INVALID_DOUBLE_VALUE,
737 : const std::string& intended = "", double depart = INVALID_DOUBLE_VALUE, double departPos = INVALID_DOUBLE_VALUE,
738 8423 : double arrivalPos = INVALID_DOUBLE_VALUE, const std::string& description = "") :
739 25269 : type(type), vType(vType), line(line), destStop(destStop), edges(edges), travelTime(travelTime), cost(cost),
740 33692 : length(length), intended(intended), depart(depart), departPos(departPos), arrivalPos(arrivalPos), description(description) {}
741 : /// @brief The type of stage (walking, driving, ...)
742 : int type;
743 : /// @brief The vehicle type when using a private car or bike
744 : std::string vType;
745 : /// @brief The line or the id of the vehicle type
746 : std::string line;
747 : /// @brief The id of the destination stop
748 : std::string destStop;
749 : /// @brief The sequence of edges to travel
750 : std::vector<std::string> edges;
751 : /// @brief duration of the stage in seconds
752 : double travelTime;
753 : /// @brief effort needed
754 : double cost;
755 : /// @brief length in m
756 : double length;
757 : /// @brief id of the intended vehicle for public transport ride
758 : std::string intended;
759 : /// @brief intended depart time for public transport ride or INVALID_DOUBLE_VALUE
760 : double depart;
761 : /// @brief position on the lane when starting the stage
762 : double departPos;
763 : /// @brief position on the lane when ending the stage
764 : double arrivalPos;
765 : /// @brief arbitrary description string
766 : std::string description;
767 : };
768 :
769 :
770 :
771 : struct TraCIReservation {
772 1535 : TraCIReservation() {}
773 8100 : TraCIReservation(const std::string& id,
774 : const std::vector<std::string>& persons,
775 : const std::string& group,
776 : const std::string& fromEdge,
777 : const std::string& toEdge,
778 : double departPos,
779 : double arrivalPos,
780 : double depart,
781 : double reservationTime,
782 8100 : int state) :
783 24300 : id(id), persons(persons), group(group), fromEdge(fromEdge), toEdge(toEdge), departPos(departPos), arrivalPos(arrivalPos),
784 8100 : depart(depart), reservationTime(reservationTime), state(state) {}
785 : /// @brief The id of the taxi reservation (usable for traci.vehicle.dispatchTaxi)
786 : std::string id;
787 : /// @brief The persons ids that are part of this reservation
788 : std::vector<std::string> persons;
789 : /// @brief The group id of this reservation
790 : std::string group;
791 : /// @brief The origin edge id
792 : std::string fromEdge;
793 : /// @brief The destination edge id
794 : std::string toEdge;
795 : /// @brief pickup position on the origin edge
796 : double departPos;
797 : /// @brief drop-off position on the destination edge
798 : double arrivalPos;
799 : /// @brief pickup-time
800 : double depart;
801 : /// @brief time when the reservation was made
802 : double reservationTime;
803 : /// @brief the state of this reservation
804 : int state;
805 :
806 0 : std::string getString() const {
807 0 : std::ostringstream os;
808 0 : os << "TraCIReservation(id=" << id << ")";
809 0 : return os.str();
810 0 : }
811 : };
812 :
813 :
814 4 : struct TraCIReservationVectorWrapped : TraCIResult {
815 0 : std::string getString() const override {
816 0 : std::ostringstream os;
817 0 : os << "TraCIReservationVectorWrapped[";
818 0 : for (const TraCIReservation& v : value) {
819 0 : os << v.getString() << ",";
820 : }
821 0 : os << "]";
822 0 : return os.str();
823 0 : }
824 :
825 : std::vector<TraCIReservation> value;
826 : };
827 :
828 :
829 : struct TraCICollision {
830 : /// @brief The ids of the participating vehicles and persons
831 : std::string collider;
832 : std::string victim;
833 : std::string colliderType;
834 : std::string victimType;
835 : double colliderSpeed;
836 : double victimSpeed;
837 : /// @brief The type of collision
838 : std::string type;
839 : /// @brief The lane where the collision happended
840 : std::string lane;
841 : /// @brief The position of the collision along the lane
842 : double pos;
843 :
844 0 : std::string getString() const {
845 0 : std::ostringstream os;
846 0 : os << "TraCICollision(collider=" << collider << ", victim=" << victim << ")";
847 0 : return os.str();
848 0 : }
849 : };
850 :
851 :
852 2 : struct TraCICollisionVectorWrapped : TraCIResult {
853 0 : std::string getString() const override {
854 0 : std::ostringstream os;
855 0 : os << "TraCICollisionVectorWrapped[";
856 0 : for (const TraCICollision& v : value) {
857 0 : os << v.getString() << ",";
858 : }
859 0 : os << "]";
860 0 : return os.str();
861 0 : }
862 :
863 : std::vector<TraCICollision> value;
864 : };
865 :
866 :
867 : struct TraCISignalConstraint {
868 : /// @brief the idea of the rail signal where this constraint is active
869 : std::string signalId;
870 : /// @brief the tripId or vehicle id of the train that is constrained
871 : std::string tripId;
872 : /// @brief the tripId or vehicle id of the train that must pass first
873 : std::string foeId;
874 : /// @brief the tlsID of the rail signla that the foe must pass first
875 : std::string foeSignal;
876 : /// @brief the number of trains that must be recorded at the foeSignal
877 : int limit;
878 : /// @brief the type of constraint (predecessor:0, insertionPredecessor:1)
879 : int type;
880 : /// @brief whether tripId must still wait for foeId to pass foeSignal
881 : bool mustWait;
882 : /// @brief whether this constraint is active
883 : bool active;
884 : /// @brief additional parameters
885 : std::map<std::string, std::string> param;
886 :
887 0 : std::string getString() const {
888 0 : std::ostringstream os;
889 0 : os << "TraCISignalConstraint(signalId=" << signalId << ", tripid=" << tripId << ", foeSignal=" << foeSignal << ", foeId=" << foeId << ")";
890 0 : return os.str();
891 0 : }
892 : };
893 :
894 :
895 8 : struct TraCISignalConstraintVectorWrapped : TraCIResult {
896 0 : std::string getString() const override {
897 0 : std::ostringstream os;
898 0 : os << "TraCISignalConstraintVectorWrapped[";
899 0 : for (const TraCISignalConstraint& v : value) {
900 0 : os << v.getString() << ",";
901 : }
902 0 : os << "]";
903 0 : return os.str();
904 0 : }
905 :
906 : std::vector<TraCISignalConstraint> value;
907 : };
908 :
909 :
910 : struct TraCIJunctionFoe {
911 : /// @brief the id of the vehicle with intersecting trajectory
912 : std::string foeId;
913 : double egoDist;
914 : double foeDist;
915 : double egoExitDist;
916 : double foeExitDist;
917 : std::string egoLane;
918 : std::string foeLane;
919 : bool egoResponse;
920 : bool foeResponse;
921 :
922 0 : std::string getString() const {
923 0 : std::ostringstream os;
924 0 : os << "TraCIJunctionFoe(foeId=" << foeId << ", egoDist=" << egoDist << ", foeDist=" << foeDist << ", foeDist=" << foeDist << ")";
925 0 : return os.str();
926 0 : }
927 : };
928 :
929 :
930 4 : struct TraCIJunctionFoeVectorWrapped : TraCIResult {
931 0 : std::string getString() const override {
932 0 : std::ostringstream os;
933 0 : os << "TraCIJunctionFoeVectorWrapped[";
934 0 : for (const TraCIJunctionFoe& v : value) {
935 0 : os << v.getString() << ",";
936 : }
937 0 : os << "]";
938 0 : return os.str();
939 0 : }
940 :
941 : std::vector<TraCIJunctionFoe> value;
942 : };
943 :
944 :
945 : }
946 :
947 : // pop MSVC warnings
948 : #ifdef _MSC_VER
949 : #pragma warning(pop)
950 : #endif
|