Eclipse SUMO - Simulation of Urban MObility
libtraci/Person.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2017-2022 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/****************************************************************************/
18// C++ TraCI client API implementation
19/****************************************************************************/
20#include <config.h>
21
22#define LIBTRACI 1
23#include "Domain.h"
24#include <libsumo/Person.h>
26
27namespace libtraci {
28
29typedef Domain<libsumo::CMD_GET_PERSON_VARIABLE, libsumo::CMD_SET_PERSON_VARIABLE> Dom;
30
31// ===========================================================================
32// static member definitions
33// ===========================================================================
34std::vector<std::string>
35Person::getIDList() {
37}
38
39
40int
41Person::getIDCount() {
43}
44
45
47Person::getPosition(const std::string& personID, const bool includeZ) {
48 return includeZ ? getPosition3D(personID) : Dom::getPos(libsumo::VAR_POSITION, personID);
49}
50
51
53Person::getPosition3D(const std::string& personID) {
54 return Dom::getPos3D(libsumo::VAR_POSITION3D, personID);
55}
56
57
58double
59Person::getAngle(const std::string& personID) {
60 return Dom::getDouble(libsumo::VAR_ANGLE, personID);
61}
62
63
64double
65Person::getSlope(const std::string& personID) {
66 return Dom::getDouble(libsumo::VAR_SLOPE, personID);
67}
68
69
70double
71Person::getSpeed(const std::string& personID) {
72 return Dom::getDouble(libsumo::VAR_SPEED, personID);
73}
74
75
76std::string
77Person::getRoadID(const std::string& personID) {
78 return Dom::getString(libsumo::VAR_ROAD_ID, personID);
79}
80
81
82std::string
83Person::getLaneID(const std::string& personID) {
84 return Dom::getString(libsumo::VAR_LANE_ID, personID);
85}
86
87
88double
89Person::getLanePosition(const std::string& personID) {
91}
92
93
94std::vector<libsumo::TraCIReservation>
95Person::getTaxiReservations(int onlyNew) {
96 tcpip::Storage content;
97 StoHelp::writeTypedInt(content, onlyNew);
99 std::vector<libsumo::TraCIReservation> result;
100 int numReservations = ret.readInt();
101 while (numReservations-- > 0) {
103 StoHelp::readCompound(ret, 10);
114 result.emplace_back(r);
115 }
116 return result;
117}
118
119
120std::string
121Person::splitTaxiReservation(std::string reservationID, const std::vector<std::string>& personIDs) {
122 tcpip::Storage content;
123 StoHelp::writeTypedStringList(content, personIDs);
124 return Dom::getString(libsumo::SPLIT_TAXI_RESERVATIONS, reservationID, &content);
125}
126
127
129Person::getColor(const std::string& personID) {
130 return Dom::getCol(libsumo::VAR_COLOR, personID);
131}
132
133
134std::string
135Person::getTypeID(const std::string& personID) {
136 return Dom::getString(libsumo::VAR_TYPE, personID);
137}
138
139
140double
141Person::getWaitingTime(const std::string& personID) {
143}
144
145
146std::string
147Person::getNextEdge(const std::string& personID) {
148 return Dom::getString(libsumo::VAR_NEXT_EDGE, personID);
149}
150
151
152std::vector<std::string>
153Person::getEdges(const std::string& personID, int nextStageIndex) {
154 tcpip::Storage content;
156 content.writeInt(nextStageIndex);
157 return Dom::getStringVector(libsumo::VAR_EDGES, personID, &content);
158}
159
160
162Person::getStage(const std::string& personID, int nextStageIndex) {
163 tcpip::Storage content;
165 content.writeInt(nextStageIndex);
166 return Dom::getTraCIStage(libsumo::VAR_STAGE, personID, &content);
167}
168
169
170int
171Person::getRemainingStages(const std::string& personID) {
173}
174
175
176std::string
177Person::getVehicle(const std::string& personID) {
178 return Dom::getString(libsumo::VAR_VEHICLE, personID);
179}
180
181
182std::string
183Person::getEmissionClass(const std::string& personID) {
185}
186
187
188std::string
189Person::getShapeClass(const std::string& personID) {
190 return Dom::getString(libsumo::VAR_SHAPECLASS, personID);
191}
192
193
194double
195Person::getLength(const std::string& personID) {
196 return Dom::getDouble(libsumo::VAR_LENGTH, personID);
197}
198
199
200double
201Person::getSpeedFactor(const std::string& personID) {
203}
204
205
206double
207Person::getAccel(const std::string& personID) {
208 return Dom::getDouble(libsumo::VAR_ACCEL, personID);
209}
210
211
212double
213Person::getDecel(const std::string& personID) {
214 return Dom::getDouble(libsumo::VAR_DECEL, personID);
215}
216
217
218double Person::getEmergencyDecel(const std::string& personID) {
220}
221
222
223double Person::getApparentDecel(const std::string& personID) {
225}
226
227
228double Person::getActionStepLength(const std::string& personID) {
230}
231
232
233double
234Person::getTau(const std::string& personID) {
235 return Dom::getDouble(libsumo::VAR_TAU, personID);
236}
237
238
239double
240Person::getImperfection(const std::string& personID) {
242}
243
244
245double
246Person::getSpeedDeviation(const std::string& personID) {
248}
249
250
251std::string
252Person::getVehicleClass(const std::string& personID) {
254}
255
256
257double
258Person::getMinGap(const std::string& personID) {
259 return Dom::getDouble(libsumo::VAR_MINGAP, personID);
260}
261
262
263double
264Person::getMinGapLat(const std::string& personID) {
265 return Dom::getDouble(libsumo::VAR_MINGAP_LAT, personID);
266}
267
268
269double
270Person::getMaxSpeed(const std::string& personID) {
271 return Dom::getDouble(libsumo::VAR_MAXSPEED, personID);
272}
273
274
275double
276Person::getMaxSpeedLat(const std::string& personID) {
278}
279
280
281std::string
282Person::getLateralAlignment(const std::string& personID) {
284}
285
286
287double
288Person::getWidth(const std::string& personID) {
289 return Dom::getDouble(libsumo::VAR_WIDTH, personID);
290}
291
292
293double
294Person::getHeight(const std::string& personID) {
295 return Dom::getDouble(libsumo::VAR_HEIGHT, personID);
296}
297
298
299int
300Person::getPersonCapacity(const std::string& personID) {
302}
303
304
306
307
308void
309Person::setSpeed(const std::string& personID, double speed) {
310 Dom::setDouble(libsumo::VAR_SPEED, personID, speed);
311}
312
313
314void
315Person::setType(const std::string& personID, const std::string& typeID) {
316 Dom::setString(libsumo::VAR_TYPE, personID, typeID);
317}
318
319
320void
321Person::add(const std::string& personID, const std::string& edgeID, double pos, double departInSecs, const std::string typeID) {
322 tcpip::Storage content;
324 content.writeInt(4);
326 content.writeString(typeID);
328 content.writeString(edgeID);
330 content.writeDouble(departInSecs);
332 content.writeDouble(pos);
333 Dom::set(libsumo::ADD, personID, &content);
334}
335
336
337void
338Person::appendStage(const std::string& personID, const libsumo::TraCIStage& stage) {
339 tcpip::Storage content;
341 Dom::set(libsumo::APPEND_STAGE, personID, &content);
342}
343
344
345void
346Person::replaceStage(const std::string& personID, const int stageIndex, const libsumo::TraCIStage& stage) {
347 tcpip::Storage content;
349 content.writeInt(2);
351 content.writeInt(stageIndex);
353 Dom::set(libsumo::REPLACE_STAGE, personID, &content);
354}
355
356
357void
358Person::appendDrivingStage(const std::string& personID, const std::string& toEdge, const std::string& lines, const std::string& stopID) {
359 tcpip::Storage content;
361 content.writeInt(4);
365 content.writeString(toEdge);
367 content.writeString(lines);
369 content.writeString(stopID);
370 Dom::set(libsumo::APPEND_STAGE, personID, &content);
371}
372
373
374void
375Person::appendWaitingStage(const std::string& personID, double duration, const std::string& description, const std::string& stopID) {
376 tcpip::Storage content;
378 content.writeInt(4);
382 content.writeDouble(duration);
384 content.writeString(description);
386 content.writeString(stopID);
387 Dom::set(libsumo::APPEND_STAGE, personID, &content);
388}
389
390
391void
392Person::appendWalkingStage(const std::string& personID, const std::vector<std::string>& edges, double arrivalPos, double duration, double speed, const std::string& stopID) {
393 tcpip::Storage content;
395 content.writeInt(6);
399 content.writeStringList(edges);
401 content.writeDouble(arrivalPos);
403 content.writeDouble(duration);
405 content.writeDouble(speed);
407 content.writeString(stopID);
408 Dom::set(libsumo::APPEND_STAGE, personID, &content);
409}
410
411
412void
413Person::removeStage(const std::string& personID, int nextStageIndex) {
414 Dom::setInt(libsumo::REMOVE_STAGE, personID, nextStageIndex);
415}
416
417
418void
419Person::rerouteTraveltime(const std::string& personID) {
420 tcpip::Storage content;
422 content.writeInt(0);
423 Dom::set(libsumo::CMD_REROUTE_TRAVELTIME, personID, &content);
424}
425
426
427void
428Person::moveTo(const std::string& personID, const std::string& laneID, double pos, double posLat) {
429 tcpip::Storage content;
431 content.writeInt(3);
433 content.writeString(laneID);
435 content.writeDouble(pos);
437 content.writeDouble(posLat);
438 Dom::set(libsumo::VAR_MOVE_TO, personID, &content);
439}
440
441
442void
443Person::moveToXY(const std::string& personID, const std::string& edgeID, const double x, const double y, double angle, const int keepRoute, double matchThreshold) {
444 tcpip::Storage content;
446 content.writeInt(6);
448 content.writeString(edgeID);
450 content.writeDouble(x);
452 content.writeDouble(y);
454 content.writeDouble(angle);
456 content.writeByte(keepRoute);
457 StoHelp::writeTypedDouble(content, matchThreshold);
458 Dom::set(libsumo::MOVE_TO_XY, personID, &content);
459}
460
461
464void
465Person::setLength(const std::string& personID, double length) {
466 Dom::setDouble(libsumo::VAR_LENGTH, personID, length);
467}
468
469
470void
471Person::setMaxSpeed(const std::string& personID, double speed) {
472 Dom::setDouble(libsumo::VAR_MAXSPEED, personID, speed);
473}
474
475
476void
477Person::setVehicleClass(const std::string& personID, const std::string& clazz) {
479}
480
481
482void
483Person::setShapeClass(const std::string& personID, const std::string& clazz) {
484 Dom::setString(libsumo::VAR_SHAPECLASS, personID, clazz);
485}
486
487
488void
489Person::setEmissionClass(const std::string& personID, const std::string& clazz) {
491}
492
493
494void
495Person::setWidth(const std::string& personID, double width) {
496 Dom::setDouble(libsumo::VAR_WIDTH, personID, width);
497}
498
499
500void
501Person::setHeight(const std::string& personID, double height) {
502 Dom::setDouble(libsumo::VAR_HEIGHT, personID, height);
503}
504
505
506void
507Person::setMinGap(const std::string& personID, double minGap) {
508 Dom::setDouble(libsumo::VAR_MINGAP, personID, minGap);
509}
510
511
512void
513Person::setAccel(const std::string& personID, double accel) {
514 Dom::setDouble(libsumo::VAR_ACCEL, personID, accel);
515}
516
517
518void
519Person::setDecel(const std::string& personID, double decel) {
520 Dom::setDouble(libsumo::VAR_DECEL, personID, decel);
521}
522
523
524void
525Person::setEmergencyDecel(const std::string& personID, double decel) {
527}
528
529
530void
531Person::setApparentDecel(const std::string& personID, double decel) {
533}
534
535
536void
537Person::setImperfection(const std::string& personID, double imperfection) {
538 Dom::setDouble(libsumo::VAR_IMPERFECTION, personID, imperfection);
539}
540
541
542void
543Person::setTau(const std::string& personID, double tau) {
544 Dom::setDouble(libsumo::VAR_TAU, personID, tau);
545}
546
547
548void
549Person::setMinGapLat(const std::string& personID, double minGapLat) {
550 Dom::setDouble(libsumo::VAR_MINGAP_LAT, personID, minGapLat);
551}
552
553
554void
555Person::setMaxSpeedLat(const std::string& personID, double speed) {
557}
558
559
560void
561Person::setLateralAlignment(const std::string& personID, const std::string& latAlignment) {
562 Dom::setString(libsumo::VAR_LATALIGNMENT, personID, latAlignment);
563}
564
565
566void
567Person::setSpeedFactor(const std::string& personID, double factor) {
568 Dom::setDouble(libsumo::VAR_SPEED_FACTOR, personID, factor);
569}
570
571
572void
573Person::setActionStepLength(const std::string& personID, double actionStepLength, bool resetActionOffset) {
574 if (!resetActionOffset) {
575 actionStepLength *= -1;
576 }
577 Dom::setDouble(libsumo::VAR_ACTIONSTEPLENGTH, personID, actionStepLength);
578}
579
580void
581Person::remove(const std::string& personID, char reason) {
582 tcpip::Storage content;
584 content.writeUnsignedByte(reason);
585 Dom::set(libsumo::REMOVE, personID, &content);
586}
587
588
589void
590Person::setColor(const std::string& personID, const libsumo::TraCIColor& color) {
591 Dom::setCol(libsumo::VAR_COLOR, personID, color);
592}
593
594
596
597
598}
599
600
601/****************************************************************************/
#define LIBTRACI_SUBSCRIPTION_IMPLEMENTATION(CLASS, DOMAIN)
Definition: Domain.h:38
#define LIBTRACI_PARAMETER_IMPLEMENTATION(CLASS, DOMAIN)
Definition: Domain.h:77
C++ TraCI client API implementation.
static void writeTypedDouble(tcpip::Storage &content, double value)
static int readCompound(tcpip::Storage &ret, int expectedSize=-1, const std::string &error="")
Definition: StorageHelper.h:85
static std::vector< std::string > readTypedStringList(tcpip::Storage &ret, const std::string &error="")
Definition: StorageHelper.h:78
static int readTypedInt(tcpip::Storage &ret, const std::string &error="")
Definition: StorageHelper.h:50
static std::string readTypedString(tcpip::Storage &ret, const std::string &error="")
Definition: StorageHelper.h:71
static void writeTypedInt(tcpip::Storage &content, int value)
static void writeTypedStringList(tcpip::Storage &content, const std::vector< std::string > &value)
static void writeStage(tcpip::Storage &outputStorage, const libsumo::TraCIStage &stage)
static double readTypedDouble(tcpip::Storage &ret, const std::string &error="")
Definition: StorageHelper.h:64
double depart
pickup-time
Definition: TraCIDefs.h:588
double departPos
pickup position on the origin edge
Definition: TraCIDefs.h:584
double reservationTime
time when the reservation was made
Definition: TraCIDefs.h:590
double arrivalPos
drop-off position on the destination edge
Definition: TraCIDefs.h:586
std::vector< std::string > persons
The persons ids that are part of this reservation.
Definition: TraCIDefs.h:576
int state
the state of this reservation
Definition: TraCIDefs.h:592
std::string fromEdge
The origin edge id.
Definition: TraCIDefs.h:580
std::string group
The group id of this reservation.
Definition: TraCIDefs.h:578
std::string id
The id of the taxi reservation (usable for traci.vehicle.dispatchTaxi)
Definition: TraCIDefs.h:574
std::string toEdge
The destination edge id.
Definition: TraCIDefs.h:582
static void setDouble(int var, const std::string &id, double value)
Definition: Domain.h:220
static libsumo::TraCIPosition getPos(int var, const std::string &id, tcpip::Storage *add=nullptr, const bool isGeo=false)
Definition: Domain.h:150
static void setCol(int var, const std::string &id, const libsumo::TraCIColor value)
Definition: Domain.h:241
static std::vector< std::string > getStringVector(int var, const std::string &id, tcpip::Storage *add=nullptr)
Definition: Domain.h:171
static libsumo::TraCIColor getCol(int var, const std::string &id, tcpip::Storage *add=nullptr)
Definition: Domain.h:179
static std::string getString(int var, const std::string &id, tcpip::Storage *add=nullptr)
Definition: Domain.h:167
static int getInt(int var, const std::string &id, tcpip::Storage *add=nullptr)
Definition: Domain.h:125
static libsumo::TraCIStage getTraCIStage(int var, const std::string &id, tcpip::Storage *add=nullptr)
Definition: Domain.h:189
static void set(int var, const std::string &id, tcpip::Storage *add)
Definition: Domain.h:209
static libsumo::TraCIPosition getPos3D(int var, const std::string &id, tcpip::Storage *add=nullptr, const bool isGeo=false)
Definition: Domain.h:158
static double getDouble(int var, const std::string &id, tcpip::Storage *add=nullptr)
Definition: Domain.h:129
static void setInt(int var, const std::string &id, int value)
Definition: Domain.h:213
static void setString(int var, const std::string &id, const std::string &value)
Definition: Domain.h:227
static tcpip::Storage & get(int var, const std::string &id, tcpip::Storage *add=nullptr, int expectedType=libsumo::TYPE_COMPOUND)
Definition: Domain.h:111
virtual void writeString(const std::string &s)
Definition: storage.cpp:197
virtual void writeInt(int)
Definition: storage.cpp:321
virtual void writeDouble(double)
Definition: storage.cpp:354
virtual void writeStringList(const std::vector< std::string > &s)
Definition: storage.cpp:247
virtual void writeUnsignedByte(int)
Definition: storage.cpp:165
virtual void writeByte(int)
Definition: storage.cpp:140
virtual int readInt()
Definition: storage.cpp:311
TRACI_CONST int VAR_EDGES
TRACI_CONST int VAR_VEHICLECLASS
TRACI_CONST int TRACI_ID_LIST
TRACI_CONST int VAR_LATALIGNMENT
TRACI_CONST int VAR_TYPE
TRACI_CONST int VAR_MINGAP
TRACI_CONST int VAR_VEHICLE
TRACI_CONST int VAR_SHAPECLASS
TRACI_CONST int VAR_WAITING_TIME
TRACI_CONST int REPLACE_STAGE
TRACI_CONST int VAR_ROAD_ID
TRACI_CONST int VAR_TAXI_RESERVATIONS
TRACI_CONST int VAR_ACTIONSTEPLENGTH
TRACI_CONST int VAR_SPEED_FACTOR
TRACI_CONST int MOVE_TO_XY
TRACI_CONST int VAR_ANGLE
TRACI_CONST int VAR_TAU
TRACI_CONST int TYPE_COMPOUND
TRACI_CONST int VAR_STAGE
TRACI_CONST int VAR_MOVE_TO
TRACI_CONST int VAR_COLOR
TRACI_CONST int VAR_POSITION
TRACI_CONST int VAR_WIDTH
TRACI_CONST int VAR_PERSON_CAPACITY
TRACI_CONST int VAR_MAXSPEED
TRACI_CONST int STAGE_WAITING
TRACI_CONST int CMD_REROUTE_TRAVELTIME
TRACI_CONST int TYPE_STRINGLIST
TRACI_CONST int APPEND_STAGE
TRACI_CONST int TYPE_INTEGER
TRACI_CONST int VAR_SLOPE
TRACI_CONST int VAR_LENGTH
TRACI_CONST int VAR_MAXSPEED_LAT
TRACI_CONST int ID_COUNT
TRACI_CONST int VAR_LANEPOSITION
TRACI_CONST int REMOVE
TRACI_CONST int VAR_LANE_ID
TRACI_CONST int VAR_IMPERFECTION
TRACI_CONST int VAR_HEIGHT
TRACI_CONST int VAR_APPARENT_DECEL
TRACI_CONST int STAGE_WALKING
TRACI_CONST int VAR_POSITION3D
TRACI_CONST int REMOVE_STAGE
TRACI_CONST int VAR_SPEED
TRACI_CONST int VAR_DECEL
TRACI_CONST int VAR_MINGAP_LAT
TRACI_CONST int VAR_NEXT_EDGE
TRACI_CONST int TYPE_DOUBLE
TRACI_CONST int TYPE_BYTE
TRACI_CONST int VAR_EMERGENCY_DECEL
TRACI_CONST int STAGE_DRIVING
TRACI_CONST int VAR_EMISSIONCLASS
TRACI_CONST int VAR_ACCEL
TRACI_CONST int ADD
TRACI_CONST int VAR_STAGES_REMAINING
TRACI_CONST int SPLIT_TAXI_RESERVATIONS
TRACI_CONST int VAR_SPEED_DEVIATION
TRACI_CONST int TYPE_STRING
Domain< libsumo::CMD_GET_BUSSTOP_VARIABLE, libsumo::CMD_SET_BUSSTOP_VARIABLE > Dom
A 3D-position.
Definition: TraCIDefs.h:172