Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
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-2026 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::getArrivalPos(const std::string& personID) {
97}
98
99
100double
101Person::getWalkingDistance(const std::string& personID, const std::string& edgeID, double pos, int laneIndex) {
102 tcpip::Storage content;
103 StoHelp::writeCompound(content, 2);
105 content.writeString(edgeID);
106 content.writeDouble(pos);
107 content.writeUnsignedByte(laneIndex);
109 return Dom::getDouble(libsumo::DISTANCE_REQUEST, personID, &content);
110}
111
112
113double
114Person::getWalkingDistance2D(const std::string& personID, double x, double y) {
115 tcpip::Storage content;
116 StoHelp::writeCompound(content, 2);
118 content.writeDouble(x);
119 content.writeDouble(y);
121 return Dom::getDouble(libsumo::DISTANCE_REQUEST, personID, &content);
122}
123
124
125std::vector<libsumo::TraCIReservation>
126Person::getTaxiReservations(int onlyNew) {
127 std::unique_lock<std::mutex> lock{ libtraci::Connection::getActive().getMutex() };
128 tcpip::Storage content;
129 StoHelp::writeTypedInt(content, onlyNew);
131 std::vector<libsumo::TraCIReservation> result;
132 int numReservations = ret.readInt();
133 while (numReservations-- > 0) {
136 result.emplace_back(r);
137 }
138 return result;
139}
140
141
142std::string
143Person::splitTaxiReservation(std::string reservationID, const std::vector<std::string>& personIDs) {
144 tcpip::Storage content;
145 StoHelp::writeTypedStringList(content, personIDs);
146 return Dom::getString(libsumo::SPLIT_TAXI_RESERVATIONS, reservationID, &content);
147}
148
149
151Person::getColor(const std::string& personID) {
152 return Dom::getCol(libsumo::VAR_COLOR, personID);
153}
154
155
156std::string
157Person::getTypeID(const std::string& personID) {
158 return Dom::getString(libsumo::VAR_TYPE, personID);
159}
160
161
162double
163Person::getWaitingTime(const std::string& personID) {
165}
166
167
168std::string
169Person::getNextEdge(const std::string& personID) {
170 return Dom::getString(libsumo::VAR_NEXT_EDGE, personID);
171}
172
173
174std::vector<std::string>
175Person::getEdges(const std::string& personID, int nextStageIndex) {
176 tcpip::Storage content;
178 content.writeInt(nextStageIndex);
179 return Dom::getStringVector(libsumo::VAR_EDGES, personID, &content);
180}
181
182
184Person::getStage(const std::string& personID, int nextStageIndex) {
185 tcpip::Storage content;
187 content.writeInt(nextStageIndex);
188 return Dom::getTraCIStage(libsumo::VAR_STAGE, personID, &content);
189}
190
191
192int
193Person::getRemainingStages(const std::string& personID) {
195}
196
197
198std::string
199Person::getVehicle(const std::string& personID) {
200 return Dom::getString(libsumo::VAR_VEHICLE, personID);
201}
202
203
204std::string
205Person::getEmissionClass(const std::string& personID) {
207}
208
209
210std::string
211Person::getShapeClass(const std::string& personID) {
212 return Dom::getString(libsumo::VAR_SHAPECLASS, personID);
213}
214
215
216double
217Person::getLength(const std::string& personID) {
218 return Dom::getDouble(libsumo::VAR_LENGTH, personID);
219}
220
221
222double
223Person::getSpeedFactor(const std::string& personID) {
225}
226
227
228double
229Person::getAccel(const std::string& personID) {
230 return Dom::getDouble(libsumo::VAR_ACCEL, personID);
231}
232
233
234double
235Person::getDecel(const std::string& personID) {
236 return Dom::getDouble(libsumo::VAR_DECEL, personID);
237}
238
239
240double Person::getEmergencyDecel(const std::string& personID) {
242}
243
244
245double Person::getApparentDecel(const std::string& personID) {
247}
248
249
250double Person::getActionStepLength(const std::string& personID) {
252}
253
254
255double
256Person::getTau(const std::string& personID) {
257 return Dom::getDouble(libsumo::VAR_TAU, personID);
258}
259
260
261double
262Person::getImperfection(const std::string& personID) {
264}
265
266
267double
268Person::getSpeedDeviation(const std::string& personID) {
270}
271
272
273std::string
274Person::getVehicleClass(const std::string& personID) {
276}
277
278
279double
280Person::getMinGap(const std::string& personID) {
281 return Dom::getDouble(libsumo::VAR_MINGAP, personID);
282}
283
284
285double
286Person::getMinGapLat(const std::string& personID) {
287 return Dom::getDouble(libsumo::VAR_MINGAP_LAT, personID);
288}
289
290
291double
292Person::getMaxSpeed(const std::string& personID) {
293 return Dom::getDouble(libsumo::VAR_MAXSPEED, personID);
294}
295
296
297double
298Person::getMaxSpeedLat(const std::string& personID) {
300}
301
302
303std::string
304Person::getLateralAlignment(const std::string& personID) {
306}
307
308
309double
310Person::getWidth(const std::string& personID) {
311 return Dom::getDouble(libsumo::VAR_WIDTH, personID);
312}
313
314
315double
316Person::getHeight(const std::string& personID) {
317 return Dom::getDouble(libsumo::VAR_HEIGHT, personID);
318}
319
320
321double
322Person::getMass(const std::string& personID) {
323 return Dom::getDouble(libsumo::VAR_MASS, personID);
324}
325
326
327int
328Person::getPersonCapacity(const std::string& personID) {
330}
331
332
333double
334Person::getBoardingDuration(const std::string& personID) {
336}
337
338double
339Person::getImpatience(const std::string& personID) {
340 return Dom::getDouble(libsumo::VAR_IMPATIENCE, personID);
341}
342
343
344
346
347
348void
349Person::setSpeed(const std::string& personID, double speed) {
350 Dom::setDouble(libsumo::VAR_SPEED, personID, speed);
351}
352
353
354void
355Person::setType(const std::string& personID, const std::string& typeID) {
356 Dom::setString(libsumo::VAR_TYPE, personID, typeID);
357}
358
359
360void
361Person::setImpatience(const std::string& personID, double impatience) {
362 Dom::setDouble(libsumo::VAR_IMPATIENCE, personID, impatience);
363}
364
365void
366Person::setBoardingDuration(const std::string& personID, double boardingDuration) {
367 Dom::setDouble(libsumo::VAR_BOARDING_DURATION, personID, boardingDuration);
368}
369
370void
371Person::add(const std::string& personID, const std::string& edgeID, double pos, double departInSecs, const std::string typeID) {
372 tcpip::Storage content;
374 content.writeInt(4);
376 content.writeString(typeID);
378 content.writeString(edgeID);
380 content.writeDouble(departInSecs);
382 content.writeDouble(pos);
383 Dom::set(libsumo::ADD, personID, &content);
384}
385
386
387void
388Person::appendStage(const std::string& personID, const libsumo::TraCIStage& stage) {
389 tcpip::Storage content;
391 Dom::set(libsumo::APPEND_STAGE, personID, &content);
392}
393
394
395void
396Person::replaceStage(const std::string& personID, const int stageIndex, const libsumo::TraCIStage& stage) {
397 tcpip::Storage content;
399 content.writeInt(2);
401 content.writeInt(stageIndex);
403 Dom::set(libsumo::REPLACE_STAGE, personID, &content);
404}
405
406
407void
408Person::appendDrivingStage(const std::string& personID, const std::string& toEdge, const std::string& lines, const std::string& stopID) {
409 tcpip::Storage content;
411 content.writeInt(4);
415 content.writeString(toEdge);
417 content.writeString(lines);
419 content.writeString(stopID);
420 Dom::set(libsumo::APPEND_STAGE, personID, &content);
421}
422
423
424void
425Person::appendWaitingStage(const std::string& personID, double duration, const std::string& description, const std::string& stopID) {
426 tcpip::Storage content;
428 content.writeInt(4);
432 content.writeDouble(duration);
434 content.writeString(description);
436 content.writeString(stopID);
437 Dom::set(libsumo::APPEND_STAGE, personID, &content);
438}
439
440
441void
442Person::appendWalkingStage(const std::string& personID, const std::vector<std::string>& edges, double arrivalPos, double duration, double speed, const std::string& stopID) {
443 tcpip::Storage content;
445 content.writeInt(6);
449 content.writeStringList(edges);
451 content.writeDouble(arrivalPos);
453 content.writeDouble(duration);
455 content.writeDouble(speed);
457 content.writeString(stopID);
458 Dom::set(libsumo::APPEND_STAGE, personID, &content);
459}
460
461
462void
463Person::removeStage(const std::string& personID, int nextStageIndex) {
464 Dom::setInt(libsumo::REMOVE_STAGE, personID, nextStageIndex);
465}
466
467
468void
469Person::rerouteTraveltime(const std::string& personID) {
470 tcpip::Storage content;
472 content.writeInt(0);
473 Dom::set(libsumo::CMD_REROUTE_TRAVELTIME, personID, &content);
474}
475
476
477void
478Person::moveTo(const std::string& personID, const std::string& laneID, double pos, double posLat) {
479 tcpip::Storage content;
481 content.writeInt(3);
483 content.writeString(laneID);
485 content.writeDouble(pos);
487 content.writeDouble(posLat);
488 Dom::set(libsumo::VAR_MOVE_TO, personID, &content);
489}
490
491
492void
493Person::moveToXY(const std::string& personID, const std::string& edgeID, const double x, const double y, double angle, const int keepRoute, double matchThreshold) {
494 tcpip::Storage content;
496 content.writeInt(6);
498 content.writeString(edgeID);
500 content.writeDouble(x);
502 content.writeDouble(y);
504 content.writeDouble(angle);
506 content.writeByte(keepRoute);
507 StoHelp::writeTypedDouble(content, matchThreshold);
508 Dom::set(libsumo::MOVE_TO_XY, personID, &content);
509}
510
511
514void
515Person::setLength(const std::string& personID, double length) {
516 Dom::setDouble(libsumo::VAR_LENGTH, personID, length);
517}
518
519
520void
521Person::setMaxSpeed(const std::string& personID, double speed) {
522 Dom::setDouble(libsumo::VAR_MAXSPEED, personID, speed);
523}
524
525
526void
527Person::setVehicleClass(const std::string& personID, const std::string& clazz) {
529}
530
531
532void
533Person::setShapeClass(const std::string& personID, const std::string& clazz) {
534 Dom::setString(libsumo::VAR_SHAPECLASS, personID, clazz);
535}
536
537
538void
539Person::setEmissionClass(const std::string& personID, const std::string& clazz) {
541}
542
543
544void
545Person::setWidth(const std::string& personID, double width) {
546 Dom::setDouble(libsumo::VAR_WIDTH, personID, width);
547}
548
549
550void
551Person::setHeight(const std::string& personID, double height) {
552 Dom::setDouble(libsumo::VAR_HEIGHT, personID, height);
553}
554
555
556void
557Person::setMass(const std::string& personID, double mass) {
558 Dom::setDouble(libsumo::VAR_HEIGHT, personID, mass);
559}
560
561
562void
563Person::setMinGap(const std::string& personID, double minGap) {
564 Dom::setDouble(libsumo::VAR_MINGAP, personID, minGap);
565}
566
567
568void
569Person::setAccel(const std::string& personID, double accel) {
570 Dom::setDouble(libsumo::VAR_ACCEL, personID, accel);
571}
572
573
574void
575Person::setDecel(const std::string& personID, double decel) {
576 Dom::setDouble(libsumo::VAR_DECEL, personID, decel);
577}
578
579
580void
581Person::setEmergencyDecel(const std::string& personID, double decel) {
583}
584
585
586void
587Person::setApparentDecel(const std::string& personID, double decel) {
589}
590
591
592void
593Person::setImperfection(const std::string& personID, double imperfection) {
594 Dom::setDouble(libsumo::VAR_IMPERFECTION, personID, imperfection);
595}
596
597
598void
599Person::setTau(const std::string& personID, double tau) {
600 Dom::setDouble(libsumo::VAR_TAU, personID, tau);
601}
602
603
604void
605Person::setMinGapLat(const std::string& personID, double minGapLat) {
606 Dom::setDouble(libsumo::VAR_MINGAP_LAT, personID, minGapLat);
607}
608
609
610void
611Person::setMaxSpeedLat(const std::string& personID, double speed) {
613}
614
615
616void
617Person::setLateralAlignment(const std::string& personID, const std::string& latAlignment) {
618 Dom::setString(libsumo::VAR_LATALIGNMENT, personID, latAlignment);
619}
620
621
622void
623Person::setSpeedFactor(const std::string& personID, double factor) {
624 Dom::setDouble(libsumo::VAR_SPEED_FACTOR, personID, factor);
625}
626
627
628void
629Person::setActionStepLength(const std::string& personID, double actionStepLength, bool resetActionOffset) {
630 if (!resetActionOffset) {
631 actionStepLength *= -1;
632 }
633 Dom::setDouble(libsumo::VAR_ACTIONSTEPLENGTH, personID, actionStepLength);
634}
635
636void
637Person::remove(const std::string& personID, char reason) {
638 tcpip::Storage content;
640 content.writeUnsignedByte(reason);
641 Dom::set(libsumo::REMOVE, personID, &content);
642}
643
644
645void
646Person::setColor(const std::string& personID, const libsumo::TraCIColor& color) {
647 Dom::setCol(libsumo::VAR_COLOR, personID, color);
648}
649
650
652
653
654}
655
656
657/****************************************************************************/
#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 VAR_ARRIVALPOS
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:184