Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
libsumo/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#include <cmath>
23
26#include <microsim/MSEdge.h>
27#include <microsim/MSLane.h>
28#include <microsim/MSNet.h>
45#include "Helper.h"
46#include "StorageHelper.h"
47#include "VehicleType.h"
48#include "Person.h"
49
50#define FAR_AWAY 1000.0
51
52//#define DEBUG_MOVEXY
53//#define DEBUG_MOVEXY_ANGLE
54
55namespace libsumo {
56// ===========================================================================
57// static member initializations
58// ===========================================================================
59SubscriptionResults Person::mySubscriptionResults;
60ContextSubscriptionResults Person::myContextSubscriptionResults;
61
62
63// ===========================================================================
64// static member definitions
65// ===========================================================================
66std::vector<std::string>
67Person::getIDList() {
69 std::vector<std::string> ids;
70 for (MSTransportableControl::constVehIt i = c.loadedBegin(); i != c.loadedEnd(); ++i) {
71 if (i->second->getCurrentStageType() != MSStageType::WAITING_FOR_DEPART) {
72 ids.push_back(i->first);
73 }
74 }
75 return ids;
76}
77
78
79int
80Person::getIDCount() {
82}
83
84
85TraCIPosition
86Person::getPosition(const std::string& personID, const bool includeZ) {
87 return Helper::makeTraCIPosition(getPerson(personID)->getPosition(), includeZ);
88}
89
90
91TraCIPosition
92Person::getPosition3D(const std::string& personID) {
93 return Helper::makeTraCIPosition(getPerson(personID)->getPosition(), true);
94}
95
96
97double
98Person::getAngle(const std::string& personID) {
99 return GeomHelper::naviDegree(getPerson(personID)->getAngle());
100}
101
102
103double
104Person::getSlope(const std::string& personID) {
105 MSPerson* person = getPerson(personID);
106 const double ep = person->getEdgePos();
107 const MSLane* lane = getSidewalk<MSEdge, MSLane>(person->getEdge());
108 if (lane == nullptr) {
109 lane = person->getEdge()->getLanes()[0];
110 }
111 const double gp = lane->interpolateLanePosToGeometryPos(ep);
112 return lane->getShape().slopeDegreeAtOffset(gp);
113}
114
115
116double
117Person::getArrivalPos(const std::string& personID) {
118 return getPerson(personID)->getArrivalPos();
119}
120
121
122double
123Person::getSpeed(const std::string& personID) {
124 return getPerson(personID)->getSpeed();
125}
126
127
128std::string
129Person::getRoadID(const std::string& personID) {
130 return getPerson(personID)->getEdge()->getID();
131}
132
133
134std::string
135Person::getLaneID(const std::string& personID) {
136 return Named::getIDSecure(getPerson(personID)->getLane(), "");
137}
138
139
140double
141Person::getLanePosition(const std::string& personID) {
142 return getPerson(personID)->getEdgePos();
143}
144
145
146double
147Person::getWalkingDistance(const std::string& personID, const std::string& edgeID, double pos, int laneIndex) {
148 MSPerson* p = getPerson(personID);
150 const MSStageWalking* walk = dynamic_cast<const MSStageWalking*>(p->getCurrentStage());
151 ConstMSEdgeVector edges = walk->getEdges();
152 edges.erase(edges.begin(), edges.begin() + walk->getRoutePosition());
153 const MSLane* lane = Helper::getLaneChecking(edgeID, laneIndex, pos);
154 auto it = std::find(edges.begin(), edges.end(), &lane->getEdge());
155 if (it == edges.end()) {
156 // Vehicle would return INVALID_DOUBLE_VALUE;
157 throw TraCIException(TLF("Edge '%' does not occur within the remaining walk of person '%'.", edgeID, personID));
158
159 }
160 edges.erase(it + 1, edges.end());
161 double distance = 0;
163 router.recomputeWalkCosts(edges, p->getMaxSpeed(), p->getEdgePos(), pos, SIMSTEP, p->getVTypeParameter(), distance);
164 if (distance == std::numeric_limits<double>::max()) {
166 }
167 return distance;
168 } else {
169 // Vehicle would return INVALID_DOUBLE_VALUE;
170 throw TraCIException(TLF("Person '%' is not walking", personID));
171 }
172}
173
174
175double
176Person::getWalkingDistance2D(const std::string& personID, double x, double y) {
177 MSPerson* p = getPerson(personID);
178 std::pair<MSLane*, double> roadPos = Helper::convertCartesianToRoadMap(Position(x, y), p->getVehicleType().getVehicleClass());
179 return getWalkingDistance(personID, roadPos.first->getEdge().getID(), roadPos.second, roadPos.first->getIndex());
180}
181
182
183
184std::vector<TraCIReservation>
185Person::getTaxiReservations(int onlyNew) {
186 std::vector<TraCIReservation> result;
188 if (dispatcher != nullptr) {
189 for (Reservation* res : dispatcher->getReservations()) {
190 if (filterReservation(onlyNew, res, result)) {
191 if (res->state == Reservation::NEW) {
192 res->state = Reservation::RETRIEVED;
193 }
194 }
195 }
196 const bool includeRunning = onlyNew == 0 || (onlyNew & (Reservation::ASSIGNED | Reservation::ONBOARD)) != 0;
197 if (includeRunning) {
198 for (const Reservation* res : dispatcher->getRunningReservations()) {
199 filterReservation(onlyNew, res, result);
200 }
201 }
202 }
203 std::sort(result.begin(), result.end(), reservation_by_id_sorter());
204 return result;
205}
206
207int
208Person::reservation_by_id_sorter::operator()(const TraCIReservation& r1, const TraCIReservation& r2) const {
209 return r1.id < r2.id;
210}
211
212
213std::string
214Person::splitTaxiReservation(std::string reservationID, const std::vector<std::string>& personIDs) {
216 if (dispatcher != nullptr) {
217 MSDispatch_TraCI* traciDispatcher = dynamic_cast<MSDispatch_TraCI*>(dispatcher);
218 if (traciDispatcher != nullptr) {
219 return traciDispatcher->splitReservation(reservationID, personIDs);
220 }
221 }
222 throw TraCIException("device.taxi.dispatch-algorithm 'traci' has not been loaded");
223}
224
225bool
226Person::filterReservation(int onlyNew, const Reservation* res, std::vector<libsumo::TraCIReservation>& reservations) {
227 if (onlyNew != 0 && (onlyNew & res->state) == 0) {
228 return false;
229 }
230 std::vector<std::string> personIDs;
231 for (const MSTransportable* p : res->persons) {
232 personIDs.push_back(p->getID());
233 }
234 std::sort(personIDs.begin(), personIDs.end());
235 reservations.push_back(TraCIReservation(res->id,
236 personIDs,
237 res->group,
238 res->from->getID(),
239 res->to->getID(),
240 res->fromPos,
241 res->toPos,
244 res->state
245 ));
246 return true;
247}
248
249
250TraCIColor
251Person::getColor(const std::string& personID) {
252 const RGBColor& col = getPerson(personID)->getParameter().color;
253 TraCIColor tcol;
254 tcol.r = col.red();
255 tcol.g = col.green();
256 tcol.b = col.blue();
257 tcol.a = col.alpha();
258 return tcol;
259}
260
261
262std::string
263Person::getTypeID(const std::string& personID) {
264 return getPerson(personID)->getVehicleType().getID();
265}
266
267
268double
269Person::getWaitingTime(const std::string& personID) {
270 return getPerson(personID)->getWaitingSeconds();
271}
272
273
274std::string
275Person::getNextEdge(const std::string& personID) {
276 return getPerson(personID)->getNextEdge();
277}
278
279
280std::vector<std::string>
281Person::getEdges(const std::string& personID, int nextStageIndex) {
282 MSTransportable* p = getPerson(personID);
283 if (nextStageIndex >= p->getNumRemainingStages()) {
284 throw TraCIException("The stage index must be lower than the number of remaining stages.");
285 }
286 if (nextStageIndex < (p->getNumRemainingStages() - p->getNumStages())) {
287 throw TraCIException("The negative stage index must refer to a valid previous stage.");
288 }
289 std::vector<std::string> edgeIDs;
290 for (auto& e : p->getNextStage(nextStageIndex)->getEdges()) {
291 if (e != nullptr) {
292 edgeIDs.push_back(e->getID());
293 }
294 }
295 return edgeIDs;
296}
297
298
299TraCIStage
300Person::getStage(const std::string& personID, int nextStageIndex) {
301 MSTransportable* p = getPerson(personID);
302 TraCIStage result;
303 if (nextStageIndex >= p->getNumRemainingStages()) {
304 throw TraCIException("The stage index must be lower than the number of remaining stages.");
305 }
306 if (nextStageIndex < (p->getNumRemainingStages() - p->getNumStages())) {
307 throw TraCIException("The negative stage index " + toString(nextStageIndex) + " must refer to a valid previous stage.");
308 }
309 //stageType, arrivalPos, edges, destStop, vType, and description can be retrieved directly from the base Stage class.
310 MSStage* stage = p->getNextStage(nextStageIndex);
311 result.type = (int)stage->getStageType();
312 result.arrivalPos = stage->getArrivalPos();
313 for (auto e : stage->getEdges()) {
314 if (e != nullptr) {
315 result.edges.push_back(e->getID());
316 }
317 }
318 MSStoppingPlace* destinationStop = stage->getDestinationStop();
319 if (destinationStop != nullptr) {
320 result.destStop = destinationStop->getID();
321 }
322 result.description = stage->getStageDescription(p->isPerson());
323 result.length = stage->getDistance();
324 if (result.length == -1.) {
325 result.length = INVALID_DOUBLE_VALUE;
326 }
327 result.departPos = INVALID_DOUBLE_VALUE;
328 result.cost = INVALID_DOUBLE_VALUE;
329 result.depart = stage->getDeparted() >= 0 ? STEPS2TIME(stage->getDeparted()) : INVALID_DOUBLE_VALUE;
330 result.travelTime = INVALID_DOUBLE_VALUE;
331 if (stage->getArrived() >= 0) {
332 result.travelTime = STEPS2TIME(stage->getArrived() - stage->getDeparted());
333 } else if (stage->getDeparted() >= 0) {
334 result.travelTime = STEPS2TIME(SIMSTEP - stage->getDeparted());
335 }
336
337 // Some stage type dependant attributes
338 switch (stage->getStageType()) {
340 MSStageDriving* const drivingStage = static_cast<MSStageDriving*>(stage);
341 result.vType = drivingStage->getVehicleType();
342 result.intended = drivingStage->getIntendedVehicleID();
343 if (result.depart < 0 && drivingStage->getIntendedDepart() >= 0) {
344 result.depart = STEPS2TIME(drivingStage->getIntendedDepart());
345 }
346 const std::set<std::string> lines = drivingStage->getLines();
347 for (auto line = lines.begin(); line != lines.end(); line++) {
348 if (line != lines.begin()) {
349 result.line += " ";
350 }
351 result.line += *line;
352 }
353 break;
354 }
356 auto* walkingStage = (MSStageWalking*) stage;
357 result.departPos = walkingStage->getDepartPos();
358 break;
359 }
361 auto* waitingStage = (MSStageWaiting*) stage;
362 if (waitingStage->getPlannedDuration() > 0) {
363 result.travelTime = STEPS2TIME(waitingStage->getPlannedDuration());
364 }
365 break;
366 }
367 default:
368 break;
369 }
370 return result;
371}
372
373
374int
375Person::getRemainingStages(const std::string& personID) {
376 return getPerson(personID)->getNumRemainingStages();
377}
378
379
380std::string
381Person::getVehicle(const std::string& personID) {
382 const SUMOVehicle* veh = getPerson(personID)->getVehicle();
383 if (veh == nullptr) {
384 return "";
385 } else {
386 return veh->getID();
387 }
388}
389
390
391std::string
392Person::getParameter(const std::string& personID, const std::string& param) {
393 return getPerson(personID)->getParameter().getParameter(param, "");
394}
395
396
398
399
400std::string
401Person::getEmissionClass(const std::string& personID) {
402 return PollutantsInterface::getName(getPerson(personID)->getVehicleType().getEmissionClass());
403}
404
405
406std::string
407Person::getShapeClass(const std::string& personID) {
408 return getVehicleShapeName(getPerson(personID)->getVehicleType().getGuiShape());
409}
410
411
412double
413Person::getLength(const std::string& personID) {
414 return getPerson(personID)->getVehicleType().getLength();
415}
416
417
418double
419Person::getSpeedFactor(const std::string& personID) {
420 return getPerson(personID)->getChosenSpeedFactor();
421}
422
423
424double
425Person::getAccel(const std::string& personID) {
426 return getPerson(personID)->getVehicleType().getCarFollowModel().getMaxAccel();
427}
428
429
430double
431Person::getDecel(const std::string& personID) {
432 return getPerson(personID)->getVehicleType().getCarFollowModel().getMaxDecel();
433}
434
435
436double Person::getEmergencyDecel(const std::string& personID) {
437 return getPerson(personID)->getVehicleType().getCarFollowModel().getEmergencyDecel();
438}
439
440
441double Person::getApparentDecel(const std::string& personID) {
442 return getPerson(personID)->getVehicleType().getCarFollowModel().getApparentDecel();
443}
444
445
446double Person::getActionStepLength(const std::string& personID) {
447 return getPerson(personID)->getVehicleType().getActionStepLengthSecs();
448}
449
450
451double
452Person::getTau(const std::string& personID) {
453 return getPerson(personID)->getVehicleType().getCarFollowModel().getHeadwayTime();
454}
455
456
457double
458Person::getImperfection(const std::string& personID) {
459 return getPerson(personID)->getVehicleType().getCarFollowModel().getImperfection();
460}
461
462
463double
464Person::getSpeedDeviation(const std::string& personID) {
465 return getPerson(personID)->getVehicleType().getSpeedFactor().getParameter(1);
466}
467
468
469std::string
470Person::getVehicleClass(const std::string& personID) {
471 return toString(getPerson(personID)->getVehicleType().getVehicleClass());
472}
473
474
475double
476Person::getMinGap(const std::string& personID) {
477 return getPerson(personID)->getVehicleType().getMinGap();
478}
479
480
481double
482Person::getMinGapLat(const std::string& personID) {
483 return getPerson(personID)->getVehicleType().getMinGapLat();
484}
485
486
487double
488Person::getMaxSpeed(const std::string& personID) {
489 return getPerson(personID)->getMaxSpeed();
490}
491
492
493double
494Person::getMaxSpeedLat(const std::string& personID) {
495 return getPerson(personID)->getVehicleType().getMaxSpeedLat();
496}
497
498
499std::string
500Person::getLateralAlignment(const std::string& personID) {
501 return toString(getPerson(personID)->getVehicleType().getPreferredLateralAlignment());
502}
503
504
505double
506Person::getWidth(const std::string& personID) {
507 return getPerson(personID)->getVehicleType().getWidth();
508}
509
510
511double
512Person::getHeight(const std::string& personID) {
513 return getPerson(personID)->getVehicleType().getHeight();
514}
515
516
517double
518Person::getMass(const std::string& personID) {
519 return getPerson(personID)->getVehicleType().getMass();
520}
521
522
523int
524Person::getPersonCapacity(const std::string& personID) {
525 return getPerson(personID)->getVehicleType().getPersonCapacity();
526}
527
528
529double
530Person::getBoardingDuration(const std::string& personID) {
531 return STEPS2TIME(getPerson(personID)->getVehicleType().getBoardingDuration(true));
532}
533
534
535double
536Person::getImpatience(const std::string& personID) {
537 return getPerson(personID)->getImpatience();
538}
539
540
541void
542Person::setSpeed(const std::string& personID, double speed) {
543 getPerson(personID)->setSpeed(speed);
544}
545
546
547void
548Person::setType(const std::string& personID, const std::string& typeID) {
550 if (vehicleType == nullptr) {
551 throw TraCIException("The vehicle type '" + typeID + "' is not known.");
552 }
553 getPerson(personID)->replaceVehicleType(vehicleType);
554}
555
556
557void
558Person::add(const std::string& personID, const std::string& edgeID, double pos, double departInSecs, const std::string typeID) {
560 try {
561 p = getPerson(personID);
562 } catch (TraCIException&) {
563 p = nullptr;
564 }
565
566 if (p != nullptr) {
567 throw TraCIException("The person " + personID + " to add already exists.");
568 }
569
570 SUMOTime depart = TIME2STEPS(departInSecs);
571 SUMOVehicleParameter vehicleParams;
572 vehicleParams.id = personID;
573
575 if (!vehicleType) {
576 throw TraCIException("Invalid type '" + typeID + "' for person '" + personID + "'");
577 }
578
579 const MSEdge* edge = MSEdge::dictionary(edgeID);
580 if (!edge) {
581 throw TraCIException("Invalid edge '" + edgeID + "' for person: '" + personID + "'");
582 }
583
584 if (departInSecs < 0.) {
585 const int proc = (int) - departInSecs;
586 if (proc >= static_cast<int>(DepartDefinition::DEF_MAX)) {
587 throw TraCIException("Invalid departure time." + toString(depart) + " " + toString(proc));
588 }
589 vehicleParams.departProcedure = (DepartDefinition)proc;
590 vehicleParams.depart = MSNet::getInstance()->getCurrentTimeStep();
591 } else if (depart < MSNet::getInstance()->getCurrentTimeStep()) {
592 vehicleParams.depart = MSNet::getInstance()->getCurrentTimeStep();
593 WRITE_WARNINGF(TL("Departure time=% for person '%' is in the past; using current time=% instead."),
594 toString(departInSecs), personID, time2string(vehicleParams.depart));
595 } else {
596 vehicleParams.depart = depart;
597 }
598
600 if (fabs(pos) > edge->getLength()) {
601 throw TraCIException("Invalid departure position.");
602 }
603 if (pos < 0) {
604 pos += edge->getLength();
605 }
606 vehicleParams.departPos = pos;
607
608 SUMOVehicleParameter* params = new SUMOVehicleParameter(vehicleParams);
610 plan->push_back(new MSStageWaiting(edge, nullptr, 0, depart, pos, "awaiting departure", true));
611
612 try {
613 MSTransportable* person = MSNet::getInstance()->getPersonControl().buildPerson(params, vehicleType, plan, nullptr);
615 } catch (ProcessError& e) {
616 delete params;
617 delete plan;
618 throw TraCIException(e.what());
619 }
620}
621
622MSStage*
623Person::convertTraCIStage(const TraCIStage& stage, const std::string personID) {
624 MSStoppingPlace* bs = nullptr;
625 if (!stage.destStop.empty()) {
626 bs = MSNet::getInstance()->getStoppingPlace(stage.destStop);
627 if (bs == nullptr) {
628 throw TraCIException("Invalid stopping place id '" + stage.destStop + "' for person: '" + personID + "'");
629 }
630 }
631 switch (stage.type) {
632 case STAGE_DRIVING: {
633 if (stage.edges.empty()) {
634 throw TraCIException("The stage should have at least one edge");
635 }
636 std::string toId = stage.edges.back();
637 MSEdge* to = MSEdge::dictionary(toId);
638 if (!to) {
639 throw TraCIException("Invalid edge '" + toId + "' for person: '" + personID + "'");
640 }
641 //std::string fromId = stage.edges.front();
642 //MSEdge* from = MSEdge::dictionary(fromId);
643 //if (!from) {
644 // throw TraCIException("Invalid edge '" + fromId + "' for person: '" + personID + "'");
645 //}
646 if (stage.line.empty()) {
647 throw TraCIException("Empty lines parameter for person: '" + personID + "'");
648 }
649 double arrivalPos = stage.arrivalPos;
650 if (arrivalPos == INVALID_DOUBLE_VALUE) {
651 if (bs != nullptr) {
652 arrivalPos = bs->getEndLanePosition();
653 } else {
654 arrivalPos = to->getLength();
655 }
656 }
657 return new MSStageDriving(nullptr, to, bs, arrivalPos, 0.0, StringTokenizer(stage.line).getVector());
658 }
659
660 case STAGE_WALKING: {
661 MSTransportable* p = getPerson(personID);
662 ConstMSEdgeVector edges;
663 try {
664 MSEdge::parseEdgesList(stage.edges, edges, "<unknown>");
665 } catch (ProcessError& e) {
666 throw TraCIException(e.what());
667 }
668 if (edges.empty()) {
669 throw TraCIException("Empty edge list for walking stage of person '" + personID + "'.");
670 }
671 double arrivalPos = stage.arrivalPos;
672 if (fabs(arrivalPos) > edges.back()->getLength()) {
673 throw TraCIException("Invalid arrivalPos for walking stage of person '" + personID + "'.");
674 }
675 if (arrivalPos < 0) {
676 arrivalPos += edges.back()->getLength();
677 }
678 return new MSStageWalking(p->getID(), edges, bs, -1, -1, p->getArrivalPos(), arrivalPos, MSPModel::UNSPECIFIED_POS_LAT);
679 }
680
681 case STAGE_WAITING: {
682 MSTransportable* p = getPerson(personID);
683 if (stage.travelTime < 0) {
684 throw TraCIException("Duration for person: '" + personID + "' must not be negative");
685 }
686 return new MSStageWaiting(p->getArrivalEdge(), nullptr, TIME2STEPS(stage.travelTime), 0, p->getArrivalPos(), stage.description, false);
687 }
688 case STAGE_TRIP: {
689 MSTransportable* p = getPerson(personID);
690 ConstMSEdgeVector edges;
691 try {
692 MSEdge::parseEdgesList(stage.edges, edges, "<unknown>");
693 } catch (ProcessError& e) {
694 throw TraCIException(e.what());
695 }
696 if ((edges.size() == 0 && bs == nullptr) || edges.size() > 1) {
697 throw TraCIException("A trip should be defined with a destination edge or a destination stop for person '" + personID + "'.");
698 }
699 const MSEdge* to = nullptr;
700 if (bs != nullptr) {
701 to = &bs->getLane().getEdge();
702 if (edges.size() > 0 && to != edges.back()) {
703 throw TraCIException("Mismatching destination edge and destination stop edge for person '" + personID + "'.");
704 }
705 } else {
706 to = edges.back();
707 }
708 SVCPermissions modeSet = 0;
710 for (std::string vtypeid : StringTokenizer(stage.vType).getVector()) {
711 const MSVehicleType* const vType = vehControl.getVType(vtypeid);
712 if (vType == nullptr) {
713 throw TraCIException("The vehicle type '" + vtypeid + "' in a trip for person '" + personID + "' is not known.");
714 }
715 modeSet |= (vType->getVehicleClass() == SVC_BICYCLE) ? SVC_BICYCLE : SVC_PASSENGER;
716 }
717 if (stage.line.empty()) {
718 modeSet = p->getParameter().modes;
719 } else {
720 std::string errorMsg;
721 if (!SUMOVehicleParameter::parsePersonModes(stage.line, "person", personID, modeSet, errorMsg)) {
722 throw TraCIException(errorMsg);
723 }
724 }
725 bool hasArrivalPos = stage.arrivalPos != INVALID_DOUBLE_VALUE;
726 double arrivalPos = stage.arrivalPos;
727 if (hasArrivalPos) {
728 if (fabs(arrivalPos) > to->getLength()) {
729 throw TraCIException("Invalid arrivalPos for walking stage of person '" + personID + "'.");
730 }
731 if (arrivalPos < 0) {
732 arrivalPos += to->getLength();
733 }
734 }
735 const MSStage* cur = p->getCurrentStage();
736 double walkfactor = OptionsCont::getOptions().getFloat("persontrip.walkfactor");
737 std::string group = stage.intended; //OptionsCont::getOptions().getString("persontrip.default.group");
738 const SUMOTime duration = -1;
739 const double speed = -1;
740 return new MSStageTrip(cur->getDestination(), cur->getDestinationStop(), to, bs,
741 duration, modeSet, stage.vType, speed, walkfactor, group,
742 MSPModel::UNSPECIFIED_POS_LAT, hasArrivalPos, arrivalPos);
743 }
744 default:
745 return nullptr;
746 }
747}
748
749
750void
751Person::appendStage(const std::string& personID, const TraCIStage& stage) {
752 MSTransportable* p = getPerson(personID);
753 MSStage* personStage = convertTraCIStage(stage, personID);
754 p->appendStage(personStage);
755}
756
757
758void
759Person::replaceStage(const std::string& personID, const int stageIndex, const TraCIStage& stage) {
760 MSTransportable* p = getPerson(personID);
761 if (stageIndex < 0) {
762 throw TraCIException("The stage index may not be negative.");
763 }
764 if (stageIndex >= p->getNumRemainingStages()) {
765 throw TraCIException("Specified stage index: is not valid for person " + personID);
766 }
767 MSStage* personStage = convertTraCIStage(stage, personID);
768 // removing the current stage triggers abort+proceed so the replacement
769 // stage must be ready beforehand
770 p->appendStage(personStage, stageIndex + 1);
771 p->removeStage(stageIndex);
772}
773
774
775void
776Person::appendDrivingStage(const std::string& personID, const std::string& toEdge, const std::string& lines, const std::string& stopID) {
777 MSTransportable* p = getPerson(personID);
778 const MSEdge* edge = MSEdge::dictionary(toEdge);
779 if (!edge) {
780 throw TraCIException("Invalid edge '" + toEdge + "' for person: '" + personID + "'");
781 }
782 if (lines.size() == 0) {
783 throw TraCIException("Empty lines parameter for person: '" + personID + "'");
784 }
785 MSStoppingPlace* bs = nullptr;
786 if (stopID != "") {
787 bs = MSNet::getInstance()->getStoppingPlace(stopID);
788 if (bs == nullptr) {
789 throw TraCIException("Invalid stopping place id '" + stopID + "' for person: '" + personID + "'");
790 }
791 }
792 p->appendStage(new MSStageDriving(nullptr, edge, bs, edge->getLength() - NUMERICAL_EPS, 0.0, StringTokenizer(lines).getVector()));
793}
794
795
796void
797Person::appendWaitingStage(const std::string& personID, double duration, const std::string& description, const std::string& stopID) {
798 MSTransportable* p = getPerson(personID);
799 if (duration < 0) {
800 throw TraCIException("Duration for person: '" + personID + "' must not be negative");
801 }
802 MSStoppingPlace* bs = nullptr;
803 if (stopID != "") {
805 if (bs == nullptr) {
806 throw TraCIException("Invalid stopping place id '" + stopID + "' for person: '" + personID + "'");
807 }
808 }
809 p->appendStage(new MSStageWaiting(p->getArrivalEdge(), nullptr, TIME2STEPS(duration), 0, p->getArrivalPos(), description, false));
810}
811
812
813void
814Person::appendWalkingStage(const std::string& personID, const std::vector<std::string>& edgeIDs, double arrivalPos, double duration, double speed, const std::string& stopID) {
815 MSTransportable* p = getPerson(personID);
816 ConstMSEdgeVector edges;
817 try {
818 MSEdge::parseEdgesList(edgeIDs, edges, "<unknown>");
819 } catch (ProcessError& e) {
820 throw TraCIException(e.what());
821 }
822 if (edges.empty()) {
823 throw TraCIException("Empty edge list for walking stage of person '" + personID + "'.");
824 }
825 if (fabs(arrivalPos) > edges.back()->getLength()) {
826 throw TraCIException("Invalid arrivalPos for walking stage of person '" + personID + "'.");
827 }
828 if (arrivalPos < 0) {
829 arrivalPos += edges.back()->getLength();
830 }
831 MSStoppingPlace* bs = nullptr;
832 if (stopID != "") {
834 if (bs == nullptr) {
835 throw TraCIException("Invalid stopping place id '" + stopID + "' for person: '" + personID + "'");
836 }
837 }
838 p->appendStage(new MSStageWalking(p->getID(), edges, bs, TIME2STEPS(duration), speed, p->getArrivalPos(), arrivalPos, MSPModel::UNSPECIFIED_POS_LAT));
839}
840
841
842void
843Person::removeStage(const std::string& personID, int nextStageIndex) {
844 MSTransportable* p = getPerson(personID);
845 if (nextStageIndex >= p->getNumRemainingStages()) {
846 throw TraCIException("The stage index must be lower than the number of remaining stages.");
847 }
848 if (nextStageIndex < 0) {
849 throw TraCIException("The stage index may not be negative.");
850 }
851 p->removeStage(nextStageIndex);
852}
853
854
855void
856Person::rerouteTraveltime(const std::string& personID) {
857 MSPerson* p = getPerson(personID);
858 if (p->getNumRemainingStages() == 0) {
859 throw TraCIException("Person '" + personID + "' has no remaining stages.");
860 }
861 const MSEdge* from = p->getEdge();
862 double departPos = p->getEdgePos();
863 // reroute to the start of the next-non-walking stage
864 int firstIndex;
866 firstIndex = 0;
867 } else if (p->getCurrentStageType() == MSStageType::WAITING) {
869 throw TraCIException("Person '" + personID + "' cannot reroute after the current stop.");
870 }
871 firstIndex = 1;
872 } else {
873 throw TraCIException("Person '" + personID + "' cannot reroute in stage type '" + toString((int)p->getCurrentStageType()) + "'.");
874 }
875 int nextIndex = firstIndex + 1;
876 for (; nextIndex < p->getNumRemainingStages(); nextIndex++) {
877 if (p->getStageType(nextIndex) != MSStageType::WALKING) {
878 break;
879 }
880 }
881 MSStage* destStage = p->getNextStage(nextIndex - 1);
882 const MSEdge* to = destStage->getEdges().back();
883 double arrivalPos = destStage->getArrivalPos();
884 double speed = p->getMaxSpeed();
885 ConstMSEdgeVector newEdges;
886 MSNet::getInstance()->getPedestrianRouter(0).compute(from, to, departPos, arrivalPos, speed, 0, nullptr, p->getVTypeParameter(), newEdges);
887 if (newEdges.empty()) {
888 throw TraCIException("Could not find new route for person '" + personID + "'.");
889 }
890 ConstMSEdgeVector oldEdges = p->getNextStage(firstIndex)->getEdges();
891 assert(!oldEdges.empty());
892 if (oldEdges.front()->getFunction() != SumoXMLEdgeFunc::NORMAL) {
893 oldEdges.erase(oldEdges.begin());
894 }
895 //std::cout << " remainingStages=" << p->getNumRemainingStages() << " oldEdges=" << toString(oldEdges) << " newEdges=" << toString(newEdges) << " firstIndex=" << firstIndex << " nextIndex=" << nextIndex << "\n";
896 if (newEdges == oldEdges && (firstIndex + 1 == nextIndex)) {
897 return;
898 }
899 if (newEdges.front() != from) {
900 // @note: maybe this should be done automatically by the router
901 newEdges.insert(newEdges.begin(), from);
902 }
903 p->replaceWalk(newEdges, departPos, firstIndex, nextIndex);
904}
905
906
907void
908Person::moveTo(const std::string& personID, const std::string& laneID, double pos, double posLat) {
909 MSPerson* p = getPerson(personID);
910 MSLane* l = MSLane::dictionary(laneID);
911 if (l == nullptr) {
912 throw TraCIException("Unknown lane '" + laneID + "'.");
913 }
914 if (posLat == INVALID_DOUBLE_VALUE) {
915 posLat = 0;
916 } else if (fabs(posLat) >= (0.5 * (l->getWidth() + p->getVehicleType().getWidth()) + MSPModel::SIDEWALK_OFFSET)) {
917 // see MSPModel_Striping::moveToXY
918 throw TraCIException("Invalid lateral position " + toString(posLat) + " on lane '" + laneID + "'.");
919 }
920 switch (p->getStageType(0)) {
922 MSStageWalking* s = dynamic_cast<MSStageWalking*>(p->getCurrentStage());
923 assert(s != 0);
924 s->getPState()->moveTo(p, l, pos, posLat, SIMSTEP);
925 break;
926 }
927 default:
928 throw TraCIException("Command moveTo is not supported for person '" + personID + "' while " + p->getCurrentStageDescription() + ".");
929 }
930}
931
932
933void
934Person::moveToXY(const std::string& personID, const std::string& edgeID, const double x, const double y, double angle, const int keepRoute, double matchThreshold) {
935 MSPerson* p = getPerson(personID);
936 const bool doKeepRoute = (keepRoute & 1) != 0;
937 const bool mayLeaveNetwork = (keepRoute & 2) != 0;
938 const bool ignorePermissions = (keepRoute & 4) != 0;
939 SUMOVehicleClass vClass = ignorePermissions ? SVC_IGNORING : p->getVClass();
940 Position pos(x, y);
941#ifdef DEBUG_MOVEXY
942 const double origAngle = angle;
943#endif
944 // angle must be in [0,360] because it will be compared against those returned by naviDegree()
945 // angle set to INVALID_DOUBLE_VALUE is ignored in the evaluated and later set to the angle of the matched lane
946 if (angle != INVALID_DOUBLE_VALUE) {
947 if (!std::isfinite(angle)) {
948 throw TraCIException("Angle must be finite.");
949 }
950 angle = std::fmod(angle, 360.);
951 if (angle < 0.) {
952 angle += 360.;
953 }
954 }
955#ifdef DEBUG_MOVEXY
956 std::cout << std::endl << "begin person " << p->getID() << " lanePos:" << p->getEdgePos() << " edge:" << Named::getIDSecure(p->getEdge()) << "\n";
957 std::cout << " want pos:" << pos << " edgeID:" << edgeID << " origAngle:" << origAngle << " angle:" << angle << " keepRoute:" << keepRoute << std::endl;
958#endif
959
960 ConstMSEdgeVector edges;
961 MSLane* lane = nullptr;
962 double lanePos;
963 double lanePosLat = 0;
964 double bestDistance = std::numeric_limits<double>::max();
965 int routeOffset = 0;
966 bool found = false;
967 double maxRouteDistance = matchThreshold;
968
970 ev.push_back(p->getEdge());
971 int routeIndex = 0;
972 MSLane* currentLane = const_cast<MSLane*>(getSidewalk<MSEdge, MSLane>(p->getEdge()));
973 switch (p->getStageType(0)) {
975 MSStageWalking* s = dynamic_cast<MSStageWalking*>(p->getCurrentStage());
976 assert(s != 0);
977 ev = s->getEdges();
978 routeIndex = (int)(s->getRouteStep() - s->getRoute().begin());
979 }
980 break;
981 default:
982 break;
983 }
984 if (doKeepRoute) {
985 // case a): vehicle is on its earlier route
986 // we additionally assume it is moving forward (SUMO-limit);
987 // note that the route ("edges") is not changed in this case
989 ev, routeIndex, vClass, true,
990 bestDistance, &lane, lanePos, routeOffset);
991 if (bestDistance > maxRouteDistance) {
992 found = false;
993 lane = nullptr;
994 }
995 } else {
996 double speed = pos.distanceTo2D(p->getPosition()); // !!!veh->getSpeed();
997 found = Helper::moveToXYMap(pos, maxRouteDistance, mayLeaveNetwork, edgeID, angle,
998 speed, ev, routeIndex, currentLane, p->getEdgePos(), currentLane != nullptr,
999 vClass, GeomHelper::naviDegree(p->getAngle()), true,
1000 bestDistance, &lane, lanePos, routeOffset, edges);
1001 if (edges.size() != 0 && ev.size() > 1) {
1002 // try to rebuild the route
1003 const MSEdge* origEdge = p->getEdge();
1004 assert(lane != nullptr);
1005 const MSJunction* originalTarget = nullptr;
1006 if (origEdge->isNormal()) {
1007 if (routeIndex == 0) {
1008 if (origEdge->getToJunction() == ev[1]->getToJunction() || origEdge->getToJunction() == ev[1]->getFromJunction()) {
1009 originalTarget = origEdge->getToJunction();
1010 } else {
1011 originalTarget = origEdge->getFromJunction();
1012 }
1013 } else {
1014 if (origEdge->getToJunction() == ev[routeIndex - 1]->getToJunction() || origEdge->getToJunction() == ev[routeIndex - 1]->getFromJunction()) {
1015 originalTarget = origEdge->getFromJunction();
1016 } else {
1017 originalTarget = origEdge->getToJunction();
1018 }
1019 }
1020 } else {
1021 originalTarget = origEdge->getToJunction();
1022 assert(originalTarget == origEdge->getFromJunction());
1023 }
1024 const MSEdge* newEdge = edges[0];
1025 if (edges[0]->getFromJunction() == originalTarget || edges[0]->getToJunction() == originalTarget) {
1026 edges = ev;
1027 edges[routeIndex] = newEdge;
1028 }
1029 }
1030 }
1031 if (found || mayLeaveNetwork) {
1032 // compute lateral offset
1033 if (found) {
1034 const double perpDist = lane->getShape().distance2D(pos, false);
1035 if (perpDist != GeomHelper::INVALID_OFFSET) {
1036 lanePosLat = perpDist;
1037 if (!mayLeaveNetwork) {
1038 lanePosLat = MIN2(lanePosLat, 0.5 * (lane->getWidth() + p->getVehicleType().getWidth()));
1039 }
1040 // figure out whether the offset is to the left or to the right
1041 PositionVector tmp = lane->getShape();
1042 try {
1043 tmp.move2side(-lanePosLat); // moved to left
1044 } catch (ProcessError&) {
1045 WRITE_WARNINGF(TL("Could not determine position on lane '%' at lateral position %."), lane->getID(), toString(-lanePosLat));
1046 }
1047 //std::cout << " lane=" << lane->getID() << " posLat=" << lanePosLat << " shape=" << lane->getShape() << " tmp=" << tmp << " tmpDist=" << tmp.distance2D(pos) << "\n";
1048 if (tmp.distance2D(pos) > perpDist) {
1049 lanePosLat = -lanePosLat;
1050 }
1051 }
1052 }
1053 if (found && !mayLeaveNetwork && MSGlobals::gLateralResolution < 0) {
1054 // mapped position may differ from pos
1055 pos = lane->geometryPositionAtOffset(lanePos, -lanePosLat);
1056 }
1057 assert((found && lane != nullptr) || (!found && lane == nullptr));
1058 switch (p->getStageType(0)) {
1059 case MSStageType::WALKING: {
1060 if (angle == INVALID_DOUBLE_VALUE) {
1061 // walking angle cannot be deduced from road angle so we always use the last pos
1062 angle = GeomHelper::naviDegree(p->getPosition().angleTo2D(pos));
1063 }
1064 break;
1065 }
1067 case MSStageType::WAITING: {
1068 if (p->getNumRemainingStages() <= 1 || p->getStageType(1) != MSStageType::WALKING) {
1069 // insert walking stage after the current stage
1070 ConstMSEdgeVector route({p->getEdge()});
1071 const double departPos = p->getCurrentStage()->getArrivalPos();
1072 p->appendStage(new MSStageWalking(p->getID(), route, nullptr, -1, -1, departPos, departPos, MSPModel::UNSPECIFIED_POS_LAT), 1);
1073 }
1074 // abort waiting stage and proceed to walking stage
1075 p->removeStage(0);
1076 assert(p->getStageType(0) == MSStageType::WALKING);
1077 if (angle == INVALID_DOUBLE_VALUE) {
1078 if (lane != nullptr && !lane->isWalkingArea()) {
1079 angle = GeomHelper::naviDegree(lane->getShape().rotationAtOffset(lanePos));
1080 } else {
1081 // compute angle outside road network or on walkingarea from old and new position
1082 angle = GeomHelper::naviDegree(p->getPosition().angleTo2D(pos));
1083 }
1084 }
1085 break;
1086 }
1087 default:
1088 throw TraCIException("Command moveToXY is not supported for person '" + personID + "' while " + p->getCurrentStageDescription() + ".");
1089 }
1090 Helper::setRemoteControlled(p, pos, lane, lanePos, lanePosLat, angle, routeOffset, edges, MSNet::getInstance()->getCurrentTimeStep());
1091 } else {
1092 if (lane == nullptr) {
1093 throw TraCIException("Could not map person '" + personID + "' no road found within " + toString(maxRouteDistance) + "m.");
1094 } else {
1095 throw TraCIException("Could not map person '" + personID + "' distance to road is " + toString(bestDistance) + ".");
1096 }
1097 }
1098}
1099
1100
1103void
1104Person::setParameter(const std::string& personID, const std::string& key, const std::string& value) {
1105 MSTransportable* p = getPerson(personID);
1106 if (StringUtils::startsWith(key, "device.")) {
1107 throw TraCIException("Person '" + personID + "' does not support device parameters\n");
1108 } else if (StringUtils::startsWith(key, "laneChangeModel.")) {
1109 throw TraCIException("Person '" + personID + "' does not support laneChangeModel parameters\n");
1110 } else if (StringUtils::startsWith(key, "carFollowModel.")) {
1111 throw TraCIException("Person '" + personID + "' does not support carFollowModel parameters\n");
1112 } else if (StringUtils::startsWith(key, "junctionModel.")) {
1113 try {
1114 // use the whole key (including junctionModel prefix)
1115 p->setJunctionModelParameter(key, value);
1116 } catch (InvalidArgument& e) {
1117 // error message includes id since it is also used for xml input
1118 throw TraCIException(e.what());
1119 }
1120 } else if (StringUtils::startsWith(key, "has.") && StringUtils::endsWith(key, ".device")) {
1121 throw TraCIException("Person '" + personID + "' does not support chanigng device status\n");
1122 } else {
1123 ((SUMOVehicleParameter&)p->getParameter()).setParameter(key, value);
1124 }
1125}
1126
1127
1128void
1129Person::setLength(const std::string& personID, double length) {
1130 getPerson(personID)->getSingularType().setLength(length);
1131}
1132
1133
1134void
1135Person::setMaxSpeed(const std::string& personID, double speed) {
1136 getPerson(personID)->getSingularType().setMaxSpeed(speed);
1137}
1138
1139
1140void
1141Person::setVehicleClass(const std::string& personID, const std::string& clazz) {
1142 getPerson(personID)->getSingularType().setVClass(getVehicleClassID(clazz));
1143}
1144
1145
1146void
1147Person::setShapeClass(const std::string& personID, const std::string& clazz) {
1148 getPerson(personID)->getSingularType().setShape(getVehicleShapeID(clazz));
1149}
1150
1151
1152void
1153Person::setEmissionClass(const std::string& personID, const std::string& clazz) {
1154 getPerson(personID)->getSingularType().setEmissionClass(PollutantsInterface::getClassByName(clazz));
1155}
1156
1157
1158void
1159Person::setWidth(const std::string& personID, double width) {
1160 getPerson(personID)->getSingularType().setWidth(width);
1161}
1162
1163
1164void
1165Person::setHeight(const std::string& personID, double height) {
1166 getPerson(personID)->getSingularType().setHeight(height);
1167}
1168
1169
1170void
1171Person::setMass(const std::string& personID, double mass) {
1172 getPerson(personID)->getSingularType().setMass(mass);
1173}
1174
1175
1176void
1177Person::setMinGap(const std::string& personID, double minGap) {
1178 getPerson(personID)->getSingularType().setMinGap(minGap);
1179}
1180
1181
1182void
1183Person::setAccel(const std::string& personID, double accel) {
1184 getPerson(personID)->getSingularType().setAccel(accel);
1185}
1186
1187
1188void
1189Person::setDecel(const std::string& personID, double decel) {
1190 getPerson(personID)->getSingularType().setDecel(decel);
1191}
1192
1193
1194void
1195Person::setEmergencyDecel(const std::string& personID, double decel) {
1196 getPerson(personID)->getSingularType().setEmergencyDecel(decel);
1197}
1198
1199
1200void
1201Person::setApparentDecel(const std::string& personID, double decel) {
1202 getPerson(personID)->getSingularType().setApparentDecel(decel);
1203}
1204
1205
1206void
1207Person::setImperfection(const std::string& personID, double imperfection) {
1208 getPerson(personID)->getSingularType().setImperfection(imperfection);
1209}
1210
1211
1212void
1213Person::setBoardingDuration(const std::string& personID, double boardingDuration) {
1214 Helper::getPerson(personID)->getSingularType().setBoardingDuration(TIME2STEPS(boardingDuration));
1215}
1216
1217
1218void
1219Person::setImpatience(const std::string& personID, double impatience) {
1220 Helper::getVehicle(personID)->getSingularType().setImpatience(impatience);
1221}
1222
1223
1224
1225void
1226Person::setTau(const std::string& personID, double tau) {
1227 getPerson(personID)->getSingularType().setTau(tau);
1228}
1229
1230
1231void
1232Person::setMinGapLat(const std::string& personID, double minGapLat) {
1233 getPerson(personID)->getSingularType().setMinGapLat(minGapLat);
1234}
1235
1236
1237void
1238Person::setMaxSpeedLat(const std::string& personID, double speed) {
1239 getPerson(personID)->getSingularType().setMaxSpeedLat(speed);
1240}
1241
1242
1243void
1244Person::setLateralAlignment(const std::string& personID, const std::string& latAlignment) {
1245 double lao;
1247 if (SUMOVTypeParameter::parseLatAlignment(latAlignment, lao, lad)) {
1248 getPerson(personID)->getSingularType().setPreferredLateralAlignment(lad, lao);
1249 } else {
1250 throw TraCIException("Unknown value '" + latAlignment + "' when setting latAlignment for person '" + personID + "';\n must be one of (\"right\", \"center\", \"arbitrary\", \"nice\", \"compact\", \"left\" or a float)");
1251 }
1252}
1253
1254
1255void
1256Person::setSpeedFactor(const std::string& personID, double factor) {
1257 getPerson(personID)->setChosenSpeedFactor(factor);
1258}
1259
1260
1261void
1262Person::setActionStepLength(const std::string& personID, double actionStepLength, bool resetActionOffset) {
1263 getPerson(personID)->getSingularType().setActionStepLength(SUMOVehicleParserHelper::processActionStepLength(actionStepLength), resetActionOffset);
1264}
1265
1266void
1267Person::remove(const std::string& personID, char /*reason*/) {
1268 MSPerson* person = getPerson(personID);
1269 // remove all stages after the current and then abort the current stage
1270 // (without adding a zero-length waiting stage)
1271 while (person->getNumRemainingStages() > 1) {
1272 person->removeStage(1);
1273 }
1274 person->removeStage(0, false);
1275}
1276
1277void
1278Person::setColor(const std::string& personID, const TraCIColor& c) {
1279 const SUMOVehicleParameter& p = getPerson(personID)->getParameter();
1280 p.color.set((unsigned char)c.r, (unsigned char)c.g, (unsigned char)c.b, (unsigned char)c.a);
1282}
1283
1284
1286
1287
1288MSPerson*
1289Person::getPerson(const std::string& personID) {
1290 return Helper::getPerson(personID);
1291}
1292
1293
1294void
1295Person::storeShape(const std::string& id, PositionVector& shape) {
1296 shape.push_back(getPerson(id)->getPosition());
1297}
1298
1299
1300std::shared_ptr<VariableWrapper>
1301Person::makeWrapper() {
1302 return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);
1303}
1304
1305
1306bool
1307Person::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper, tcpip::Storage* paramData) {
1308 switch (variable) {
1309 case TRACI_ID_LIST:
1310 return wrapper->wrapStringList(objID, variable, getIDList());
1311 case ID_COUNT:
1312 return wrapper->wrapInt(objID, variable, getIDCount());
1313 case VAR_POSITION:
1314 return wrapper->wrapPosition(objID, variable, getPosition(objID));
1315 case VAR_POSITION3D:
1316 return wrapper->wrapPosition(objID, variable, getPosition(objID, true));
1317 case VAR_ANGLE:
1318 return wrapper->wrapDouble(objID, variable, getAngle(objID));
1319 case VAR_SLOPE:
1320 return wrapper->wrapDouble(objID, variable, getSlope(objID));
1321 case VAR_SPEED:
1322 return wrapper->wrapDouble(objID, variable, getSpeed(objID));
1323 case VAR_ROAD_ID:
1324 return wrapper->wrapString(objID, variable, getRoadID(objID));
1325 case VAR_LANE_ID:
1326 return wrapper->wrapString(objID, variable, getLaneID(objID));
1327 case VAR_LANEPOSITION:
1328 return wrapper->wrapDouble(objID, variable, getLanePosition(objID));
1329 case VAR_ARRIVALPOS:
1330 return wrapper->wrapDouble(objID, variable, getArrivalPos(objID));
1331 case VAR_COLOR:
1332 return wrapper->wrapColor(objID, variable, getColor(objID));
1333 case VAR_WAITING_TIME:
1334 return wrapper->wrapDouble(objID, variable, getWaitingTime(objID));
1335 case VAR_IMPATIENCE:
1336 return wrapper->wrapDouble(objID, variable, getImpatience(objID));
1337 case VAR_TYPE:
1338 return wrapper->wrapString(objID, variable, getTypeID(objID));
1339 case VAR_SPEED_FACTOR:
1340 return wrapper->wrapDouble(objID, variable, getSpeedFactor(objID));
1341 case VAR_NEXT_EDGE:
1342 return wrapper->wrapString(objID, variable, getNextEdge(objID));
1343 case VAR_EDGES:
1344 return wrapper->wrapStringList(objID, variable, getEdges(objID, StoHelp::readTypedInt(*paramData)));
1345 case VAR_STAGE:
1346 return wrapper->wrapStage(objID, variable, getStage(objID, StoHelp::readTypedInt(*paramData)));
1348 return wrapper->wrapInt(objID, variable, getRemainingStages(objID));
1349 case VAR_VEHICLE:
1350 return wrapper->wrapString(objID, variable, getVehicle(objID));
1351 case VAR_MAXSPEED:
1352 // integrate desiredMaxSpeed and individual speedFactor
1353 return wrapper->wrapDouble(objID, variable, getMaxSpeed(objID));
1354 case DISTANCE_REQUEST: {
1355 TraCIRoadPosition roadPos;
1356 Position pos;
1357 if (Helper::readDistanceRequest(*paramData, roadPos, pos) == libsumo::POSITION_ROADMAP) {
1358 return wrapper->wrapDouble(objID, variable, getWalkingDistance(objID, roadPos.edgeID, roadPos.pos, roadPos.laneIndex));
1359 }
1360 return wrapper->wrapDouble(objID, variable, getWalkingDistance2D(objID, pos.x(), pos.y()));
1361 }
1362 case VAR_PARAMETER:
1363 return wrapper->wrapString(objID, variable, getParameter(objID, StoHelp::readTypedString(*paramData)));
1365 return wrapper->wrapStringPair(objID, variable, getParameterWithKey(objID, StoHelp::readTypedString(*paramData)));
1367 return wrapper->wrapReservationVector(objID, variable, getTaxiReservations(StoHelp::readTypedInt(*paramData)));
1369 return wrapper->wrapString(objID, variable, splitTaxiReservation(objID, StoHelp::readTypedStringList(*paramData)));
1370 default:
1371 return libsumo::VehicleType::handleVariable(getTypeID(objID), variable, wrapper, paramData);
1372 }
1373}
1374
1375
1376}
1377
1378
1379/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
std::vector< const MSEdge * > ConstMSEdgeVector
Definition MSEdge.h:75
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:299
#define TL(string)
Definition MsgHandler.h:316
#define TLF(string,...)
Definition MsgHandler.h:318
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:107
#define STEPS2TIME(x)
Definition SUMOTime.h:58
#define SIMSTEP
Definition SUMOTime.h:69
constexpr SUMOTime TIME2STEPS(double x)
Definition SUMOTime.h:60
LatAlignmentDefinition
Possible ways to choose the lateral alignment, i.e., how vehicles align themselves within their lane.
SUMOVehicleClass getVehicleClassID(const std::string &name)
Returns the class id of the abstract class given by its name.
SUMOVehicleShape getVehicleShapeID(const std::string &name)
Returns the class id of the shape class given by its name.
std::string getVehicleShapeName(SUMOVehicleShape id)
Returns the class name of the shape class given by its id.
long long int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_IGNORING
vehicles ignoring classes
@ SVC_PASSENGER
vehicle is a passenger car (a "normal" car)
@ SVC_BICYCLE
vehicle is a bicycle
@ GIVEN
The position is given.
const long long int VEHPARS_COLOR_SET
DepartDefinition
Possible ways to depart.
@ DEF_MAX
Tag for the last element in the enum for safe int casting.
@ SUMO_TAG_BUS_STOP
A bus stop.
T MIN2(T a, T b)
Definition StdDefs.h:80
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:57
#define LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(CLASS, DOM)
Definition TraCIDefs.h:77
#define LIBSUMO_GET_PARAMETER_WITH_KEY_IMPLEMENTATION(CLASS)
Definition TraCIDefs.h:124
static const double INVALID_OFFSET
a value to signify offsets outside the range of [0, Line.length()]
Definition GeomHelper.h:50
static double naviDegree(const double angle)
MSVehicleType & getSingularType()
Replaces the current vehicle type with a new one used by this vehicle only.
static MSDispatch * getDispatchAlgorithm()
A dispatch algorithm that services customers in reservation order and always sends the closest availa...
std::string splitReservation(std::string resID, std::vector< std::string > personIDs)
split existing reservations and return the new reservation id
An algorithm that performs distpach for a taxi fleet.
Definition MSDispatch.h:114
std::vector< Reservation * > getReservations()
retrieve all reservations
virtual std::vector< const Reservation * > getRunningReservations()
retrieve all reservations that were already dispatched and are still active
A road/street connecting two junctions.
Definition MSEdge.h:78
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition MSEdge.h:169
static void parseEdgesList(const std::string &desc, ConstMSEdgeVector &into, const std::string &rid)
Parses the given string assuming it contains a list of edge ids divided by spaces.
Definition MSEdge.cpp:1183
bool isNormal() const
return whether this edge is an internal edge
Definition MSEdge.h:265
const MSJunction * getToJunction() const
Definition MSEdge.h:428
double getLength() const
return the length of the edge
Definition MSEdge.h:695
const MSJunction * getFromJunction() const
Definition MSEdge.h:424
static bool dictionary(const std::string &id, MSEdge *edge)
Inserts edge into the static dictionary Returns true if the key id isn't already in the dictionary....
Definition MSEdge.cpp:1117
static double gLateralResolution
Definition MSGlobals.h:100
The base class for an intersection.
Definition MSJunction.h:58
Representation of a lane in the micro simulation.
Definition MSLane.h:84
bool isWalkingArea() const
Definition MSLane.cpp:2693
static bool dictionary(const std::string &id, MSLane *lane)
Static (sic!) container methods {.
Definition MSLane.cpp:2538
double interpolateLanePosToGeometryPos(double lanePos) const
Definition MSLane.h:555
virtual const PositionVector & getShape(bool) const
Definition MSLane.h:294
MSEdge & getEdge() const
Returns the lane's edge.
Definition MSLane.h:790
double getWidth() const
Returns the lane's width.
Definition MSLane.h:661
const Position geometryPositionAtOffset(double offset, double lateralOffset=0) const
Definition MSLane.h:561
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:201
MSPedestrianRouter & getPedestrianRouter(int rngIndex, const Prohibitions &prohibited={}) const
Definition MSNet.cpp:1715
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition MSNet.h:335
MSStoppingPlace * getStoppingPlace(const std::string &id, const SumoXMLTag category) const
Returns the named stopping place of the given category.
Definition MSNet.cpp:1527
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition MSNet.h:403
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition MSNet.cpp:1317
static const double SIDEWALK_OFFSET
the offset for computing person positions when walking on edges without a sidewalk
Definition MSPModel.h:62
static const double UNSPECIFIED_POS_LAT
the default lateral offset for persons when starting a walk
Definition MSPModel.h:65
void replaceWalk(const ConstMSEdgeVector &newEdges, double departPos, int firstIndex, int nextIndex)
set new walk and replace the stages with relative indices in the interval [firstIndex,...
Definition MSPerson.cpp:293
SUMOTime getIntendedDepart() const
std::string getIntendedVehicleID() const
const std::set< std::string > & getLines() const
std::string getVehicleType() const
const MSEdge * getDestination() const
returns the destination edge
Definition MSStage.cpp:65
virtual ConstMSEdgeVector getEdges() const
the edges of the current stage
Definition MSStage.cpp:107
virtual double getArrivalPos() const
Definition MSStage.h:97
SUMOTime getDeparted() const
get departure time of stage
Definition MSStage.cpp:129
virtual std::string getStageDescription(const bool isPerson) const =0
return (brief) string representation of the current stage
SUMOTime getArrived() const
get arrival time of stage
Definition MSStage.cpp:134
MSStoppingPlace * getDestinationStop() const
returns the destination stop (if any)
Definition MSStage.h:88
MSStageType getStageType() const
Definition MSStage.h:138
virtual double getDistance() const =0
get travel distance in this stage
ConstMSEdgeVector getEdges() const
the edges of the current stage
const std::vector< const MSEdge * > & getRoute() const
MSTransportableStateAdapter * getPState() const
const std::vector< constMSEdge * >::iterator getRouteStep() const
int getRoutePosition() const
return index of current edge within route
A lane area vehicles can halt at.
double getEndLanePosition() const
Returns the end position of this stop.
const MSLane & getLane() const
Returns the lane this stop is located at.
constVehIt loadedBegin() const
Returns the begin of the internal transportables map.
int size() const
Returns the number of known transportables.
constVehIt loadedEnd() const
Returns the end of the internal transportables map.
std::map< std::string, MSTransportable * >::const_iterator constVehIt
Definition of the internal transportables map iterator.
virtual MSTransportable * buildPerson(const SUMOVehicleParameter *pars, MSVehicleType *vtype, MSTransportable::MSTransportablePlan *plan, SumoRNG *rng) const
Builds a new person.
bool add(MSTransportable *transportable)
Adds a single transportable, returns false if an id clash occurred.
Position getPosition(const double) const override
Return current position (x/y, cartesian)
virtual double getEdgePos() const
Return the position on the edge.
std::string getCurrentStageDescription() const
Returns the current stage description as a string.
const MSEdge * getArrivalEdge() const
returns the final arrival edge
MSStageType getStageType(int next) const
the stage type for the nth next stage
MSStage * getNextStage(int offset) const
Return the next (or previous) stage denoted by the offset.
void setJunctionModelParameter(const std::string &key, const std::string &value)
set individual junction model paramete (not type related)
int getNumRemainingStages() const
Return the number of remaining stages (including the current)
MSStage * getCurrentStage() const
Return the current stage.
SUMOVehicleClass getVClass() const override
Returns the object's access class.
double getMaxSpeed() const override
Returns the maximum speed (the minimum of desired and physical maximum speed)
void removeStage(int next, bool stayInSim=true)
removes the nth next stage
const SUMOVTypeParameter & getVTypeParameter() const override
Returns the object's "vehicle" type parameter.
bool isPerson() const override
Whether it is a person.
double getArrivalPos() const
returns the final arrival pos
int getNumStages() const
Return the total number stages in this person's plan.
MSStageType getCurrentStageType() const
the current stage type of the transportable
const SUMOVehicleParameter & getParameter() const override
Returns the vehicle's parameter (including departure definition)
const MSVehicleType & getVehicleType() const override
Returns the object's "vehicle" type.
virtual double getAngle() const override
return the current angle of the transportable
void appendStage(MSStage *stage, int next=-1)
Appends the given stage to the current plan.
MSVehicleType & getSingularType()
Replaces the current vehicle type with a new one used by this vehicle only.
const MSEdge * getEdge() const override
Returns the current edge.
std::vector< MSStage * > MSTransportablePlan
the structure holding the plan of a transportable
virtual void moveTo(MSPerson *p, MSLane *lane, double lanePos, double lanePosLat, SUMOTime t)
try to move transportable to the given position
Definition MSPModel.h:189
The class responsible for building and deletion of vehicles.
MSVehicleType * getVType(const std::string &id=DEFAULT_VTYPE_ID, SumoRNG *rng=nullptr, bool readOnly=false)
Returns the named vehicle type or a sample from the named distribution.
The car-following model and parameter.
double getWidth() const
Get the width which vehicles of this class shall have when being drawn.
SUMOVehicleClass getVehicleClass() const
Get this vehicle type's vehicle class.
void setBoardingDuration(SUMOTime duration, bool isPerson=true)
Set a new value for this type's boardingDuration.
void setImpatience(const double impatience)
Set a new value for this type's impatience.
static std::string getIDSecure(const T *obj, const std::string &fallBack="NULL")
get an identifier for Named-like object which may be Null
Definition Named.h:66
const std::string & getID() const
Returns the id.
Definition Named.h:73
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
static OptionsCont & getOptions()
Retrieves the options.
double compute(const E *from, const E *to, double departPos, double arrivalPos, double speed, SUMOTime msTime, const N *onlyNode, const SUMOVTypeParameter &pars, std::vector< const E * > &into, bool allEdges=false) const
Builds the route between the given edges using the minimum effort at the given time The definition of...
double recomputeWalkCosts(const std::vector< const E * > &edges, double speed, double fromPos, double toPos, SUMOTime msTime, const SUMOVTypeParameter &pars, double &length) const
C++ TraCI client API implementation.
static std::string getName(const SUMOEmissionClass c)
Checks whether the string describes a known vehicle class.
static SUMOEmissionClass getClassByName(const std::string &eClass, const SUMOVehicleClass vc=SVC_IGNORING)
Checks whether the string describes a known vehicle class.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
double distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition Position.h:273
double x() const
Returns the x-position.
Definition Position.h:52
double angleTo2D(const Position &other) const
returns the angle in the plane of the vector pointing from here to the other position (in radians bet...
Definition Position.h:283
double y() const
Returns the y-position.
Definition Position.h:57
A list of positions.
double rotationAtOffset(double pos) const
Returns the rotation at the given length.
double distance2D(const Position &p, bool perpendicular=false) const
closest 2D-distance to point p (or -1 if perpendicular is true and the point is beyond this vector)
void move2side(double amount, double maxExtension=100)
move position vector to side using certain amount
double slopeDegreeAtOffset(double pos) const
Returns the slope at the given length.
unsigned char red() const
Returns the red-amount of the color.
Definition RGBColor.cpp:78
unsigned char alpha() const
Returns the alpha-amount of the color.
Definition RGBColor.cpp:96
unsigned char green() const
Returns the green-amount of the color.
Definition RGBColor.cpp:84
unsigned char blue() const
Returns the blue-amount of the color.
Definition RGBColor.cpp:90
void set(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
assigns new values
Definition RGBColor.cpp:102
static bool parseLatAlignment(const std::string &val, double &lao, LatAlignmentDefinition &lad)
Parses and validates a given latAlignment value.
Representation of a vehicle.
Definition SUMOVehicle.h:63
Structure representing possible vehicle parameter.
long long int parametersSet
Information for the router which parameter were set, TraCI may modify this (when changing color)
SVCPermissions modes
The modes a person or container can use.
double departPos
(optional) The position the vehicle shall depart from
RGBColor color
The vehicle's color, TraCI may change this.
std::string id
The vehicle's id.
static bool parsePersonModes(const std::string &modes, const std::string &element, const std::string &id, SVCPermissions &modeSet, std::string &error)
Validates a given person modes value.
DepartDefinition departProcedure
Information how the vehicle shall choose the depart time.
DepartPosDefinition departPosProcedure
Information how the vehicle shall choose the departure position.
static SUMOTime processActionStepLength(double given)
Checks and converts given value for the action step length from seconds to miliseconds assuring it be...
std::vector< std::string > getVector()
return vector of strings
static bool startsWith(const std::string &str, const std::string prefix)
Checks whether a given string starts with the prefix.
static bool endsWith(const std::string &str, const std::string suffix)
Checks whether a given string ends with the suffix.
static TraCIPosition makeTraCIPosition(const Position &position, const bool includeZ=false)
Definition Helper.cpp:415
static bool moveToXYMap_matchingRoutePosition(const Position &pos, const std::string &origID, const ConstMSEdgeVector &currentRoute, int routeIndex, SUMOVehicleClass vClass, bool setLateralPos, double &bestDistance, MSLane **lane, double &lanePos, int &routeOffset)
Definition Helper.cpp:1781
static MSPerson * getPerson(const std::string &id)
Definition Helper.cpp:530
static int readDistanceRequest(tcpip::Storage &data, TraCIRoadPosition &roadPos, Position &pos)
Definition Helper.cpp:1906
static MSBaseVehicle * getVehicle(const std::string &id)
Definition Helper.cpp:516
static void setRemoteControlled(MSVehicle *v, Position xyPos, MSLane *l, double pos, double posLat, double angle, int edgeOffset, ConstMSEdgeVector route, SUMOTime t)
Definition Helper.cpp:1424
static bool moveToXYMap(const Position &pos, double maxRouteDistance, bool mayLeaveNetwork, const std::string &origID, const double angle, double speed, const ConstMSEdgeVector &currentRoute, const int routePosition, const MSLane *currentLane, double currentLanePos, bool onRoad, SUMOVehicleClass vClass, double currentAngle, bool setLateralPos, double &bestDistance, MSLane **lane, double &lanePos, int &routeOffset, ConstMSEdgeVector &edges)
Definition Helper.cpp:1464
static std::pair< MSLane *, double > convertCartesianToRoadMap(const Position &pos, const SUMOVehicleClass vClass)
Definition Helper.cpp:458
static const MSLane * getLaneChecking(const std::string &edgeID, int laneIndex, double pos)
Definition Helper.cpp:441
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="")
TRACI_CONST double INVALID_DOUBLE_VALUE
TRACI_CONST int VAR_EDGES
TRACI_CONST int POSITION_ROADMAP
TRACI_CONST int TRACI_ID_LIST
TRACI_CONST int VAR_IMPATIENCE
TRACI_CONST int STAGE_TRIP
TRACI_CONST int VAR_TYPE
TRACI_CONST int VAR_VEHICLE
TRACI_CONST int VAR_WAITING_TIME
std::map< std::string, libsumo::SubscriptionResults > ContextSubscriptionResults
Definition TraCIDefs.h:384
TRACI_CONST int VAR_ROAD_ID
TRACI_CONST int VAR_TAXI_RESERVATIONS
TRACI_CONST int VAR_SPEED_FACTOR
TRACI_CONST int VAR_ANGLE
TRACI_CONST int VAR_STAGE
TRACI_CONST int VAR_COLOR
TRACI_CONST int VAR_POSITION
TRACI_CONST int VAR_MAXSPEED
TRACI_CONST int STAGE_WAITING
std::map< std::string, libsumo::TraCIResults > SubscriptionResults
{object->{variable->value}}
Definition TraCIDefs.h:383
TRACI_CONST int VAR_SLOPE
TRACI_CONST int ID_COUNT
TRACI_CONST int VAR_PARAMETER
TRACI_CONST int VAR_LANEPOSITION
TRACI_CONST int VAR_LANE_ID
TRACI_CONST int VAR_ARRIVALPOS
TRACI_CONST int STAGE_WALKING
TRACI_CONST int VAR_POSITION3D
TRACI_CONST int VAR_SPEED
TRACI_CONST int VAR_PARAMETER_WITH_KEY
TRACI_CONST int VAR_NEXT_EDGE
TRACI_CONST int DISTANCE_REQUEST
TRACI_CONST int STAGE_DRIVING
TRACI_CONST int VAR_STAGES_REMAINING
TRACI_CONST int SPLIT_TAXI_RESERVATIONS
SUMOTime pickupTime
Definition MSDispatch.h:79
std::string id
Definition MSDispatch.h:76
const MSEdge * to
Definition MSDispatch.h:84
double fromPos
Definition MSDispatch.h:82
const MSEdge * from
Definition MSDispatch.h:81
SUMOTime reservationTime
Definition MSDispatch.h:78
std::string group
Definition MSDispatch.h:87
ReservationState state
Definition MSDispatch.h:90
std::set< const MSTransportable *, ComparatorNumericalIdLess > persons
Definition MSDispatch.h:77
double toPos
Definition MSDispatch.h:85