Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/libsumo/TraCIDefs.h
169667 views
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
: 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
: std::runtime_error(what) {}
161
};
162
163
/// @name Structures definitions
164
/// @{
165
166
struct TraCIResult {
167
virtual ~TraCIResult() {}
168
virtual std::string getString() const {
169
return "";
170
}
171
virtual int getType() const {
172
return -1;
173
}
174
};
175
176
/** @struct TraCIPosition
177
* @brief A 2D or 3D-position, for 2D positions z == INVALID_DOUBLE_VALUE
178
*/
179
struct TraCIPosition : TraCIResult {
180
std::string getString() const {
181
std::ostringstream os;
182
os << "TraCIPosition(" << x << "," << y;
183
if (z != INVALID_DOUBLE_VALUE) {
184
os << "," << z;
185
}
186
os << ")";
187
return os.str();
188
}
189
int getType() const {
190
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
SWIGJAVA_CAST(TraCIPosition)
195
#endif
196
};
197
198
/** @struct TraCIRoadPosition
199
* @brief An edgeId, position and laneIndex
200
*/
201
struct TraCIRoadPosition : TraCIResult {
202
TraCIRoadPosition(const std::string e = "", const double p = INVALID_DOUBLE_VALUE, const int li = INVALID_INT_VALUE) : edgeID(e), pos(p), laneIndex(li) {}
203
std::string getString() const {
204
std::ostringstream os;
205
os << "TraCIRoadPosition(" << edgeID << "_" << laneIndex << "," << pos << ")";
206
return os.str();
207
}
208
int getType() const {
209
return POSITION_ROADMAP;
210
}
211
std::string edgeID;
212
double pos;
213
int laneIndex;
214
#ifdef SWIGJAVA
215
SWIGJAVA_CAST(TraCIRoadPosition)
216
#endif
217
};
218
219
/** @struct TraCIColor
220
* @brief A color
221
*/
222
struct TraCIColor : TraCIResult {
223
TraCIColor() : r(0), g(0), b(0), a(255) {}
224
TraCIColor(int r, int g, int b, int a = 255) : r(r), g(g), b(b), a(a) {}
225
std::string getString() const {
226
std::ostringstream os;
227
os << "TraCIColor(" << r << "," << g << "," << b << "," << a << ")";
228
return os.str();
229
}
230
int r, g, b, a;
231
#ifdef SWIGJAVA
232
SWIGJAVA_CAST(TraCIColor)
233
#endif
234
};
235
236
237
/** @struct TraCIPositionVector
238
* @brief A list of positions
239
*/
240
struct TraCIPositionVector : TraCIResult {
241
std::string getString() const {
242
std::ostringstream os;
243
os << "[";
244
for (const TraCIPosition& v : value) {
245
os << "(" << v.x << "," << v.y << "," << v.z << ")";
246
}
247
os << "]";
248
return os.str();
249
}
250
std::vector<TraCIPosition> value;
251
#ifdef SWIGJAVA
252
SWIGJAVA_CAST(TraCIPositionVector)
253
#endif
254
};
255
256
257
struct TraCIInt : TraCIResult {
258
TraCIInt(int v = 0, int t = libsumo::TYPE_INTEGER) : value(v), traciType(t) {}
259
std::string getString() const {
260
std::ostringstream os;
261
os << value;
262
return os.str();
263
}
264
int getType() const {
265
return traciType;
266
}
267
int value;
268
int traciType;
269
#ifdef SWIGJAVA
270
SWIGJAVA_CAST(TraCIInt)
271
#endif
272
};
273
274
275
struct TraCIDouble : TraCIResult {
276
TraCIDouble(double v = 0.) : value(v) {}
277
std::string getString() const {
278
std::ostringstream os;
279
os << value;
280
return os.str();
281
}
282
int getType() const {
283
return libsumo::TYPE_DOUBLE;
284
}
285
double value;
286
#ifdef SWIGJAVA
287
SWIGJAVA_CAST(TraCIDouble)
288
#endif
289
};
290
291
292
struct TraCIString : TraCIResult {
293
TraCIString(std::string v = "") : value(v) {}
294
std::string getString() const {
295
return value;
296
}
297
int getType() const {
298
return libsumo::TYPE_STRING;
299
}
300
std::string value;
301
#ifdef SWIGJAVA
302
SWIGJAVA_CAST(TraCIString)
303
#endif
304
};
305
306
307
struct TraCIStringList : TraCIResult {
308
std::string getString() const {
309
std::ostringstream os;
310
os << "[";
311
for (std::string v : value) {
312
os << v << ",";
313
}
314
os << "]";
315
return os.str();
316
}
317
std::vector<std::string> value;
318
#ifdef SWIGJAVA
319
SWIGJAVA_CAST(TraCIStringList)
320
#endif
321
};
322
323
324
struct TraCIDoubleList : TraCIResult {
325
std::string getString() const {
326
std::ostringstream os;
327
os << "[";
328
for (double v : value) {
329
os << v << ",";
330
}
331
os << "]";
332
return os.str();
333
}
334
std::vector<double> value;
335
#ifdef SWIGJAVA
336
SWIGJAVA_CAST(TraCIDoubleList)
337
#endif
338
};
339
340
341
struct TraCIIntList : TraCIResult {
342
std::string getString() const {
343
std::ostringstream os;
344
os << "[";
345
for (int v : value) {
346
os << v << ",";
347
}
348
os << "]";
349
return os.str();
350
}
351
std::vector<int> value;
352
#ifdef SWIGJAVA
353
SWIGJAVA_CAST(TraCIIntList)
354
#endif
355
};
356
357
358
struct TraCIStringDoublePairList : TraCIResult {
359
std::string getString() const {
360
std::ostringstream os;
361
os << "[";
362
for (const auto& v : value) {
363
os << "(" << v.first << "," << v.second << "),";
364
}
365
os << "]";
366
return os.str();
367
}
368
std::vector<std::pair<std::string, double> > value;
369
#ifdef SWIGJAVA
370
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
TraCIPhase() {}
384
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
const std::string& _earlyTarget = "") :
389
duration(_duration), state(_state), minDur(_minDur), maxDur(_maxDur), next(_next), name(_name), earlyTarget(_earlyTarget) {}
390
~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
TraCILogic() {}
410
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
: programID(_programID), type(_type), currentPhaseIndex(_currentPhaseIndex), phases(_phases) {}
413
~TraCILogic() {}
414
415
std::string getString() const {
416
std::ostringstream os;
417
os << "TraCILink(" << programID << "," << type << "," << currentPhaseIndex << ")";
418
return os.str();
419
}
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
struct TraCILogicVectorWrapped : TraCIResult {
430
std::string getString() const {
431
std::ostringstream os;
432
os << "TraCILogicVectorWrapped[";
433
for (const TraCILogic& v : value) {
434
os << v.getString() << ",";
435
}
436
os << "]";
437
return os.str();
438
}
439
440
std::vector<TraCILogic> value;
441
};
442
443
444
struct TraCILink {
445
TraCILink() {}
446
TraCILink(const std::string& _from, const std::string& _via, const std::string& _to)
447
: fromLane(_from), viaLane(_via), toLane(_to) {}
448
~TraCILink() {}
449
450
std::string getString() const {
451
std::ostringstream os;
452
os << "TraCILink(" << fromLane << "," << viaLane << "," << toLane << ")";
453
return os.str();
454
}
455
456
std::string fromLane;
457
std::string viaLane;
458
std::string toLane;
459
};
460
461
462
struct TraCILinkVectorVectorWrapped : TraCIResult {
463
std::string getString() const {
464
std::ostringstream os;
465
os << "TraCILinkVectorVectorWrapped[";
466
for (const std::vector<TraCILink>& v : value) {
467
os << "[";
468
for (const TraCILink& tl : v) {
469
os << tl.getString() << ",";
470
}
471
}
472
os << "]";
473
return os.str();
474
}
475
476
std::vector<std::vector<TraCILink> > value;
477
};
478
479
480
struct TraCIConnection {
481
TraCIConnection() {} // this is needed by SWIG when building a vector of this type, please don't use it
482
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
: approachedLane(_approachedLane), hasPrio(_hasPrio), isOpen(_isOpen), hasFoe(_hasFoe),
485
approachedInternal(_approachedInternal), state(_state), direction(_direction), length(_length) {}
486
~TraCIConnection() {}
487
488
std::string getString() const {
489
std::ostringstream os;
490
os << "TraCIConnection(" << approachedLane << "," << hasPrio << "," << isOpen
491
<< "," << hasFoe << "," << approachedInternal << "," << state << "," << direction << "," << length << ")";
492
return os.str();
493
}
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
struct TraCIConnectionVectorWrapped : TraCIResult {
507
std::string getString() const {
508
std::ostringstream os;
509
os << "TraCIConnectionVectorWrapped[";
510
for (const TraCIConnection& v : value) {
511
os << v.getString() << ",";
512
}
513
os << "]";
514
return os.str();
515
}
516
517
std::vector<TraCIConnection> value;
518
};
519
520
521
/// @brief mirrors MSInductLoop::VehicleData
522
struct TraCIVehicleData {
523
std::string getString() const {
524
std::ostringstream os;
525
os << "TraCIVehicleData(" << id << "," << length << "," << entryTime
526
<< "," << leaveTime << "," << typeID << ")";
527
return os.str();
528
}
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
struct TraCIVehicleDataVectorWrapped : TraCIResult {
544
std::string getString() const {
545
std::ostringstream os;
546
os << "TraCIVehicleDataVectorWrapped[";
547
for (const TraCIVehicleData& v : value) {
548
os << v.getString() << ",";
549
}
550
os << "]";
551
return os.str();
552
}
553
554
std::vector<TraCIVehicleData> value;
555
};
556
557
558
struct TraCINextTLSData {
559
std::string getString() const {
560
std::ostringstream os;
561
os << "TraCINextTLSData(" << id << "," << tlIndex << "," << dist
562
<< "," << state << ")";
563
return os.str();
564
}
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
struct TraCINextTLSDataVectorWrapped : TraCIResult {
578
std::string getString() const {
579
std::ostringstream os;
580
os << "TraCINextTLSDataVectorWrapped[";
581
for (const TraCINextTLSData& v : value) {
582
os << v.getString() << ",";
583
}
584
os << "]";
585
return os.str();
586
}
587
588
std::vector<TraCINextTLSData> value;
589
};
590
591
592
struct TraCINextStopData {
593
594
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
double speed = 0):
610
lane(lane),
611
startPos(startPos),
612
endPos(endPos),
613
stoppingPlaceID(stoppingPlaceID),
614
stopFlags(stopFlags),
615
duration(duration),
616
until(until),
617
intendedArrival(intendedArrival),
618
arrival(arrival),
619
depart(depart),
620
split(split),
621
join(join),
622
actType(actType),
623
tripId(tripId),
624
line(line),
625
speed(speed)
626
{}
627
628
std::string getString() const {
629
std::ostringstream os;
630
os << "TraCINextStopData(" << lane << "," << endPos << "," << stoppingPlaceID
631
<< "," << stopFlags << "," << duration << "," << until
632
<< "," << arrival << ")";
633
return os.str();
634
}
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
struct TraCINextStopDataVectorWrapped : TraCIResult {
676
std::string getString() const {
677
std::ostringstream os;
678
os << "TraCINextStopDataVectorWrapped[";
679
for (const TraCINextStopData& v : value) {
680
os << v.getString() << ",";
681
}
682
os << "]";
683
return os.str();
684
}
685
686
std::vector<TraCINextStopData> value;
687
};
688
689
690
struct TraCIBestLanesData {
691
std::string getString() const {
692
std::ostringstream os;
693
os << "TraCIBestLanesData(" << laneID << "," << length << "," << occupation
694
<< "," << bestLaneOffset << "," << allowsContinuation << ",[";
695
for (const std::string& s : continuationLanes) {
696
os << s << ",";
697
}
698
os << "])";
699
return os.str();
700
}
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
struct TraCIBestLanesDataVectorWrapped : TraCIResult {
718
std::string getString() const {
719
std::ostringstream os;
720
os << "TraCIBestLanesDataVectorWrapped[";
721
for (const TraCIBestLanesData& v : value) {
722
os << v.getString() << ",";
723
}
724
os << "]";
725
return os.str();
726
}
727
728
std::vector<TraCIBestLanesData> value;
729
};
730
731
732
struct TraCIStage : TraCIResult {
733
public:
734
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
double arrivalPos = INVALID_DOUBLE_VALUE, const std::string& description = "") :
739
type(type), vType(vType), line(line), destStop(destStop), edges(edges), travelTime(travelTime), cost(cost),
740
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
TraCIReservation() {}
773
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
int state) :
783
id(id), persons(persons), group(group), fromEdge(fromEdge), toEdge(toEdge), departPos(departPos), arrivalPos(arrivalPos),
784
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
std::string getString() const {
807
std::ostringstream os;
808
os << "TraCIReservation(id=" << id << ")";
809
return os.str();
810
}
811
};
812
813
814
struct TraCIReservationVectorWrapped : TraCIResult {
815
std::string getString() const {
816
std::ostringstream os;
817
os << "TraCIReservationVectorWrapped[";
818
for (const TraCIReservation& v : value) {
819
os << v.getString() << ",";
820
}
821
os << "]";
822
return os.str();
823
}
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
std::string getString() const {
845
std::ostringstream os;
846
os << "TraCICollision(collider=" << collider << ", victim=" << victim << ")";
847
return os.str();
848
}
849
};
850
851
852
struct TraCICollisionVectorWrapped : TraCIResult {
853
std::string getString() const {
854
std::ostringstream os;
855
os << "TraCICollisionVectorWrapped[";
856
for (const TraCICollision& v : value) {
857
os << v.getString() << ",";
858
}
859
os << "]";
860
return os.str();
861
}
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
std::string getString() const {
888
std::ostringstream os;
889
os << "TraCISignalConstraint(signalId=" << signalId << ", tripid=" << tripId << ", foeSignal=" << foeSignal << ", foeId=" << foeId << ")";
890
return os.str();
891
}
892
};
893
894
895
struct TraCISignalConstraintVectorWrapped : TraCIResult {
896
std::string getString() const {
897
std::ostringstream os;
898
os << "TraCISignalConstraintVectorWrapped[";
899
for (const TraCISignalConstraint& v : value) {
900
os << v.getString() << ",";
901
}
902
os << "]";
903
return os.str();
904
}
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
std::string getString() const {
923
std::ostringstream os;
924
os << "TraCIJunctionFoe(foeId=" << foeId << ", egoDist=" << egoDist << ", foeDist=" << foeDist << ", foeDist=" << foeDist << ")";
925
return os.str();
926
}
927
};
928
929
930
struct TraCIJunctionFoeVectorWrapped : TraCIResult {
931
std::string getString() const {
932
std::ostringstream os;
933
os << "TraCIJunctionFoeVectorWrapped[";
934
for (const TraCIJunctionFoe& v : value) {
935
os << v.getString() << ",";
936
}
937
os << "]";
938
return os.str();
939
}
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
951
952