Eclipse SUMO - Simulation of Urban MObility
libsumo/Person.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2017-2023 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
24#include <microsim/MSEdge.h>
25#include <microsim/MSLane.h>
26#include <microsim/MSNet.h>
41#include "Helper.h"
42#include "VehicleType.h"
43#include "Person.h"
44
45#define FAR_AWAY 1000.0
46
47//#define DEBUG_MOVEXY
48//#define DEBUG_MOVEXY_ANGLE
49
50namespace libsumo {
51// ===========================================================================
52// static member initializations
53// ===========================================================================
54SubscriptionResults Person::mySubscriptionResults;
55ContextSubscriptionResults Person::myContextSubscriptionResults;
56
57
58// ===========================================================================
59// static member definitions
60// ===========================================================================
61std::vector<std::string>
62Person::getIDList() {
64 std::vector<std::string> ids;
65 for (MSTransportableControl::constVehIt i = c.loadedBegin(); i != c.loadedEnd(); ++i) {
66 if (i->second->getCurrentStageType() != MSStageType::WAITING_FOR_DEPART) {
67 ids.push_back(i->first);
68 }
69 }
70 return ids;
71}
72
73
74int
75Person::getIDCount() {
77}
78
79
80TraCIPosition
81Person::getPosition(const std::string& personID, const bool includeZ) {
82 return Helper::makeTraCIPosition(getPerson(personID)->getPosition(), includeZ);
83}
84
85
86TraCIPosition
87Person::getPosition3D(const std::string& personID) {
88 return Helper::makeTraCIPosition(getPerson(personID)->getPosition(), true);
89}
90
91
92double
93Person::getAngle(const std::string& personID) {
94 return GeomHelper::naviDegree(getPerson(personID)->getAngle());
95}
96
97
98double
99Person::getSlope(const std::string& personID) {
100 MSPerson* person = getPerson(personID);
101 const double ep = person->getEdgePos();
102 const MSLane* lane = getSidewalk<MSEdge, MSLane>(person->getEdge());
103 if (lane == nullptr) {
104 lane = person->getEdge()->getLanes()[0];
105 }
106 const double gp = lane->interpolateLanePosToGeometryPos(ep);
107 return lane->getShape().slopeDegreeAtOffset(gp);
108}
109
110
111double
112Person::getSpeed(const std::string& personID) {
113 return getPerson(personID)->getSpeed();
114}
115
116
117std::string
118Person::getRoadID(const std::string& personID) {
119 return getPerson(personID)->getEdge()->getID();
120}
121
122
123std::string
124Person::getLaneID(const std::string& personID) {
125 return Named::getIDSecure(getPerson(personID)->getLane(), "");
126}
127
128
129double
130Person::getLanePosition(const std::string& personID) {
131 return getPerson(personID)->getEdgePos();
132}
133
134std::vector<TraCIReservation>
135Person::getTaxiReservations(int stateFilter) {
136 std::vector<TraCIReservation> result;
138 if (dispatcher != nullptr) {
139 MSDispatch_TraCI* traciDispatcher = dynamic_cast<MSDispatch_TraCI*>(dispatcher);
140 if (traciDispatcher == nullptr) {
141 throw TraCIException("device.taxi.dispatch-algorithm 'traci' has not been loaded");
142 }
143 for (Reservation* res : dispatcher->getReservations()) {
144 if (filterReservation(stateFilter, res, result)) {
145 if (res->state == Reservation::NEW) {
146 res->state = Reservation::RETRIEVED;
147 }
148 }
149 }
150 const bool includeRunning = stateFilter == 0 || (stateFilter & (Reservation::ASSIGNED | Reservation::ONBOARD)) != 0;
151 if (includeRunning) {
152 for (const Reservation* res : dispatcher->getRunningReservations()) {
153 filterReservation(stateFilter, res, result);
154 }
155 }
156 }
157 std::sort(result.begin(), result.end(), reservation_by_id_sorter());
158 return result;
159}
160
161int
162Person::reservation_by_id_sorter::operator()(const TraCIReservation& r1, const TraCIReservation& r2) const {
163 return r1.id < r2.id;
164}
165
166
167std::string
168Person::splitTaxiReservation(std::string reservationID, const std::vector<std::string>& personIDs) {
170 if (dispatcher != nullptr) {
171 MSDispatch_TraCI* traciDispatcher = dynamic_cast<MSDispatch_TraCI*>(dispatcher);
172 if (traciDispatcher != nullptr) {
173 return traciDispatcher->splitReservation(reservationID, personIDs);
174 }
175 }
176 throw TraCIException("device.taxi.dispatch-algorithm 'traci' has not been loaded");
177}
178
179bool
180Person::filterReservation(int stateFilter, const Reservation* res, std::vector<libsumo::TraCIReservation>& reservations) {
181 if (stateFilter != 0 && (stateFilter & res->state) == 0) {
182 return false;
183 }
184 std::vector<std::string> personIDs;
185 for (MSTransportable* p : res->persons) {
186 personIDs.push_back(p->getID());
187 }
188 std::sort(personIDs.begin(), personIDs.end());
189 reservations.push_back(TraCIReservation(res->id,
190 personIDs,
191 res->group,
192 res->from->getID(),
193 res->to->getID(),
194 res->fromPos,
195 res->toPos,
198 res->state
199 ));
200 return true;
201}
202
203
204TraCIColor
205Person::getColor(const std::string& personID) {
206 const RGBColor& col = getPerson(personID)->getParameter().color;
207 TraCIColor tcol;
208 tcol.r = col.red();
209 tcol.g = col.green();
210 tcol.b = col.blue();
211 tcol.a = col.alpha();
212 return tcol;
213}
214
215
216std::string
217Person::getTypeID(const std::string& personID) {
218 return getPerson(personID)->getVehicleType().getID();
219}
220
221
222double
223Person::getWaitingTime(const std::string& personID) {
224 return getPerson(personID)->getWaitingSeconds();
225}
226
227
228std::string
229Person::getNextEdge(const std::string& personID) {
230 return getPerson(personID)->getNextEdge();
231}
232
233
234std::vector<std::string>
235Person::getEdges(const std::string& personID, int nextStageIndex) {
236 MSTransportable* p = getPerson(personID);
237 if (nextStageIndex >= p->getNumRemainingStages()) {
238 throw TraCIException("The stage index must be lower than the number of remaining stages.");
239 }
240 if (nextStageIndex < (p->getNumRemainingStages() - p->getNumStages())) {
241 throw TraCIException("The negative stage index must refer to a valid previous stage.");
242 }
243 std::vector<std::string> edgeIDs;
244 for (auto& e : p->getEdges(nextStageIndex)) {
245 if (e != nullptr) {
246 edgeIDs.push_back(e->getID());
247 }
248 }
249 return edgeIDs;
250}
251
252
253TraCIStage
254Person::getStage(const std::string& personID, int nextStageIndex) {
255 MSTransportable* p = getPerson(personID);
256 TraCIStage result;
257 if (nextStageIndex >= p->getNumRemainingStages()) {
258 throw TraCIException("The stage index must be lower than the number of remaining stages.");
259 }
260 if (nextStageIndex < (p->getNumRemainingStages() - p->getNumStages())) {
261 throw TraCIException("The negative stage index " + toString(nextStageIndex) + " must refer to a valid previous stage.");
262 }
263 //stageType, arrivalPos, edges, destStop, vType, and description can be retrieved directly from the base Stage class.
264 MSStage* stage = p->getNextStage(nextStageIndex);
265 result.type = (int)stage->getStageType();
266 result.arrivalPos = stage->getArrivalPos();
267 for (auto e : stage->getEdges()) {
268 if (e != nullptr) {
269 result.edges.push_back(e->getID());
270 }
271 }
272 MSStoppingPlace* destinationStop = stage->getDestinationStop();
273 if (destinationStop != nullptr) {
274 result.destStop = destinationStop->getID();
275 }
276 result.description = stage->getStageDescription(p->isPerson());
277 result.length = stage->getDistance();
278 if (result.length == -1.) {
279 result.length = INVALID_DOUBLE_VALUE;
280 }
281 result.departPos = INVALID_DOUBLE_VALUE;
282 result.cost = INVALID_DOUBLE_VALUE;
283 result.depart = stage->getDeparted() >= 0 ? STEPS2TIME(stage->getDeparted()) : INVALID_DOUBLE_VALUE;
284 result.travelTime = stage->getArrived() >= 0 ? STEPS2TIME(stage->getArrived() - stage->getDeparted()) : INVALID_DOUBLE_VALUE;
285 // Some stage type dependant attributes
286 switch (stage->getStageType()) {
288 MSStageDriving* const drivingStage = static_cast<MSStageDriving*>(stage);
289 result.vType = drivingStage->getVehicleType();
290 result.intended = drivingStage->getIntendedVehicleID();
291 if (result.depart < 0 && drivingStage->getIntendedDepart() >= 0) {
292 result.depart = STEPS2TIME(drivingStage->getIntendedDepart());
293 }
294 const std::set<std::string> lines = drivingStage->getLines();
295 for (auto line = lines.begin(); line != lines.end(); line++) {
296 if (line != lines.begin()) {
297 result.line += " ";
298 }
299 result.line += *line;
300 }
301 break;
302 }
304 auto* walkingStage = (MSPerson::MSPersonStage_Walking*) stage;
305 result.departPos = walkingStage->getDepartPos();
306 break;
307 }
309 auto* waitingStage = (MSStageWaiting*) stage;
310 if (waitingStage->getDuration() > 0) {
311 result.travelTime = STEPS2TIME(waitingStage->getDuration());
312 }
313 break;
314 }
315 default:
316 break;
317 }
318 return result;
319}
320
321
322int
323Person::getRemainingStages(const std::string& personID) {
324 return getPerson(personID)->getNumRemainingStages();
325}
326
327
328std::string
329Person::getVehicle(const std::string& personID) {
330 const SUMOVehicle* veh = getPerson(personID)->getVehicle();
331 if (veh == nullptr) {
332 return "";
333 } else {
334 return veh->getID();
335 }
336}
337
338
339std::string
340Person::getParameter(const std::string& personID, const std::string& param) {
341 return getPerson(personID)->getParameter().getParameter(param, "");
342}
343
344
346
347
348std::string
349Person::getEmissionClass(const std::string& personID) {
350 return PollutantsInterface::getName(getPerson(personID)->getVehicleType().getEmissionClass());
351}
352
353
354std::string
355Person::getShapeClass(const std::string& personID) {
356 return getVehicleShapeName(getPerson(personID)->getVehicleType().getGuiShape());
357}
358
359
360double
361Person::getLength(const std::string& personID) {
362 return getPerson(personID)->getVehicleType().getLength();
363}
364
365
366double
367Person::getSpeedFactor(const std::string& personID) {
368 return getPerson(personID)->getChosenSpeedFactor();
369}
370
371
372double
373Person::getAccel(const std::string& personID) {
374 return getPerson(personID)->getVehicleType().getCarFollowModel().getMaxAccel();
375}
376
377
378double
379Person::getDecel(const std::string& personID) {
380 return getPerson(personID)->getVehicleType().getCarFollowModel().getMaxDecel();
381}
382
383
384double Person::getEmergencyDecel(const std::string& personID) {
385 return getPerson(personID)->getVehicleType().getCarFollowModel().getEmergencyDecel();
386}
387
388
389double Person::getApparentDecel(const std::string& personID) {
390 return getPerson(personID)->getVehicleType().getCarFollowModel().getApparentDecel();
391}
392
393
394double Person::getActionStepLength(const std::string& personID) {
395 return getPerson(personID)->getVehicleType().getActionStepLengthSecs();
396}
397
398
399double
400Person::getTau(const std::string& personID) {
401 return getPerson(personID)->getVehicleType().getCarFollowModel().getHeadwayTime();
402}
403
404
405double
406Person::getImperfection(const std::string& personID) {
407 return getPerson(personID)->getVehicleType().getCarFollowModel().getImperfection();
408}
409
410
411double
412Person::getSpeedDeviation(const std::string& personID) {
413 return getPerson(personID)->getVehicleType().getSpeedFactor().getParameter()[1];
414}
415
416
417std::string
418Person::getVehicleClass(const std::string& personID) {
419 return toString(getPerson(personID)->getVehicleType().getVehicleClass());
420}
421
422
423double
424Person::getMinGap(const std::string& personID) {
425 return getPerson(personID)->getVehicleType().getMinGap();
426}
427
428
429double
430Person::getMinGapLat(const std::string& personID) {
431 return getPerson(personID)->getVehicleType().getMinGapLat();
432}
433
434
435double
436Person::getMaxSpeed(const std::string& personID) {
437 return getPerson(personID)->getMaxSpeed();
438}
439
440
441double
442Person::getMaxSpeedLat(const std::string& personID) {
443 return getPerson(personID)->getVehicleType().getMaxSpeedLat();
444}
445
446
447std::string
448Person::getLateralAlignment(const std::string& personID) {
449 return toString(getPerson(personID)->getVehicleType().getPreferredLateralAlignment());
450}
451
452
453double
454Person::getWidth(const std::string& personID) {
455 return getPerson(personID)->getVehicleType().getWidth();
456}
457
458
459double
460Person::getHeight(const std::string& personID) {
461 return getPerson(personID)->getVehicleType().getHeight();
462}
463
464
465int
466Person::getPersonCapacity(const std::string& personID) {
467 return getPerson(personID)->getVehicleType().getPersonCapacity();
468}
469
470
471double
472Person::getBoardingDuration(const std::string& personID) {
473 return STEPS2TIME(getPerson(personID)->getVehicleType().getLoadingDuration(true));
474}
475
476
477
478void
479Person::setSpeed(const std::string& personID, double speed) {
480 getPerson(personID)->setSpeed(speed);
481}
482
483
484void
485Person::setType(const std::string& personID, const std::string& typeID) {
487 if (vehicleType == nullptr) {
488 throw TraCIException("The vehicle type '" + typeID + "' is not known.");
489 }
490 getPerson(personID)->replaceVehicleType(vehicleType);
491}
492
493
494void
495Person::add(const std::string& personID, const std::string& edgeID, double pos, double departInSecs, const std::string typeID) {
497 try {
498 p = getPerson(personID);
499 } catch (TraCIException&) {
500 p = nullptr;
501 }
502
503 if (p != nullptr) {
504 throw TraCIException("The person " + personID + " to add already exists.");
505 }
506
507 SUMOTime depart = TIME2STEPS(departInSecs);
508 SUMOVehicleParameter vehicleParams;
509 vehicleParams.id = personID;
510
512 if (!vehicleType) {
513 throw TraCIException("Invalid type '" + typeID + "' for person '" + personID + "'");
514 }
515
516 const MSEdge* edge = MSEdge::dictionary(edgeID);
517 if (!edge) {
518 throw TraCIException("Invalid edge '" + edgeID + "' for person: '" + personID + "'");
519 }
520
521 if (departInSecs < 0.) {
522 const int proc = (int) - departInSecs;
523 if (proc >= static_cast<int>(DepartDefinition::DEF_MAX)) {
524 throw TraCIException("Invalid departure time." + toString(depart) + " " + toString(proc));
525 }
526 vehicleParams.departProcedure = (DepartDefinition)proc;
527 vehicleParams.depart = MSNet::getInstance()->getCurrentTimeStep();
528 } else if (depart < MSNet::getInstance()->getCurrentTimeStep()) {
529 vehicleParams.depart = MSNet::getInstance()->getCurrentTimeStep();
530 WRITE_WARNINGF(TL("Departure time=% for person '%' is in the past; using current time=% instead."),
531 toString(departInSecs), personID, time2string(vehicleParams.depart));
532 } else {
533 vehicleParams.depart = depart;
534 }
535
537 if (fabs(pos) > edge->getLength()) {
538 throw TraCIException("Invalid departure position.");
539 }
540 if (pos < 0) {
541 pos += edge->getLength();
542 }
543 vehicleParams.departPos = pos;
544
545 SUMOVehicleParameter* params = new SUMOVehicleParameter(vehicleParams);
547 plan->push_back(new MSStageWaiting(edge, nullptr, 0, depart, pos, "awaiting departure", true));
548
549 try {
550 MSTransportable* person = MSNet::getInstance()->getPersonControl().buildPerson(params, vehicleType, plan, nullptr);
552 } catch (ProcessError& e) {
553 delete params;
554 delete plan;
555 throw TraCIException(e.what());
556 }
557}
558
559MSStage*
560Person::convertTraCIStage(const TraCIStage& stage, const std::string personID) {
561 MSStoppingPlace* bs = nullptr;
562 if (!stage.destStop.empty()) {
564 if (bs == nullptr) {
566 if (bs == nullptr) {
567 throw TraCIException("Invalid stopping place id '" + stage.destStop + "' for person: '" + personID + "'");
568 } else {
569 // parkingArea is not a proper arrival place
570 bs = nullptr;
571 }
572 }
573 }
574 switch (stage.type) {
575 case STAGE_DRIVING: {
576 if (stage.edges.empty()) {
577 throw TraCIException("The stage should have at least one edge");
578 }
579 std::string toId = stage.edges.back();
580 MSEdge* to = MSEdge::dictionary(toId);
581 if (!to) {
582 throw TraCIException("Invalid edge '" + toId + "' for person: '" + personID + "'");
583 }
584 //std::string fromId = stage.edges.front();
585 //MSEdge* from = MSEdge::dictionary(fromId);
586 //if (!from) {
587 // throw TraCIException("Invalid edge '" + fromId + "' for person: '" + personID + "'");
588 //}
589 if (stage.line.empty()) {
590 throw TraCIException("Empty lines parameter for person: '" + personID + "'");
591 }
592 double arrivalPos = stage.arrivalPos;
593 if (arrivalPos == INVALID_DOUBLE_VALUE) {
594 if (bs != nullptr) {
595 arrivalPos = bs->getEndLanePosition();
596 } else {
597 arrivalPos = to->getLength();
598 }
599 }
600 return new MSStageDriving(nullptr, to, bs, arrivalPos, StringTokenizer(stage.line).getVector());
601 }
602
603 case STAGE_WALKING: {
604 MSTransportable* p = getPerson(personID);
605 ConstMSEdgeVector edges;
606 try {
607 MSEdge::parseEdgesList(stage.edges, edges, "<unknown>");
608 } catch (ProcessError& e) {
609 throw TraCIException(e.what());
610 }
611 if (edges.empty()) {
612 throw TraCIException("Empty edge list for walking stage of person '" + personID + "'.");
613 }
614 double arrivalPos = stage.arrivalPos;
615 if (fabs(arrivalPos) > edges.back()->getLength()) {
616 throw TraCIException("Invalid arrivalPos for walking stage of person '" + personID + "'.");
617 }
618 if (arrivalPos < 0) {
619 arrivalPos += edges.back()->getLength();
620 }
621 double speed = p->getMaxSpeed();
622 return new MSPerson::MSPersonStage_Walking(p->getID(), edges, bs, -1, speed, p->getArrivalPos(), arrivalPos, MSPModel::UNSPECIFIED_POS_LAT);
623 }
624
625 case STAGE_WAITING: {
626 MSTransportable* p = getPerson(personID);
627 if (stage.travelTime < 0) {
628 throw TraCIException("Duration for person: '" + personID + "' must not be negative");
629 }
630 return new MSStageWaiting(p->getArrivalEdge(), nullptr, TIME2STEPS(stage.travelTime), 0, p->getArrivalPos(), stage.description, false);
631 }
632 default:
633 return nullptr;
634 }
635}
636
637
638void
639Person::appendStage(const std::string& personID, const TraCIStage& stage) {
640 MSTransportable* p = getPerson(personID);
641 MSStage* personStage = convertTraCIStage(stage, personID);
642 p->appendStage(personStage);
643}
644
645
646void
647Person::replaceStage(const std::string& personID, const int stageIndex, const TraCIStage& stage) {
648 MSTransportable* p = getPerson(personID);
649 if (stageIndex >= p->getNumRemainingStages()) {
650 throw TraCIException("Specified stage index: is not valid for person " + personID);
651 }
652 MSStage* personStage = convertTraCIStage(stage, personID);
653 // removing the current stage triggers abort+proceed so the replacement
654 // stage must be ready beforehand
655 p->appendStage(personStage, stageIndex + 1);
656 p->removeStage(stageIndex);
657}
658
659
660void
661Person::appendDrivingStage(const std::string& personID, const std::string& toEdge, const std::string& lines, const std::string& stopID) {
662 MSTransportable* p = getPerson(personID);
663 const MSEdge* edge = MSEdge::dictionary(toEdge);
664 if (!edge) {
665 throw TraCIException("Invalid edge '" + toEdge + "' for person: '" + personID + "'");
666 }
667 if (lines.size() == 0) {
668 throw TraCIException("Empty lines parameter for person: '" + personID + "'");
669 }
670 MSStoppingPlace* bs = nullptr;
671 if (stopID != "") {
673 if (bs == nullptr) {
674 throw TraCIException("Invalid stopping place id '" + stopID + "' for person: '" + personID + "'");
675 }
676 }
677 p->appendStage(new MSStageDriving(nullptr, edge, bs, edge->getLength() - NUMERICAL_EPS, StringTokenizer(lines).getVector()));
678}
679
680
681void
682Person::appendWaitingStage(const std::string& personID, double duration, const std::string& description, const std::string& stopID) {
683 MSTransportable* p = getPerson(personID);
684 if (duration < 0) {
685 throw TraCIException("Duration for person: '" + personID + "' must not be negative");
686 }
687 MSStoppingPlace* bs = nullptr;
688 if (stopID != "") {
690 if (bs == nullptr) {
691 throw TraCIException("Invalid stopping place id '" + stopID + "' for person: '" + personID + "'");
692 }
693 }
694 p->appendStage(new MSStageWaiting(p->getArrivalEdge(), nullptr, TIME2STEPS(duration), 0, p->getArrivalPos(), description, false));
695}
696
697
698void
699Person::appendWalkingStage(const std::string& personID, const std::vector<std::string>& edgeIDs, double arrivalPos, double duration, double speed, const std::string& stopID) {
700 MSTransportable* p = getPerson(personID);
701 ConstMSEdgeVector edges;
702 try {
703 MSEdge::parseEdgesList(edgeIDs, edges, "<unknown>");
704 } catch (ProcessError& e) {
705 throw TraCIException(e.what());
706 }
707 if (edges.empty()) {
708 throw TraCIException("Empty edge list for walking stage of person '" + personID + "'.");
709 }
710 if (fabs(arrivalPos) > edges.back()->getLength()) {
711 throw TraCIException("Invalid arrivalPos for walking stage of person '" + personID + "'.");
712 }
713 if (arrivalPos < 0) {
714 arrivalPos += edges.back()->getLength();
715 }
716 if (speed < 0) {
717 speed = p->getMaxSpeed();
718 }
719 MSStoppingPlace* bs = nullptr;
720 if (stopID != "") {
722 if (bs == nullptr) {
723 throw TraCIException("Invalid stopping place id '" + stopID + "' for person: '" + personID + "'");
724 }
725 }
726 p->appendStage(new MSPerson::MSPersonStage_Walking(p->getID(), edges, bs, TIME2STEPS(duration), speed, p->getArrivalPos(), arrivalPos, MSPModel::UNSPECIFIED_POS_LAT));
727}
728
729
730void
731Person::removeStage(const std::string& personID, int nextStageIndex) {
732 MSTransportable* p = getPerson(personID);
733 if (nextStageIndex >= p->getNumRemainingStages()) {
734 throw TraCIException("The stage index must be lower than the number of remaining stages.");
735 }
736 if (nextStageIndex < 0) {
737 throw TraCIException("The stage index may not be negative.");
738 }
739 p->removeStage(nextStageIndex);
740}
741
742
743void
744Person::rerouteTraveltime(const std::string& personID) {
745 MSPerson* p = getPerson(personID);
746 if (p->getNumRemainingStages() == 0) {
747 throw TraCIException("Person '" + personID + "' has no remaining stages.");
748 }
749 const MSEdge* from = p->getEdge();
750 double departPos = p->getEdgePos();
751 // reroute to the start of the next-non-walking stage
752 int firstIndex;
754 firstIndex = 0;
755 } else if (p->getCurrentStageType() == MSStageType::WAITING) {
757 throw TraCIException("Person '" + personID + "' cannot reroute after the current stop.");
758 }
759 firstIndex = 1;
760 } else {
761 throw TraCIException("Person '" + personID + "' cannot reroute in stage type '" + toString((int)p->getCurrentStageType()) + "'.");
762 }
763 int nextIndex = firstIndex + 1;
764 for (; nextIndex < p->getNumRemainingStages(); nextIndex++) {
765 if (p->getStageType(nextIndex) != MSStageType::WALKING) {
766 break;
767 }
768 }
769 MSStage* destStage = p->getNextStage(nextIndex - 1);
770 const MSEdge* to = destStage->getEdges().back();
771 double arrivalPos = destStage->getArrivalPos();
772 double speed = p->getMaxSpeed();
773 ConstMSEdgeVector newEdges;
774 MSNet::getInstance()->getPedestrianRouter(0).compute(from, to, departPos, arrivalPos, speed, 0, nullptr, newEdges);
775 if (newEdges.empty()) {
776 throw TraCIException("Could not find new route for person '" + personID + "'.");
777 }
778 ConstMSEdgeVector oldEdges = p->getEdges(firstIndex);
779 assert(!oldEdges.empty());
780 if (oldEdges.front()->getFunction() != SumoXMLEdgeFunc::NORMAL) {
781 oldEdges.erase(oldEdges.begin());
782 }
783 //std::cout << " remainingStages=" << p->getNumRemainingStages() << " oldEdges=" << toString(oldEdges) << " newEdges=" << toString(newEdges) << " firstIndex=" << firstIndex << " nextIndex=" << nextIndex << "\n";
784 if (newEdges == oldEdges && (firstIndex + 1 == nextIndex)) {
785 return;
786 }
787 if (newEdges.front() != from) {
788 // @note: maybe this should be done automatically by the router
789 newEdges.insert(newEdges.begin(), from);
790 }
791 p->reroute(newEdges, departPos, firstIndex, nextIndex);
792}
793
794
795void
796Person::moveTo(const std::string& personID, const std::string& laneID, double pos, double posLat) {
797 MSPerson* p = getPerson(personID);
798 MSLane* l = MSLane::dictionary(laneID);
799 if (l == nullptr) {
800 throw TraCIException("Unknown lane '" + laneID + "'.");
801 }
802 if (posLat == INVALID_DOUBLE_VALUE) {
803 posLat = 0;
804 } else if (fabs(posLat) >= (0.5 * (l->getWidth() + p->getVehicleType().getWidth()) + MSPModel::SIDEWALK_OFFSET)) {
805 // see MSPModel_Striping::moveToXY
806 throw TraCIException("Invalid lateral position " + toString(posLat) + " on lane '" + laneID + "'.");
807 }
808 switch (p->getStageType(0)) {
811 assert(s != 0);
812 s->getState()->moveTo(p, l, pos, posLat, SIMSTEP);
813 break;
814 }
815 default:
816 throw TraCIException("Command moveTo is not supported for person '" + personID + "' while " + p->getCurrentStageDescription() + ".");
817 }
818}
819
820
821void
822Person::moveToXY(const std::string& personID, const std::string& edgeID, const double x, const double y, double angle, const int keepRoute, double matchThreshold) {
823 MSPerson* p = getPerson(personID);
824 const bool doKeepRoute = (keepRoute & 1) != 0;
825 const bool mayLeaveNetwork = (keepRoute & 2) != 0;
826 const bool ignorePermissions = (keepRoute & 4) != 0;
827 SUMOVehicleClass vClass = ignorePermissions ? SVC_IGNORING : p->getVClass();
828 Position pos(x, y);
829#ifdef DEBUG_MOVEXY
830 const double origAngle = angle;
831#endif
832 // angle must be in [0,360] because it will be compared against those returned by naviDegree()
833 // angle set to INVALID_DOUBLE_VALUE is ignored in the evaluated and later set to the angle of the matched lane
834 if (angle != INVALID_DOUBLE_VALUE) {
835 while (angle >= 360.) {
836 angle -= 360.;
837 }
838 while (angle < 0.) {
839 angle += 360.;
840 }
841 }
842 Position currentPos = p->getPosition();
843#ifdef DEBUG_MOVEXY
844 std::cout << std::endl << "begin person " << p->getID() << " lanePos:" << p->getEdgePos() << " edge:" << Named::getIDSecure(p->getEdge()) << "\n";
845 std::cout << " want pos:" << pos << " edgeID:" << edgeID << " origAngle:" << origAngle << " angle:" << angle << " keepRoute:" << keepRoute << std::endl;
846#endif
847
848 ConstMSEdgeVector edges;
849 MSLane* lane = nullptr;
850 double lanePos;
851 double lanePosLat = 0;
852 double bestDistance = std::numeric_limits<double>::max();
853 int routeOffset = 0;
854 bool found = false;
855 double maxRouteDistance = matchThreshold;
856
858 ev.push_back(p->getEdge());
859 int routeIndex = 0;
860 MSLane* currentLane = const_cast<MSLane*>(getSidewalk<MSEdge, MSLane>(p->getEdge()));
861 switch (p->getStageType(0)) {
864 assert(s != 0);
865 ev = s->getEdges();
866 routeIndex = (int)(s->getRouteStep() - s->getRoute().begin());
867 }
868 break;
869 default:
870 break;
871 }
872 if (doKeepRoute) {
873 // case a): vehicle is on its earlier route
874 // we additionally assume it is moving forward (SUMO-limit);
875 // note that the route ("edges") is not changed in this case
877 ev, routeIndex, vClass, true,
878 bestDistance, &lane, lanePos, routeOffset);
879 } else {
880 double speed = pos.distanceTo2D(p->getPosition()); // !!!veh->getSpeed();
881 found = Helper::moveToXYMap(pos, maxRouteDistance, mayLeaveNetwork, edgeID, angle,
882 speed, ev, routeIndex, currentLane, p->getEdgePos(), currentLane != nullptr,
883 vClass, true,
884 bestDistance, &lane, lanePos, routeOffset, edges);
885 if (edges.size() != 0 && ev.size() > 1) {
886 // try to rebuild the route
887 const MSEdge* origEdge = p->getEdge();
888 assert(lane != nullptr);
889 const MSJunction* originalTarget = nullptr;
890 if (origEdge->isNormal()) {
891 if (routeIndex == 0) {
892 if (origEdge->getToJunction() == ev[1]->getToJunction() || origEdge->getToJunction() == ev[1]->getFromJunction()) {
893 originalTarget = origEdge->getToJunction();
894 } else {
895 originalTarget = origEdge->getFromJunction();
896 }
897 } else {
898 if (origEdge->getToJunction() == ev[routeIndex - 1]->getToJunction() || origEdge->getToJunction() == ev[routeIndex - 1]->getFromJunction()) {
899 originalTarget = origEdge->getFromJunction();
900 } else {
901 originalTarget = origEdge->getToJunction();
902 }
903 }
904 } else {
905 originalTarget = origEdge->getToJunction();
906 assert(originalTarget == origEdge->getFromJunction());
907 }
908 const MSEdge* newEdge = edges[0];
909 if (edges[0]->getFromJunction() == originalTarget || edges[0]->getToJunction() == originalTarget) {
910 edges = ev;
911 edges[routeIndex] = newEdge;
912 }
913 }
914 }
915 if ((found && bestDistance <= maxRouteDistance) || mayLeaveNetwork) {
916 // compute lateral offset
917 if (found) {
918 const double perpDist = lane->getShape().distance2D(pos, false);
919 if (perpDist != GeomHelper::INVALID_OFFSET) {
920 lanePosLat = perpDist;
921 if (!mayLeaveNetwork) {
922 lanePosLat = MIN2(lanePosLat, 0.5 * (lane->getWidth() + p->getVehicleType().getWidth()));
923 }
924 // figure out whether the offset is to the left or to the right
925 PositionVector tmp = lane->getShape();
926 try {
927 tmp.move2side(-lanePosLat); // moved to left
928 } catch (ProcessError&) {
929 WRITE_WARNINGF(TL("Could not determine position on lane '% at lateral position %."), lane->getID(), toString(-lanePosLat));
930 }
931 //std::cout << " lane=" << lane->getID() << " posLat=" << lanePosLat << " shape=" << lane->getShape() << " tmp=" << tmp << " tmpDist=" << tmp.distance2D(pos) << "\n";
932 if (tmp.distance2D(pos) > perpDist) {
933 lanePosLat = -lanePosLat;
934 }
935 }
936 }
937 if (found && !mayLeaveNetwork && MSGlobals::gLateralResolution < 0) {
938 // mapped position may differ from pos
939 pos = lane->geometryPositionAtOffset(lanePos, -lanePosLat);
940 }
941 assert((found && lane != 0) || (!found && lane == 0));
942 switch (p->getStageType(0)) {
944 if (angle == INVALID_DOUBLE_VALUE) {
945 // walking angle cannot be deduced from road angle so we always use the last pos
947 }
948 break;
949 }
952 if (p->getNumRemainingStages() <= 1 || p->getStageType(1) != MSStageType::WALKING) {
953 // insert walking stage after the current stage
954 ConstMSEdgeVector route({p->getEdge()});
955 const double departPos = p->getCurrentStage()->getArrivalPos();
956 p->appendStage(new MSPerson::MSPersonStage_Walking(p->getID(), route, nullptr, -1, -1, departPos, departPos, MSPModel::UNSPECIFIED_POS_LAT), 1);
957 }
958 // abort waiting stage and proceed to walking stage
959 p->removeStage(0);
960 assert(p->getStageType(0) == MSStageType::WALKING);
961 if (angle == INVALID_DOUBLE_VALUE) {
962 if (lane != nullptr && !lane->getEdge().isWalkingArea()) {
963 angle = GeomHelper::naviDegree(lane->getShape().rotationAtOffset(lanePos));
964 } else {
965 // compute angle outside road network or on walkingarea from old and new position
967 }
968 }
969 break;
970 }
971 default:
972 throw TraCIException("Command moveToXY is not supported for person '" + personID + "' while " + p->getCurrentStageDescription() + ".");
973 }
974 Helper::setRemoteControlled(p, pos, lane, lanePos, lanePosLat, angle, routeOffset, edges, MSNet::getInstance()->getCurrentTimeStep());
975 } else {
976 if (lane == nullptr) {
977 throw TraCIException("Could not map person '" + personID + "' no road found within " + toString(maxRouteDistance) + "m.");
978 } else {
979 throw TraCIException("Could not map person '" + personID + "' distance to road is " + toString(bestDistance) + ".");
980 }
981 }
982}
983
984
987void
988Person::setParameter(const std::string& personID, const std::string& key, const std::string& value) {
989 MSTransportable* p = getPerson(personID);
990 if (StringUtils::startsWith(key, "device.")) {
991 throw TraCIException("Person '" + personID + "' does not support device parameters\n");
992 } else if (StringUtils::startsWith(key, "laneChangeModel.")) {
993 throw TraCIException("Person '" + personID + "' does not support laneChangeModel parameters\n");
994 } else if (StringUtils::startsWith(key, "carFollowModel.")) {
995 throw TraCIException("Person '" + personID + "' does not support carFollowModel parameters\n");
996 } else if (StringUtils::startsWith(key, "junctionModel.")) {
997 try {
998 // use the whole key (including junctionModel prefix)
999 p->setJunctionModelParameter(key, value);
1000 } catch (InvalidArgument& e) {
1001 // error message includes id since it is also used for xml input
1002 throw TraCIException(e.what());
1003 }
1004 } else if (StringUtils::startsWith(key, "has.") && StringUtils::endsWith(key, ".device")) {
1005 throw TraCIException("Person '" + personID + "' does not support chanigng device status\n");
1006 } else {
1007 ((SUMOVehicleParameter&)p->getParameter()).setParameter(key, value);
1008 }
1009}
1010
1011
1012void
1013Person::setLength(const std::string& personID, double length) {
1014 getPerson(personID)->getSingularType().setLength(length);
1015}
1016
1017
1018void
1019Person::setMaxSpeed(const std::string& personID, double speed) {
1020 getPerson(personID)->getSingularType().setMaxSpeed(speed);
1021}
1022
1023
1024void
1025Person::setVehicleClass(const std::string& personID, const std::string& clazz) {
1026 getPerson(personID)->getSingularType().setVClass(getVehicleClassID(clazz));
1027}
1028
1029
1030void
1031Person::setShapeClass(const std::string& personID, const std::string& clazz) {
1032 getPerson(personID)->getSingularType().setShape(getVehicleShapeID(clazz));
1033}
1034
1035
1036void
1037Person::setEmissionClass(const std::string& personID, const std::string& clazz) {
1038 getPerson(personID)->getSingularType().setEmissionClass(PollutantsInterface::getClassByName(clazz));
1039}
1040
1041
1042void
1043Person::setWidth(const std::string& personID, double width) {
1044 getPerson(personID)->getSingularType().setWidth(width);
1045}
1046
1047
1048void
1049Person::setHeight(const std::string& personID, double height) {
1050 getPerson(personID)->getSingularType().setHeight(height);
1051}
1052
1053
1054void
1055Person::setMinGap(const std::string& personID, double minGap) {
1056 getPerson(personID)->getSingularType().setMinGap(minGap);
1057}
1058
1059
1060void
1061Person::setAccel(const std::string& personID, double accel) {
1062 getPerson(personID)->getSingularType().setAccel(accel);
1063}
1064
1065
1066void
1067Person::setDecel(const std::string& personID, double decel) {
1068 getPerson(personID)->getSingularType().setDecel(decel);
1069}
1070
1071
1072void
1073Person::setEmergencyDecel(const std::string& personID, double decel) {
1074 getPerson(personID)->getSingularType().setEmergencyDecel(decel);
1075}
1076
1077
1078void
1079Person::setApparentDecel(const std::string& personID, double decel) {
1080 getPerson(personID)->getSingularType().setApparentDecel(decel);
1081}
1082
1083
1084void
1085Person::setImperfection(const std::string& personID, double imperfection) {
1086 getPerson(personID)->getSingularType().setImperfection(imperfection);
1087}
1088
1089
1090void
1091Person::setTau(const std::string& personID, double tau) {
1092 getPerson(personID)->getSingularType().setTau(tau);
1093}
1094
1095
1096void
1097Person::setMinGapLat(const std::string& personID, double minGapLat) {
1098 getPerson(personID)->getSingularType().setMinGapLat(minGapLat);
1099}
1100
1101
1102void
1103Person::setMaxSpeedLat(const std::string& personID, double speed) {
1104 getPerson(personID)->getSingularType().setMaxSpeedLat(speed);
1105}
1106
1107
1108void
1109Person::setLateralAlignment(const std::string& personID, const std::string& latAlignment) {
1110 double lao;
1112 if (SUMOVTypeParameter::parseLatAlignment(latAlignment, lao, lad)) {
1113 getPerson(personID)->getSingularType().setPreferredLateralAlignment(lad, lao);
1114 } else {
1115 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)");
1116 }
1117}
1118
1119
1120void
1121Person::setSpeedFactor(const std::string& personID, double factor) {
1122 getPerson(personID)->setChosenSpeedFactor(factor);
1123}
1124
1125
1126void
1127Person::setActionStepLength(const std::string& personID, double actionStepLength, bool resetActionOffset) {
1128 getPerson(personID)->getSingularType().setActionStepLength(SUMOVehicleParserHelper::processActionStepLength(actionStepLength), resetActionOffset);
1129}
1130
1131void
1132Person::remove(const std::string& personID, char /*reason*/) {
1133 MSPerson* person = getPerson(personID);
1134 // remove all stages after the current and then abort the current stage
1135 // (without adding a zero-length waiting stage)
1136 while (person->getNumRemainingStages() > 1) {
1137 person->removeStage(1);
1138 }
1139 person->removeStage(0, false);
1140}
1141
1142void
1143Person::setColor(const std::string& personID, const TraCIColor& c) {
1144 const SUMOVehicleParameter& p = getPerson(personID)->getParameter();
1145 p.color.set((unsigned char)c.r, (unsigned char)c.g, (unsigned char)c.b, (unsigned char)c.a);
1147}
1148
1149
1151
1152
1153MSPerson*
1154Person::getPerson(const std::string& personID) {
1155 return Helper::getPerson(personID);
1156}
1157
1158
1159void
1160Person::storeShape(const std::string& id, PositionVector& shape) {
1161 shape.push_back(getPerson(id)->getPosition());
1162}
1163
1164
1165std::shared_ptr<VariableWrapper>
1166Person::makeWrapper() {
1167 return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);
1168}
1169
1170
1171bool
1172Person::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper, tcpip::Storage* paramData) {
1173 switch (variable) {
1174 case TRACI_ID_LIST:
1175 return wrapper->wrapStringList(objID, variable, getIDList());
1176 case ID_COUNT:
1177 return wrapper->wrapInt(objID, variable, getIDCount());
1178 case VAR_POSITION:
1179 return wrapper->wrapPosition(objID, variable, getPosition(objID));
1180 case VAR_POSITION3D:
1181 return wrapper->wrapPosition(objID, variable, getPosition(objID, true));
1182 case VAR_ANGLE:
1183 return wrapper->wrapDouble(objID, variable, getAngle(objID));
1184 case VAR_SLOPE:
1185 return wrapper->wrapDouble(objID, variable, getSlope(objID));
1186 case VAR_SPEED:
1187 return wrapper->wrapDouble(objID, variable, getSpeed(objID));
1188 case VAR_ROAD_ID:
1189 return wrapper->wrapString(objID, variable, getRoadID(objID));
1190 case VAR_LANE_ID:
1191 return wrapper->wrapString(objID, variable, getLaneID(objID));
1192 case VAR_LANEPOSITION:
1193 return wrapper->wrapDouble(objID, variable, getLanePosition(objID));
1194 case VAR_COLOR:
1195 return wrapper->wrapColor(objID, variable, getColor(objID));
1196 case VAR_WAITING_TIME:
1197 return wrapper->wrapDouble(objID, variable, getWaitingTime(objID));
1198 case VAR_TYPE:
1199 return wrapper->wrapString(objID, variable, getTypeID(objID));
1200 case VAR_SPEED_FACTOR:
1201 return wrapper->wrapDouble(objID, variable, getSpeedFactor(objID));
1202 case VAR_NEXT_EDGE:
1203 return wrapper->wrapString(objID, variable, getNextEdge(objID));
1205 return wrapper->wrapInt(objID, variable, getRemainingStages(objID));
1206 case VAR_VEHICLE:
1207 return wrapper->wrapString(objID, variable, getVehicle(objID));
1208 case VAR_MAXSPEED:
1209 // integrate desiredMaxSpeed and individual speedFactor
1210 return wrapper->wrapDouble(objID, variable, getMaxSpeed(objID));
1212 paramData->readUnsignedByte();
1213 return wrapper->wrapString(objID, variable, getParameter(objID, paramData->readString()));
1215 paramData->readUnsignedByte();
1216 return wrapper->wrapStringPair(objID, variable, getParameterWithKey(objID, paramData->readString()));
1218 // we cannot use the general fall through here because we do not have an object id
1219 return false;
1220 default:
1221 return libsumo::VehicleType::handleVariable(getTypeID(objID), variable, wrapper, paramData);
1222 }
1223}
1224
1225
1226}
1227
1228
1229/****************************************************************************/
long long int SUMOTime
Definition: GUI.h:36
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:74
#define WRITE_WARNINGF(...)
Definition: MsgHandler.h:268
#define TL(string)
Definition: MsgHandler.h:284
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
#define STEPS2TIME(x)
Definition: SUMOTime.h:54
#define SIMSTEP
Definition: SUMOTime.h:60
#define TIME2STEPS(x)
Definition: SUMOTime.h:56
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.
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_IGNORING
vehicles ignoring classes
const int VEHPARS_COLOR_SET
@ GIVEN
The position is given.
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.
@ SUMO_TAG_PARKING_AREA
A parking area.
T MIN2(T a, T b)
Definition: StdDefs.h:76
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
#define LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(CLASS, DOM)
Definition: TraCIDefs.h:76
#define LIBSUMO_GET_PARAMETER_WITH_KEY_IMPLEMENTATION(CLASS)
Definition: TraCIDefs.h:123
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)
Definition: GeomHelper.cpp:192
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:102
std::vector< Reservation * > getReservations()
retrieve all reservations
Definition: MSDispatch.cpp:178
virtual std::vector< const Reservation * > getRunningReservations()
retrieve all reservations that were already dispatched and are still active
Definition: MSDispatch.cpp:188
A road/street connecting two junctions.
Definition: MSEdge.h:77
bool isWalkingArea() const
return whether this edge is walking area
Definition: MSEdge.h:284
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition: MSEdge.h:168
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:1008
bool isNormal() const
return whether this edge is an internal edge
Definition: MSEdge.h:260
const MSJunction * getToJunction() const
Definition: MSEdge.h:415
double getLength() const
return the length of the edge
Definition: MSEdge.h:658
const MSJunction * getFromJunction() const
Definition: MSEdge.h:411
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:945
static double gLateralResolution
Definition: MSGlobals.h:97
The base class for an intersection.
Definition: MSJunction.h:58
Representation of a lane in the micro simulation.
Definition: MSLane.h:84
static bool dictionary(const std::string &id, MSLane *lane)
Static (sic!) container methods {.
Definition: MSLane.cpp:2234
double interpolateLanePosToGeometryPos(double lanePos) const
Definition: MSLane.h:545
virtual const PositionVector & getShape(bool) const
Definition: MSLane.h:293
MSEdge & getEdge() const
Returns the lane's edge.
Definition: MSLane.h:745
double getWidth() const
Returns the lane's width.
Definition: MSLane.h:622
const Position geometryPositionAtOffset(double offset, double lateralOffset=0) const
Definition: MSLane.h:551
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:183
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:320
MSStoppingPlace * getStoppingPlace(const std::string &id, const SumoXMLTag category) const
Returns the named stopping place of the given category.
Definition: MSNet.cpp:1350
MSPedestrianRouter & getPedestrianRouter(const int rngIndex, const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:1480
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:378
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:1159
static const double SIDEWALK_OFFSET
the offset for computing person positions when walking on edges without a sidewalk
Definition: MSPModel.h:127
static const double UNSPECIFIED_POS_LAT
the default lateral offset for persons when starting a walk
Definition: MSPModel.h:130
void reroute(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:592
SUMOTime getIntendedDepart() const
std::string getIntendedVehicleID() const
const std::set< std::string > & getLines() const
std::string getVehicleType() const
virtual ConstMSEdgeVector getEdges() const
the edges of the current stage
Definition: MSStage.cpp:102
virtual double getArrivalPos() const
Definition: MSStage.h:89
SUMOTime getDeparted() const
get departure time of stage
Definition: MSStage.cpp:117
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:122
MSStoppingPlace * getDestinationStop() const
returns the destination stop (if any)
Definition: MSStage.h:80
MSStageType getStageType() const
Definition: MSStage.h:117
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
virtual MSTransportableStateAdapter * getState() const
Definition: MSStageMoving.h:49
const std::vector< constMSEdge * >::iterator getRouteStep() const
A lane area vehicles can halt at.
double getEndLanePosition() const
Returns the end position of this stop.
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.
virtual double getEdgePos() const
Return the position on the edge.
SUMOVehicleClass getVClass() const
Returns the object's access class.
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
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.
void removeStage(int next, bool stayInSim=true)
removes the nth next stage
bool isPerson() const
Whether it is a person.
ConstMSEdgeVector getEdges(int next) const
Return the edges of the nth next stage.
Position getPosition(const double) const
Return current position (x/y, cartesian)
double getArrivalPos() const
returns the final arrival pos
const MSVehicleType & getVehicleType() const
Returns the object's "vehicle" type.
int getNumStages() const
Return the total number stages in this persons plan.
MSStageType getCurrentStageType() const
the current stage type of the transportable
MSStage * getNextStage(int next) const
Return the current stage.
void appendStage(MSStage *stage, int next=-1)
Appends the given stage to the current plan.
const MSEdge * getEdge() const
Returns the current edge.
std::vector< MSStage * > MSTransportablePlan
the structure holding the plan of a transportable
const SUMOVehicleParameter & getParameter() const
Returns the vehicle's parameter (including departure definition)
double getMaxSpeed() const
Returns the maximum speed (the minimum of desired and physical maximum speed)
virtual void moveTo(MSPerson *p, MSLane *lane, double lanePos, double lanePosLat, SUMOTime t)
try to move transportable to the given position
Definition: MSPModel.h:176
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.
Definition: MSVehicleType.h:63
double getWidth() const
Get the width which vehicles of this class shall have when being drawn.
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:67
const std::string & getID() const
Returns the id.
Definition: Named.h:74
double compute(const E *from, const E *to, double departPos, double arrivalPos, double speed, SUMOTime msTime, const N *onlyNode, std::vector< const E * > &into, bool allEdges=false)
Builds the route between the given edges using the minimum effort at the given time The definition of...
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:254
double angleTo2D(const Position &other) const
returns the angle in the plane of the vector pointing from here to the other position
Definition: Position.h:264
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 ammount
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:74
unsigned char alpha() const
Returns the alpha-amount of the color.
Definition: RGBColor.cpp:92
unsigned char green() const
Returns the green-amount of the color.
Definition: RGBColor.cpp:80
unsigned char blue() const
Returns the blue-amount of the color.
Definition: RGBColor.cpp:86
void set(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
assigns new values
Definition: RGBColor.cpp:98
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:62
Structure representing possible vehicle parameter.
int parametersSet
Information for the router which parameter were set, TraCI may modify this (when changing color)
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.
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:377
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:1725
static MSPerson * getPerson(const std::string &id)
Definition: Helper.cpp:491
static void setRemoteControlled(MSVehicle *v, Position xyPos, MSLane *l, double pos, double posLat, double angle, int edgeOffset, ConstMSEdgeVector route, SUMOTime t)
Definition: Helper.cpp:1377
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, bool setLateralPos, double &bestDistance, MSLane **lane, double &lanePos, int &routeOffset, ConstMSEdgeVector &edges)
Definition: Helper.cpp:1417
virtual std::string readString()
Definition: storage.cpp:180
virtual int readUnsignedByte()
Definition: storage.cpp:155
TRACI_CONST double INVALID_DOUBLE_VALUE
TRACI_CONST int TRACI_ID_LIST
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:338
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_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:337
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 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 STAGE_DRIVING
TRACI_CONST int VAR_STAGES_REMAINING
SUMOTime pickupTime
Definition: MSDispatch.h:72
std::string id
Definition: MSDispatch.h:69
const MSEdge * to
Definition: MSDispatch.h:75
double fromPos
Definition: MSDispatch.h:74
const MSEdge * from
Definition: MSDispatch.h:73
SUMOTime reservationTime
Definition: MSDispatch.h:71
std::string group
Definition: MSDispatch.h:77
ReservationState state
Definition: MSDispatch.h:80
std::set< MSTransportable * > persons
Definition: MSDispatch.h:70
double toPos
Definition: MSDispatch.h:76