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-2024 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 std::unique_lock<std::mutex> lock{ libtraci::Connection::getActive().getMutex() };
97 tcpip::Storage content;
98 StoHelp::writeTypedInt(content, onlyNew);
100 std::vector<libsumo::TraCIReservation> result;
101 int numReservations = ret.readInt();
102 while (numReservations-- > 0) {
104 StoHelp::readCompound(ret, 10);
115 result.emplace_back(r);
116 }
117 return result;
118}
119
120
121std::string
122Person::splitTaxiReservation(std::string reservationID, const std::vector<std::string>& personIDs) {
123 tcpip::Storage content;
124 StoHelp::writeTypedStringList(content, personIDs);
125 return Dom::getString(libsumo::SPLIT_TAXI_RESERVATIONS, reservationID, &content);
126}
127
128
130Person::getColor(const std::string& personID) {
131 return Dom::getCol(libsumo::VAR_COLOR, personID);
132}
133
134
135std::string
136Person::getTypeID(const std::string& personID) {
137 return Dom::getString(libsumo::VAR_TYPE, personID);
138}
139
140
141double
142Person::getWaitingTime(const std::string& personID) {
144}
145
146
147std::string
148Person::getNextEdge(const std::string& personID) {
149 return Dom::getString(libsumo::VAR_NEXT_EDGE, personID);
150}
151
152
153std::vector<std::string>
154Person::getEdges(const std::string& personID, int nextStageIndex) {
155 tcpip::Storage content;
157 content.writeInt(nextStageIndex);
158 return Dom::getStringVector(libsumo::VAR_EDGES, personID, &content);
159}
160
161
163Person::getStage(const std::string& personID, int nextStageIndex) {
164 tcpip::Storage content;
166 content.writeInt(nextStageIndex);
167 return Dom::getTraCIStage(libsumo::VAR_STAGE, personID, &content);
168}
169
170
171int
172Person::getRemainingStages(const std::string& personID) {
174}
175
176
177std::string
178Person::getVehicle(const std::string& personID) {
179 return Dom::getString(libsumo::VAR_VEHICLE, personID);
180}
181
182
183std::string
184Person::getEmissionClass(const std::string& personID) {
186}
187
188
189std::string
190Person::getShapeClass(const std::string& personID) {
191 return Dom::getString(libsumo::VAR_SHAPECLASS, personID);
192}
193
194
195double
196Person::getLength(const std::string& personID) {
197 return Dom::getDouble(libsumo::VAR_LENGTH, personID);
198}
199
200
201double
202Person::getSpeedFactor(const std::string& personID) {
204}
205
206
207double
208Person::getAccel(const std::string& personID) {
209 return Dom::getDouble(libsumo::VAR_ACCEL, personID);
210}
211
212
213double
214Person::getDecel(const std::string& personID) {
215 return Dom::getDouble(libsumo::VAR_DECEL, personID);
216}
217
218
219double Person::getEmergencyDecel(const std::string& personID) {
221}
222
223
224double Person::getApparentDecel(const std::string& personID) {
226}
227
228
229double Person::getActionStepLength(const std::string& personID) {
231}
232
233
234double
235Person::getTau(const std::string& personID) {
236 return Dom::getDouble(libsumo::VAR_TAU, personID);
237}
238
239
240double
241Person::getImperfection(const std::string& personID) {
243}
244
245
246double
247Person::getSpeedDeviation(const std::string& personID) {
249}
250
251
252std::string
253Person::getVehicleClass(const std::string& personID) {
255}
256
257
258double
259Person::getMinGap(const std::string& personID) {
260 return Dom::getDouble(libsumo::VAR_MINGAP, personID);
261}
262
263
264double
265Person::getMinGapLat(const std::string& personID) {
266 return Dom::getDouble(libsumo::VAR_MINGAP_LAT, personID);
267}
268
269
270double
271Person::getMaxSpeed(const std::string& personID) {
272 return Dom::getDouble(libsumo::VAR_MAXSPEED, personID);
273}
274
275
276double
277Person::getMaxSpeedLat(const std::string& personID) {
279}
280
281
282std::string
283Person::getLateralAlignment(const std::string& personID) {
285}
286
287
288double
289Person::getWidth(const std::string& personID) {
290 return Dom::getDouble(libsumo::VAR_WIDTH, personID);
291}
292
293
294double
295Person::getHeight(const std::string& personID) {
296 return Dom::getDouble(libsumo::VAR_HEIGHT, personID);
297}
298
299
300double
301Person::getMass(const std::string& personID) {
302 return Dom::getDouble(libsumo::VAR_MASS, personID);
303}
304
305
306int
307Person::getPersonCapacity(const std::string& personID) {
309}
310
311
312double
313Person::getBoardingDuration(const std::string& personID) {
315}
316
317double
318Person::getImpatience(const std::string& personID) {
319 return Dom::getDouble(libsumo::VAR_IMPATIENCE, personID);
320}
321
322
323
325
326
327void
328Person::setSpeed(const std::string& personID, double speed) {
329 Dom::setDouble(libsumo::VAR_SPEED, personID, speed);
330}
331
332
333void
334Person::setType(const std::string& personID, const std::string& typeID) {
335 Dom::setString(libsumo::VAR_TYPE, personID, typeID);
336}
337
338
339void
340Person::setImpatience(const std::string& personID, double impatience) {
341 Dom::setDouble(libsumo::VAR_IMPATIENCE, personID, impatience);
342}
343
344void
345Person::setBoardingDuration(const std::string& personID, double boardingDuration) {
346 Dom::setDouble(libsumo::VAR_BOARDING_DURATION, personID, boardingDuration);
347}
348
349void
350Person::add(const std::string& personID, const std::string& edgeID, double pos, double departInSecs, const std::string typeID) {
351 tcpip::Storage content;
353 content.writeInt(4);
355 content.writeString(typeID);
357 content.writeString(edgeID);
359 content.writeDouble(departInSecs);
361 content.writeDouble(pos);
362 Dom::set(libsumo::ADD, personID, &content);
363}
364
365
366void
367Person::appendStage(const std::string& personID, const libsumo::TraCIStage& stage) {
368 tcpip::Storage content;
370 Dom::set(libsumo::APPEND_STAGE, personID, &content);
371}
372
373
374void
375Person::replaceStage(const std::string& personID, const int stageIndex, const libsumo::TraCIStage& stage) {
376 tcpip::Storage content;
378 content.writeInt(2);
380 content.writeInt(stageIndex);
382 Dom::set(libsumo::REPLACE_STAGE, personID, &content);
383}
384
385
386void
387Person::appendDrivingStage(const std::string& personID, const std::string& toEdge, const std::string& lines, const std::string& stopID) {
388 tcpip::Storage content;
390 content.writeInt(4);
394 content.writeString(toEdge);
396 content.writeString(lines);
398 content.writeString(stopID);
399 Dom::set(libsumo::APPEND_STAGE, personID, &content);
400}
401
402
403void
404Person::appendWaitingStage(const std::string& personID, double duration, const std::string& description, const std::string& stopID) {
405 tcpip::Storage content;
407 content.writeInt(4);
411 content.writeDouble(duration);
413 content.writeString(description);
415 content.writeString(stopID);
416 Dom::set(libsumo::APPEND_STAGE, personID, &content);
417}
418
419
420void
421Person::appendWalkingStage(const std::string& personID, const std::vector<std::string>& edges, double arrivalPos, double duration, double speed, const std::string& stopID) {
422 tcpip::Storage content;
424 content.writeInt(6);
428 content.writeStringList(edges);
430 content.writeDouble(arrivalPos);
432 content.writeDouble(duration);
434 content.writeDouble(speed);
436 content.writeString(stopID);
437 Dom::set(libsumo::APPEND_STAGE, personID, &content);
438}
439
440
441void
442Person::removeStage(const std::string& personID, int nextStageIndex) {
443 Dom::setInt(libsumo::REMOVE_STAGE, personID, nextStageIndex);
444}
445
446
447void
448Person::rerouteTraveltime(const std::string& personID) {
449 tcpip::Storage content;
451 content.writeInt(0);
452 Dom::set(libsumo::CMD_REROUTE_TRAVELTIME, personID, &content);
453}
454
455
456void
457Person::moveTo(const std::string& personID, const std::string& laneID, double pos, double posLat) {
458 tcpip::Storage content;
460 content.writeInt(3);
462 content.writeString(laneID);
464 content.writeDouble(pos);
466 content.writeDouble(posLat);
467 Dom::set(libsumo::VAR_MOVE_TO, personID, &content);
468}
469
470
471void
472Person::moveToXY(const std::string& personID, const std::string& edgeID, const double x, const double y, double angle, const int keepRoute, double matchThreshold) {
473 tcpip::Storage content;
475 content.writeInt(6);
477 content.writeString(edgeID);
479 content.writeDouble(x);
481 content.writeDouble(y);
483 content.writeDouble(angle);
485 content.writeByte(keepRoute);
486 StoHelp::writeTypedDouble(content, matchThreshold);
487 Dom::set(libsumo::MOVE_TO_XY, personID, &content);
488}
489
490
493void
494Person::setLength(const std::string& personID, double length) {
495 Dom::setDouble(libsumo::VAR_LENGTH, personID, length);
496}
497
498
499void
500Person::setMaxSpeed(const std::string& personID, double speed) {
501 Dom::setDouble(libsumo::VAR_MAXSPEED, personID, speed);
502}
503
504
505void
506Person::setVehicleClass(const std::string& personID, const std::string& clazz) {
508}
509
510
511void
512Person::setShapeClass(const std::string& personID, const std::string& clazz) {
513 Dom::setString(libsumo::VAR_SHAPECLASS, personID, clazz);
514}
515
516
517void
518Person::setEmissionClass(const std::string& personID, const std::string& clazz) {
520}
521
522
523void
524Person::setWidth(const std::string& personID, double width) {
525 Dom::setDouble(libsumo::VAR_WIDTH, personID, width);
526}
527
528
529void
530Person::setHeight(const std::string& personID, double height) {
531 Dom::setDouble(libsumo::VAR_HEIGHT, personID, height);
532}
533
534
535void
536Person::setMass(const std::string& personID, double mass) {
537 Dom::setDouble(libsumo::VAR_HEIGHT, personID, mass);
538}
539
540
541void
542Person::setMinGap(const std::string& personID, double minGap) {
543 Dom::setDouble(libsumo::VAR_MINGAP, personID, minGap);
544}
545
546
547void
548Person::setAccel(const std::string& personID, double accel) {
549 Dom::setDouble(libsumo::VAR_ACCEL, personID, accel);
550}
551
552
553void
554Person::setDecel(const std::string& personID, double decel) {
555 Dom::setDouble(libsumo::VAR_DECEL, personID, decel);
556}
557
558
559void
560Person::setEmergencyDecel(const std::string& personID, double decel) {
562}
563
564
565void
566Person::setApparentDecel(const std::string& personID, double decel) {
568}
569
570
571void
572Person::setImperfection(const std::string& personID, double imperfection) {
573 Dom::setDouble(libsumo::VAR_IMPERFECTION, personID, imperfection);
574}
575
576
577void
578Person::setTau(const std::string& personID, double tau) {
579 Dom::setDouble(libsumo::VAR_TAU, personID, tau);
580}
581
582
583void
584Person::setMinGapLat(const std::string& personID, double minGapLat) {
585 Dom::setDouble(libsumo::VAR_MINGAP_LAT, personID, minGapLat);
586}
587
588
589void
590Person::setMaxSpeedLat(const std::string& personID, double speed) {
592}
593
594
595void
596Person::setLateralAlignment(const std::string& personID, const std::string& latAlignment) {
597 Dom::setString(libsumo::VAR_LATALIGNMENT, personID, latAlignment);
598}
599
600
601void
602Person::setSpeedFactor(const std::string& personID, double factor) {
603 Dom::setDouble(libsumo::VAR_SPEED_FACTOR, personID, factor);
604}
605
606
607void
608Person::setActionStepLength(const std::string& personID, double actionStepLength, bool resetActionOffset) {
609 if (!resetActionOffset) {
610 actionStepLength *= -1;
611 }
612 Dom::setDouble(libsumo::VAR_ACTIONSTEPLENGTH, personID, actionStepLength);
613}
614
615void
616Person::remove(const std::string& personID, char reason) {
617 tcpip::Storage content;
619 content.writeUnsignedByte(reason);
620 Dom::set(libsumo::REMOVE, personID, &content);
621}
622
623
624void
625Person::setColor(const std::string& personID, const libsumo::TraCIColor& color) {
626 Dom::setCol(libsumo::VAR_COLOR, personID, color);
627}
628
629
631
632
633}
634
635
636/****************************************************************************/
#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="")
static std::vector< std::string > readTypedStringList(tcpip::Storage &ret, const std::string &error="")
static int readTypedInt(tcpip::Storage &ret, const std::string &error="")
static std::string readTypedString(tcpip::Storage &ret, const std::string &error="")
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="")
double depart
pickup-time
Definition TraCIDefs.h:625
double departPos
pickup position on the origin edge
Definition TraCIDefs.h:621
double reservationTime
time when the reservation was made
Definition TraCIDefs.h:627
double arrivalPos
drop-off position on the destination edge
Definition TraCIDefs.h:623
std::vector< std::string > persons
The persons ids that are part of this reservation.
Definition TraCIDefs.h:613
int state
the state of this reservation
Definition TraCIDefs.h:629
std::string fromEdge
The origin edge id.
Definition TraCIDefs.h:617
std::string group
The group id of this reservation.
Definition TraCIDefs.h:615
std::string id
The id of the taxi reservation (usable for traci.vehicle.dispatchTaxi)
Definition TraCIDefs.h:611
std::string toEdge
The destination edge id.
Definition TraCIDefs.h:619
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:231
static libsumo::TraCIPosition getPos(int var, const std::string &id, tcpip::Storage *add=nullptr, const bool isGeo=false)
Definition Domain.h:153
static void setCol(int var, const std::string &id, const libsumo::TraCIColor value)
Definition Domain.h:252
static std::vector< std::string > getStringVector(int var, const std::string &id, tcpip::Storage *add=nullptr)
Definition Domain.h:177
static libsumo::TraCIColor getCol(int var, const std::string &id, tcpip::Storage *add=nullptr)
Definition Domain.h:187
static std::string getString(int var, const std::string &id, tcpip::Storage *add=nullptr)
Definition Domain.h:172
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:198
static void set(int var, const std::string &id, tcpip::Storage *add)
Definition Domain.h:219
static libsumo::TraCIPosition getPos3D(int var, const std::string &id, tcpip::Storage *add=nullptr, const bool isGeo=false)
Definition Domain.h:162
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:224
static void setString(int var, const std::string &id, const std::string &value)
Definition Domain.h:238
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_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 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 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 2D or 3D-position, for 2D positions z == INVALID_DOUBLE_VALUE.
Definition TraCIDefs.h:178