Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/traci/TraCIAPI.cpp
169678 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 TraCIAPI.cpp
15
/// @author Daniel Krajzewicz
16
/// @author Mario Krumnow
17
/// @author Jakob Erdmann
18
/// @author Michael Behrisch
19
/// @date 30.05.2012
20
///
21
// C++ TraCI client API implementation
22
/****************************************************************************/
23
#include "TraCIAPI.h"
24
25
26
// ===========================================================================
27
// member definitions
28
// ===========================================================================
29
30
// ---------------------------------------------------------------------------
31
// TraCIAPI-methods
32
// ---------------------------------------------------------------------------
33
#ifdef _MSC_VER
34
#pragma warning(push)
35
#pragma warning(disable: 4355) // mask warning about "this" in initializers
36
#endif
37
TraCIAPI::TraCIAPI() :
38
edge(*this), gui(*this), inductionloop(*this),
39
junction(*this), lane(*this), lanearea(*this), multientryexit(*this),
40
person(*this), poi(*this), polygon(*this),
41
rerouter(*this), route(*this), routeprobe(*this),
42
simulation(*this), trafficlights(*this),
43
vehicle(*this), vehicletype(*this),
44
mySocket(nullptr) {
45
std::cerr << "TraCIAPI is deprecated. Please use libtraci instead, see https://sumo.dlr.de/docs/Libtraci.html.\n";
46
myDomains[libsumo::RESPONSE_SUBSCRIBE_EDGE_VARIABLE] = &edge;
47
myDomains[libsumo::RESPONSE_SUBSCRIBE_GUI_VARIABLE] = &gui;
48
myDomains[libsumo::RESPONSE_SUBSCRIBE_JUNCTION_VARIABLE] = &junction;
49
myDomains[libsumo::RESPONSE_SUBSCRIBE_LANE_VARIABLE] = &lane;
50
myDomains[libsumo::RESPONSE_SUBSCRIBE_LANEAREA_VARIABLE] = &lanearea;
51
myDomains[libsumo::RESPONSE_SUBSCRIBE_MULTIENTRYEXIT_VARIABLE] = &multientryexit;
52
myDomains[libsumo::RESPONSE_SUBSCRIBE_PERSON_VARIABLE] = &person;
53
myDomains[libsumo::RESPONSE_SUBSCRIBE_POI_VARIABLE] = &poi;
54
myDomains[libsumo::RESPONSE_SUBSCRIBE_POLYGON_VARIABLE] = &polygon;
55
myDomains[libsumo::RESPONSE_SUBSCRIBE_REROUTER_VARIABLE] = &rerouter;
56
myDomains[libsumo::RESPONSE_SUBSCRIBE_ROUTE_VARIABLE] = &route;
57
myDomains[libsumo::RESPONSE_SUBSCRIBE_ROUTEPROBE_VARIABLE] = &routeprobe;
58
myDomains[libsumo::RESPONSE_SUBSCRIBE_SIM_VARIABLE] = &simulation;
59
myDomains[libsumo::RESPONSE_SUBSCRIBE_TL_VARIABLE] = &trafficlights;
60
myDomains[libsumo::RESPONSE_SUBSCRIBE_VEHICLE_VARIABLE] = &vehicle;
61
myDomains[libsumo::RESPONSE_SUBSCRIBE_VEHICLETYPE_VARIABLE] = &vehicletype;
62
}
63
#ifdef _MSC_VER
64
#pragma warning(pop)
65
#endif
66
67
TraCIAPI::~TraCIAPI() {
68
delete mySocket;
69
}
70
71
72
void
73
TraCIAPI::connect(const std::string& host, int port) {
74
mySocket = new tcpip::Socket(host, port);
75
try {
76
mySocket->connect();
77
} catch (tcpip::SocketException&) {
78
delete mySocket;
79
mySocket = nullptr;
80
throw;
81
}
82
}
83
84
85
void
86
TraCIAPI::setOrder(int order) {
87
tcpip::Storage outMsg;
88
// command length
89
outMsg.writeUnsignedByte(1 + 1 + 4);
90
// command id
91
outMsg.writeUnsignedByte(libsumo::CMD_SETORDER);
92
outMsg.writeInt(order);
93
// send request message
94
mySocket->sendExact(outMsg);
95
tcpip::Storage inMsg;
96
check_resultState(inMsg, libsumo::CMD_SETORDER);
97
}
98
99
100
void
101
TraCIAPI::close() {
102
send_commandClose();
103
tcpip::Storage inMsg;
104
std::string acknowledgement;
105
check_resultState(inMsg, libsumo::CMD_CLOSE, false, &acknowledgement);
106
closeSocket();
107
}
108
109
110
void
111
TraCIAPI::closeSocket() {
112
if (mySocket == nullptr) {
113
return;
114
}
115
mySocket->close();
116
delete mySocket;
117
mySocket = nullptr;
118
}
119
120
121
void
122
TraCIAPI::send_commandSimulationStep(double time) const {
123
tcpip::Storage outMsg;
124
// command length
125
outMsg.writeUnsignedByte(1 + 1 + 8);
126
// command id
127
outMsg.writeUnsignedByte(libsumo::CMD_SIMSTEP);
128
outMsg.writeDouble(time);
129
// send request message
130
mySocket->sendExact(outMsg);
131
}
132
133
134
void
135
TraCIAPI::send_commandClose() const {
136
tcpip::Storage outMsg;
137
// command length
138
outMsg.writeUnsignedByte(1 + 1);
139
// command id
140
outMsg.writeUnsignedByte(libsumo::CMD_CLOSE);
141
mySocket->sendExact(outMsg);
142
}
143
144
145
void
146
TraCIAPI::send_commandSetOrder(int order) const {
147
tcpip::Storage outMsg;
148
// command length
149
outMsg.writeUnsignedByte(1 + 1 + 4);
150
// command id
151
outMsg.writeUnsignedByte(libsumo::CMD_SETORDER);
152
// client index
153
outMsg.writeInt(order);
154
mySocket->sendExact(outMsg);
155
}
156
157
158
void
159
TraCIAPI::createCommand(int cmdID, int varID, const std::string& objID, tcpip::Storage* add) const {
160
myOutput.reset();
161
// command length
162
int length = 1 + 1 + 1 + 4 + (int) objID.length();
163
if (add != nullptr) {
164
length += (int)add->size();
165
}
166
if (length <= 255) {
167
myOutput.writeUnsignedByte(length);
168
} else {
169
myOutput.writeUnsignedByte(0);
170
myOutput.writeInt(length + 4);
171
}
172
myOutput.writeUnsignedByte(cmdID);
173
myOutput.writeUnsignedByte(varID);
174
myOutput.writeString(objID);
175
// additional values
176
if (add != nullptr) {
177
myOutput.writeStorage(*add);
178
}
179
}
180
181
182
void
183
TraCIAPI::createFilterCommand(int cmdID, int varID, tcpip::Storage* add) const {
184
myOutput.reset();
185
// command length
186
int length = 1 + 1 + 1;
187
if (add != nullptr) {
188
length += (int)add->size();
189
}
190
if (length <= 255) {
191
myOutput.writeUnsignedByte(length);
192
} else {
193
myOutput.writeUnsignedByte(0);
194
myOutput.writeInt(length + 4);
195
}
196
myOutput.writeUnsignedByte(cmdID);
197
myOutput.writeUnsignedByte(varID);
198
// additional values
199
if (add != nullptr) {
200
myOutput.writeStorage(*add);
201
}
202
}
203
204
205
void
206
TraCIAPI::send_commandSubscribeObjectVariable(int domID, const std::string& objID, double beginTime, double endTime,
207
const std::vector<int>& vars) const {
208
if (mySocket == nullptr) {
209
throw tcpip::SocketException("Socket is not initialised");
210
}
211
tcpip::Storage outMsg;
212
// command length (domID, objID, beginTime, endTime, length, vars)
213
int varNo = (int) vars.size();
214
outMsg.writeUnsignedByte(0);
215
outMsg.writeInt(5 + 1 + 8 + 8 + 4 + (int) objID.length() + 1 + varNo);
216
// command id
217
outMsg.writeUnsignedByte(domID);
218
// time
219
outMsg.writeDouble(beginTime);
220
outMsg.writeDouble(endTime);
221
// object id
222
outMsg.writeString(objID);
223
// command id
224
outMsg.writeUnsignedByte((int)vars.size());
225
for (int i = 0; i < varNo; ++i) {
226
outMsg.writeUnsignedByte(vars[i]);
227
}
228
// send message
229
mySocket->sendExact(outMsg);
230
}
231
232
233
void
234
TraCIAPI::send_commandSubscribeObjectContext(int domID, const std::string& objID, double beginTime, double endTime,
235
int domain, double range, const std::vector<int>& vars) const {
236
if (mySocket == nullptr) {
237
throw tcpip::SocketException("Socket is not initialised");
238
}
239
tcpip::Storage outMsg;
240
// command length (domID, objID, beginTime, endTime, length, vars)
241
int varNo = (int) vars.size();
242
outMsg.writeUnsignedByte(0);
243
outMsg.writeInt(5 + 1 + 8 + 8 + 4 + (int) objID.length() + 1 + 8 + 1 + varNo);
244
// command id
245
outMsg.writeUnsignedByte(domID);
246
// time
247
outMsg.writeDouble(beginTime);
248
outMsg.writeDouble(endTime);
249
// object id
250
outMsg.writeString(objID);
251
// domain and range
252
outMsg.writeUnsignedByte(domain);
253
outMsg.writeDouble(range);
254
// command id
255
outMsg.writeUnsignedByte((int)vars.size());
256
for (int i = 0; i < varNo; ++i) {
257
outMsg.writeUnsignedByte(vars[i]);
258
}
259
// send message
260
mySocket->sendExact(outMsg);
261
}
262
263
264
void
265
TraCIAPI::check_resultState(tcpip::Storage& inMsg, int command, bool ignoreCommandId, std::string* acknowledgement) const {
266
mySocket->receiveExact(inMsg);
267
int cmdLength;
268
int cmdId;
269
int resultType;
270
int cmdStart;
271
std::string msg;
272
try {
273
cmdStart = inMsg.position();
274
cmdLength = inMsg.readUnsignedByte();
275
cmdId = inMsg.readUnsignedByte();
276
if (command != cmdId && !ignoreCommandId) {
277
throw libsumo::TraCIException("#Error: received status response to command: " + toString(cmdId) + " but expected: " + toString(command));
278
}
279
resultType = inMsg.readUnsignedByte();
280
msg = inMsg.readString();
281
} catch (std::invalid_argument&) {
282
throw libsumo::TraCIException("#Error: an exception was thrown while reading result state message");
283
}
284
switch (resultType) {
285
case libsumo::RTYPE_ERR:
286
throw libsumo::TraCIException(".. Answered with error to command (" + toString(command) + "), [description: " + msg + "]");
287
case libsumo::RTYPE_NOTIMPLEMENTED:
288
throw libsumo::TraCIException(".. Sent command is not implemented (" + toString(command) + "), [description: " + msg + "]");
289
case libsumo::RTYPE_OK:
290
if (acknowledgement != nullptr) {
291
(*acknowledgement) = ".. Command acknowledged (" + toString(command) + "), [description: " + msg + "]";
292
}
293
break;
294
default:
295
throw libsumo::TraCIException(".. Answered with unknown result code(" + toString(resultType) + ") to command(" + toString(command) + "), [description: " + msg + "]");
296
}
297
if ((cmdStart + cmdLength) != (int) inMsg.position()) {
298
throw libsumo::TraCIException("#Error: command at position " + toString(cmdStart) + " has wrong length");
299
}
300
}
301
302
303
int
304
TraCIAPI::check_commandGetResult(tcpip::Storage& inMsg, int command, int expectedType, bool ignoreCommandId) const {
305
inMsg.position(); // respStart
306
int length = inMsg.readUnsignedByte();
307
if (length == 0) {
308
length = inMsg.readInt();
309
}
310
int cmdId = inMsg.readUnsignedByte();
311
if (!ignoreCommandId && cmdId != (command + 0x10)) {
312
throw libsumo::TraCIException("#Error: received response with command id: " + toString(cmdId) + "but expected: " + toString(command + 0x10));
313
}
314
if (expectedType >= 0) {
315
// not called from the TraCITestClient but from within the TraCIAPI
316
inMsg.readUnsignedByte(); // variableID
317
inMsg.readString(); // objectID
318
int valueDataType = inMsg.readUnsignedByte();
319
if (valueDataType != expectedType) {
320
throw libsumo::TraCIException("Expected " + toString(expectedType) + " but got " + toString(valueDataType));
321
}
322
}
323
return cmdId;
324
}
325
326
327
bool
328
TraCIAPI::processGet(int command, int expectedType, bool ignoreCommandId) {
329
if (mySocket != nullptr) {
330
mySocket->sendExact(myOutput);
331
myInput.reset();
332
check_resultState(myInput, command, ignoreCommandId);
333
check_commandGetResult(myInput, command, expectedType, ignoreCommandId);
334
return true;
335
}
336
return false;
337
}
338
339
340
bool
341
TraCIAPI::processSet(int command) {
342
if (mySocket != nullptr) {
343
mySocket->sendExact(myOutput);
344
myInput.reset();
345
check_resultState(myInput, command);
346
return true;
347
}
348
return false;
349
}
350
351
352
void
353
TraCIAPI::readVariables(tcpip::Storage& inMsg, const std::string& objectID, int variableCount, libsumo::SubscriptionResults& into) {
354
while (variableCount > 0) {
355
356
const int variableID = inMsg.readUnsignedByte();
357
const int status = inMsg.readUnsignedByte();
358
const int type = inMsg.readUnsignedByte();
359
360
if (status == libsumo::RTYPE_OK) {
361
switch (type) {
362
case libsumo::TYPE_DOUBLE:
363
into[objectID][variableID] = std::make_shared<libsumo::TraCIDouble>(inMsg.readDouble());
364
break;
365
case libsumo::TYPE_STRING:
366
into[objectID][variableID] = std::make_shared<libsumo::TraCIString>(inMsg.readString());
367
break;
368
case libsumo::POSITION_2D: {
369
auto p = std::make_shared<libsumo::TraCIPosition>();
370
p->x = inMsg.readDouble();
371
p->y = inMsg.readDouble();
372
p->z = 0.;
373
into[objectID][variableID] = p;
374
break;
375
}
376
case libsumo::POSITION_3D: {
377
auto p = std::make_shared<libsumo::TraCIPosition>();
378
p->x = inMsg.readDouble();
379
p->y = inMsg.readDouble();
380
p->z = inMsg.readDouble();
381
into[objectID][variableID] = p;
382
break;
383
}
384
case libsumo::TYPE_COLOR: {
385
auto c = std::make_shared<libsumo::TraCIColor>();
386
c->r = (unsigned char)inMsg.readUnsignedByte();
387
c->g = (unsigned char)inMsg.readUnsignedByte();
388
c->b = (unsigned char)inMsg.readUnsignedByte();
389
c->a = (unsigned char)inMsg.readUnsignedByte();
390
into[objectID][variableID] = c;
391
break;
392
}
393
case libsumo::TYPE_INTEGER:
394
into[objectID][variableID] = std::make_shared<libsumo::TraCIInt>(inMsg.readInt());
395
break;
396
case libsumo::TYPE_STRINGLIST: {
397
auto sl = std::make_shared<libsumo::TraCIStringList>();
398
int n = inMsg.readInt();
399
for (int i = 0; i < n; ++i) {
400
sl->value.push_back(inMsg.readString());
401
}
402
into[objectID][variableID] = sl;
403
}
404
break;
405
406
// TODO Other data types
407
408
default:
409
throw libsumo::TraCIException("Unimplemented subscription type: " + toString(type));
410
}
411
} else {
412
throw libsumo::TraCIException("Subscription response error: variableID=" + toString(variableID) + " status=" + toString(status));
413
}
414
415
variableCount--;
416
}
417
}
418
419
420
void
421
TraCIAPI::readVariableSubscription(int cmdId, tcpip::Storage& inMsg) {
422
const std::string objectID = inMsg.readString();
423
const int variableCount = inMsg.readUnsignedByte();
424
readVariables(inMsg, objectID, variableCount, myDomains[cmdId]->getModifiableSubscriptionResults());
425
}
426
427
428
void
429
TraCIAPI::readContextSubscription(int cmdId, tcpip::Storage& inMsg) {
430
const std::string contextID = inMsg.readString();
431
inMsg.readUnsignedByte(); // context domain
432
const int variableCount = inMsg.readUnsignedByte();
433
int numObjects = inMsg.readInt();
434
435
while (numObjects > 0) {
436
std::string objectID = inMsg.readString();
437
readVariables(inMsg, objectID, variableCount, myDomains[cmdId]->getModifiableContextSubscriptionResults(contextID));
438
numObjects--;
439
}
440
}
441
442
443
void
444
TraCIAPI::simulationStep(double time) {
445
send_commandSimulationStep(time);
446
tcpip::Storage inMsg;
447
check_resultState(inMsg, libsumo::CMD_SIMSTEP);
448
449
for (auto it : myDomains) {
450
it.second->clearSubscriptionResults();
451
}
452
int numSubs = inMsg.readInt();
453
while (numSubs > 0) {
454
int cmdId = check_commandGetResult(inMsg, 0, -1, true);
455
if (cmdId >= libsumo::RESPONSE_SUBSCRIBE_INDUCTIONLOOP_VARIABLE && cmdId <= libsumo::RESPONSE_SUBSCRIBE_PERSON_VARIABLE) {
456
readVariableSubscription(cmdId, inMsg);
457
} else {
458
readContextSubscription(cmdId + 0x50, inMsg);
459
}
460
numSubs--;
461
}
462
}
463
464
465
void
466
TraCIAPI::load(const std::vector<std::string>& args) {
467
int numChars = 0;
468
for (int i = 0; i < (int)args.size(); ++i) {
469
numChars += (int)args[i].size();
470
}
471
tcpip::Storage content;
472
content.writeUnsignedByte(0);
473
content.writeInt(1 + 4 + 1 + 1 + 4 + numChars + 4 * (int)args.size());
474
content.writeUnsignedByte(libsumo::CMD_LOAD);
475
content.writeUnsignedByte(libsumo::TYPE_STRINGLIST);
476
content.writeStringList(args);
477
mySocket->sendExact(content);
478
tcpip::Storage inMsg;
479
check_resultState(inMsg, libsumo::CMD_LOAD);
480
}
481
482
483
std::pair<int, std::string>
484
TraCIAPI::getVersion() {
485
tcpip::Storage content;
486
content.writeUnsignedByte(2);
487
content.writeUnsignedByte(libsumo::CMD_GETVERSION);
488
mySocket->sendExact(content);
489
tcpip::Storage inMsg;
490
check_resultState(inMsg, libsumo::CMD_GETVERSION);
491
inMsg.readUnsignedByte(); // msg length
492
inMsg.readUnsignedByte(); // libsumo::CMD_GETVERSION again, see #7284
493
const int traciVersion = inMsg.readInt(); // to fix evaluation order
494
return std::make_pair(traciVersion, inMsg.readString());
495
}
496
497
498
// ---------------------------------------------------------------------------
499
// TraCIAPI::EdgeScope-methods
500
// ---------------------------------------------------------------------------
501
double
502
TraCIAPI::EdgeScope::getAdaptedTraveltime(const std::string& edgeID, double time) const {
503
tcpip::Storage content;
504
content.writeByte(libsumo::TYPE_DOUBLE);
505
content.writeDouble(time);
506
return getDouble(libsumo::VAR_EDGE_TRAVELTIME, edgeID, &content);
507
}
508
509
double
510
TraCIAPI::EdgeScope::getEffort(const std::string& edgeID, double time) const {
511
tcpip::Storage content;
512
content.writeByte(libsumo::TYPE_DOUBLE);
513
content.writeDouble(time);
514
return getDouble(libsumo::VAR_EDGE_EFFORT, edgeID, &content);
515
}
516
517
double
518
TraCIAPI::EdgeScope::getCO2Emission(const std::string& edgeID) const {
519
return getDouble(libsumo::VAR_CO2EMISSION, edgeID);
520
}
521
522
523
double
524
TraCIAPI::EdgeScope::getCOEmission(const std::string& edgeID) const {
525
return getDouble(libsumo::VAR_COEMISSION, edgeID);
526
}
527
528
double
529
TraCIAPI::EdgeScope::getHCEmission(const std::string& edgeID) const {
530
return getDouble(libsumo::VAR_HCEMISSION, edgeID);
531
}
532
533
double
534
TraCIAPI::EdgeScope::getPMxEmission(const std::string& edgeID) const {
535
return getDouble(libsumo::VAR_PMXEMISSION, edgeID);
536
}
537
538
double
539
TraCIAPI::EdgeScope::getNOxEmission(const std::string& edgeID) const {
540
return getDouble(libsumo::VAR_NOXEMISSION, edgeID);
541
}
542
543
double
544
TraCIAPI::EdgeScope::getFuelConsumption(const std::string& edgeID) const {
545
return getDouble(libsumo::VAR_FUELCONSUMPTION, edgeID);
546
}
547
548
double
549
TraCIAPI::EdgeScope::getNoiseEmission(const std::string& edgeID) const {
550
return getDouble(libsumo::VAR_NOISEEMISSION, edgeID);
551
}
552
553
double
554
TraCIAPI::EdgeScope::getElectricityConsumption(const std::string& edgeID) const {
555
return getDouble(libsumo::VAR_ELECTRICITYCONSUMPTION, edgeID);
556
}
557
558
double
559
TraCIAPI::EdgeScope::getLastStepMeanSpeed(const std::string& edgeID) const {
560
return getDouble(libsumo::LAST_STEP_MEAN_SPEED, edgeID);
561
}
562
563
double
564
TraCIAPI::EdgeScope::getLastStepOccupancy(const std::string& edgeID) const {
565
return getDouble(libsumo::LAST_STEP_OCCUPANCY, edgeID);
566
}
567
568
double
569
TraCIAPI::EdgeScope::getLastStepLength(const std::string& edgeID) const {
570
return getDouble(libsumo::LAST_STEP_LENGTH, edgeID);
571
}
572
573
double
574
TraCIAPI::EdgeScope::getTraveltime(const std::string& edgeID) const {
575
return getDouble(libsumo::VAR_CURRENT_TRAVELTIME, edgeID);
576
}
577
578
int
579
TraCIAPI::EdgeScope::getLastStepVehicleNumber(const std::string& edgeID) const {
580
return getInt(libsumo::LAST_STEP_VEHICLE_NUMBER, edgeID);
581
}
582
583
double
584
TraCIAPI::EdgeScope::getLastStepHaltingNumber(const std::string& edgeID) const {
585
return getInt(libsumo::LAST_STEP_VEHICLE_HALTING_NUMBER, edgeID);
586
}
587
588
std::vector<std::string>
589
TraCIAPI::EdgeScope::getLastStepVehicleIDs(const std::string& edgeID) const {
590
return getStringVector(libsumo::LAST_STEP_VEHICLE_ID_LIST, edgeID);
591
}
592
593
594
int
595
TraCIAPI::EdgeScope::getLaneNumber(const std::string& edgeID) const {
596
return getInt(libsumo::VAR_LANE_INDEX, edgeID);
597
}
598
599
600
std::string
601
TraCIAPI::EdgeScope::getStreetName(const std::string& edgeID) const {
602
return getString(libsumo::VAR_NAME, edgeID);
603
}
604
605
606
void
607
TraCIAPI::EdgeScope::adaptTraveltime(const std::string& edgeID, double time, double beginSeconds, double endSeconds) const {
608
tcpip::Storage content;
609
content.writeByte(libsumo::TYPE_COMPOUND);
610
if (endSeconds != std::numeric_limits<double>::max()) {
611
content.writeInt(3);
612
content.writeByte(libsumo::TYPE_DOUBLE);
613
content.writeDouble(beginSeconds);
614
content.writeByte(libsumo::TYPE_DOUBLE);
615
content.writeDouble(endSeconds);
616
} else {
617
content.writeInt(1);
618
}
619
content.writeByte(libsumo::TYPE_DOUBLE);
620
content.writeDouble(time);
621
myParent.createCommand(libsumo::CMD_SET_EDGE_VARIABLE, libsumo::VAR_EDGE_TRAVELTIME, edgeID, &content);
622
myParent.processSet(libsumo::CMD_SET_EDGE_VARIABLE);
623
}
624
625
626
void
627
TraCIAPI::EdgeScope::setEffort(const std::string& edgeID, double effort, double beginSeconds, double endSeconds) const {
628
tcpip::Storage content;
629
content.writeByte(libsumo::TYPE_COMPOUND);
630
if (endSeconds != std::numeric_limits<double>::max()) {
631
content.writeInt(3);
632
content.writeByte(libsumo::TYPE_DOUBLE);
633
content.writeDouble(beginSeconds);
634
content.writeByte(libsumo::TYPE_DOUBLE);
635
content.writeDouble(endSeconds);
636
} else {
637
content.writeInt(1);
638
}
639
content.writeByte(libsumo::TYPE_DOUBLE);
640
content.writeDouble(effort);
641
myParent.createCommand(libsumo::CMD_SET_EDGE_VARIABLE, libsumo::VAR_EDGE_EFFORT, edgeID, &content);
642
myParent.processSet(libsumo::CMD_SET_EDGE_VARIABLE);
643
}
644
645
void
646
TraCIAPI::EdgeScope::setMaxSpeed(const std::string& edgeID, double speed) const {
647
setDouble(libsumo::VAR_MAXSPEED, edgeID, speed);
648
}
649
650
651
// ---------------------------------------------------------------------------
652
// TraCIAPI::GUIScope-methods
653
// ---------------------------------------------------------------------------
654
double
655
TraCIAPI::GUIScope::getZoom(const std::string& viewID) const {
656
return getDouble(libsumo::VAR_VIEW_ZOOM, viewID);
657
}
658
659
libsumo::TraCIPosition
660
TraCIAPI::GUIScope::getOffset(const std::string& viewID) const {
661
return getPos(libsumo::VAR_VIEW_OFFSET, viewID);
662
}
663
664
std::string
665
TraCIAPI::GUIScope::getSchema(const std::string& viewID) const {
666
return getString(libsumo::VAR_VIEW_SCHEMA, viewID);
667
}
668
669
libsumo::TraCIPositionVector
670
TraCIAPI::GUIScope::getBoundary(const std::string& viewID) const {
671
return getPolygon(libsumo::VAR_VIEW_BOUNDARY, viewID);
672
}
673
674
675
void
676
TraCIAPI::GUIScope::setZoom(const std::string& viewID, double zoom) const {
677
setDouble(libsumo::VAR_VIEW_ZOOM, viewID, zoom);
678
}
679
680
void
681
TraCIAPI::GUIScope::setOffset(const std::string& viewID, double x, double y) const {
682
tcpip::Storage content;
683
content.writeUnsignedByte(libsumo::POSITION_2D);
684
content.writeDouble(x);
685
content.writeDouble(y);
686
myParent.createCommand(libsumo::CMD_SET_GUI_VARIABLE, libsumo::VAR_VIEW_OFFSET, viewID, &content);
687
myParent.processSet(libsumo::CMD_SET_GUI_VARIABLE);
688
}
689
690
void
691
TraCIAPI::GUIScope::setSchema(const std::string& viewID, const std::string& schemeName) const {
692
setString(libsumo::VAR_VIEW_SCHEMA, viewID, schemeName);
693
}
694
695
void
696
TraCIAPI::GUIScope::setBoundary(const std::string& viewID, double xmin, double ymin, double xmax, double ymax) const {
697
tcpip::Storage content;
698
content.writeUnsignedByte(libsumo::TYPE_POLYGON);
699
content.writeByte(2);
700
content.writeDouble(xmin);
701
content.writeDouble(ymin);
702
content.writeDouble(xmax);
703
content.writeDouble(ymax);
704
myParent.createCommand(libsumo::CMD_SET_GUI_VARIABLE, libsumo::VAR_VIEW_BOUNDARY, viewID, &content);
705
myParent.processSet(libsumo::CMD_SET_GUI_VARIABLE);
706
}
707
708
void
709
TraCIAPI::GUIScope::screenshot(const std::string& viewID, const std::string& filename, const int width, const int height) const {
710
tcpip::Storage content;
711
content.writeByte(libsumo::TYPE_COMPOUND);
712
content.writeInt(3);
713
content.writeByte(libsumo::TYPE_STRING);
714
content.writeString(filename);
715
content.writeByte(libsumo::TYPE_INTEGER);
716
content.writeInt(width);
717
content.writeByte(libsumo::TYPE_INTEGER);
718
content.writeInt(height);
719
myParent.createCommand(libsumo::CMD_SET_GUI_VARIABLE, libsumo::VAR_SCREENSHOT, viewID, &content);
720
myParent.processSet(libsumo::CMD_SET_GUI_VARIABLE);
721
}
722
723
void
724
TraCIAPI::GUIScope::trackVehicle(const std::string& viewID, const std::string& vehID) const {
725
setString(libsumo::VAR_VIEW_SCHEMA, viewID, vehID);
726
}
727
728
729
// ---------------------------------------------------------------------------
730
// TraCIAPI::InductionLoopScope-methods
731
// ---------------------------------------------------------------------------
732
733
int TraCIAPI::InductionLoopScope::getIntervalVehicleNumber(const std::string& loopID) const {
734
return getInt(libsumo::VAR_LAST_INTERVAL_NUMBER, loopID);
735
}
736
737
double
738
TraCIAPI::InductionLoopScope::getPosition(const std::string& loopID) const {
739
return getDouble(libsumo::VAR_POSITION, loopID);
740
}
741
742
std::string
743
TraCIAPI::InductionLoopScope::getLaneID(const std::string& loopID) const {
744
return getString(libsumo::VAR_LANE_ID, loopID);
745
}
746
747
int
748
TraCIAPI::InductionLoopScope::getLastStepVehicleNumber(const std::string& loopID) const {
749
return getInt(libsumo::LAST_STEP_VEHICLE_NUMBER, loopID);
750
}
751
752
double
753
TraCIAPI::InductionLoopScope::getLastStepMeanSpeed(const std::string& loopID) const {
754
return getDouble(libsumo::LAST_STEP_MEAN_SPEED, loopID);
755
}
756
757
std::vector<std::string>
758
TraCIAPI::InductionLoopScope::getLastStepVehicleIDs(const std::string& loopID) const {
759
return getStringVector(libsumo::LAST_STEP_VEHICLE_ID_LIST, loopID);
760
}
761
762
double
763
TraCIAPI::InductionLoopScope::getLastStepOccupancy(const std::string& loopID) const {
764
return getDouble(libsumo::LAST_STEP_OCCUPANCY, loopID);
765
}
766
767
double
768
TraCIAPI::InductionLoopScope::getLastStepMeanLength(const std::string& loopID) const {
769
return getDouble(libsumo::LAST_STEP_LENGTH, loopID);
770
}
771
772
double
773
TraCIAPI::InductionLoopScope::getTimeSinceDetection(const std::string& loopID) const {
774
return getDouble(libsumo::LAST_STEP_TIME_SINCE_DETECTION, loopID);
775
}
776
777
778
std::vector<libsumo::TraCIVehicleData>
779
TraCIAPI::InductionLoopScope::getVehicleData(const std::string& loopID) const {
780
std::vector<libsumo::TraCIVehicleData> result;
781
myParent.createCommand(libsumo::CMD_GET_INDUCTIONLOOP_VARIABLE, libsumo::LAST_STEP_VEHICLE_DATA, loopID);
782
if (myParent.processGet(libsumo::CMD_GET_INDUCTIONLOOP_VARIABLE, libsumo::TYPE_COMPOUND)) {
783
myParent.myInput.readInt(); // components
784
// number of items
785
myParent.myInput.readUnsignedByte();
786
const int n = myParent.myInput.readInt();
787
for (int i = 0; i < n; ++i) {
788
libsumo::TraCIVehicleData vd;
789
790
myParent.myInput.readUnsignedByte();
791
vd.id = myParent.myInput.readString();
792
793
myParent.myInput.readUnsignedByte();
794
vd.length = myParent.myInput.readDouble();
795
796
myParent.myInput.readUnsignedByte();
797
vd.entryTime = myParent.myInput.readDouble();
798
799
myParent.myInput.readUnsignedByte();
800
vd.leaveTime = myParent.myInput.readDouble();
801
802
myParent.myInput.readUnsignedByte();
803
vd.typeID = myParent.myInput.readString();
804
805
result.push_back(vd);
806
}
807
}
808
return result;
809
}
810
811
812
// ---------------------------------------------------------------------------
813
// TraCIAPI::JunctionScope-methods
814
// ---------------------------------------------------------------------------
815
libsumo::TraCIPosition
816
TraCIAPI::JunctionScope::getPosition(const std::string& junctionID) const {
817
return getPos(libsumo::VAR_POSITION, junctionID);
818
}
819
820
libsumo::TraCIPositionVector
821
TraCIAPI::JunctionScope::getShape(const std::string& junctionID) const {
822
return getPolygon(libsumo::VAR_SHAPE, junctionID);
823
}
824
825
826
// ---------------------------------------------------------------------------
827
// TraCIAPI::LaneScope-methods
828
// ---------------------------------------------------------------------------
829
double
830
TraCIAPI::LaneScope::getLength(const std::string& laneID) const {
831
return getDouble(libsumo::VAR_LENGTH, laneID);
832
}
833
834
double
835
TraCIAPI::LaneScope::getMaxSpeed(const std::string& laneID) const {
836
return getDouble(libsumo::VAR_MAXSPEED, laneID);
837
}
838
839
double
840
TraCIAPI::LaneScope::getWidth(const std::string& laneID) const {
841
return getDouble(libsumo::VAR_WIDTH, laneID);
842
}
843
844
std::vector<std::string>
845
TraCIAPI::LaneScope::getAllowed(const std::string& laneID) const {
846
return getStringVector(libsumo::LANE_ALLOWED, laneID);
847
}
848
849
std::vector<std::string>
850
TraCIAPI::LaneScope::getDisallowed(const std::string& laneID) const {
851
return getStringVector(libsumo::LANE_DISALLOWED, laneID);
852
}
853
854
int
855
TraCIAPI::LaneScope::getLinkNumber(const std::string& laneID) const {
856
return getInt(libsumo::LANE_LINK_NUMBER, laneID);
857
}
858
859
std::vector<libsumo::TraCIConnection>
860
TraCIAPI::LaneScope::getLinks(const std::string& laneID) const {
861
std::vector<libsumo::TraCIConnection> ret;
862
myParent.createCommand(libsumo::CMD_GET_LANE_VARIABLE, libsumo::LANE_LINKS, laneID);
863
if (myParent.processGet(libsumo::CMD_GET_LANE_VARIABLE, libsumo::TYPE_COMPOUND)) {
864
myParent.myInput.readUnsignedByte();
865
myParent.myInput.readInt();
866
867
int linkNo = myParent.myInput.readInt();
868
for (int i = 0; i < linkNo; ++i) {
869
870
myParent.myInput.readUnsignedByte();
871
std::string approachedLane = myParent.myInput.readString();
872
873
myParent.myInput.readUnsignedByte();
874
std::string approachedLaneInternal = myParent.myInput.readString();
875
876
myParent.myInput.readUnsignedByte();
877
bool hasPrio = myParent.myInput.readUnsignedByte() != 0;
878
879
myParent.myInput.readUnsignedByte();
880
bool isOpen = myParent.myInput.readUnsignedByte() != 0;
881
882
myParent.myInput.readUnsignedByte();
883
bool hasFoe = myParent.myInput.readUnsignedByte() != 0;
884
885
myParent.myInput.readUnsignedByte();
886
std::string state = myParent.myInput.readString();
887
888
myParent.myInput.readUnsignedByte();
889
std::string direction = myParent.myInput.readString();
890
891
myParent.myInput.readUnsignedByte();
892
double length = myParent.myInput.readDouble();
893
894
ret.push_back(libsumo::TraCIConnection(approachedLane,
895
hasPrio,
896
isOpen,
897
hasFoe,
898
approachedLaneInternal,
899
state,
900
direction,
901
length));
902
903
}
904
905
}
906
return ret;
907
}
908
909
libsumo::TraCIPositionVector
910
TraCIAPI::LaneScope::getShape(const std::string& laneID) const {
911
return getPolygon(libsumo::VAR_SHAPE, laneID);
912
}
913
914
std::string
915
TraCIAPI::LaneScope::getEdgeID(const std::string& laneID) const {
916
return getString(libsumo::LANE_EDGE_ID, laneID);
917
}
918
919
double
920
TraCIAPI::LaneScope::getCO2Emission(const std::string& laneID) const {
921
return getDouble(libsumo::VAR_CO2EMISSION, laneID);
922
}
923
924
double
925
TraCIAPI::LaneScope::getCOEmission(const std::string& laneID) const {
926
return getDouble(libsumo::VAR_COEMISSION, laneID);
927
}
928
929
double
930
TraCIAPI::LaneScope::getHCEmission(const std::string& laneID) const {
931
return getDouble(libsumo::VAR_HCEMISSION, laneID);
932
}
933
934
double
935
TraCIAPI::LaneScope::getPMxEmission(const std::string& laneID) const {
936
return getDouble(libsumo::VAR_PMXEMISSION, laneID);
937
}
938
939
double
940
TraCIAPI::LaneScope::getNOxEmission(const std::string& laneID) const {
941
return getDouble(libsumo::VAR_NOXEMISSION, laneID);
942
}
943
944
double
945
TraCIAPI::LaneScope::getFuelConsumption(const std::string& laneID) const {
946
return getDouble(libsumo::VAR_FUELCONSUMPTION, laneID);
947
}
948
949
double
950
TraCIAPI::LaneScope::getNoiseEmission(const std::string& laneID) const {
951
return getDouble(libsumo::VAR_NOISEEMISSION, laneID);
952
}
953
954
double
955
TraCIAPI::LaneScope::getElectricityConsumption(const std::string& laneID) const {
956
return getDouble(libsumo::VAR_ELECTRICITYCONSUMPTION, laneID);
957
}
958
959
double
960
TraCIAPI::LaneScope::getLastStepMeanSpeed(const std::string& laneID) const {
961
return getDouble(libsumo::LAST_STEP_MEAN_SPEED, laneID);
962
}
963
964
double
965
TraCIAPI::LaneScope::getLastStepOccupancy(const std::string& laneID) const {
966
return getDouble(libsumo::LAST_STEP_OCCUPANCY, laneID);
967
}
968
969
double
970
TraCIAPI::LaneScope::getLastStepLength(const std::string& laneID) const {
971
return getDouble(libsumo::LAST_STEP_LENGTH, laneID);
972
}
973
974
double
975
TraCIAPI::LaneScope::getTraveltime(const std::string& laneID) const {
976
return getDouble(libsumo::VAR_CURRENT_TRAVELTIME, laneID);
977
}
978
979
int
980
TraCIAPI::LaneScope::getLastStepVehicleNumber(const std::string& laneID) const {
981
return getInt(libsumo::LAST_STEP_VEHICLE_NUMBER, laneID);
982
}
983
984
int
985
TraCIAPI::LaneScope::getLastStepHaltingNumber(const std::string& laneID) const {
986
return getInt(libsumo::LAST_STEP_VEHICLE_HALTING_NUMBER, laneID);
987
}
988
989
std::vector<std::string>
990
TraCIAPI::LaneScope::getLastStepVehicleIDs(const std::string& laneID) const {
991
return getStringVector(libsumo::LAST_STEP_VEHICLE_ID_LIST, laneID);
992
}
993
994
995
std::vector<std::string>
996
TraCIAPI::LaneScope::getFoes(const std::string& laneID, const std::string& toLaneID) const {
997
std::vector<std::string> r;
998
tcpip::Storage content;
999
content.writeUnsignedByte(libsumo::TYPE_STRING);
1000
content.writeString(toLaneID);
1001
myParent.createCommand(libsumo::CMD_GET_LANE_VARIABLE, libsumo::VAR_FOES, laneID, &content);
1002
if (myParent.processGet(libsumo::CMD_GET_LANE_VARIABLE, libsumo::TYPE_STRINGLIST)) {
1003
const int size = myParent.myInput.readInt();
1004
for (int i = 0; i < size; ++i) {
1005
r.push_back(myParent.myInput.readString());
1006
}
1007
}
1008
return r;
1009
}
1010
1011
std::vector<std::string>
1012
TraCIAPI::LaneScope::getInternalFoes(const std::string& laneID) const {
1013
return getFoes(laneID, "");
1014
}
1015
1016
1017
void
1018
TraCIAPI::LaneScope::setAllowed(const std::string& laneID, const std::vector<std::string>& allowedClasses) const {
1019
setStringVector(libsumo::LANE_ALLOWED, laneID, allowedClasses);
1020
}
1021
1022
void
1023
TraCIAPI::LaneScope::setDisallowed(const std::string& laneID, const std::vector<std::string>& disallowedClasses) const {
1024
setStringVector(libsumo::LANE_DISALLOWED, laneID, disallowedClasses);
1025
}
1026
1027
void
1028
TraCIAPI::LaneScope::setMaxSpeed(const std::string& laneID, double speed) const {
1029
setDouble(libsumo::VAR_MAXSPEED, laneID, speed);
1030
}
1031
1032
void
1033
TraCIAPI::LaneScope::setLength(const std::string& laneID, double length) const {
1034
setDouble(libsumo::VAR_LENGTH, laneID, length);
1035
}
1036
1037
1038
// ---------------------------------------------------------------------------
1039
// TraCIAPI::LaneAreaDetector-methods
1040
// ---------------------------------------------------------------------------
1041
1042
1043
// ---------------------------------------------------------------------------
1044
// TraCIAPI::MeMeScope-methods
1045
// ---------------------------------------------------------------------------
1046
int
1047
TraCIAPI::MeMeScope::getLastStepVehicleNumber(const std::string& detID) const {
1048
return getInt(libsumo::LAST_STEP_VEHICLE_NUMBER, detID);
1049
}
1050
1051
double
1052
TraCIAPI::MeMeScope::getLastStepMeanSpeed(const std::string& detID) const {
1053
return getDouble(libsumo::LAST_STEP_MEAN_SPEED, detID);
1054
}
1055
1056
std::vector<std::string>
1057
TraCIAPI::MeMeScope::getLastStepVehicleIDs(const std::string& detID) const {
1058
return getStringVector(libsumo::LAST_STEP_VEHICLE_ID_LIST, detID);
1059
}
1060
1061
int
1062
TraCIAPI::MeMeScope::getLastStepHaltingNumber(const std::string& detID) const {
1063
return getInt(libsumo::LAST_STEP_VEHICLE_HALTING_NUMBER, detID);
1064
}
1065
1066
std::vector<std::string>
1067
TraCIAPI::MeMeScope::getEntryLanes(const std::string& detID) const {
1068
return getStringVector(libsumo::VAR_LANES, detID);
1069
}
1070
1071
std::vector<std::string>
1072
TraCIAPI::MeMeScope::getExitLanes(const std::string& detID) const {
1073
return getStringVector(libsumo::VAR_EXIT_LANES, detID);
1074
}
1075
1076
std::vector<double>
1077
TraCIAPI::MeMeScope::getEntryPositions(const std::string& detID) const {
1078
return getDoubleVector(libsumo::VAR_POSITION, detID);
1079
}
1080
1081
std::vector<double>
1082
TraCIAPI::MeMeScope::getExitPositions(const std::string& detID) const {
1083
return getDoubleVector(libsumo::VAR_EXIT_POSITIONS, detID);
1084
}
1085
1086
// ---------------------------------------------------------------------------
1087
// TraCIAPI::POIScope-methods
1088
// ---------------------------------------------------------------------------
1089
std::string
1090
TraCIAPI::POIScope::getType(const std::string& poiID) const {
1091
return getString(libsumo::VAR_TYPE, poiID);
1092
}
1093
1094
libsumo::TraCIPosition
1095
TraCIAPI::POIScope::getPosition(const std::string& poiID) const {
1096
return getPos(libsumo::VAR_POSITION, poiID);
1097
}
1098
1099
libsumo::TraCIColor
1100
TraCIAPI::POIScope::getColor(const std::string& poiID) const {
1101
return getCol(libsumo::VAR_COLOR, poiID);
1102
}
1103
1104
double
1105
TraCIAPI::POIScope::getWidth(const std::string& poiID) const {
1106
return getDouble(libsumo::VAR_WIDTH, poiID);
1107
}
1108
1109
double
1110
TraCIAPI::POIScope::getHeight(const std::string& poiID) const {
1111
return getDouble(libsumo::VAR_HEIGHT, poiID);
1112
}
1113
1114
double
1115
TraCIAPI::POIScope::getAngle(const std::string& poiID) const {
1116
return getDouble(libsumo::VAR_ANGLE, poiID);
1117
}
1118
1119
std::string
1120
TraCIAPI::POIScope::getImageFile(const std::string& poiID) const {
1121
return getString(libsumo::VAR_IMAGEFILE, poiID);
1122
}
1123
1124
1125
void
1126
TraCIAPI::POIScope::setType(const std::string& poiID, const std::string& setType) const {
1127
setString(libsumo::VAR_TYPE, poiID, setType);
1128
}
1129
1130
1131
void
1132
TraCIAPI::POIScope::setPosition(const std::string& poiID, double x, double y) const {
1133
tcpip::Storage content;
1134
content.writeUnsignedByte(libsumo::POSITION_2D);
1135
content.writeDouble(x);
1136
content.writeDouble(y);
1137
myParent.createCommand(libsumo::CMD_SET_POI_VARIABLE, libsumo::VAR_POSITION, poiID, &content);
1138
myParent.processSet(libsumo::CMD_SET_POI_VARIABLE);
1139
}
1140
1141
1142
void
1143
TraCIAPI::POIScope::setColor(const std::string& poiID, const libsumo::TraCIColor& c) const {
1144
tcpip::Storage content;
1145
content.writeUnsignedByte(libsumo::TYPE_COLOR);
1146
content.writeUnsignedByte(c.r);
1147
content.writeUnsignedByte(c.g);
1148
content.writeUnsignedByte(c.b);
1149
content.writeUnsignedByte(c.a);
1150
myParent.createCommand(libsumo::CMD_SET_POI_VARIABLE, libsumo::VAR_COLOR, poiID, &content);
1151
myParent.processSet(libsumo::CMD_SET_POI_VARIABLE);
1152
}
1153
1154
1155
void
1156
TraCIAPI::POIScope::setWidth(const std::string& poiID, double width) const {
1157
setDouble(libsumo::VAR_WIDTH, poiID, width);
1158
}
1159
1160
1161
void
1162
TraCIAPI::POIScope::setHeight(const std::string& poiID, double height) const {
1163
setDouble(libsumo::VAR_HEIGHT, poiID, height);
1164
}
1165
1166
1167
void
1168
TraCIAPI::POIScope::setAngle(const std::string& poiID, double angle) const {
1169
setDouble(libsumo::VAR_ANGLE, poiID, angle);
1170
}
1171
1172
1173
void
1174
TraCIAPI::POIScope::setImageFile(const std::string& poiID, const std::string& imageFile) const {
1175
setString(libsumo::VAR_IMAGEFILE, poiID, imageFile);
1176
}
1177
1178
1179
void
1180
TraCIAPI::POIScope::add(const std::string& poiID, double x, double y, const libsumo::TraCIColor& c, const std::string& type, int layer, const std::string& imgFile, double width, double height, double angle) const {
1181
tcpip::Storage content;
1182
content.writeUnsignedByte(libsumo::TYPE_COMPOUND);
1183
content.writeInt(8);
1184
content.writeUnsignedByte(libsumo::TYPE_STRING);
1185
content.writeString(type);
1186
content.writeUnsignedByte(libsumo::TYPE_COLOR);
1187
content.writeUnsignedByte(c.r);
1188
content.writeUnsignedByte(c.g);
1189
content.writeUnsignedByte(c.b);
1190
content.writeUnsignedByte(c.a);
1191
content.writeUnsignedByte(libsumo::TYPE_INTEGER);
1192
content.writeInt(layer);
1193
content.writeUnsignedByte(libsumo::POSITION_2D);
1194
content.writeDouble(x);
1195
content.writeDouble(y);
1196
content.writeUnsignedByte(libsumo::TYPE_STRING);
1197
content.writeString(imgFile);
1198
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
1199
content.writeDouble(width);
1200
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
1201
content.writeDouble(height);
1202
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
1203
content.writeDouble(angle);
1204
myParent.createCommand(libsumo::CMD_SET_POI_VARIABLE, libsumo::ADD, poiID, &content);
1205
myParent.processSet(libsumo::CMD_SET_POI_VARIABLE);
1206
}
1207
1208
void
1209
TraCIAPI::POIScope::remove(const std::string& poiID, int layer) const {
1210
tcpip::Storage content;
1211
content.writeUnsignedByte(libsumo::TYPE_INTEGER);
1212
content.writeInt(layer);
1213
myParent.createCommand(libsumo::CMD_SET_POI_VARIABLE, libsumo::REMOVE, poiID, &content);
1214
myParent.processSet(libsumo::CMD_SET_POI_VARIABLE);
1215
}
1216
1217
1218
// ---------------------------------------------------------------------------
1219
// TraCIAPI::PolygonScope-methods
1220
// ---------------------------------------------------------------------------
1221
double
1222
TraCIAPI::PolygonScope::getLineWidth(const std::string& polygonID) const {
1223
return getDouble(libsumo::VAR_WIDTH, polygonID);
1224
}
1225
1226
bool
1227
TraCIAPI::PolygonScope::getFilled(const std::string& polygonID) const {
1228
return getInt(libsumo::VAR_FILL, polygonID) != 0;
1229
}
1230
1231
std::string
1232
TraCIAPI::PolygonScope::getType(const std::string& polygonID) const {
1233
return getString(libsumo::VAR_TYPE, polygonID);
1234
}
1235
1236
libsumo::TraCIPositionVector
1237
TraCIAPI::PolygonScope::getShape(const std::string& polygonID) const {
1238
return getPolygon(libsumo::VAR_SHAPE, polygonID);
1239
}
1240
1241
libsumo::TraCIColor
1242
TraCIAPI::PolygonScope::getColor(const std::string& polygonID) const {
1243
return getCol(libsumo::VAR_COLOR, polygonID);
1244
}
1245
1246
void
1247
TraCIAPI::PolygonScope::setLineWidth(const std::string& polygonID, const double lineWidth) const {
1248
tcpip::Storage content;
1249
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
1250
content.writeDouble(lineWidth);
1251
myParent.createCommand(libsumo::CMD_SET_POLYGON_VARIABLE, libsumo::VAR_WIDTH, polygonID, &content);
1252
myParent.processSet(libsumo::CMD_SET_POLYGON_VARIABLE);
1253
}
1254
1255
void
1256
TraCIAPI::PolygonScope::setType(const std::string& polygonID, const std::string& setType) const {
1257
tcpip::Storage content;
1258
content.writeUnsignedByte(libsumo::TYPE_STRING);
1259
content.writeString(setType);
1260
myParent.createCommand(libsumo::CMD_SET_POLYGON_VARIABLE, libsumo::VAR_TYPE, polygonID, &content);
1261
myParent.processSet(libsumo::CMD_SET_POLYGON_VARIABLE);
1262
}
1263
1264
1265
void
1266
TraCIAPI::PolygonScope::setShape(const std::string& polygonID, const libsumo::TraCIPositionVector& shape) const {
1267
tcpip::Storage content;
1268
content.writeUnsignedByte(libsumo::TYPE_POLYGON);
1269
if (shape.value.size() < 256) {
1270
content.writeUnsignedByte((int)shape.value.size());
1271
} else {
1272
content.writeUnsignedByte(0);
1273
content.writeInt((int)shape.value.size());
1274
}
1275
for (const libsumo::TraCIPosition& pos : shape.value) {
1276
content.writeDouble(pos.x);
1277
content.writeDouble(pos.y);
1278
}
1279
myParent.createCommand(libsumo::CMD_SET_POLYGON_VARIABLE, libsumo::VAR_SHAPE, polygonID, &content);
1280
myParent.processSet(libsumo::CMD_SET_POLYGON_VARIABLE);
1281
}
1282
1283
1284
void
1285
TraCIAPI::PolygonScope::setColor(const std::string& polygonID, const libsumo::TraCIColor& c) const {
1286
tcpip::Storage content;
1287
content.writeUnsignedByte(libsumo::TYPE_COLOR);
1288
content.writeUnsignedByte(c.r);
1289
content.writeUnsignedByte(c.g);
1290
content.writeUnsignedByte(c.b);
1291
content.writeUnsignedByte(c.a);
1292
myParent.createCommand(libsumo::CMD_SET_POLYGON_VARIABLE, libsumo::VAR_COLOR, polygonID, &content);
1293
myParent.processSet(libsumo::CMD_SET_POLYGON_VARIABLE);
1294
}
1295
1296
void
1297
TraCIAPI::PolygonScope::add(const std::string& polygonID, const libsumo::TraCIPositionVector& shape, const libsumo::TraCIColor& c, bool fill, const std::string& type, int layer) const {
1298
tcpip::Storage content;
1299
content.writeUnsignedByte(libsumo::TYPE_COMPOUND);
1300
content.writeInt(5);
1301
content.writeUnsignedByte(libsumo::TYPE_STRING);
1302
content.writeString(type);
1303
content.writeUnsignedByte(libsumo::TYPE_COLOR);
1304
content.writeUnsignedByte(c.r);
1305
content.writeUnsignedByte(c.g);
1306
content.writeUnsignedByte(c.b);
1307
content.writeUnsignedByte(c.a);
1308
content.writeUnsignedByte(libsumo::TYPE_UBYTE);
1309
int f = fill ? 1 : 0;
1310
content.writeUnsignedByte(f);
1311
content.writeUnsignedByte(libsumo::TYPE_INTEGER);
1312
content.writeInt(layer);
1313
content.writeUnsignedByte(libsumo::TYPE_POLYGON);
1314
content.writeUnsignedByte((int)shape.value.size());
1315
for (int i = 0; i < (int)shape.value.size(); ++i) {
1316
content.writeDouble(shape.value[i].x);
1317
content.writeDouble(shape.value[i].y);
1318
}
1319
myParent.createCommand(libsumo::CMD_SET_POLYGON_VARIABLE, libsumo::ADD, polygonID, &content);
1320
myParent.processSet(libsumo::CMD_SET_POLYGON_VARIABLE);
1321
}
1322
1323
void
1324
TraCIAPI::PolygonScope::remove(const std::string& polygonID, int layer) const {
1325
tcpip::Storage content;
1326
content.writeUnsignedByte(libsumo::TYPE_INTEGER);
1327
content.writeInt(layer);
1328
myParent.createCommand(libsumo::CMD_SET_POLYGON_VARIABLE, libsumo::REMOVE, polygonID, &content);
1329
myParent.processSet(libsumo::CMD_SET_POLYGON_VARIABLE);
1330
}
1331
1332
1333
// ---------------------------------------------------------------------------
1334
// TraCIAPI::RouteScope-methods
1335
// ---------------------------------------------------------------------------
1336
std::vector<std::string>
1337
TraCIAPI::RouteScope::getEdges(const std::string& routeID) const {
1338
return getStringVector(libsumo::VAR_EDGES, routeID);
1339
}
1340
1341
1342
void
1343
TraCIAPI::RouteScope::add(const std::string& routeID, const std::vector<std::string>& edges) const {
1344
tcpip::Storage content;
1345
content.writeUnsignedByte(libsumo::TYPE_STRINGLIST);
1346
content.writeStringList(edges);
1347
myParent.createCommand(libsumo::CMD_SET_ROUTE_VARIABLE, libsumo::ADD, routeID, &content);
1348
myParent.processSet(libsumo::CMD_SET_ROUTE_VARIABLE);
1349
}
1350
1351
1352
// ---------------------------------------------------------------------------
1353
// TraCIAPI::SimulationScope-methods
1354
// ---------------------------------------------------------------------------
1355
int
1356
TraCIAPI::SimulationScope::getCurrentTime() const {
1357
return getInt(libsumo::VAR_TIME_STEP, "");
1358
}
1359
1360
double
1361
TraCIAPI::SimulationScope::getTime() const {
1362
return getDouble(libsumo::VAR_TIME, "");
1363
}
1364
1365
int
1366
TraCIAPI::SimulationScope::getLoadedNumber() const {
1367
return (int) getInt(libsumo::VAR_LOADED_VEHICLES_NUMBER, "");
1368
}
1369
1370
std::vector<std::string>
1371
TraCIAPI::SimulationScope::getLoadedIDList() const {
1372
return getStringVector(libsumo::VAR_LOADED_VEHICLES_IDS, "");
1373
}
1374
1375
int
1376
TraCIAPI::SimulationScope::getDepartedNumber() const {
1377
return (int) getInt(libsumo::VAR_DEPARTED_VEHICLES_NUMBER, "");
1378
}
1379
1380
std::vector<std::string>
1381
TraCIAPI::SimulationScope::getDepartedIDList() const {
1382
return getStringVector(libsumo::VAR_DEPARTED_VEHICLES_IDS, "");
1383
}
1384
1385
int
1386
TraCIAPI::SimulationScope::getArrivedNumber() const {
1387
return (int) getInt(libsumo::VAR_ARRIVED_VEHICLES_NUMBER, "");
1388
}
1389
1390
std::vector<std::string>
1391
TraCIAPI::SimulationScope::getArrivedIDList() const {
1392
return getStringVector(libsumo::VAR_ARRIVED_VEHICLES_IDS, "");
1393
}
1394
1395
int
1396
TraCIAPI::SimulationScope::getStartingTeleportNumber() const {
1397
return (int) getInt(libsumo::VAR_TELEPORT_STARTING_VEHICLES_NUMBER, "");
1398
}
1399
1400
std::vector<std::string>
1401
TraCIAPI::SimulationScope::getStartingTeleportIDList() const {
1402
return getStringVector(libsumo::VAR_TELEPORT_STARTING_VEHICLES_IDS, "");
1403
}
1404
1405
int
1406
TraCIAPI::SimulationScope::getEndingTeleportNumber() const {
1407
return (int) getInt(libsumo::VAR_TELEPORT_ENDING_VEHICLES_NUMBER, "");
1408
}
1409
1410
std::vector<std::string>
1411
TraCIAPI::SimulationScope::getEndingTeleportIDList() const {
1412
return getStringVector(libsumo::VAR_TELEPORT_ENDING_VEHICLES_IDS, "");
1413
}
1414
1415
int
1416
TraCIAPI::SimulationScope::getDepartedPersonNumber() const {
1417
return (int)getInt(libsumo::VAR_DEPARTED_PERSONS_NUMBER, "");
1418
}
1419
1420
std::vector<std::string>
1421
TraCIAPI::SimulationScope::getDepartedPersonIDList() const {
1422
return getStringVector(libsumo::VAR_DEPARTED_PERSONS_IDS, "");
1423
}
1424
1425
int
1426
TraCIAPI::SimulationScope::getArrivedPersonNumber() const {
1427
return (int)getInt(libsumo::VAR_ARRIVED_PERSONS_NUMBER, "");
1428
}
1429
1430
std::vector<std::string>
1431
TraCIAPI::SimulationScope::getArrivedPersonIDList() const {
1432
return getStringVector(libsumo::VAR_ARRIVED_PERSONS_IDS, "");
1433
}
1434
1435
double
1436
TraCIAPI::SimulationScope::getDeltaT() const {
1437
return getDouble(libsumo::VAR_DELTA_T, "");
1438
}
1439
1440
libsumo::TraCIPositionVector
1441
TraCIAPI::SimulationScope::getNetBoundary() const {
1442
return getPolygon(libsumo::VAR_NET_BOUNDING_BOX, "");
1443
}
1444
1445
1446
int
1447
TraCIAPI::SimulationScope::getMinExpectedNumber() const {
1448
return getInt(libsumo::VAR_MIN_EXPECTED_VEHICLES, "");
1449
}
1450
1451
std::string
1452
TraCIAPI::SimulationScope::getOption(const std::string& option) const {
1453
return getString(libsumo::VAR_OPTION, option);
1454
}
1455
1456
int
1457
TraCIAPI::SimulationScope::getBusStopWaiting(const std::string& stopID) const {
1458
return (int) getInt(libsumo::VAR_BUS_STOP_WAITING, stopID);
1459
}
1460
1461
std::vector<std::string>
1462
TraCIAPI::SimulationScope::getBusStopWaitingIDList(const std::string& stopID) const {
1463
return getStringVector(libsumo::VAR_BUS_STOP_WAITING_IDS, stopID);
1464
}
1465
1466
1467
libsumo::TraCIPosition
1468
TraCIAPI::SimulationScope::convert2D(const std::string& edgeID, double pos, int laneIndex, bool toGeo) const {
1469
const int posType = toGeo ? libsumo::POSITION_LON_LAT : libsumo::POSITION_2D;
1470
libsumo::TraCIPosition result;
1471
tcpip::Storage content;
1472
content.writeByte(libsumo::TYPE_COMPOUND);
1473
content.writeInt(2);
1474
content.writeByte(libsumo::POSITION_ROADMAP);
1475
content.writeString(edgeID);
1476
content.writeDouble(pos);
1477
content.writeByte(laneIndex);
1478
content.writeByte(libsumo::TYPE_UBYTE);
1479
content.writeByte(posType);
1480
myParent.createCommand(libsumo::CMD_GET_SIM_VARIABLE, libsumo::POSITION_CONVERSION, "", &content);
1481
if (myParent.processGet(libsumo::CMD_GET_SIM_VARIABLE, posType)) {
1482
result.x = myParent.myInput.readDouble();
1483
result.y = myParent.myInput.readDouble();
1484
}
1485
return result;
1486
}
1487
1488
1489
libsumo::TraCIPosition
1490
TraCIAPI::SimulationScope::convert3D(const std::string& edgeID, double pos, int laneIndex, bool toGeo) const {
1491
const int posType = toGeo ? libsumo::POSITION_LON_LAT_ALT : libsumo::POSITION_3D;
1492
libsumo::TraCIPosition result;
1493
tcpip::Storage content;
1494
content.writeByte(libsumo::TYPE_COMPOUND);
1495
content.writeInt(2);
1496
content.writeByte(libsumo::POSITION_ROADMAP);
1497
content.writeString(edgeID);
1498
content.writeDouble(pos);
1499
content.writeByte(laneIndex);
1500
content.writeByte(libsumo::TYPE_UBYTE);
1501
content.writeByte(posType);
1502
myParent.createCommand(libsumo::CMD_GET_SIM_VARIABLE, libsumo::POSITION_CONVERSION, "", &content);
1503
if (myParent.processGet(libsumo::CMD_GET_SIM_VARIABLE, posType)) {
1504
result.x = myParent.myInput.readDouble();
1505
result.y = myParent.myInput.readDouble();
1506
result.z = myParent.myInput.readDouble();
1507
}
1508
return result;
1509
}
1510
1511
1512
libsumo::TraCIRoadPosition
1513
TraCIAPI::SimulationScope::convertRoad(double x, double y, bool isGeo, const std::string& vClass) const {
1514
libsumo::TraCIRoadPosition result;
1515
tcpip::Storage content;
1516
content.writeByte(libsumo::TYPE_COMPOUND);
1517
content.writeInt(3);
1518
content.writeByte(isGeo ? libsumo::POSITION_LON_LAT : libsumo::POSITION_2D);
1519
content.writeDouble(x);
1520
content.writeDouble(y);
1521
content.writeByte(libsumo::TYPE_UBYTE);
1522
content.writeByte(libsumo::POSITION_ROADMAP);
1523
content.writeByte(libsumo::TYPE_STRING);
1524
content.writeString(vClass);
1525
myParent.createCommand(libsumo::CMD_GET_SIM_VARIABLE, libsumo::POSITION_CONVERSION, "", &content);
1526
if (myParent.processGet(libsumo::CMD_GET_SIM_VARIABLE, libsumo::POSITION_ROADMAP)) {
1527
result.edgeID = myParent.myInput.readString();
1528
result.pos = myParent.myInput.readDouble();
1529
result.laneIndex = myParent.myInput.readUnsignedByte();
1530
}
1531
return result;
1532
}
1533
1534
1535
libsumo::TraCIPosition
1536
TraCIAPI::SimulationScope::convertGeo(double x, double y, bool fromGeo) const {
1537
const int posType = fromGeo ? libsumo::POSITION_2D : libsumo::POSITION_LON_LAT;
1538
libsumo::TraCIPosition result;
1539
tcpip::Storage content;
1540
content.writeByte(libsumo::TYPE_COMPOUND);
1541
content.writeInt(2);
1542
content.writeByte(fromGeo ? libsumo::POSITION_LON_LAT : libsumo::POSITION_2D);
1543
content.writeDouble(x);
1544
content.writeDouble(y);
1545
content.writeByte(libsumo::TYPE_UBYTE);
1546
content.writeByte(posType);
1547
myParent.createCommand(libsumo::CMD_GET_SIM_VARIABLE, libsumo::POSITION_CONVERSION, "", &content);
1548
if (myParent.processGet(libsumo::CMD_GET_SIM_VARIABLE, posType)) {
1549
result.x = myParent.myInput.readDouble();
1550
result.y = myParent.myInput.readDouble();
1551
}
1552
return result;
1553
}
1554
1555
1556
double
1557
TraCIAPI::SimulationScope::getDistance2D(double x1, double y1, double x2, double y2, bool isGeo, bool isDriving) {
1558
tcpip::Storage content;
1559
content.writeByte(libsumo::TYPE_COMPOUND);
1560
content.writeInt(3);
1561
content.writeByte(isGeo ? libsumo::POSITION_LON_LAT : libsumo::POSITION_2D);
1562
content.writeDouble(x1);
1563
content.writeDouble(y1);
1564
content.writeByte(isGeo ? libsumo::POSITION_LON_LAT : libsumo::POSITION_2D);
1565
content.writeDouble(x2);
1566
content.writeDouble(y2);
1567
content.writeByte(isDriving ? libsumo::REQUEST_DRIVINGDIST : libsumo::REQUEST_AIRDIST);
1568
myParent.createCommand(libsumo::CMD_GET_SIM_VARIABLE, libsumo::DISTANCE_REQUEST, "", &content);
1569
if (myParent.processGet(libsumo::CMD_GET_SIM_VARIABLE, libsumo::TYPE_DOUBLE)) {
1570
return myParent.myInput.readDouble();
1571
}
1572
return 0.;
1573
}
1574
1575
1576
double
1577
TraCIAPI::SimulationScope::getDistanceRoad(const std::string& edgeID1, double pos1, const std::string& edgeID2, double pos2, bool isDriving) {
1578
tcpip::Storage content;
1579
content.writeByte(libsumo::TYPE_COMPOUND);
1580
content.writeInt(3);
1581
content.writeByte(libsumo::POSITION_ROADMAP);
1582
content.writeString(edgeID1);
1583
content.writeDouble(pos1);
1584
content.writeByte(0); // lane
1585
content.writeByte(libsumo::POSITION_ROADMAP);
1586
content.writeString(edgeID2);
1587
content.writeDouble(pos2);
1588
content.writeByte(0); // lane
1589
content.writeByte(isDriving ? libsumo::REQUEST_DRIVINGDIST : libsumo::REQUEST_AIRDIST);
1590
myParent.createCommand(libsumo::CMD_GET_SIM_VARIABLE, libsumo::DISTANCE_REQUEST, "", &content);
1591
if (myParent.processGet(libsumo::CMD_GET_SIM_VARIABLE, libsumo::TYPE_DOUBLE)) {
1592
return myParent.myInput.readDouble();
1593
}
1594
return 0.;
1595
}
1596
1597
1598
libsumo::TraCIStage
1599
TraCIAPI::SimulationScope::findRoute(const std::string& fromEdge, const std::string& toEdge, const std::string& vType, double pos, int routingMode) const {
1600
tcpip::Storage content;
1601
content.writeByte(libsumo::TYPE_COMPOUND);
1602
content.writeInt(5);
1603
content.writeUnsignedByte(libsumo::TYPE_STRING);
1604
content.writeString(fromEdge);
1605
content.writeUnsignedByte(libsumo::TYPE_STRING);
1606
content.writeString(toEdge);
1607
content.writeUnsignedByte(libsumo::TYPE_STRING);
1608
content.writeString(vType);
1609
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
1610
content.writeDouble(pos);
1611
content.writeUnsignedByte(libsumo::TYPE_INTEGER);
1612
content.writeInt(routingMode);
1613
return getTraCIStage(libsumo::FIND_ROUTE, "", &content);
1614
}
1615
1616
void
1617
TraCIAPI::SimulationScope::loadState(const std::string& path) const {
1618
tcpip::Storage content;
1619
content.writeUnsignedByte(libsumo::TYPE_STRING);
1620
content.writeString(path);
1621
myParent.createCommand(libsumo::CMD_SET_SIM_VARIABLE, libsumo::CMD_LOAD_SIMSTATE, "", &content);
1622
myParent.processSet(libsumo::CMD_SET_SIM_VARIABLE);
1623
}
1624
1625
void
1626
TraCIAPI::SimulationScope::saveState(const std::string& destination) const {
1627
tcpip::Storage content;
1628
content.writeUnsignedByte(libsumo::TYPE_STRING);
1629
content.writeString(destination);
1630
myParent.createCommand(libsumo::CMD_SET_SIM_VARIABLE, libsumo::CMD_SAVE_SIMSTATE, "", &content);
1631
myParent.processSet(libsumo::CMD_SET_SIM_VARIABLE);
1632
}
1633
1634
void
1635
TraCIAPI::SimulationScope::writeMessage(const std::string msg) {
1636
tcpip::Storage content;
1637
content.writeUnsignedByte(libsumo::TYPE_STRING);
1638
content.writeString(msg);
1639
myParent.createCommand(libsumo::CMD_SET_SIM_VARIABLE, libsumo::CMD_MESSAGE, "", &content);
1640
myParent.processSet(libsumo::CMD_SET_SIM_VARIABLE);
1641
}
1642
1643
1644
// ---------------------------------------------------------------------------
1645
// TraCIAPI::TrafficLightScope-methods
1646
// ---------------------------------------------------------------------------
1647
std::string
1648
TraCIAPI::TrafficLightScope::getRedYellowGreenState(const std::string& tlsID) const {
1649
return getString(libsumo::TL_RED_YELLOW_GREEN_STATE, tlsID);
1650
}
1651
1652
std::vector<libsumo::TraCILogic>
1653
TraCIAPI::TrafficLightScope::getAllProgramLogics(const std::string& tlsID) const {
1654
std::vector<libsumo::TraCILogic> ret;
1655
myParent.createCommand(libsumo::CMD_GET_TL_VARIABLE, libsumo::TL_COMPLETE_DEFINITION_RYG, tlsID);
1656
if (myParent.processGet(libsumo::CMD_GET_TL_VARIABLE, libsumo::TYPE_COMPOUND)) {
1657
const int logicNo = myParent.myInput.readInt();
1658
for (int i = 0; i < logicNo; ++i) {
1659
myParent.myInput.readUnsignedByte();
1660
myParent.myInput.readInt();
1661
myParent.myInput.readUnsignedByte();
1662
const std::string programID = myParent.myInput.readString();
1663
myParent.myInput.readUnsignedByte();
1664
const int type = myParent.myInput.readInt();
1665
myParent.myInput.readUnsignedByte();
1666
const int phaseIndex = myParent.myInput.readInt();
1667
myParent.myInput.readUnsignedByte();
1668
const int phaseNumber = myParent.myInput.readInt();
1669
libsumo::TraCILogic logic(programID, type, phaseIndex);
1670
for (int j = 0; j < phaseNumber; j++) {
1671
myParent.myInput.readUnsignedByte();
1672
myParent.myInput.readInt();
1673
myParent.myInput.readUnsignedByte();
1674
const double duration = myParent.myInput.readDouble();
1675
myParent.myInput.readUnsignedByte();
1676
const std::string state = myParent.myInput.readString();
1677
myParent.myInput.readUnsignedByte();
1678
const double minDur = myParent.myInput.readDouble();
1679
myParent.myInput.readUnsignedByte();
1680
const double maxDur = myParent.myInput.readDouble();
1681
myParent.myInput.readUnsignedByte();
1682
const int numNext = myParent.myInput.readInt();
1683
std::vector<int> next;
1684
for (int k = 0; k < numNext; k++) {
1685
myParent.myInput.readUnsignedByte();
1686
next.push_back(myParent.myInput.readInt());
1687
}
1688
myParent.myInput.readUnsignedByte();
1689
const std::string name = myParent.myInput.readString();
1690
logic.phases.emplace_back(new libsumo::TraCIPhase(duration, state, minDur, maxDur, next, name));
1691
}
1692
myParent.myInput.readUnsignedByte();
1693
const int paramNumber = myParent.myInput.readInt();
1694
for (int j = 0; j < paramNumber; j++) {
1695
myParent.myInput.readUnsignedByte();
1696
const std::vector<std::string> par = myParent.myInput.readStringList();
1697
logic.subParameter[par[0]] = par[1];
1698
}
1699
ret.emplace_back(logic);
1700
}
1701
}
1702
return ret;
1703
}
1704
1705
std::vector<std::string>
1706
TraCIAPI::TrafficLightScope::getControlledLanes(const std::string& tlsID) const {
1707
return getStringVector(libsumo::TL_CONTROLLED_LANES, tlsID);
1708
}
1709
1710
std::vector<std::vector<libsumo::TraCILink> >
1711
TraCIAPI::TrafficLightScope::getControlledLinks(const std::string& tlsID) const {
1712
std::vector<std::vector<libsumo::TraCILink> > result;
1713
myParent.createCommand(libsumo::CMD_GET_TL_VARIABLE, libsumo::TL_CONTROLLED_LINKS, tlsID);
1714
if (myParent.processGet(libsumo::CMD_GET_TL_VARIABLE, libsumo::TYPE_COMPOUND)) {
1715
1716
myParent.myInput.readUnsignedByte();
1717
myParent.myInput.readInt();
1718
1719
int linkNo = myParent.myInput.readInt();
1720
for (int i = 0; i < linkNo; ++i) {
1721
myParent.myInput.readUnsignedByte();
1722
int no = myParent.myInput.readInt();
1723
std::vector<libsumo::TraCILink> ret;
1724
for (int i1 = 0; i1 < no; ++i1) {
1725
myParent.myInput.readUnsignedByte();
1726
myParent.myInput.readInt();
1727
std::string from = myParent.myInput.readString();
1728
std::string to = myParent.myInput.readString();
1729
std::string via = myParent.myInput.readString();
1730
ret.emplace_back(libsumo::TraCILink(from, via, to));
1731
}
1732
result.emplace_back(ret);
1733
}
1734
}
1735
return result;
1736
}
1737
1738
std::string
1739
TraCIAPI::TrafficLightScope::getProgram(const std::string& tlsID) const {
1740
return getString(libsumo::TL_CURRENT_PROGRAM, tlsID);
1741
}
1742
1743
int
1744
TraCIAPI::TrafficLightScope::getPhase(const std::string& tlsID) const {
1745
return getInt(libsumo::TL_CURRENT_PHASE, tlsID);
1746
}
1747
1748
std::string
1749
TraCIAPI::TrafficLightScope::getPhaseName(const std::string& tlsID) const {
1750
return getString(libsumo::VAR_NAME, tlsID);
1751
}
1752
1753
double
1754
TraCIAPI::TrafficLightScope::getPhaseDuration(const std::string& tlsID) const {
1755
return getDouble(libsumo::TL_PHASE_DURATION, tlsID);
1756
}
1757
1758
double
1759
TraCIAPI::TrafficLightScope::getNextSwitch(const std::string& tlsID) const {
1760
return getDouble(libsumo::TL_NEXT_SWITCH, tlsID);
1761
}
1762
1763
1764
int
1765
TraCIAPI::TrafficLightScope::getServedPersonCount(const std::string& tlsID, int index) const {
1766
tcpip::Storage content;
1767
content.writeByte(libsumo::TYPE_INTEGER);
1768
content.writeInt(index);
1769
return getInt(libsumo::VAR_PERSON_NUMBER, tlsID, &content);
1770
}
1771
1772
1773
void
1774
TraCIAPI::TrafficLightScope::setRedYellowGreenState(const std::string& tlsID, const std::string& state) const {
1775
tcpip::Storage content;
1776
content.writeUnsignedByte(libsumo::TYPE_STRING);
1777
content.writeString(state);
1778
myParent.createCommand(libsumo::CMD_SET_TL_VARIABLE, libsumo::TL_RED_YELLOW_GREEN_STATE, tlsID, &content);
1779
myParent.processSet(libsumo::CMD_SET_TL_VARIABLE);
1780
}
1781
1782
void
1783
TraCIAPI::TrafficLightScope::setPhase(const std::string& tlsID, int index) const {
1784
tcpip::Storage content;
1785
content.writeUnsignedByte(libsumo::TYPE_INTEGER);
1786
content.writeInt(index);
1787
myParent.createCommand(libsumo::CMD_SET_TL_VARIABLE, libsumo::TL_PHASE_INDEX, tlsID, &content);
1788
myParent.processSet(libsumo::CMD_SET_TL_VARIABLE);
1789
}
1790
1791
void
1792
TraCIAPI::TrafficLightScope::setPhaseName(const std::string& tlsID, const std::string& name) const {
1793
tcpip::Storage content;
1794
content.writeUnsignedByte(libsumo::TYPE_STRING);
1795
content.writeString(name);
1796
myParent.createCommand(libsumo::CMD_SET_TL_VARIABLE, libsumo::VAR_NAME, tlsID, &content);
1797
myParent.processSet(libsumo::CMD_SET_TL_VARIABLE);
1798
}
1799
1800
void
1801
TraCIAPI::TrafficLightScope::setProgram(const std::string& tlsID, const std::string& programID) const {
1802
tcpip::Storage content;
1803
content.writeUnsignedByte(libsumo::TYPE_STRING);
1804
content.writeString(programID);
1805
myParent.createCommand(libsumo::CMD_SET_TL_VARIABLE, libsumo::TL_PROGRAM, tlsID, &content);
1806
myParent.processSet(libsumo::CMD_SET_TL_VARIABLE);
1807
}
1808
1809
void
1810
TraCIAPI::TrafficLightScope::setPhaseDuration(const std::string& tlsID, double phaseDuration) const {
1811
tcpip::Storage content;
1812
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
1813
content.writeDouble(phaseDuration);
1814
myParent.createCommand(libsumo::CMD_SET_TL_VARIABLE, libsumo::TL_PHASE_DURATION, tlsID, &content);
1815
myParent.processSet(libsumo::CMD_SET_TL_VARIABLE);
1816
}
1817
1818
void
1819
TraCIAPI::TrafficLightScope::setProgramLogic(const std::string& tlsID, const libsumo::TraCILogic& logic) const {
1820
tcpip::Storage content;
1821
content.writeUnsignedByte(libsumo::TYPE_COMPOUND);
1822
content.writeInt(5);
1823
content.writeUnsignedByte(libsumo::TYPE_STRING);
1824
content.writeString(logic.programID);
1825
content.writeUnsignedByte(libsumo::TYPE_INTEGER);
1826
content.writeInt(logic.type);
1827
content.writeUnsignedByte(libsumo::TYPE_INTEGER);
1828
content.writeInt(logic.currentPhaseIndex);
1829
content.writeUnsignedByte(libsumo::TYPE_COMPOUND);
1830
content.writeInt((int)logic.phases.size());
1831
for (const std::shared_ptr<libsumo::TraCIPhase>& p : logic.phases) {
1832
content.writeUnsignedByte(libsumo::TYPE_COMPOUND);
1833
content.writeInt(6);
1834
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
1835
content.writeDouble(p->duration);
1836
content.writeUnsignedByte(libsumo::TYPE_STRING);
1837
content.writeString(p->state);
1838
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
1839
content.writeDouble(p->minDur);
1840
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
1841
content.writeDouble(p->maxDur);
1842
content.writeUnsignedByte(libsumo::TYPE_COMPOUND);
1843
content.writeInt((int)p->next.size());
1844
for (int n : p->next) {
1845
content.writeUnsignedByte(libsumo::TYPE_INTEGER);
1846
content.writeInt(n);
1847
}
1848
content.writeUnsignedByte(libsumo::TYPE_STRING);
1849
content.writeString(p->name);
1850
}
1851
content.writeUnsignedByte(libsumo::TYPE_COMPOUND);
1852
content.writeInt((int)logic.subParameter.size());
1853
for (const auto& item : logic.subParameter) {
1854
content.writeUnsignedByte(libsumo::TYPE_STRINGLIST);
1855
content.writeInt(2);
1856
content.writeString(item.first);
1857
content.writeString(item.second);
1858
}
1859
myParent.createCommand(libsumo::CMD_SET_TL_VARIABLE, libsumo::TL_COMPLETE_PROGRAM_RYG, tlsID, &content);
1860
myParent.processSet(libsumo::CMD_SET_TL_VARIABLE);
1861
}
1862
1863
1864
// ---------------------------------------------------------------------------
1865
// TraCIAPI::VehicleTypeScope-methods
1866
// ---------------------------------------------------------------------------
1867
double
1868
TraCIAPI::VehicleTypeScope::getLength(const std::string& typeID) const {
1869
return getDouble(libsumo::VAR_LENGTH, typeID);
1870
}
1871
1872
double
1873
TraCIAPI::VehicleTypeScope::getMaxSpeed(const std::string& typeID) const {
1874
return getDouble(libsumo::VAR_MAXSPEED, typeID);
1875
}
1876
1877
double
1878
TraCIAPI::VehicleTypeScope::getSpeedFactor(const std::string& typeID) const {
1879
return getDouble(libsumo::VAR_SPEED_FACTOR, typeID);
1880
}
1881
1882
double
1883
TraCIAPI::VehicleTypeScope::getSpeedDeviation(const std::string& typeID) const {
1884
return getDouble(libsumo::VAR_SPEED_DEVIATION, typeID);
1885
}
1886
1887
double
1888
TraCIAPI::VehicleTypeScope::getAccel(const std::string& typeID) const {
1889
return getDouble(libsumo::VAR_ACCEL, typeID);
1890
}
1891
1892
double
1893
TraCIAPI::VehicleTypeScope::getDecel(const std::string& typeID) const {
1894
return getDouble(libsumo::VAR_DECEL, typeID);
1895
}
1896
1897
double
1898
TraCIAPI::VehicleTypeScope::getEmergencyDecel(const std::string& typeID) const {
1899
return getDouble(libsumo::VAR_EMERGENCY_DECEL, typeID);
1900
}
1901
1902
double
1903
TraCIAPI::VehicleTypeScope::getApparentDecel(const std::string& typeID) const {
1904
return getDouble(libsumo::VAR_APPARENT_DECEL, typeID);
1905
}
1906
1907
double
1908
TraCIAPI::VehicleTypeScope::getImperfection(const std::string& typeID) const {
1909
return getDouble(libsumo::VAR_IMPERFECTION, typeID);
1910
}
1911
1912
double
1913
TraCIAPI::VehicleTypeScope::getTau(const std::string& typeID) const {
1914
return getDouble(libsumo::VAR_TAU, typeID);
1915
}
1916
1917
std::string
1918
TraCIAPI::VehicleTypeScope::getVehicleClass(const std::string& typeID) const {
1919
return getString(libsumo::VAR_VEHICLECLASS, typeID);
1920
}
1921
1922
std::string
1923
TraCIAPI::VehicleTypeScope::getEmissionClass(const std::string& typeID) const {
1924
return getString(libsumo::VAR_EMISSIONCLASS, typeID);
1925
}
1926
1927
std::string
1928
TraCIAPI::VehicleTypeScope::getShapeClass(const std::string& typeID) const {
1929
return getString(libsumo::VAR_SHAPECLASS, typeID);
1930
}
1931
1932
double
1933
TraCIAPI::VehicleTypeScope::getMinGap(const std::string& typeID) const {
1934
return getDouble(libsumo::VAR_MINGAP, typeID);
1935
}
1936
1937
double
1938
TraCIAPI::VehicleTypeScope::getMinGapLat(const std::string& typeID) const {
1939
return getDouble(libsumo::VAR_MINGAP_LAT, typeID);
1940
}
1941
1942
double
1943
TraCIAPI::VehicleTypeScope::getMaxSpeedLat(const std::string& typeID) const {
1944
return getDouble(libsumo::VAR_MAXSPEED_LAT, typeID);
1945
}
1946
1947
std::string
1948
TraCIAPI::VehicleTypeScope::getLateralAlignment(const std::string& typeID) const {
1949
return getString(libsumo::VAR_LATALIGNMENT, typeID);
1950
}
1951
1952
int
1953
TraCIAPI::VehicleTypeScope::getPersonCapacity(const std::string& typeID) const {
1954
return getInt(libsumo::VAR_PERSON_CAPACITY, typeID);
1955
}
1956
1957
double
1958
TraCIAPI::VehicleTypeScope::getWidth(const std::string& typeID) const {
1959
return getDouble(libsumo::VAR_WIDTH, typeID);
1960
}
1961
1962
double
1963
TraCIAPI::VehicleTypeScope::getHeight(const std::string& typeID) const {
1964
return getDouble(libsumo::VAR_HEIGHT, typeID);
1965
}
1966
1967
libsumo::TraCIColor
1968
TraCIAPI::VehicleTypeScope::getColor(const std::string& typeID) const {
1969
return getCol(libsumo::VAR_COLOR, typeID);
1970
}
1971
1972
1973
1974
void
1975
TraCIAPI::VehicleTypeScope::setLength(const std::string& typeID, double length) const {
1976
tcpip::Storage content;
1977
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
1978
content.writeDouble(length);
1979
myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_LENGTH, typeID, &content);
1980
myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
1981
}
1982
1983
void
1984
TraCIAPI::VehicleTypeScope::setMaxSpeed(const std::string& typeID, double speed) const {
1985
tcpip::Storage content;
1986
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
1987
content.writeDouble(speed);
1988
myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_MAXSPEED, typeID, &content);
1989
myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
1990
}
1991
1992
void
1993
TraCIAPI::VehicleTypeScope::setVehicleClass(const std::string& typeID, const std::string& clazz) const {
1994
tcpip::Storage content;
1995
content.writeUnsignedByte(libsumo::TYPE_STRING);
1996
content.writeString(clazz);
1997
myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_VEHICLECLASS, typeID, &content);
1998
myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
1999
}
2000
2001
void
2002
TraCIAPI::VehicleTypeScope::setSpeedFactor(const std::string& typeID, double factor) const {
2003
tcpip::Storage content;
2004
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
2005
content.writeDouble(factor);
2006
myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_SPEED_FACTOR, typeID, &content);
2007
myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2008
}
2009
2010
void
2011
TraCIAPI::VehicleTypeScope::setSpeedDeviation(const std::string& typeID, double deviation) const {
2012
tcpip::Storage content;
2013
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
2014
content.writeDouble(deviation);
2015
myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_SPEED_DEVIATION, typeID, &content);
2016
myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2017
}
2018
2019
2020
void
2021
TraCIAPI::VehicleTypeScope::setEmissionClass(const std::string& typeID, const std::string& clazz) const {
2022
tcpip::Storage content;
2023
content.writeUnsignedByte(libsumo::TYPE_STRING);
2024
content.writeString(clazz);
2025
myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_EMISSIONCLASS, typeID, &content);
2026
myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2027
}
2028
2029
void
2030
TraCIAPI::VehicleTypeScope::setWidth(const std::string& typeID, double width) const {
2031
tcpip::Storage content;
2032
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
2033
content.writeDouble(width);
2034
myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_WIDTH, typeID, &content);
2035
myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2036
}
2037
2038
void
2039
TraCIAPI::VehicleTypeScope::setHeight(const std::string& typeID, double height) const {
2040
tcpip::Storage content;
2041
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
2042
content.writeDouble(height);
2043
myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_HEIGHT, typeID, &content);
2044
myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2045
}
2046
2047
void
2048
TraCIAPI::VehicleTypeScope::setMinGap(const std::string& typeID, double minGap) const {
2049
tcpip::Storage content;
2050
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
2051
content.writeDouble(minGap);
2052
myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_MINGAP, typeID, &content);
2053
myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2054
}
2055
2056
2057
void
2058
TraCIAPI::VehicleTypeScope::setMinGapLat(const std::string& typeID, double minGapLat) const {
2059
tcpip::Storage content;
2060
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
2061
content.writeDouble(minGapLat);
2062
myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_MINGAP_LAT, typeID, &content);
2063
myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2064
}
2065
2066
void
2067
TraCIAPI::VehicleTypeScope::setMaxSpeedLat(const std::string& typeID, double speed) const {
2068
tcpip::Storage content;
2069
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
2070
content.writeDouble(speed);
2071
myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_MAXSPEED_LAT, typeID, &content);
2072
myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2073
}
2074
2075
void
2076
TraCIAPI::VehicleTypeScope::setLateralAlignment(const std::string& typeID, const std::string& latAlignment) const {
2077
tcpip::Storage content;
2078
content.writeUnsignedByte(libsumo::TYPE_STRING);
2079
content.writeString(latAlignment);
2080
myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_LATALIGNMENT, typeID, &content);
2081
myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2082
}
2083
2084
void
2085
TraCIAPI::VehicleTypeScope::copy(const std::string& origTypeID, const std::string& newTypeID) const {
2086
tcpip::Storage content;
2087
content.writeUnsignedByte(libsumo::TYPE_STRING);
2088
content.writeString(newTypeID);
2089
myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::COPY, origTypeID, &content);
2090
myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2091
}
2092
2093
void
2094
TraCIAPI::VehicleTypeScope::setShapeClass(const std::string& typeID, const std::string& clazz) const {
2095
tcpip::Storage content;
2096
content.writeUnsignedByte(libsumo::TYPE_STRING);
2097
content.writeString(clazz);
2098
myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_SHAPECLASS, typeID, &content);
2099
myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2100
}
2101
2102
void
2103
TraCIAPI::VehicleTypeScope::setAccel(const std::string& typeID, double accel) const {
2104
tcpip::Storage content;
2105
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
2106
content.writeDouble(accel);
2107
myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_ACCEL, typeID, &content);
2108
myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2109
}
2110
2111
void
2112
TraCIAPI::VehicleTypeScope::setDecel(const std::string& typeID, double decel) const {
2113
tcpip::Storage content;
2114
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
2115
content.writeDouble(decel);
2116
myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_DECEL, typeID, &content);
2117
myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2118
}
2119
2120
void
2121
TraCIAPI::VehicleTypeScope::setEmergencyDecel(const std::string& typeID, double decel) const {
2122
tcpip::Storage content;
2123
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
2124
content.writeDouble(decel);
2125
myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_EMERGENCY_DECEL, typeID, &content);
2126
myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2127
}
2128
2129
void
2130
TraCIAPI::VehicleTypeScope::setApparentDecel(const std::string& typeID, double decel) const {
2131
tcpip::Storage content;
2132
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
2133
content.writeDouble(decel);
2134
myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_APPARENT_DECEL, typeID, &content);
2135
myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2136
}
2137
2138
void
2139
TraCIAPI::VehicleTypeScope::setImperfection(const std::string& typeID, double imperfection) const {
2140
tcpip::Storage content;
2141
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
2142
content.writeDouble(imperfection);
2143
myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_IMPERFECTION, typeID, &content);
2144
myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2145
}
2146
2147
void
2148
TraCIAPI::VehicleTypeScope::setTau(const std::string& typeID, double tau) const {
2149
tcpip::Storage content;
2150
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
2151
content.writeDouble(tau);
2152
myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_TAU, typeID, &content);
2153
myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2154
}
2155
2156
void
2157
TraCIAPI::VehicleTypeScope::setColor(const std::string& typeID, const libsumo::TraCIColor& c) const {
2158
tcpip::Storage content;
2159
content.writeUnsignedByte(libsumo::TYPE_COLOR);
2160
content.writeUnsignedByte(c.r);
2161
content.writeUnsignedByte(c.g);
2162
content.writeUnsignedByte(c.b);
2163
content.writeUnsignedByte(c.a);
2164
myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_COLOR, typeID, &content);
2165
myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2166
}
2167
2168
2169
// ---------------------------------------------------------------------------
2170
// TraCIAPI::VehicleScope-methods
2171
// ---------------------------------------------------------------------------
2172
double
2173
TraCIAPI::VehicleScope::getSpeed(const std::string& vehicleID) const {
2174
return getDouble(libsumo::VAR_SPEED, vehicleID);
2175
}
2176
2177
double
2178
TraCIAPI::VehicleScope::getLateralSpeed(const std::string& vehicleID) const {
2179
return getDouble(libsumo::VAR_SPEED_LAT, vehicleID);
2180
}
2181
2182
double
2183
TraCIAPI::VehicleScope::getAcceleration(const std::string& vehicleID) const {
2184
return getDouble(libsumo::VAR_ACCELERATION, vehicleID);
2185
}
2186
2187
double
2188
TraCIAPI::VehicleScope::getFollowSpeed(const std::string& vehicleID, double speed, double gap, double leaderSpeed, double leaderMaxDecel, const std::string& leaderID) const {
2189
tcpip::Storage content;
2190
content.writeUnsignedByte(libsumo::TYPE_COMPOUND);
2191
content.writeInt(5);
2192
content.writeByte(libsumo::TYPE_DOUBLE);
2193
content.writeDouble(speed);
2194
content.writeByte(libsumo::TYPE_DOUBLE);
2195
content.writeDouble(gap);
2196
content.writeByte(libsumo::TYPE_DOUBLE);
2197
content.writeDouble(leaderSpeed);
2198
content.writeByte(libsumo::TYPE_DOUBLE);
2199
content.writeDouble(leaderMaxDecel);
2200
content.writeByte(libsumo::TYPE_STRING);
2201
content.writeString(leaderID);
2202
return getDouble(libsumo::VAR_FOLLOW_SPEED, vehicleID, &content);
2203
}
2204
2205
2206
double
2207
TraCIAPI::VehicleScope::getSecureGap(const std::string& vehicleID, double speed, double leaderSpeed, double leaderMaxDecel, const std::string& leaderID) const {
2208
tcpip::Storage content;
2209
content.writeUnsignedByte(libsumo::TYPE_COMPOUND);
2210
content.writeInt(4);
2211
content.writeByte(libsumo::TYPE_DOUBLE);
2212
content.writeDouble(speed);
2213
content.writeByte(libsumo::TYPE_DOUBLE);
2214
content.writeDouble(leaderSpeed);
2215
content.writeByte(libsumo::TYPE_DOUBLE);
2216
content.writeDouble(leaderMaxDecel);
2217
content.writeByte(libsumo::TYPE_STRING);
2218
content.writeString(leaderID);
2219
return getDouble(libsumo::VAR_SECURE_GAP, vehicleID, &content);
2220
}
2221
2222
double
2223
TraCIAPI::VehicleScope::getStopSpeed(const std::string& vehicleID, double speed, double gap) const {
2224
tcpip::Storage content;
2225
content.writeUnsignedByte(libsumo::TYPE_COMPOUND);
2226
content.writeInt(2);
2227
content.writeByte(libsumo::TYPE_DOUBLE);
2228
content.writeDouble(speed);
2229
content.writeByte(libsumo::TYPE_DOUBLE);
2230
content.writeDouble(gap);
2231
return getDouble(libsumo::VAR_STOP_SPEED, vehicleID, &content);
2232
}
2233
2234
2235
double
2236
TraCIAPI::VehicleScope::getMaxSpeed(const std::string& vehicleID) const {
2237
return getDouble(libsumo::VAR_MAXSPEED, vehicleID);
2238
}
2239
2240
libsumo::TraCIPosition
2241
TraCIAPI::VehicleScope::getPosition(const std::string& vehicleID) const {
2242
return getPos(libsumo::VAR_POSITION, vehicleID);
2243
}
2244
2245
libsumo::TraCIPosition
2246
TraCIAPI::VehicleScope::getPosition3D(const std::string& vehicleID) const {
2247
return getPos3D(libsumo::VAR_POSITION3D, vehicleID);
2248
}
2249
2250
double
2251
TraCIAPI::VehicleScope::getAngle(const std::string& vehicleID) const {
2252
return getDouble(libsumo::VAR_ANGLE, vehicleID);
2253
}
2254
2255
std::string
2256
TraCIAPI::VehicleScope::getRoadID(const std::string& vehicleID) const {
2257
return getString(libsumo::VAR_ROAD_ID, vehicleID);
2258
}
2259
2260
std::string
2261
TraCIAPI::VehicleScope::getLaneID(const std::string& vehicleID) const {
2262
return getString(libsumo::VAR_LANE_ID, vehicleID);
2263
}
2264
2265
int
2266
TraCIAPI::VehicleScope::getLaneIndex(const std::string& vehicleID) const {
2267
return getInt(libsumo::VAR_LANE_INDEX, vehicleID);
2268
}
2269
2270
std::string
2271
TraCIAPI::VehicleScope::getTypeID(const std::string& vehicleID) const {
2272
return getString(libsumo::VAR_TYPE, vehicleID);
2273
}
2274
2275
std::string
2276
TraCIAPI::VehicleScope::getRouteID(const std::string& vehicleID) const {
2277
return getString(libsumo::VAR_ROUTE_ID, vehicleID);
2278
}
2279
2280
int
2281
TraCIAPI::VehicleScope::getRouteIndex(const std::string& vehicleID) const {
2282
return getInt(libsumo::VAR_ROUTE_INDEX, vehicleID);
2283
}
2284
2285
2286
std::vector<std::string>
2287
TraCIAPI::VehicleScope::getRoute(const std::string& vehicleID) const {
2288
return getStringVector(libsumo::VAR_EDGES, vehicleID);
2289
}
2290
2291
libsumo::TraCIColor
2292
TraCIAPI::VehicleScope::getColor(const std::string& vehicleID) const {
2293
return getCol(libsumo::VAR_COLOR, vehicleID);
2294
}
2295
2296
double
2297
TraCIAPI::VehicleScope::getLanePosition(const std::string& vehicleID) const {
2298
return getDouble(libsumo::VAR_LANEPOSITION, vehicleID);
2299
}
2300
2301
double
2302
TraCIAPI::VehicleScope::getDistance(const std::string& vehicleID) const {
2303
return getDouble(libsumo::VAR_DISTANCE, vehicleID);
2304
}
2305
2306
int
2307
TraCIAPI::VehicleScope::getSignals(const std::string& vehicleID) const {
2308
return getInt(libsumo::VAR_SIGNALS, vehicleID);
2309
}
2310
2311
double
2312
TraCIAPI::VehicleScope::getLateralLanePosition(const std::string& vehicleID) const {
2313
return getDouble(libsumo::VAR_LANEPOSITION_LAT, vehicleID);
2314
}
2315
2316
double
2317
TraCIAPI::VehicleScope::getCO2Emission(const std::string& vehicleID) const {
2318
return getDouble(libsumo::VAR_CO2EMISSION, vehicleID);
2319
}
2320
2321
double
2322
TraCIAPI::VehicleScope::getCOEmission(const std::string& vehicleID) const {
2323
return getDouble(libsumo::VAR_COEMISSION, vehicleID);
2324
}
2325
2326
double
2327
TraCIAPI::VehicleScope::getHCEmission(const std::string& vehicleID) const {
2328
return getDouble(libsumo::VAR_HCEMISSION, vehicleID);
2329
}
2330
2331
double
2332
TraCIAPI::VehicleScope::getPMxEmission(const std::string& vehicleID) const {
2333
return getDouble(libsumo::VAR_PMXEMISSION, vehicleID);
2334
}
2335
2336
double
2337
TraCIAPI::VehicleScope::getNOxEmission(const std::string& vehicleID) const {
2338
return getDouble(libsumo::VAR_NOXEMISSION, vehicleID);
2339
}
2340
2341
double
2342
TraCIAPI::VehicleScope::getFuelConsumption(const std::string& vehicleID) const {
2343
return getDouble(libsumo::VAR_FUELCONSUMPTION, vehicleID);
2344
}
2345
2346
double
2347
TraCIAPI::VehicleScope::getNoiseEmission(const std::string& vehicleID) const {
2348
return getDouble(libsumo::VAR_NOISEEMISSION, vehicleID);
2349
}
2350
2351
double
2352
TraCIAPI::VehicleScope::getElectricityConsumption(const std::string& vehicleID) const {
2353
return getDouble(libsumo::VAR_ELECTRICITYCONSUMPTION, vehicleID);
2354
}
2355
2356
double
2357
TraCIAPI::VehicleScope::getWaitingTime(const std::string& vehID) const {
2358
return getDouble(libsumo::VAR_WAITING_TIME, vehID);
2359
}
2360
2361
int
2362
TraCIAPI::VehicleScope::getLaneChangeMode(const std::string& vehID) const {
2363
return getInt(libsumo::VAR_LANECHANGE_MODE, vehID);
2364
}
2365
2366
2367
int
2368
TraCIAPI::VehicleScope::getSpeedMode(const std::string& vehID) const {
2369
return getInt(libsumo::VAR_SPEEDSETMODE, vehID);
2370
}
2371
2372
2373
double
2374
TraCIAPI::VehicleScope::getSlope(const std::string& vehID) const {
2375
return getDouble(libsumo::VAR_SLOPE, vehID);
2376
}
2377
2378
2379
std::string
2380
TraCIAPI::VehicleScope::getLine(const std::string& typeID) const {
2381
return getString(libsumo::VAR_LINE, typeID);
2382
}
2383
2384
std::vector<std::string>
2385
TraCIAPI::VehicleScope::getVia(const std::string& vehicleID) const {
2386
return getStringVector(libsumo::VAR_VIA, vehicleID);
2387
}
2388
2389
std::string
2390
TraCIAPI::VehicleScope::getEmissionClass(const std::string& vehicleID) const {
2391
return getString(libsumo::VAR_EMISSIONCLASS, vehicleID);
2392
}
2393
2394
std::string
2395
TraCIAPI::VehicleScope::getShapeClass(const std::string& vehicleID) const {
2396
return getString(libsumo::VAR_SHAPECLASS, vehicleID);
2397
}
2398
2399
std::vector<libsumo::TraCINextTLSData>
2400
TraCIAPI::VehicleScope::getNextTLS(const std::string& vehID) const {
2401
std::vector<libsumo::TraCINextTLSData> result;
2402
myParent.createCommand(libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::VAR_NEXT_TLS, vehID);
2403
if (myParent.processGet(libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::TYPE_COMPOUND)) {
2404
myParent.myInput.readInt(); // components
2405
// number of items
2406
myParent.myInput.readUnsignedByte();
2407
const int n = myParent.myInput.readInt();
2408
for (int i = 0; i < n; ++i) {
2409
libsumo::TraCINextTLSData d;
2410
myParent.myInput.readUnsignedByte();
2411
d.id = myParent.myInput.readString();
2412
2413
myParent.myInput.readUnsignedByte();
2414
d.tlIndex = myParent.myInput.readInt();
2415
2416
myParent.myInput.readUnsignedByte();
2417
d.dist = myParent.myInput.readDouble();
2418
2419
myParent.myInput.readUnsignedByte();
2420
d.state = (char)myParent.myInput.readByte();
2421
2422
result.push_back(d);
2423
}
2424
}
2425
return result;
2426
}
2427
2428
std::vector<libsumo::TraCIBestLanesData>
2429
TraCIAPI::VehicleScope::getBestLanes(const std::string& vehicleID) const {
2430
std::vector<libsumo::TraCIBestLanesData> result;
2431
myParent.createCommand(libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::VAR_BEST_LANES, vehicleID);
2432
if (myParent.processGet(libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::TYPE_COMPOUND)) {
2433
myParent.myInput.readInt();
2434
myParent.myInput.readUnsignedByte();
2435
2436
const int n = myParent.myInput.readInt(); // number of following edge information
2437
for (int i = 0; i < n; ++i) {
2438
libsumo::TraCIBestLanesData info;
2439
myParent.myInput.readUnsignedByte();
2440
info.laneID = myParent.myInput.readString();
2441
2442
myParent.myInput.readUnsignedByte();
2443
info.length = myParent.myInput.readDouble();
2444
2445
myParent.myInput.readUnsignedByte();
2446
info.occupation = myParent.myInput.readDouble();
2447
2448
myParent.myInput.readUnsignedByte();
2449
info.bestLaneOffset = myParent.myInput.readByte();
2450
2451
myParent.myInput.readUnsignedByte();
2452
info.allowsContinuation = (myParent.myInput.readUnsignedByte() == 1);
2453
2454
myParent.myInput.readUnsignedByte();
2455
const int m = myParent.myInput.readInt();
2456
for (int j = 0; j < m; ++j) {
2457
info.continuationLanes.push_back(myParent.myInput.readString());
2458
}
2459
2460
result.push_back(info);
2461
}
2462
}
2463
return result;
2464
}
2465
2466
2467
std::pair<std::string, double>
2468
TraCIAPI::VehicleScope::getLeader(const std::string& vehicleID, double dist) const {
2469
tcpip::Storage content;
2470
content.writeByte(libsumo::TYPE_DOUBLE);
2471
content.writeDouble(dist);
2472
myParent.createCommand(libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::VAR_LEADER, vehicleID, &content);
2473
if (myParent.processGet(libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::TYPE_COMPOUND)) {
2474
myParent.myInput.readInt(); // components
2475
myParent.myInput.readUnsignedByte();
2476
const std::string leaderID = myParent.myInput.readString();
2477
myParent.myInput.readUnsignedByte();
2478
const double gap = myParent.myInput.readDouble();
2479
return std::make_pair(leaderID, gap);
2480
}
2481
return std::make_pair("", libsumo::INVALID_DOUBLE_VALUE);
2482
}
2483
2484
2485
std::pair<std::string, double>
2486
TraCIAPI::VehicleScope::getFollower(const std::string& vehicleID, double dist) const {
2487
tcpip::Storage content;
2488
content.writeByte(libsumo::TYPE_DOUBLE);
2489
content.writeDouble(dist);
2490
myParent.createCommand(libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::VAR_FOLLOWER, vehicleID, &content);
2491
if (myParent.processGet(libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::TYPE_COMPOUND)) {
2492
myParent.myInput.readInt(); // components
2493
myParent.myInput.readUnsignedByte();
2494
const std::string leaderID = myParent.myInput.readString();
2495
myParent.myInput.readUnsignedByte();
2496
const double gap = myParent.myInput.readDouble();
2497
return std::make_pair(leaderID, gap);
2498
}
2499
return std::make_pair("", libsumo::INVALID_DOUBLE_VALUE);
2500
}
2501
2502
2503
std::pair<int, int>
2504
TraCIAPI::VehicleScope::getLaneChangeState(const std::string& vehicleID, int direction) const {
2505
tcpip::Storage content;
2506
content.writeByte(libsumo::TYPE_INTEGER);
2507
content.writeInt(direction);
2508
myParent.createCommand(libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::CMD_CHANGELANE, vehicleID, &content);
2509
if (myParent.processGet(libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::TYPE_COMPOUND)) {
2510
myParent.myInput.readInt(); // components
2511
myParent.myInput.readUnsignedByte();
2512
const int stateWithoutTraCI = myParent.myInput.readInt();
2513
myParent.myInput.readUnsignedByte();
2514
const int state = myParent.myInput.readInt();
2515
return std::make_pair(stateWithoutTraCI, state);
2516
}
2517
return std::make_pair(libsumo::INVALID_INT_VALUE, libsumo::INVALID_INT_VALUE);
2518
}
2519
2520
2521
int
2522
TraCIAPI::VehicleScope::getStopState(const std::string& vehicleID) const {
2523
return getInt(libsumo::VAR_STOPSTATE, vehicleID);
2524
}
2525
2526
int
2527
TraCIAPI::VehicleScope::getRoutingMode(const std::string& vehicleID) const {
2528
return getInt(libsumo::VAR_ROUTING_MODE, vehicleID);
2529
}
2530
2531
double
2532
TraCIAPI::VehicleScope::getStopDelay(const std::string& vehicleID) const {
2533
return getDouble(libsumo::VAR_STOP_DELAY, vehicleID);
2534
}
2535
2536
double
2537
TraCIAPI::VehicleScope::getStopArrivalDelay(const std::string& vehicleID) const {
2538
return getDouble(libsumo::VAR_STOP_ARRIVALDELAY, vehicleID);
2539
}
2540
2541
2542
double
2543
TraCIAPI::VehicleScope::getAccel(const std::string& vehicleID) const {
2544
return getDouble(libsumo::VAR_ACCEL, vehicleID);
2545
}
2546
2547
double
2548
TraCIAPI::VehicleScope::getDecel(const std::string& vehicleID) const {
2549
return getDouble(libsumo::VAR_DECEL, vehicleID);
2550
}
2551
2552
double
2553
TraCIAPI::VehicleScope::getTau(const std::string& vehicleID) const {
2554
return getDouble(libsumo::VAR_TAU, vehicleID);
2555
}
2556
2557
double
2558
TraCIAPI::VehicleScope::getImperfection(const std::string& vehicleID) const {
2559
return getDouble(libsumo::VAR_IMPERFECTION, vehicleID);
2560
}
2561
2562
double
2563
TraCIAPI::VehicleScope::getSpeedFactor(const std::string& vehicleID) const {
2564
return getDouble(libsumo::VAR_SPEED_FACTOR, vehicleID);
2565
}
2566
2567
double
2568
TraCIAPI::VehicleScope::getSpeedDeviation(const std::string& vehicleID) const {
2569
return getDouble(libsumo::VAR_SPEED_DEVIATION, vehicleID);
2570
}
2571
2572
std::string
2573
TraCIAPI::VehicleScope::getVehicleClass(const std::string& vehicleID) const {
2574
return getString(libsumo::VAR_VEHICLECLASS, vehicleID);
2575
}
2576
2577
double
2578
TraCIAPI::VehicleScope::getMinGap(const std::string& vehicleID) const {
2579
return getDouble(libsumo::VAR_MINGAP, vehicleID);
2580
}
2581
2582
double
2583
TraCIAPI::VehicleScope::getWidth(const std::string& vehicleID) const {
2584
return getDouble(libsumo::VAR_WIDTH, vehicleID);
2585
}
2586
2587
double
2588
TraCIAPI::VehicleScope::getLength(const std::string& vehicleID) const {
2589
return getDouble(libsumo::VAR_LENGTH, vehicleID);
2590
}
2591
2592
double
2593
TraCIAPI::VehicleScope::getHeight(const std::string& vehicleID) const {
2594
return getDouble(libsumo::VAR_HEIGHT, vehicleID);
2595
}
2596
2597
double
2598
TraCIAPI::VehicleScope::getAccumulatedWaitingTime(const std::string& vehicleID) const {
2599
return getDouble(libsumo::VAR_ACCUMULATED_WAITING_TIME, vehicleID);
2600
}
2601
2602
double
2603
TraCIAPI::VehicleScope::getAllowedSpeed(const std::string& vehicleID) const {
2604
return getDouble(libsumo::VAR_ALLOWED_SPEED, vehicleID);
2605
}
2606
2607
int
2608
TraCIAPI::VehicleScope::getPersonNumber(const std::string& vehicleID) const {
2609
return getInt(libsumo::VAR_PERSON_NUMBER, vehicleID);
2610
}
2611
2612
int
2613
TraCIAPI::VehicleScope::getPersonCapacity(const std::string& vehicleID) const {
2614
return getInt(libsumo::VAR_PERSON_CAPACITY, vehicleID);
2615
}
2616
2617
std::vector<std::string>
2618
TraCIAPI::VehicleScope::getPersonIDList(const std::string& vehicleID) const {
2619
return getStringVector(libsumo::LAST_STEP_PERSON_ID_LIST, vehicleID);
2620
}
2621
2622
double
2623
TraCIAPI::VehicleScope::getSpeedWithoutTraCI(const std::string& vehicleID) const {
2624
return getDouble(libsumo::VAR_SPEED_WITHOUT_TRACI, vehicleID);
2625
}
2626
2627
bool
2628
TraCIAPI::VehicleScope::isRouteValid(const std::string& vehicleID) const {
2629
return getInt(libsumo::VAR_ROUTE_VALID, vehicleID) != 0;
2630
}
2631
2632
double
2633
TraCIAPI::VehicleScope::getMaxSpeedLat(const std::string& vehicleID) const {
2634
return getDouble(libsumo::VAR_MAXSPEED_LAT, vehicleID);
2635
}
2636
2637
double
2638
TraCIAPI::VehicleScope::getMinGapLat(const std::string& vehicleID) const {
2639
return getDouble(libsumo::VAR_MINGAP_LAT, vehicleID);
2640
}
2641
2642
std::string
2643
TraCIAPI::VehicleScope::getLateralAlignment(const std::string& vehicleID) const {
2644
return getString(libsumo::VAR_LATALIGNMENT, vehicleID);
2645
}
2646
2647
void
2648
TraCIAPI::VehicleScope::add(const std::string& vehicleID,
2649
const std::string& routeID,
2650
const std::string& typeID,
2651
std::string depart,
2652
const std::string& departLane,
2653
const std::string& departPos,
2654
const std::string& departSpeed,
2655
const std::string& arrivalLane,
2656
const std::string& arrivalPos,
2657
const std::string& arrivalSpeed,
2658
const std::string& fromTaz,
2659
const std::string& toTaz,
2660
const std::string& line,
2661
int personCapacity,
2662
int personNumber) const {
2663
2664
if (depart == "-1") {
2665
depart = toString(myParent.simulation.getCurrentTime() / 1000.0);
2666
}
2667
tcpip::Storage content;
2668
content.writeUnsignedByte(libsumo::TYPE_COMPOUND);
2669
content.writeInt(14);
2670
content.writeUnsignedByte(libsumo::TYPE_STRING);
2671
content.writeString(routeID);
2672
content.writeUnsignedByte(libsumo::TYPE_STRING);
2673
content.writeString(typeID);
2674
content.writeUnsignedByte(libsumo::TYPE_STRING);
2675
content.writeString(depart);
2676
content.writeUnsignedByte(libsumo::TYPE_STRING);
2677
content.writeString(departLane);
2678
content.writeUnsignedByte(libsumo::TYPE_STRING);
2679
content.writeString(departPos);
2680
content.writeUnsignedByte(libsumo::TYPE_STRING);
2681
content.writeString(departSpeed);
2682
2683
content.writeUnsignedByte(libsumo::TYPE_STRING);
2684
content.writeString(arrivalLane);
2685
content.writeUnsignedByte(libsumo::TYPE_STRING);
2686
content.writeString(arrivalPos);
2687
content.writeUnsignedByte(libsumo::TYPE_STRING);
2688
content.writeString(arrivalSpeed);
2689
2690
content.writeUnsignedByte(libsumo::TYPE_STRING);
2691
content.writeString(fromTaz);
2692
content.writeUnsignedByte(libsumo::TYPE_STRING);
2693
content.writeString(toTaz);
2694
content.writeUnsignedByte(libsumo::TYPE_STRING);
2695
content.writeString(line);
2696
2697
content.writeUnsignedByte(libsumo::TYPE_INTEGER);
2698
content.writeInt(personCapacity);
2699
content.writeUnsignedByte(libsumo::TYPE_INTEGER);
2700
content.writeInt(personNumber);
2701
2702
myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::ADD_FULL, vehicleID, &content);
2703
myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2704
}
2705
2706
2707
void
2708
TraCIAPI::VehicleScope::remove(const std::string& vehicleID, char reason) const {
2709
tcpip::Storage content;
2710
content.writeUnsignedByte(libsumo::TYPE_BYTE);
2711
content.writeUnsignedByte(reason);
2712
myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::REMOVE, vehicleID, &content);
2713
myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2714
2715
}
2716
2717
2718
void
2719
TraCIAPI::VehicleScope::changeTarget(const std::string& vehicleID, const std::string& edgeID) const {
2720
tcpip::Storage content;
2721
content.writeUnsignedByte(libsumo::TYPE_STRING);
2722
content.writeString(edgeID);
2723
myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::CMD_CHANGETARGET, vehicleID, &content);
2724
myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2725
}
2726
2727
2728
void
2729
TraCIAPI::VehicleScope::changeLane(const std::string& vehicleID, int laneIndex, double duration) const {
2730
tcpip::Storage content;
2731
content.writeUnsignedByte(libsumo::TYPE_COMPOUND);
2732
content.writeInt(2);
2733
content.writeUnsignedByte(libsumo::TYPE_BYTE);
2734
content.writeByte(laneIndex);
2735
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
2736
content.writeDouble(duration);
2737
myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::CMD_CHANGELANE, vehicleID, &content);
2738
myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2739
}
2740
2741
2742
void
2743
TraCIAPI::VehicleScope::changeLaneRelative(const std::string& vehicleID, int laneChange, double duration) const {
2744
tcpip::Storage content;
2745
content.writeUnsignedByte(libsumo::TYPE_COMPOUND);
2746
content.writeInt(3);
2747
content.writeUnsignedByte(libsumo::TYPE_BYTE);
2748
content.writeByte(laneChange);
2749
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
2750
content.writeDouble(duration);
2751
content.writeUnsignedByte(libsumo::TYPE_BYTE);
2752
content.writeByte(1);
2753
myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::CMD_CHANGELANE, vehicleID, &content);
2754
myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2755
}
2756
2757
2758
void
2759
TraCIAPI::VehicleScope::changeSublane(const std::string& vehicleID, double latDist) const {
2760
tcpip::Storage content;
2761
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
2762
content.writeDouble(latDist);
2763
myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::CMD_CHANGESUBLANE, vehicleID, &content);
2764
myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2765
}
2766
2767
2768
void
2769
TraCIAPI::VehicleScope::setRouteID(const std::string& vehicleID, const std::string& routeID) const {
2770
tcpip::Storage content;
2771
content.writeUnsignedByte(libsumo::TYPE_STRING);
2772
content.writeString(routeID);
2773
myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_ROUTE_ID, vehicleID, &content);
2774
myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2775
}
2776
2777
2778
void
2779
TraCIAPI::VehicleScope::setRoute(const std::string& vehicleID, const std::vector<std::string>& edges) const {
2780
tcpip::Storage content;
2781
content.writeUnsignedByte(libsumo::TYPE_STRINGLIST);
2782
content.writeInt((int)edges.size());
2783
for (int i = 0; i < (int)edges.size(); ++i) {
2784
content.writeString(edges[i]);
2785
}
2786
myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_ROUTE, vehicleID, &content);
2787
myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2788
}
2789
2790
2791
void
2792
TraCIAPI::VehicleScope::rerouteTraveltime(const std::string& vehicleID, bool currentTravelTimes) const {
2793
if (currentTravelTimes) {
2794
// updated edge weights with current network traveltimes (at most once per simulation step)
2795
std::vector<std::string> edges = myParent.edge.getIDList();
2796
for (std::vector<std::string>::iterator it = edges.begin(); it != edges.end(); ++it) {
2797
myParent.edge.adaptTraveltime(*it, myParent.edge.getTraveltime(*it));
2798
}
2799
}
2800
2801
tcpip::Storage content;
2802
content.writeUnsignedByte(libsumo::TYPE_COMPOUND);
2803
content.writeInt(0);
2804
myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::CMD_REROUTE_TRAVELTIME, vehicleID, &content);
2805
myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2806
}
2807
2808
void
2809
TraCIAPI::VehicleScope::moveTo(const std::string& vehicleID, const std::string& laneID, double position, int reason) const {
2810
tcpip::Storage content;
2811
content.writeUnsignedByte(libsumo::TYPE_COMPOUND);
2812
content.writeInt(3);
2813
content.writeUnsignedByte(libsumo::TYPE_STRING);
2814
content.writeString(laneID);
2815
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
2816
content.writeDouble(position);
2817
content.writeUnsignedByte(libsumo::TYPE_INTEGER);
2818
content.writeInt(reason);
2819
myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_MOVE_TO, vehicleID, &content);
2820
myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2821
}
2822
2823
void
2824
TraCIAPI::VehicleScope::moveToXY(const std::string& vehicleID, const std::string& edgeID, const int lane, const double x, const double y, const double angle, const int keepRoute) const {
2825
tcpip::Storage content;
2826
content.writeUnsignedByte(libsumo::TYPE_COMPOUND);
2827
content.writeInt(6);
2828
content.writeUnsignedByte(libsumo::TYPE_STRING);
2829
content.writeString(edgeID);
2830
content.writeUnsignedByte(libsumo::TYPE_INTEGER);
2831
content.writeInt(lane);
2832
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
2833
content.writeDouble(x);
2834
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
2835
content.writeDouble(y);
2836
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
2837
content.writeDouble(angle);
2838
content.writeUnsignedByte(libsumo::TYPE_BYTE);
2839
content.writeByte(keepRoute);
2840
myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::MOVE_TO_XY, vehicleID, &content);
2841
myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2842
}
2843
2844
2845
void
2846
TraCIAPI::VehicleScope::slowDown(const std::string& vehicleID, double speed, double duration) const {
2847
tcpip::Storage content;
2848
content.writeUnsignedByte(libsumo::TYPE_COMPOUND);
2849
content.writeInt(2);
2850
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
2851
content.writeDouble(speed);
2852
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
2853
content.writeDouble(duration);
2854
myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::CMD_SLOWDOWN, vehicleID, &content);
2855
myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2856
}
2857
2858
void
2859
TraCIAPI::VehicleScope::openGap(const std::string& vehicleID, double newTau, double duration, double changeRate, double maxDecel) const {
2860
tcpip::Storage content;
2861
content.writeUnsignedByte(libsumo::TYPE_COMPOUND);
2862
if (maxDecel > 0) {
2863
content.writeInt(4);
2864
} else {
2865
content.writeInt(3);
2866
}
2867
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
2868
content.writeDouble(newTau);
2869
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
2870
content.writeDouble(duration);
2871
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
2872
content.writeDouble(changeRate);
2873
if (maxDecel > 0) {
2874
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
2875
content.writeDouble(maxDecel);
2876
}
2877
myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::CMD_OPENGAP, vehicleID, &content);
2878
myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2879
}
2880
2881
void
2882
TraCIAPI::VehicleScope::setSpeed(const std::string& vehicleID, double speed) const {
2883
tcpip::Storage content;
2884
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
2885
content.writeDouble(speed);
2886
myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_SPEED, vehicleID, &content);
2887
myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2888
}
2889
2890
void
2891
TraCIAPI::VehicleScope::setAcceleration(const std::string& vehicleID, double accel, double duration) const {
2892
tcpip::Storage content;
2893
content.writeUnsignedByte(libsumo::TYPE_COMPOUND);
2894
content.writeInt(2);
2895
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
2896
content.writeDouble(accel);
2897
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
2898
content.writeDouble(duration);
2899
myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_ACCELERATION, vehicleID, &content);
2900
myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2901
}
2902
2903
void
2904
TraCIAPI::VehicleScope::setPreviousSpeed(const std::string& vehicleID, double prevSpeed, double prevAcceleration) const {
2905
tcpip::Storage content;
2906
content.writeUnsignedByte(libsumo::TYPE_COMPOUND);
2907
content.writeInt(2);
2908
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
2909
content.writeDouble(prevSpeed);
2910
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
2911
content.writeDouble(prevAcceleration);
2912
myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_PREV_SPEED, vehicleID, &content);
2913
myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2914
}
2915
2916
void
2917
TraCIAPI::VehicleScope::setLaneChangeMode(const std::string& vehicleID, int mode) const {
2918
tcpip::Storage content;
2919
content.writeByte(libsumo::TYPE_INTEGER);
2920
content.writeInt(mode);
2921
myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_LANECHANGE_MODE, vehicleID, &content);
2922
myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2923
}
2924
2925
void
2926
TraCIAPI::VehicleScope::setSpeedMode(const std::string& vehicleID, int mode) const {
2927
tcpip::Storage content;
2928
content.writeByte(libsumo::TYPE_INTEGER);
2929
content.writeInt(mode);
2930
myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_SPEEDSETMODE, vehicleID, &content);
2931
myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2932
}
2933
2934
void
2935
TraCIAPI::VehicleScope::setStop(const std::string vehicleID, const std::string edgeID, const double endPos, const int laneIndex,
2936
const double duration, const int flags, const double startPos, const double until) const {
2937
tcpip::Storage content;
2938
content.writeUnsignedByte(libsumo::TYPE_COMPOUND);
2939
content.writeInt(7);
2940
content.writeUnsignedByte(libsumo::TYPE_STRING);
2941
content.writeString(edgeID);
2942
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
2943
content.writeDouble(endPos);
2944
content.writeUnsignedByte(libsumo::TYPE_BYTE);
2945
content.writeByte(laneIndex);
2946
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
2947
content.writeDouble(duration);
2948
content.writeUnsignedByte(libsumo::TYPE_BYTE);
2949
content.writeByte(flags);
2950
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
2951
content.writeDouble(startPos);
2952
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
2953
content.writeDouble(until);
2954
myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::CMD_STOP, vehicleID, &content);
2955
myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2956
}
2957
2958
void
2959
TraCIAPI::VehicleScope::setType(const std::string& vehicleID, const std::string& typeID) const {
2960
tcpip::Storage content;
2961
content.writeUnsignedByte(libsumo::TYPE_STRING);
2962
content.writeString(typeID);
2963
myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_TYPE, vehicleID, &content);
2964
myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2965
}
2966
2967
void
2968
TraCIAPI::VehicleScope::setSpeedFactor(const std::string& vehicleID, double factor) const {
2969
tcpip::Storage content;
2970
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
2971
content.writeDouble(factor);
2972
myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_SPEED_FACTOR, vehicleID, &content);
2973
myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2974
}
2975
2976
void
2977
TraCIAPI::VehicleScope::setMinGap(const std::string& vehicleID, double minGap) const {
2978
tcpip::Storage content;
2979
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
2980
content.writeDouble(minGap);
2981
myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_MINGAP, vehicleID, &content);
2982
myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2983
}
2984
2985
void
2986
TraCIAPI::VehicleScope::setMaxSpeed(const std::string& vehicleID, double speed) const {
2987
tcpip::Storage content;
2988
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
2989
content.writeDouble(speed);
2990
myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_MAXSPEED, vehicleID, &content);
2991
myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2992
}
2993
2994
void
2995
TraCIAPI::VehicleScope::setColor(const std::string& vehicleID, const libsumo::TraCIColor& c) const {
2996
tcpip::Storage content;
2997
content.writeUnsignedByte(libsumo::TYPE_COLOR);
2998
content.writeUnsignedByte(c.r);
2999
content.writeUnsignedByte(c.g);
3000
content.writeUnsignedByte(c.b);
3001
content.writeUnsignedByte(c.a);
3002
myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_COLOR, vehicleID, &content);
3003
myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
3004
}
3005
3006
void
3007
TraCIAPI::VehicleScope::setLine(const std::string& vehicleID, const std::string& line) const {
3008
tcpip::Storage content;
3009
content.writeUnsignedByte(libsumo::TYPE_STRING);
3010
content.writeString(line);
3011
myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_LINE, vehicleID, &content);
3012
myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
3013
}
3014
3015
void
3016
TraCIAPI::VehicleScope::setVia(const std::string& vehicleID, const std::vector<std::string>& via) const {
3017
tcpip::Storage content;
3018
content.writeUnsignedByte(libsumo::TYPE_STRINGLIST);
3019
content.writeInt((int)via.size());
3020
for (int i = 0; i < (int)via.size(); ++i) {
3021
content.writeString(via[i]);
3022
}
3023
myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_VIA, vehicleID, &content);
3024
myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
3025
}
3026
3027
void
3028
TraCIAPI::VehicleScope::setSignals(const std::string& vehicleID, int signals) const {
3029
tcpip::Storage content;
3030
content.writeUnsignedByte(libsumo::TYPE_INTEGER);
3031
content.writeInt(signals);
3032
myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_SIGNALS, vehicleID, &content);
3033
myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
3034
}
3035
3036
void
3037
TraCIAPI::VehicleScope::setRoutingMode(const std::string& vehicleID, int routingMode) const {
3038
tcpip::Storage content;
3039
content.writeUnsignedByte(libsumo::TYPE_INTEGER);
3040
content.writeInt(routingMode);
3041
myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_ROUTING_MODE, vehicleID, &content);
3042
myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
3043
}
3044
3045
void
3046
TraCIAPI::VehicleScope::setShapeClass(const std::string& vehicleID, const std::string& clazz) const {
3047
tcpip::Storage content;
3048
content.writeUnsignedByte(libsumo::TYPE_STRING);
3049
content.writeString(clazz);
3050
myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_SHAPECLASS, vehicleID, &content);
3051
myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
3052
}
3053
3054
3055
void
3056
TraCIAPI::VehicleScope::setEmissionClass(const std::string& vehicleID, const std::string& clazz) const {
3057
tcpip::Storage content;
3058
content.writeUnsignedByte(libsumo::TYPE_STRING);
3059
content.writeString(clazz);
3060
myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_EMISSIONCLASS, vehicleID, &content);
3061
myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
3062
}
3063
3064
void
3065
TraCIAPI::VehicleScope::addSubscriptionFilterLanes(const std::vector<int>& lanes,
3066
bool noOpposite, double downstreamDist, double upstreamDist) const {
3067
addSubscriptionFilterByteList(libsumo::FILTER_TYPE_LANES, lanes);
3068
if (noOpposite) {
3069
addSubscriptionFilterNoOpposite();
3070
}
3071
if (downstreamDist >= 0) {
3072
addSubscriptionFilterDownstreamDistance(downstreamDist);
3073
}
3074
if (upstreamDist >= 0) {
3075
addSubscriptionFilterUpstreamDistance(upstreamDist);
3076
}
3077
}
3078
3079
3080
void
3081
TraCIAPI::VehicleScope::addSubscriptionFilterNoOpposite() const {
3082
addSubscriptionFilterEmpty(libsumo::FILTER_TYPE_NOOPPOSITE);
3083
}
3084
3085
void
3086
TraCIAPI::VehicleScope::addSubscriptionFilterDownstreamDistance(double dist) const {
3087
addSubscriptionFilterFloat(libsumo::FILTER_TYPE_DOWNSTREAM_DIST, dist);
3088
}
3089
3090
void
3091
TraCIAPI::VehicleScope::addSubscriptionFilterUpstreamDistance(double dist) const {
3092
addSubscriptionFilterFloat(libsumo::FILTER_TYPE_UPSTREAM_DIST, dist);
3093
}
3094
3095
3096
void
3097
TraCIAPI::VehicleScope::addSubscriptionFilterCFManeuver(double downstreamDist, double upstreamDist) const {
3098
addSubscriptionFilterLeadFollow(std::vector<int>({0}));
3099
if (downstreamDist >= 0) {
3100
addSubscriptionFilterDownstreamDistance(downstreamDist);
3101
}
3102
if (upstreamDist >= 0) {
3103
addSubscriptionFilterUpstreamDistance(upstreamDist);
3104
}
3105
}
3106
3107
void
3108
TraCIAPI::VehicleScope::addSubscriptionFilterLCManeuver(int direction, bool noOpposite, double downstreamDist, double upstreamDist) const {
3109
if (abs(direction) != 1) {
3110
std::cerr << "Ignoring lane change subscription filter with non-neighboring lane offset direction " << direction << "\n";
3111
return;
3112
}
3113
addSubscriptionFilterLeadFollow(std::vector<int>({0, direction}));
3114
if (noOpposite) {
3115
addSubscriptionFilterNoOpposite();
3116
}
3117
if (downstreamDist >= 0) {
3118
addSubscriptionFilterDownstreamDistance(downstreamDist);
3119
}
3120
if (upstreamDist >= 0) {
3121
addSubscriptionFilterUpstreamDistance(upstreamDist);
3122
}
3123
}
3124
3125
void
3126
TraCIAPI::VehicleScope::addSubscriptionFilterLeadFollow(const std::vector<int>& lanes) const {
3127
addSubscriptionFilterEmpty(libsumo::FILTER_TYPE_LEAD_FOLLOW);
3128
addSubscriptionFilterByteList(libsumo::FILTER_TYPE_LANES, lanes);
3129
}
3130
3131
void
3132
TraCIAPI::VehicleScope::addSubscriptionFilterTurn(double downstreamDist, double foeDistToJunction) const {
3133
addSubscriptionFilterFloat(libsumo::FILTER_TYPE_TURN, foeDistToJunction);
3134
if (downstreamDist >= 0) {
3135
addSubscriptionFilterDownstreamDistance(downstreamDist);
3136
}
3137
}
3138
3139
3140
void
3141
TraCIAPI::VehicleScope::addSubscriptionFilterVClass(const std::vector<std::string>& vClasses) const {
3142
addSubscriptionFilterStringList(libsumo::FILTER_TYPE_VCLASS, vClasses);
3143
}
3144
3145
3146
void
3147
TraCIAPI::VehicleScope::addSubscriptionFilterVType(const std::vector<std::string>& vTypes) const {
3148
addSubscriptionFilterStringList(libsumo::FILTER_TYPE_VTYPE, vTypes);
3149
}
3150
3151
3152
void
3153
TraCIAPI::VehicleScope::addSubscriptionFilterFieldOfVision(double angle) const {
3154
addSubscriptionFilterFloat(libsumo::FILTER_TYPE_FIELD_OF_VISION, angle);
3155
}
3156
3157
void
3158
TraCIAPI::VehicleScope::addSubscriptionFilterLateralDistance(double lateralDist, double downstreamDist, double upstreamDist) const {
3159
addSubscriptionFilterFloat(libsumo::FILTER_TYPE_LATERAL_DIST, lateralDist);
3160
if (downstreamDist >= 0) {
3161
addSubscriptionFilterDownstreamDistance(downstreamDist);
3162
}
3163
if (upstreamDist >= 0) {
3164
addSubscriptionFilterUpstreamDistance(upstreamDist);
3165
}
3166
}
3167
3168
void
3169
TraCIAPI::VehicleScope::addSubscriptionFilterEmpty(int filterType) const {
3170
myParent.createFilterCommand(libsumo::CMD_ADD_SUBSCRIPTION_FILTER, filterType);
3171
myParent.processSet(libsumo::CMD_ADD_SUBSCRIPTION_FILTER);
3172
}
3173
3174
void
3175
TraCIAPI::VehicleScope::addSubscriptionFilterFloat(int filterType, double val) const {
3176
tcpip::Storage content;
3177
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
3178
content.writeDouble(val);
3179
myParent.createFilterCommand(libsumo::CMD_ADD_SUBSCRIPTION_FILTER, filterType, &content);
3180
myParent.processSet(libsumo::CMD_ADD_SUBSCRIPTION_FILTER);
3181
}
3182
3183
3184
void
3185
TraCIAPI::VehicleScope::addSubscriptionFilterStringList(int filterType, const std::vector<std::string>& vals) const {
3186
tcpip::Storage content;
3187
content.writeUnsignedByte(libsumo::TYPE_STRINGLIST);
3188
content.writeStringList(vals);
3189
myParent.createFilterCommand(libsumo::CMD_ADD_SUBSCRIPTION_FILTER, filterType, &content);
3190
myParent.processSet(libsumo::CMD_ADD_SUBSCRIPTION_FILTER);
3191
}
3192
3193
3194
void
3195
TraCIAPI::VehicleScope::addSubscriptionFilterByteList(int filterType, const std::vector<int>& vals) const {
3196
tcpip::Storage content;
3197
content.writeUnsignedByte((int)vals.size());
3198
for (int i : vals) {
3199
content.writeByte(i);
3200
}
3201
myParent.createFilterCommand(libsumo::CMD_ADD_SUBSCRIPTION_FILTER, filterType, &content);
3202
myParent.processSet(libsumo::CMD_ADD_SUBSCRIPTION_FILTER);
3203
}
3204
3205
3206
// ---------------------------------------------------------------------------
3207
// TraCIAPI::PersonScope-methods
3208
// ---------------------------------------------------------------------------
3209
double
3210
TraCIAPI::PersonScope::getSpeed(const std::string& personID) const {
3211
return getDouble(libsumo::VAR_SPEED, personID);
3212
}
3213
3214
libsumo::TraCIPosition
3215
TraCIAPI::PersonScope::getPosition(const std::string& personID) const {
3216
return getPos(libsumo::VAR_POSITION, personID);
3217
}
3218
3219
libsumo::TraCIPosition
3220
TraCIAPI::PersonScope::getPosition3D(const std::string& personID) const {
3221
return getPos3D(libsumo::VAR_POSITION3D, personID);
3222
}
3223
3224
double
3225
TraCIAPI::PersonScope::getAngle(const std::string& personID) const {
3226
return getDouble(libsumo::VAR_ANGLE, personID);
3227
}
3228
3229
double
3230
TraCIAPI::PersonScope::getSlope(const std::string& personID) const {
3231
return getDouble(libsumo::VAR_SLOPE, personID);
3232
}
3233
3234
double
3235
TraCIAPI::PersonScope::getLanePosition(const std::string& personID) const {
3236
return getDouble(libsumo::VAR_LANEPOSITION, personID);
3237
}
3238
3239
libsumo::TraCIColor
3240
TraCIAPI::PersonScope::getColor(const std::string& personID) const {
3241
return getCol(libsumo::VAR_COLOR, personID);
3242
}
3243
3244
double
3245
TraCIAPI::PersonScope::getLength(const std::string& personID) const {
3246
return getDouble(libsumo::VAR_LENGTH, personID);
3247
}
3248
3249
std::string
3250
TraCIAPI::PersonScope::getRoadID(const std::string& personID) const {
3251
return getString(libsumo::VAR_ROAD_ID, personID);
3252
}
3253
3254
std::string
3255
TraCIAPI::PersonScope::getLaneID(const std::string& personID) const {
3256
return getString(libsumo::VAR_LANE_ID, personID);
3257
}
3258
3259
std::string
3260
TraCIAPI::PersonScope::getTypeID(const std::string& personID) const {
3261
return getString(libsumo::VAR_TYPE, personID);
3262
}
3263
3264
double
3265
TraCIAPI::PersonScope::getSpeedFactor(const std::string& personID) const {
3266
return getDouble(libsumo::VAR_SPEED_FACTOR, personID);
3267
}
3268
3269
double
3270
TraCIAPI::PersonScope::getWaitingTime(const std::string& personID) const {
3271
return getDouble(libsumo::VAR_WAITING_TIME, personID);
3272
}
3273
3274
std::string
3275
TraCIAPI::PersonScope::getNextEdge(const std::string& personID) const {
3276
return getString(libsumo::VAR_NEXT_EDGE, personID);
3277
}
3278
3279
3280
std::string
3281
TraCIAPI::PersonScope::getVehicle(const std::string& personID) const {
3282
return getString(libsumo::VAR_VEHICLE, personID);
3283
}
3284
3285
int
3286
TraCIAPI::PersonScope::getRemainingStages(const std::string& personID) const {
3287
return getInt(libsumo::VAR_STAGES_REMAINING, personID);
3288
}
3289
3290
libsumo::TraCIStage
3291
TraCIAPI::PersonScope::getStage(const std::string& personID, int nextStageIndex) const {
3292
tcpip::Storage content;
3293
content.writeByte(libsumo::TYPE_INTEGER);
3294
content.writeInt(nextStageIndex);
3295
return getTraCIStage(libsumo::VAR_STAGE, personID, &content);
3296
}
3297
3298
std::vector<std::string>
3299
TraCIAPI::PersonScope::getEdges(const std::string& personID, int nextStageIndex) const {
3300
tcpip::Storage content;
3301
content.writeByte(libsumo::TYPE_INTEGER);
3302
content.writeInt(nextStageIndex);
3303
return getStringVector(libsumo::VAR_EDGES, personID, &content);
3304
}
3305
3306
void
3307
TraCIAPI::PersonScope::removeStages(const std::string& personID) const {
3308
// remove all stages after the current and then abort the current stage
3309
while (getRemainingStages(personID) > 1) {
3310
removeStage(personID, 1);
3311
}
3312
removeStage(personID, 0);
3313
}
3314
3315
3316
void
3317
TraCIAPI::PersonScope::rerouteTraveltime(const std::string& personID) const {
3318
tcpip::Storage content;
3319
content.writeUnsignedByte(libsumo::TYPE_COMPOUND);
3320
content.writeInt(0);
3321
myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::CMD_REROUTE_TRAVELTIME, personID, &content);
3322
myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3323
}
3324
3325
3326
void
3327
TraCIAPI::PersonScope::add(const std::string& personID, const std::string& edgeID, double pos, double depart, const std::string typeID) {
3328
tcpip::Storage content;
3329
content.writeUnsignedByte(libsumo::TYPE_COMPOUND);
3330
content.writeInt(4);
3331
content.writeUnsignedByte(libsumo::TYPE_STRING);
3332
content.writeString(typeID);
3333
content.writeUnsignedByte(libsumo::TYPE_STRING);
3334
content.writeString(edgeID);
3335
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
3336
content.writeDouble(depart);
3337
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
3338
content.writeDouble(pos);
3339
myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::ADD, personID, &content);
3340
myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3341
}
3342
3343
void
3344
TraCIAPI::PersonScope::appendStage(const std::string& personID, const libsumo::TraCIStage& stage) {
3345
tcpip::Storage content;
3346
content.writeUnsignedByte(libsumo::TYPE_COMPOUND);
3347
content.writeInt(13);
3348
content.writeUnsignedByte(libsumo::TYPE_INTEGER);
3349
content.writeInt(stage.type);
3350
content.writeUnsignedByte(libsumo::TYPE_STRING);
3351
content.writeString(stage.vType);
3352
content.writeUnsignedByte(libsumo::TYPE_STRING);
3353
content.writeString(stage.line);
3354
content.writeUnsignedByte(libsumo::TYPE_STRING);
3355
content.writeString(stage.destStop);
3356
content.writeUnsignedByte(libsumo::TYPE_STRINGLIST);
3357
content.writeStringList(stage.edges);
3358
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
3359
content.writeDouble(stage.travelTime);
3360
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
3361
content.writeDouble(stage.cost);
3362
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
3363
content.writeDouble(stage.length);
3364
content.writeUnsignedByte(libsumo::TYPE_STRING);
3365
content.writeString(stage.intended);
3366
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
3367
content.writeDouble(stage.depart);
3368
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
3369
content.writeDouble(stage.departPos);
3370
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
3371
content.writeDouble(stage.arrivalPos);
3372
content.writeUnsignedByte(libsumo::TYPE_STRING);
3373
content.writeString(stage.description);
3374
myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::APPEND_STAGE, personID, &content);
3375
myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3376
}
3377
3378
3379
void
3380
TraCIAPI::PersonScope::appendWaitingStage(const std::string& personID, double duration, const std::string& description, const std::string& stopID) {
3381
tcpip::Storage content;
3382
content.writeUnsignedByte(libsumo::TYPE_COMPOUND);
3383
content.writeInt(4);
3384
content.writeUnsignedByte(libsumo::TYPE_INTEGER);
3385
content.writeInt(libsumo::STAGE_WAITING);
3386
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
3387
content.writeDouble(duration);
3388
content.writeUnsignedByte(libsumo::TYPE_STRING);
3389
content.writeString(description);
3390
content.writeUnsignedByte(libsumo::TYPE_STRING);
3391
content.writeString(stopID);
3392
myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::APPEND_STAGE, personID, &content);
3393
myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3394
}
3395
3396
void
3397
TraCIAPI::PersonScope::appendWalkingStage(const std::string& personID, const std::vector<std::string>& edges, double arrivalPos, double duration, double speed, const std::string& stopID) {
3398
tcpip::Storage content;
3399
content.writeUnsignedByte(libsumo::TYPE_COMPOUND);
3400
content.writeInt(6);
3401
content.writeUnsignedByte(libsumo::TYPE_INTEGER);
3402
content.writeInt(libsumo::STAGE_WALKING);
3403
content.writeUnsignedByte(libsumo::TYPE_STRINGLIST);
3404
content.writeStringList(edges);
3405
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
3406
content.writeDouble(arrivalPos);
3407
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
3408
content.writeDouble(duration);
3409
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
3410
content.writeDouble(speed);
3411
content.writeUnsignedByte(libsumo::TYPE_STRING);
3412
content.writeString(stopID);
3413
myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::APPEND_STAGE, personID, &content);
3414
myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3415
}
3416
3417
void
3418
TraCIAPI::PersonScope::appendDrivingStage(const std::string& personID, const std::string& toEdge, const std::string& lines, const std::string& stopID) {
3419
tcpip::Storage content;
3420
content.writeUnsignedByte(libsumo::TYPE_COMPOUND);
3421
content.writeInt(4);
3422
content.writeUnsignedByte(libsumo::TYPE_INTEGER);
3423
content.writeInt(libsumo::STAGE_DRIVING);
3424
content.writeUnsignedByte(libsumo::TYPE_STRING);
3425
content.writeString(toEdge);
3426
content.writeUnsignedByte(libsumo::TYPE_STRING);
3427
content.writeString(lines);
3428
content.writeUnsignedByte(libsumo::TYPE_STRING);
3429
content.writeString(stopID);
3430
myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::APPEND_STAGE, personID, &content);
3431
myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3432
}
3433
3434
void
3435
TraCIAPI::PersonScope::removeStage(const std::string& personID, int nextStageIndex) const {
3436
tcpip::Storage content;
3437
content.writeByte(libsumo::TYPE_INTEGER);
3438
content.writeInt(nextStageIndex);
3439
myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::REMOVE_STAGE, personID, &content);
3440
myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3441
}
3442
3443
void
3444
TraCIAPI::PersonScope::moveTo(const std::string& personID, const std::string& edgeID, double position) const {
3445
tcpip::Storage content;
3446
content.writeUnsignedByte(libsumo::TYPE_COMPOUND);
3447
content.writeInt(2);
3448
content.writeUnsignedByte(libsumo::TYPE_STRING);
3449
content.writeString(edgeID);
3450
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
3451
content.writeDouble(position);
3452
myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::VAR_MOVE_TO, personID, &content);
3453
myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3454
}
3455
3456
void
3457
TraCIAPI::PersonScope::moveToXY(const std::string& personID, const std::string& edgeID, const double x, const double y, double angle, const int keepRoute) const {
3458
tcpip::Storage content;
3459
content.writeUnsignedByte(libsumo::TYPE_COMPOUND);
3460
content.writeInt(5);
3461
content.writeUnsignedByte(libsumo::TYPE_STRING);
3462
content.writeString(edgeID);
3463
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
3464
content.writeDouble(x);
3465
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
3466
content.writeDouble(y);
3467
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
3468
content.writeDouble(angle);
3469
content.writeUnsignedByte(libsumo::TYPE_BYTE);
3470
content.writeByte(keepRoute);
3471
myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::MOVE_TO_XY, personID, &content);
3472
myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3473
}
3474
3475
void
3476
TraCIAPI::PersonScope::setSpeed(const std::string& personID, double speed) const {
3477
tcpip::Storage content;
3478
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
3479
content.writeDouble(speed);
3480
myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::VAR_SPEED, personID, &content);
3481
myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3482
}
3483
3484
3485
void
3486
TraCIAPI::PersonScope::setType(const std::string& personID, const std::string& typeID) const {
3487
tcpip::Storage content;
3488
content.writeUnsignedByte(libsumo::TYPE_STRING);
3489
content.writeString(typeID);
3490
myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::VAR_TYPE, personID, &content);
3491
myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3492
}
3493
3494
void
3495
TraCIAPI::PersonScope::setSpeedFactor(const std::string& personID, double factor) const {
3496
tcpip::Storage content;
3497
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
3498
content.writeDouble(factor);
3499
myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::VAR_SPEED_FACTOR, personID, &content);
3500
myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3501
}
3502
3503
void
3504
TraCIAPI::PersonScope::setLength(const std::string& personID, double length) const {
3505
tcpip::Storage content;
3506
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
3507
content.writeDouble(length);
3508
myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::VAR_LENGTH, personID, &content);
3509
myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3510
}
3511
3512
3513
void
3514
TraCIAPI::PersonScope::setWidth(const std::string& personID, double width) const {
3515
tcpip::Storage content;
3516
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
3517
content.writeDouble(width);
3518
myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::VAR_WIDTH, personID, &content);
3519
myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3520
}
3521
3522
void
3523
TraCIAPI::PersonScope::setHeight(const std::string& personID, double height) const {
3524
tcpip::Storage content;
3525
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
3526
content.writeDouble(height);
3527
myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::VAR_HEIGHT, personID, &content);
3528
myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3529
}
3530
3531
void
3532
TraCIAPI::PersonScope::setMinGap(const std::string& personID, double minGap) const {
3533
tcpip::Storage content;
3534
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
3535
content.writeDouble(minGap);
3536
myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::VAR_MINGAP, personID, &content);
3537
myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3538
}
3539
3540
3541
void
3542
TraCIAPI::PersonScope::setColor(const std::string& personID, const libsumo::TraCIColor& c) const {
3543
tcpip::Storage content;
3544
content.writeUnsignedByte(libsumo::TYPE_COLOR);
3545
content.writeUnsignedByte(c.r);
3546
content.writeUnsignedByte(c.g);
3547
content.writeUnsignedByte(c.b);
3548
content.writeUnsignedByte(c.a);
3549
myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::VAR_COLOR, personID, &content);
3550
myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3551
}
3552
3553
3554
// ---------------------------------------------------------------------------
3555
// TraCIAPI::TraCIScopeWrapper-methods
3556
// ---------------------------------------------------------------------------
3557
3558
int
3559
TraCIAPI::TraCIScopeWrapper::getUnsignedByte(int var, const std::string& id, tcpip::Storage* add) const {
3560
myParent.createCommand(myCmdGetID, var, id, add);
3561
if (myParent.processGet(myCmdGetID, libsumo::TYPE_UBYTE)) {
3562
return myParent.myInput.readUnsignedByte();
3563
}
3564
return libsumo::INVALID_INT_VALUE;
3565
}
3566
3567
3568
int
3569
TraCIAPI::TraCIScopeWrapper::getByte(int var, const std::string& id, tcpip::Storage* add) const {
3570
myParent.createCommand(myCmdGetID, var, id, add);
3571
if (myParent.processGet(myCmdGetID, libsumo::TYPE_BYTE)) {
3572
return myParent.myInput.readByte();
3573
}
3574
return libsumo::INVALID_INT_VALUE;
3575
}
3576
3577
3578
3579
int
3580
TraCIAPI::TraCIScopeWrapper::getInt(int var, const std::string& id, tcpip::Storage* add) const {
3581
myParent.createCommand(myCmdGetID, var, id, add);
3582
if (myParent.processGet(myCmdGetID, libsumo::TYPE_INTEGER)) {
3583
return myParent.myInput.readInt();
3584
}
3585
return libsumo::INVALID_INT_VALUE;
3586
}
3587
3588
3589
double
3590
TraCIAPI::TraCIScopeWrapper::getDouble(int var, const std::string& id, tcpip::Storage* add) const {
3591
myParent.createCommand(myCmdGetID, var, id, add);
3592
if (myParent.processGet(myCmdGetID, libsumo::TYPE_DOUBLE)) {
3593
return myParent.myInput.readDouble();
3594
}
3595
return libsumo::INVALID_DOUBLE_VALUE;
3596
}
3597
3598
3599
libsumo::TraCIPositionVector
3600
TraCIAPI::TraCIScopeWrapper::getPolygon(int var, const std::string& id, tcpip::Storage* add) const {
3601
libsumo::TraCIPositionVector ret;
3602
myParent.createCommand(myCmdGetID, var, id, add);
3603
if (myParent.processGet(myCmdGetID, libsumo::TYPE_POLYGON)) {
3604
int size = myParent.myInput.readUnsignedByte();
3605
if (size == 0) {
3606
size = myParent.myInput.readInt();
3607
}
3608
for (int i = 0; i < size; ++i) {
3609
libsumo::TraCIPosition p;
3610
p.x = myParent.myInput.readDouble();
3611
p.y = myParent.myInput.readDouble();
3612
p.z = 0.;
3613
ret.value.push_back(p);
3614
}
3615
}
3616
return ret;
3617
}
3618
3619
3620
libsumo::TraCIPosition
3621
TraCIAPI::TraCIScopeWrapper::getPos(int var, const std::string& id, tcpip::Storage* add) const {
3622
libsumo::TraCIPosition p;
3623
myParent.createCommand(myCmdGetID, var, id, add);
3624
if (myParent.processGet(myCmdGetID, libsumo::POSITION_2D)) {
3625
p.x = myParent.myInput.readDouble();
3626
p.y = myParent.myInput.readDouble();
3627
p.z = 0;
3628
}
3629
return p;
3630
}
3631
3632
3633
libsumo::TraCIPosition
3634
TraCIAPI::TraCIScopeWrapper::getPos3D(int var, const std::string& id, tcpip::Storage* add) const {
3635
libsumo::TraCIPosition p;
3636
myParent.createCommand(myCmdGetID, var, id, add);
3637
if (myParent.processGet(myCmdGetID, libsumo::POSITION_3D)) {
3638
p.x = myParent.myInput.readDouble();
3639
p.y = myParent.myInput.readDouble();
3640
p.z = myParent.myInput.readDouble();
3641
}
3642
return p;
3643
}
3644
3645
3646
std::string
3647
TraCIAPI::TraCIScopeWrapper::getString(int var, const std::string& id, tcpip::Storage* add) const {
3648
myParent.createCommand(myCmdGetID, var, id, add);
3649
if (myParent.processGet(myCmdGetID, libsumo::TYPE_STRING)) {
3650
return myParent.myInput.readString();
3651
}
3652
return "";
3653
}
3654
3655
3656
std::vector<std::string>
3657
TraCIAPI::TraCIScopeWrapper::getStringVector(int var, const std::string& id, tcpip::Storage* add) const {
3658
std::vector<std::string> r;
3659
myParent.createCommand(myCmdGetID, var, id, add);
3660
if (myParent.processGet(myCmdGetID, libsumo::TYPE_STRINGLIST)) {
3661
const int size = myParent.myInput.readInt();
3662
for (int i = 0; i < size; ++i) {
3663
r.push_back(myParent.myInput.readString());
3664
}
3665
}
3666
return r;
3667
}
3668
3669
3670
std::vector<double>
3671
TraCIAPI::TraCIScopeWrapper::getDoubleVector(int var, const std::string& id, tcpip::Storage* add) const {
3672
std::vector<double> r;
3673
myParent.createCommand(myCmdGetID, var, id, add);
3674
if (myParent.processGet(myCmdGetID, libsumo::TYPE_DOUBLELIST)) {
3675
const int size = myParent.myInput.readInt();
3676
for (int i = 0; i < size; ++i) {
3677
r.push_back(myParent.myInput.readDouble());
3678
}
3679
}
3680
return r;
3681
}
3682
3683
3684
libsumo::TraCIColor
3685
TraCIAPI::TraCIScopeWrapper::getCol(int var, const std::string& id, tcpip::Storage* add) const {
3686
libsumo::TraCIColor c;
3687
myParent.createCommand(myCmdGetID, var, id, add);
3688
if (myParent.processGet(myCmdGetID, libsumo::TYPE_COLOR)) {
3689
c.r = (unsigned char)myParent.myInput.readUnsignedByte();
3690
c.g = (unsigned char)myParent.myInput.readUnsignedByte();
3691
c.b = (unsigned char)myParent.myInput.readUnsignedByte();
3692
c.a = (unsigned char)myParent.myInput.readUnsignedByte();
3693
}
3694
return c;
3695
}
3696
3697
3698
libsumo::TraCIStage
3699
TraCIAPI::TraCIScopeWrapper::getTraCIStage(int var, const std::string& id, tcpip::Storage* add) const {
3700
libsumo::TraCIStage s;
3701
myParent.createCommand(myCmdGetID, var, id, add);
3702
if (myParent.processGet(myCmdGetID, libsumo::TYPE_COMPOUND)) {
3703
myParent.myInput.readInt(); // components
3704
myParent.myInput.readUnsignedByte();
3705
s.type = myParent.myInput.readInt();
3706
3707
myParent.myInput.readUnsignedByte();
3708
s.vType = myParent.myInput.readString();
3709
3710
myParent.myInput.readUnsignedByte();
3711
s.line = myParent.myInput.readString();
3712
3713
myParent.myInput.readUnsignedByte();
3714
s.destStop = myParent.myInput.readString();
3715
3716
myParent.myInput.readUnsignedByte();
3717
s.edges = myParent.myInput.readStringList();
3718
3719
myParent.myInput.readUnsignedByte();
3720
s.travelTime = myParent.myInput.readDouble();
3721
3722
myParent.myInput.readUnsignedByte();
3723
s.cost = myParent.myInput.readDouble();
3724
3725
myParent.myInput.readUnsignedByte();
3726
s.length = myParent.myInput.readDouble();
3727
3728
myParent.myInput.readUnsignedByte();
3729
s.intended = myParent.myInput.readString();
3730
3731
myParent.myInput.readUnsignedByte();
3732
s.depart = myParent.myInput.readDouble();
3733
3734
myParent.myInput.readUnsignedByte();
3735
s.departPos = myParent.myInput.readDouble();
3736
3737
myParent.myInput.readUnsignedByte();
3738
s.arrivalPos = myParent.myInput.readDouble();
3739
3740
myParent.myInput.readUnsignedByte();
3741
s.description = myParent.myInput.readString();
3742
}
3743
return s;
3744
}
3745
3746
3747
std::vector<std::string>
3748
TraCIAPI::TraCIScopeWrapper::getIDList() const {
3749
return getStringVector(libsumo::TRACI_ID_LIST, "");
3750
}
3751
3752
3753
int
3754
TraCIAPI::TraCIScopeWrapper::getIDCount() const {
3755
return getInt(libsumo::ID_COUNT, "");
3756
}
3757
3758
3759
std::string
3760
TraCIAPI::TraCIScopeWrapper::getParameter(const std::string& objectID, const std::string& key) const {
3761
tcpip::Storage content;
3762
content.writeByte(libsumo::TYPE_STRING);
3763
content.writeString(key);
3764
return getString(libsumo::VAR_PARAMETER, objectID, &content);
3765
}
3766
3767
3768
std::pair<std::string, std::string>
3769
TraCIAPI::TraCIScopeWrapper::getParameterWithKey(const std::string& objectID, const std::string& key) const {
3770
tcpip::Storage content;
3771
content.writeUnsignedByte(libsumo::TYPE_STRING);
3772
content.writeString(key);
3773
3774
myParent.createCommand(myCmdGetID, libsumo::VAR_PARAMETER_WITH_KEY, objectID, &content);
3775
if (myParent.processGet(myCmdGetID, libsumo::TYPE_COMPOUND)) {
3776
myParent.myInput.readInt(); // number of components
3777
myParent.myInput.readUnsignedByte();
3778
const std::string returnedKey = myParent.myInput.readString();
3779
myParent.myInput.readUnsignedByte();
3780
const std::string value = myParent.myInput.readString();
3781
return std::make_pair(returnedKey, value);
3782
}
3783
return std::make_pair(key, "");
3784
}
3785
3786
3787
void
3788
TraCIAPI::TraCIScopeWrapper::setParameter(const std::string& objectID, const std::string& key, const std::string& value) const {
3789
tcpip::Storage content;
3790
content.writeUnsignedByte(libsumo::TYPE_COMPOUND);
3791
content.writeInt(2);
3792
content.writeUnsignedByte(libsumo::TYPE_STRING);
3793
content.writeString(key);
3794
content.writeUnsignedByte(libsumo::TYPE_STRING);
3795
content.writeString(value);
3796
myParent.createCommand(myCmdSetID, libsumo::VAR_PARAMETER, objectID, &content);
3797
myParent.processSet(myCmdSetID);
3798
}
3799
3800
3801
void
3802
TraCIAPI::TraCIScopeWrapper::setInt(int var, const std::string& id, int value) const {
3803
tcpip::Storage content;
3804
content.writeUnsignedByte(libsumo::TYPE_INTEGER);
3805
content.writeInt(value);
3806
myParent.createCommand(myCmdSetID, var, id, &content);
3807
myParent.processSet(myCmdSetID);
3808
}
3809
3810
3811
void
3812
TraCIAPI::TraCIScopeWrapper::setDouble(int var, const std::string& id, double value) const {
3813
tcpip::Storage content;
3814
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
3815
content.writeDouble(value);
3816
myParent.createCommand(myCmdSetID, var, id, &content);
3817
myParent.processSet(myCmdSetID);
3818
}
3819
3820
3821
void
3822
TraCIAPI::TraCIScopeWrapper::setString(int var, const std::string& id, const std::string& value) const {
3823
tcpip::Storage content;
3824
content.writeUnsignedByte(libsumo::TYPE_STRING);
3825
content.writeString(value);
3826
myParent.createCommand(myCmdSetID, var, id, &content);
3827
myParent.processSet(myCmdSetID);
3828
}
3829
3830
3831
void
3832
TraCIAPI::TraCIScopeWrapper::setStringVector(int var, const std::string& id, const std::vector<std::string>& value) const {
3833
tcpip::Storage content;
3834
content.writeUnsignedByte(libsumo::TYPE_STRINGLIST);
3835
content.writeInt((int)value.size());
3836
for (const std::string& s : value) {
3837
content.writeString(s);
3838
}
3839
myParent.createCommand(myCmdSetID, var, id, &content);
3840
myParent.processSet(myCmdSetID);
3841
}
3842
3843
3844
void
3845
TraCIAPI::TraCIScopeWrapper::subscribe(const std::string& objID, const std::vector<int>& vars, double beginTime, double endTime) const {
3846
myParent.send_commandSubscribeObjectVariable(mySubscribeID, objID, beginTime, endTime, vars);
3847
tcpip::Storage inMsg;
3848
myParent.check_resultState(inMsg, mySubscribeID);
3849
if (vars.size() > 0) {
3850
myParent.check_commandGetResult(inMsg, mySubscribeID);
3851
myParent.readVariableSubscription(mySubscribeID + 0x10, inMsg);
3852
}
3853
}
3854
3855
3856
void
3857
TraCIAPI::TraCIScopeWrapper::subscribeContext(const std::string& objID, int domain, double range, const std::vector<int>& vars, double beginTime, double endTime) const {
3858
myParent.send_commandSubscribeObjectContext(myContextSubscribeID, objID, beginTime, endTime, domain, range, vars);
3859
tcpip::Storage inMsg;
3860
myParent.check_resultState(inMsg, myContextSubscribeID);
3861
myParent.check_commandGetResult(inMsg, myContextSubscribeID);
3862
myParent.readContextSubscription(myContextSubscribeID + 0x60, inMsg);
3863
}
3864
3865
3866
const libsumo::SubscriptionResults
3867
TraCIAPI::TraCIScopeWrapper::getAllSubscriptionResults() const {
3868
return mySubscriptionResults;
3869
}
3870
3871
3872
const libsumo::TraCIResults
3873
TraCIAPI::TraCIScopeWrapper::getSubscriptionResults(const std::string& objID) const {
3874
if (mySubscriptionResults.find(objID) != mySubscriptionResults.end()) {
3875
return mySubscriptionResults.find(objID)->second;
3876
} else {
3877
return libsumo::TraCIResults();
3878
}
3879
}
3880
3881
3882
const libsumo::ContextSubscriptionResults
3883
TraCIAPI::TraCIScopeWrapper::getAllContextSubscriptionResults() const {
3884
return myContextSubscriptionResults;
3885
}
3886
3887
3888
const libsumo::SubscriptionResults
3889
TraCIAPI::TraCIScopeWrapper::getContextSubscriptionResults(const std::string& objID) const {
3890
if (myContextSubscriptionResults.find(objID) != myContextSubscriptionResults.end()) {
3891
return myContextSubscriptionResults.find(objID)->second;
3892
} else {
3893
return libsumo::SubscriptionResults();
3894
}
3895
}
3896
3897
3898
void
3899
TraCIAPI::TraCIScopeWrapper::clearSubscriptionResults() {
3900
mySubscriptionResults.clear();
3901
myContextSubscriptionResults.clear();
3902
}
3903
3904
3905
libsumo::SubscriptionResults&
3906
TraCIAPI::TraCIScopeWrapper::getModifiableSubscriptionResults() {
3907
return mySubscriptionResults;
3908
}
3909
3910
3911
libsumo::SubscriptionResults&
3912
TraCIAPI::TraCIScopeWrapper::getModifiableContextSubscriptionResults(const std::string& objID) {
3913
return myContextSubscriptionResults[objID];
3914
}
3915
3916
3917
/****************************************************************************/
3918
3919