Eclipse SUMO - Simulation of Urban MObility
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
libtraci/Person.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2017-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/****************************************************************************/
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
94double
95Person::getWalkingDistance(const std::string& personID, const std::string& edgeID, double pos, int laneIndex) {
96 tcpip::Storage content;
97 StoHelp::writeCompound(content, 2);
99 content.writeString(edgeID);
100 content.writeDouble(pos);
101 content.writeUnsignedByte(laneIndex);
103 return Dom::getDouble(libsumo::DISTANCE_REQUEST, personID, &content);
104}
105
106
107double
108Person::getWalkingDistance2D(const std::string& personID, double x, double y) {
109 tcpip::Storage content;
110 StoHelp::writeCompound(content, 2);
112 content.writeDouble(x);
113 content.writeDouble(y);
115 return Dom::getDouble(libsumo::DISTANCE_REQUEST, personID, &content);
116}
117
118
119std::vector<libsumo::TraCIReservation>
120Person::getTaxiReservations(int onlyNew) {
121 std::unique_lock<std::mutex> lock{ libtraci::Connection::getActive().getMutex() };
122 tcpip::Storage content;
123 StoHelp::writeTypedInt(content, onlyNew);
125 std::vector<libsumo::TraCIReservation> result;
126 int numReservations = ret.readInt();
127 while (numReservations-- > 0) {
130 result.emplace_back(r);
131 }
132 return result;
133}
134
135
136std::string
137Person::splitTaxiReservation(std::string reservationID, const std::vector<std::string>& personIDs) {
138 tcpip::Storage content;
139 StoHelp::writeTypedStringList(content, personIDs);
140 return Dom::getString(libsumo::SPLIT_TAXI_RESERVATIONS, reservationID, &content);
141}
142
143
145Person::getColor(const std::string& personID) {
146 return Dom::getCol(libsumo::VAR_COLOR, personID);
147}
148
149
150std::string
151Person::getTypeID(const std::string& personID) {
152 return Dom::getString(libsumo::VAR_TYPE, personID);
153}
154
155
156double
157Person::getWaitingTime(const std::string& personID) {
159}
160
161
162std::string
163Person::getNextEdge(const std::string& personID) {
164 return Dom::getString(libsumo::VAR_NEXT_EDGE, personID);
165}
166
167
168std::vector<std::string>
169Person::getEdges(const std::string& personID, int nextStageIndex) {
170 tcpip::Storage content;
172 content.writeInt(nextStageIndex);
173 return Dom::getStringVector(libsumo::VAR_EDGES, personID, &content);
174}
175
176
178Person::getStage(const std::string& personID, int nextStageIndex) {
179 tcpip::Storage content;
181 content.writeInt(nextStageIndex);
182 return Dom::getTraCIStage(libsumo::VAR_STAGE, personID, &content);
183}
184
185
186int
187Person::getRemainingStages(const std::string& personID) {
189}
190
191
192std::string
193Person::getVehicle(const std::string& personID) {
194 return Dom::getString(libsumo::VAR_VEHICLE, personID);
195}
196
197
198std::string
199Person::getEmissionClass(const std::string& personID) {
201}
202
203
204std::string
205Person::getShapeClass(const std::string& personID) {
206 return Dom::getString(libsumo::VAR_SHAPECLASS, personID);
207}
208
209
210double
211Person::getLength(const std::string& personID) {
212 return Dom::getDouble(libsumo::VAR_LENGTH, personID);
213}
214
215
216double
217Person::getSpeedFactor(const std::string& personID) {
219}
220
221
222double
223Person::getAccel(const std::string& personID) {
224 return Dom::getDouble(libsumo::VAR_ACCEL, personID);
225}
226
227
228double
229Person::getDecel(const std::string& personID) {
230 return Dom::getDouble(libsumo::VAR_DECEL, personID);
231}
232
233
234double Person::getEmergencyDecel(const std::string& personID) {
236}
237
238
239double Person::getApparentDecel(const std::string& personID) {
241}
242
243
244double Person::getActionStepLength(const std::string& personID) {
246}
247
248
249double
250Person::getTau(const std::string& personID) {
251 return Dom::getDouble(libsumo::VAR_TAU, personID);
252}
253
254
255double
256Person::getImperfection(const std::string& personID) {
258}
259
260
261double
262Person::getSpeedDeviation(const std::string& personID) {
264}
265
266
267std::string
268Person::getVehicleClass(const std::string& personID) {
270}
271
272
273double
274Person::getMinGap(const std::string& personID) {
275 return Dom::getDouble(libsumo::VAR_MINGAP, personID);
276}
277
278
279double
280Person::getMinGapLat(const std::string& personID) {
281 return Dom::getDouble(libsumo::VAR_MINGAP_LAT, personID);
282}
283
284
285double
286Person::getMaxSpeed(const std::string& personID) {
287 return Dom::getDouble(libsumo::VAR_MAXSPEED, personID);
288}
289
290
291double
292Person::getMaxSpeedLat(const std::string& personID) {
294}
295
296
297std::string
298Person::getLateralAlignment(const std::string& personID) {
300}
301
302
303double
304Person::getWidth(const std::string& personID) {
305 return Dom::getDouble(libsumo::VAR_WIDTH, personID);
306}
307
308
309double
310Person::getHeight(const std::string& personID) {
311 return Dom::getDouble(libsumo::VAR_HEIGHT, personID);
312}
313
314
315double
316Person::getMass(const std::string& personID) {
317 return Dom::getDouble(libsumo::VAR_MASS, personID);
318}
319
320
321int
322Person::getPersonCapacity(const std::string& personID) {
324}
325
326
327double
328Person::getBoardingDuration(const std::string& personID) {
330}
331
332double
333Person::getImpatience(const std::string& personID) {
334 return Dom::getDouble(libsumo::VAR_IMPATIENCE, personID);
335}
336
337
338
340
341
342void
343Person::setSpeed(const std::string& personID, double speed) {
344 Dom::setDouble(libsumo::VAR_SPEED, personID, speed);
345}
346
347
348void
349Person::setType(const std::string& personID, const std::string& typeID) {
350 Dom::setString(libsumo::VAR_TYPE, personID, typeID);
351}
352
353
354void
355Person::setImpatience(const std::string& personID, double impatience) {
356 Dom::setDouble(libsumo::VAR_IMPATIENCE, personID, impatience);
357}
358
359void
360Person::setBoardingDuration(const std::string& personID, double boardingDuration) {
361 Dom::setDouble(libsumo::VAR_BOARDING_DURATION, personID, boardingDuration);
362}
363
364void
365Person::add(const std::string& personID, const std::string& edgeID, double pos, double departInSecs, const std::string typeID) {
366 tcpip::Storage content;
368 content.writeInt(4);
370 content.writeString(typeID);
372 content.writeString(edgeID);
374 content.writeDouble(departInSecs);
376 content.writeDouble(pos);
377 Dom::set(libsumo::ADD, personID, &content);
378}
379
380
381void
382Person::appendStage(const std::string& personID, const libsumo::TraCIStage& stage) {
383 tcpip::Storage content;
385 Dom::set(libsumo::APPEND_STAGE, personID, &content);
386}
387
388
389void
390Person::replaceStage(const std::string& personID, const int stageIndex, const libsumo::TraCIStage& stage) {
391 tcpip::Storage content;
393 content.writeInt(2);
395 content.writeInt(stageIndex);
397 Dom::set(libsumo::REPLACE_STAGE, personID, &content);
398}
399
400
401void
402Person::appendDrivingStage(const std::string& personID, const std::string& toEdge, const std::string& lines, const std::string& stopID) {
403 tcpip::Storage content;
405 content.writeInt(4);
409 content.writeString(toEdge);
411 content.writeString(lines);
413 content.writeString(stopID);
414 Dom::set(libsumo::APPEND_STAGE, personID, &content);
415}
416
417
418void
419Person::appendWaitingStage(const std::string& personID, double duration, const std::string& description, const std::string& stopID) {
420 tcpip::Storage content;
422 content.writeInt(4);
426 content.writeDouble(duration);
428 content.writeString(description);
430 content.writeString(stopID);
431 Dom::set(libsumo::APPEND_STAGE, personID, &content);
432}
433
434
435void
436Person::appendWalkingStage(const std::string& personID, const std::vector<std::string>& edges, double arrivalPos, double duration, double speed, const std::string& stopID) {
437 tcpip::Storage content;
439 content.writeInt(6);
443 content.writeStringList(edges);
445 content.writeDouble(arrivalPos);
447 content.writeDouble(duration);
449 content.writeDouble(speed);
451 content.writeString(stopID);
452 Dom::set(libsumo::APPEND_STAGE, personID, &content);
453}
454
455
456void
457Person::removeStage(const std::string& personID, int nextStageIndex) {
458 Dom::setInt(libsumo::REMOVE_STAGE, personID, nextStageIndex);
459}
460
461
462void
463Person::rerouteTraveltime(const std::string& personID) {
464 tcpip::Storage content;
466 content.writeInt(0);
467 Dom::set(libsumo::CMD_REROUTE_TRAVELTIME, personID, &content);
468}
469
470
471void
472Person::moveTo(const std::string& personID, const std::string& laneID, double pos, double posLat) {
473 tcpip::Storage content;
475 content.writeInt(3);
477 content.writeString(laneID);
479 content.writeDouble(pos);
481 content.writeDouble(posLat);
482 Dom::set(libsumo::VAR_MOVE_TO, personID, &content);
483}
484
485
486void
487Person::moveToXY(const std::string& personID, const std::string& edgeID, const double x, const double y, double angle, const int keepRoute, double matchThreshold) {
488 tcpip::Storage content;
490 content.writeInt(6);
492 content.writeString(edgeID);
494 content.writeDouble(x);
496 content.writeDouble(y);
498 content.writeDouble(angle);
500 content.writeByte(keepRoute);
501 StoHelp::writeTypedDouble(content, matchThreshold);
502 Dom::set(libsumo::MOVE_TO_XY, personID, &content);
503}
504
505
508void
509Person::setLength(const std::string& personID, double length) {
510 Dom::setDouble(libsumo::VAR_LENGTH, personID, length);
511}
512
513
514void
515Person::setMaxSpeed(const std::string& personID, double speed) {
516 Dom::setDouble(libsumo::VAR_MAXSPEED, personID, speed);
517}
518
519
520void
521Person::setVehicleClass(const std::string& personID, const std::string& clazz) {
523}
524
525
526void
527Person::setShapeClass(const std::string& personID, const std::string& clazz) {
528 Dom::setString(libsumo::VAR_SHAPECLASS, personID, clazz);
529}
530
531
532void
533Person::setEmissionClass(const std::string& personID, const std::string& clazz) {
535}
536
537
538void
539Person::setWidth(const std::string& personID, double width) {
540 Dom::setDouble(libsumo::VAR_WIDTH, personID, width);
541}
542
543
544void
545Person::setHeight(const std::string& personID, double height) {
546 Dom::setDouble(libsumo::VAR_HEIGHT, personID, height);
547}
548
549
550void
551Person::setMass(const std::string& personID, double mass) {
552 Dom::setDouble(libsumo::VAR_HEIGHT, personID, mass);
553}
554
555
556void
557Person::setMinGap(const std::string& personID, double minGap) {
558 Dom::setDouble(libsumo::VAR_MINGAP, personID, minGap);
559}
560
561
562void
563Person::setAccel(const std::string& personID, double accel) {
564 Dom::setDouble(libsumo::VAR_ACCEL, personID, accel);
565}
566
567
568void
569Person::setDecel(const std::string& personID, double decel) {
570 Dom::setDouble(libsumo::VAR_DECEL, personID, decel);
571}
572
573
574void
575Person::setEmergencyDecel(const std::string& personID, double decel) {
577}
578
579
580void
581Person::setApparentDecel(const std::string& personID, double decel) {
583}
584
585
586void
587Person::setImperfection(const std::string& personID, double imperfection) {
588 Dom::setDouble(libsumo::VAR_IMPERFECTION, personID, imperfection);
589}
590
591
592void
593Person::setTau(const std::string& personID, double tau) {
594 Dom::setDouble(libsumo::VAR_TAU, personID, tau);
595}
596
597
598void
599Person::setMinGapLat(const std::string& personID, double minGapLat) {
600 Dom::setDouble(libsumo::VAR_MINGAP_LAT, personID, minGapLat);
601}
602
603
604void
605Person::setMaxSpeedLat(const std::string& personID, double speed) {
607}
608
609
610void
611Person::setLateralAlignment(const std::string& personID, const std::string& latAlignment) {
612 Dom::setString(libsumo::VAR_LATALIGNMENT, personID, latAlignment);
613}
614
615
616void
617Person::setSpeedFactor(const std::string& personID, double factor) {
618 Dom::setDouble(libsumo::VAR_SPEED_FACTOR, personID, factor);
619}
620
621
622void
623Person::setActionStepLength(const std::string& personID, double actionStepLength, bool resetActionOffset) {
624 if (!resetActionOffset) {
625 actionStepLength *= -1;
626 }
627 Dom::setDouble(libsumo::VAR_ACTIONSTEPLENGTH, personID, actionStepLength);
628}
629
630void
631Person::remove(const std::string& personID, char reason) {
632 tcpip::Storage content;
634 content.writeUnsignedByte(reason);
635 Dom::set(libsumo::REMOVE, personID, &content);
636}
637
638
639void
640Person::setColor(const std::string& personID, const libsumo::TraCIColor& color) {
641 Dom::setCol(libsumo::VAR_COLOR, personID, color);
642}
643
644
646
647
648}
649
650
651/****************************************************************************/
#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 void readReservation(tcpip::Storage &inputStorage, libsumo::TraCIReservation &result, const std::string &error="")
static void writeStage(tcpip::Storage &content, const libsumo::TraCIStage &stage)
static void writeCompound(tcpip::Storage &content, int size)
static void writeTypedInt(tcpip::Storage &content, int value)
static void writeTypedStringList(tcpip::Storage &content, const std::vector< std::string > &value)
static Connection & getActive()
Definition Connection.h:57
std::mutex & getMutex() const
Definition Connection.h:76
static void setDouble(int var, const std::string &id, double value)
Definition Domain.h:221
static libsumo::TraCIPosition getPos(int var, const std::string &id, tcpip::Storage *add=nullptr, const bool isGeo=false)
Definition Domain.h:143
static void setCol(int var, const std::string &id, const libsumo::TraCIColor value)
Definition Domain.h:242
static std::vector< std::string > getStringVector(int var, const std::string &id, tcpip::Storage *add=nullptr)
Definition Domain.h:167
static libsumo::TraCIColor getCol(int var, const std::string &id, tcpip::Storage *add=nullptr)
Definition Domain.h:177
static std::string getString(int var, const std::string &id, tcpip::Storage *add=nullptr)
Definition Domain.h:162
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:188
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:152
static double getDouble(int var, const std::string &id, tcpip::Storage *add=nullptr)
Definition Domain.h:130
static void setInt(int var, const std::string &id, int value)
Definition Domain.h:214
static void setString(int var, const std::string &id, const std::string &value)
Definition Domain.h:228
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 POSITION_ROADMAP
TRACI_CONST int VAR_VEHICLECLASS
TRACI_CONST int TRACI_ID_LIST
TRACI_CONST int VAR_IMPATIENCE
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_BOARDING_DURATION
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 POSITION_2D
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_MASS
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 REQUEST_DRIVINGDIST
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 DISTANCE_REQUEST
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 2D or 3D-position, for 2D positions z == INVALID_DOUBLE_VALUE.
Definition TraCIDefs.h:179