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-2022 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
471void
472Person::setSpeed(const std::string& personID, double speed) {
473 getPerson(personID)->setSpeed(speed);
474}
475
476
477void
478Person::setType(const std::string& personID, const std::string& typeID) {
480 if (vehicleType == nullptr) {
481 throw TraCIException("The vehicle type '" + typeID + "' is not known.");
482 }
483 getPerson(personID)->replaceVehicleType(vehicleType);
484}
485
486
487void
488Person::add(const std::string& personID, const std::string& edgeID, double pos, double departInSecs, const std::string typeID) {
490 try {
491 p = getPerson(personID);
492 } catch (TraCIException&) {
493 p = nullptr;
494 }
495
496 if (p != nullptr) {
497 throw TraCIException("The person " + personID + " to add already exists.");
498 }
499
500 SUMOTime depart = TIME2STEPS(departInSecs);
501 SUMOVehicleParameter vehicleParams;
502 vehicleParams.id = personID;
503
505 if (!vehicleType) {
506 throw TraCIException("Invalid type '" + typeID + "' for person '" + personID + "'");
507 }
508
509 const MSEdge* edge = MSEdge::dictionary(edgeID);
510 if (!edge) {
511 throw TraCIException("Invalid edge '" + edgeID + "' for person: '" + personID + "'");
512 }
513
514 if (departInSecs < 0.) {
515 const int proc = (int) - departInSecs;
516 if (proc >= static_cast<int>(DepartDefinition::DEF_MAX)) {
517 throw TraCIException("Invalid departure time." + toString(depart) + " " + toString(proc));
518 }
519 vehicleParams.departProcedure = (DepartDefinition)proc;
520 vehicleParams.depart = MSNet::getInstance()->getCurrentTimeStep();
521 } else if (depart < MSNet::getInstance()->getCurrentTimeStep()) {
522 vehicleParams.depart = MSNet::getInstance()->getCurrentTimeStep();
523 WRITE_WARNING("Departure time=" + toString(departInSecs) + " for person '" + personID
524 + "' is in the past; using current time=" + time2string(vehicleParams.depart) + " instead.");
525 } else {
526 vehicleParams.depart = depart;
527 }
528
530 if (fabs(pos) > edge->getLength()) {
531 throw TraCIException("Invalid departure position.");
532 }
533 if (pos < 0) {
534 pos += edge->getLength();
535 }
536 vehicleParams.departPos = pos;
537
538 SUMOVehicleParameter* params = new SUMOVehicleParameter(vehicleParams);
540 plan->push_back(new MSStageWaiting(edge, nullptr, 0, depart, pos, "awaiting departure", true));
541
542 try {
543 MSTransportable* person = MSNet::getInstance()->getPersonControl().buildPerson(params, vehicleType, plan, nullptr);
545 } catch (ProcessError& e) {
546 delete params;
547 delete plan;
548 throw TraCIException(e.what());
549 }
550}
551
552MSStage*
553Person::convertTraCIStage(const TraCIStage& stage, const std::string personID) {
554 MSStoppingPlace* bs = nullptr;
555 if (!stage.destStop.empty()) {
557 if (bs == nullptr) {
559 if (bs == nullptr) {
560 throw TraCIException("Invalid stopping place id '" + stage.destStop + "' for person: '" + personID + "'");
561 } else {
562 // parkingArea is not a proper arrival place
563 bs = nullptr;
564 }
565 }
566 }
567 switch (stage.type) {
568 case STAGE_DRIVING: {
569 if (stage.edges.empty()) {
570 throw TraCIException("The stage should have at least one edge");
571 }
572 std::string toId = stage.edges.back();
573 MSEdge* to = MSEdge::dictionary(toId);
574 if (!to) {
575 throw TraCIException("Invalid edge '" + toId + "' for person: '" + personID + "'");
576 }
577 //std::string fromId = stage.edges.front();
578 //MSEdge* from = MSEdge::dictionary(fromId);
579 //if (!from) {
580 // throw TraCIException("Invalid edge '" + fromId + "' for person: '" + personID + "'");
581 //}
582 if (stage.line.empty()) {
583 throw TraCIException("Empty lines parameter for person: '" + personID + "'");
584 }
585 double arrivalPos = stage.arrivalPos;
586 if (arrivalPos == INVALID_DOUBLE_VALUE) {
587 if (bs != nullptr) {
588 arrivalPos = bs->getEndLanePosition();
589 } else {
590 arrivalPos = to->getLength();
591 }
592 }
593 return new MSStageDriving(nullptr, to, bs, arrivalPos, StringTokenizer(stage.line).getVector());
594 }
595
596 case STAGE_WALKING: {
597 MSTransportable* p = getPerson(personID);
598 ConstMSEdgeVector edges;
599 try {
600 MSEdge::parseEdgesList(stage.edges, edges, "<unknown>");
601 } catch (ProcessError& e) {
602 throw TraCIException(e.what());
603 }
604 if (edges.empty()) {
605 throw TraCIException("Empty edge list for walking stage of person '" + personID + "'.");
606 }
607 double arrivalPos = stage.arrivalPos;
608 if (fabs(arrivalPos) > edges.back()->getLength()) {
609 throw TraCIException("Invalid arrivalPos for walking stage of person '" + personID + "'.");
610 }
611 if (arrivalPos < 0) {
612 arrivalPos += edges.back()->getLength();
613 }
614 double speed = p->getMaxSpeed();
615 return new MSPerson::MSPersonStage_Walking(p->getID(), edges, bs, -1, speed, p->getArrivalPos(), arrivalPos, MSPModel::UNSPECIFIED_POS_LAT);
616 }
617
618 case STAGE_WAITING: {
619 MSTransportable* p = getPerson(personID);
620 if (stage.travelTime < 0) {
621 throw TraCIException("Duration for person: '" + personID + "' must not be negative");
622 }
623 return new MSStageWaiting(p->getArrivalEdge(), nullptr, TIME2STEPS(stage.travelTime), 0, p->getArrivalPos(), stage.description, false);
624 }
625 default:
626 return nullptr;
627 }
628}
629
630
631void
632Person::appendStage(const std::string& personID, const TraCIStage& stage) {
633 MSTransportable* p = getPerson(personID);
634 MSStage* personStage = convertTraCIStage(stage, personID);
635 p->appendStage(personStage);
636}
637
638
639void
640Person::replaceStage(const std::string& personID, const int stageIndex, const TraCIStage& stage) {
641 MSTransportable* p = getPerson(personID);
642 if (stageIndex >= p->getNumRemainingStages()) {
643 throw TraCIException("Specified stage index: is not valid for person " + personID);
644 }
645 MSStage* personStage = convertTraCIStage(stage, personID);
646 // removing the current stage triggers abort+proceed so the replacement
647 // stage must be ready beforehand
648 p->appendStage(personStage, stageIndex + 1);
649 p->removeStage(stageIndex);
650}
651
652
653void
654Person::appendDrivingStage(const std::string& personID, const std::string& toEdge, const std::string& lines, const std::string& stopID) {
655 MSTransportable* p = getPerson(personID);
656 const MSEdge* edge = MSEdge::dictionary(toEdge);
657 if (!edge) {
658 throw TraCIException("Invalid edge '" + toEdge + "' for person: '" + personID + "'");
659 }
660 if (lines.size() == 0) {
661 throw TraCIException("Empty lines parameter for person: '" + personID + "'");
662 }
663 MSStoppingPlace* bs = nullptr;
664 if (stopID != "") {
666 if (bs == nullptr) {
667 throw TraCIException("Invalid stopping place id '" + stopID + "' for person: '" + personID + "'");
668 }
669 }
670 p->appendStage(new MSStageDriving(nullptr, edge, bs, edge->getLength() - NUMERICAL_EPS, StringTokenizer(lines).getVector()));
671}
672
673
674void
675Person::appendWaitingStage(const std::string& personID, double duration, const std::string& description, const std::string& stopID) {
676 MSTransportable* p = getPerson(personID);
677 if (duration < 0) {
678 throw TraCIException("Duration for person: '" + personID + "' must not be negative");
679 }
680 MSStoppingPlace* bs = nullptr;
681 if (stopID != "") {
683 if (bs == nullptr) {
684 throw TraCIException("Invalid stopping place id '" + stopID + "' for person: '" + personID + "'");
685 }
686 }
687 p->appendStage(new MSStageWaiting(p->getArrivalEdge(), nullptr, TIME2STEPS(duration), 0, p->getArrivalPos(), description, false));
688}
689
690
691void
692Person::appendWalkingStage(const std::string& personID, const std::vector<std::string>& edgeIDs, double arrivalPos, double duration, double speed, const std::string& stopID) {
693 MSTransportable* p = getPerson(personID);
694 ConstMSEdgeVector edges;
695 try {
696 MSEdge::parseEdgesList(edgeIDs, edges, "<unknown>");
697 } catch (ProcessError& e) {
698 throw TraCIException(e.what());
699 }
700 if (edges.empty()) {
701 throw TraCIException("Empty edge list for walking stage of person '" + personID + "'.");
702 }
703 if (fabs(arrivalPos) > edges.back()->getLength()) {
704 throw TraCIException("Invalid arrivalPos for walking stage of person '" + personID + "'.");
705 }
706 if (arrivalPos < 0) {
707 arrivalPos += edges.back()->getLength();
708 }
709 if (speed < 0) {
710 speed = p->getMaxSpeed();
711 }
712 MSStoppingPlace* bs = nullptr;
713 if (stopID != "") {
715 if (bs == nullptr) {
716 throw TraCIException("Invalid stopping place id '" + stopID + "' for person: '" + personID + "'");
717 }
718 }
719 p->appendStage(new MSPerson::MSPersonStage_Walking(p->getID(), edges, bs, TIME2STEPS(duration), speed, p->getArrivalPos(), arrivalPos, MSPModel::UNSPECIFIED_POS_LAT));
720}
721
722
723void
724Person::removeStage(const std::string& personID, int nextStageIndex) {
725 MSTransportable* p = getPerson(personID);
726 if (nextStageIndex >= p->getNumRemainingStages()) {
727 throw TraCIException("The stage index must be lower than the number of remaining stages.");
728 }
729 if (nextStageIndex < 0) {
730 throw TraCIException("The stage index may not be negative.");
731 }
732 p->removeStage(nextStageIndex);
733}
734
735
736void
737Person::rerouteTraveltime(const std::string& personID) {
738 MSPerson* p = getPerson(personID);
739 if (p->getNumRemainingStages() == 0) {
740 throw TraCIException("Person '" + personID + "' has no remaining stages.");
741 }
742 const MSEdge* from = p->getEdge();
743 double departPos = p->getEdgePos();
744 // reroute to the start of the next-non-walking stage
745 int firstIndex;
747 firstIndex = 0;
748 } else if (p->getCurrentStageType() == MSStageType::WAITING) {
750 throw TraCIException("Person '" + personID + "' cannot reroute after the current stop.");
751 }
752 firstIndex = 1;
753 } else {
754 throw TraCIException("Person '" + personID + "' cannot reroute in stage type '" + toString((int)p->getCurrentStageType()) + "'.");
755 }
756 int nextIndex = firstIndex + 1;
757 for (; nextIndex < p->getNumRemainingStages(); nextIndex++) {
758 if (p->getStageType(nextIndex) != MSStageType::WALKING) {
759 break;
760 }
761 }
762 MSStage* destStage = p->getNextStage(nextIndex - 1);
763 const MSEdge* to = destStage->getEdges().back();
764 double arrivalPos = destStage->getArrivalPos();
765 double speed = p->getMaxSpeed();
766 ConstMSEdgeVector newEdges;
767 MSNet::getInstance()->getPedestrianRouter(0).compute(from, to, departPos, arrivalPos, speed, 0, nullptr, newEdges);
768 if (newEdges.empty()) {
769 throw TraCIException("Could not find new route for person '" + personID + "'.");
770 }
771 ConstMSEdgeVector oldEdges = p->getEdges(firstIndex);
772 assert(!oldEdges.empty());
773 if (oldEdges.front()->getFunction() != SumoXMLEdgeFunc::NORMAL) {
774 oldEdges.erase(oldEdges.begin());
775 }
776 //std::cout << " remainingStages=" << p->getNumRemainingStages() << " oldEdges=" << toString(oldEdges) << " newEdges=" << toString(newEdges) << " firstIndex=" << firstIndex << " nextIndex=" << nextIndex << "\n";
777 if (newEdges == oldEdges && (firstIndex + 1 == nextIndex)) {
778 return;
779 }
780 if (newEdges.front() != from) {
781 // @note: maybe this should be done automatically by the router
782 newEdges.insert(newEdges.begin(), from);
783 }
784 p->reroute(newEdges, departPos, firstIndex, nextIndex);
785}
786
787
788void
789Person::moveTo(const std::string& personID, const std::string& laneID, double pos, double posLat) {
790 MSPerson* p = getPerson(personID);
791 MSLane* l = MSLane::dictionary(laneID);
792 if (l == nullptr) {
793 throw TraCIException("Unknown lane '" + laneID + "'.");
794 }
795 if (posLat == INVALID_DOUBLE_VALUE) {
796 posLat = 0;
797 } else if (fabs(posLat) >= (0.5 * (l->getWidth() + p->getVehicleType().getWidth()) + MSPModel::SIDEWALK_OFFSET)) {
798 // see MSPModel_Striping::moveToXY
799 throw TraCIException("Invalid lateral position " + toString(posLat) + " on lane '" + laneID + "'.");
800 }
801 switch (p->getStageType(0)) {
804 assert(s != 0);
805 s->getState()->moveTo(p, l, pos, posLat, SIMSTEP);
806 break;
807 }
808 default:
809 throw TraCIException("Command moveTo is not supported for person '" + personID + "' while " + p->getCurrentStageDescription() + ".");
810 }
811}
812
813
814void
815Person::moveToXY(const std::string& personID, const std::string& edgeID, const double x, const double y, double angle, const int keepRoute, double matchThreshold) {
816 MSPerson* p = getPerson(personID);
817 const bool doKeepRoute = (keepRoute & 1) != 0;
818 const bool mayLeaveNetwork = (keepRoute & 2) != 0;
819 const bool ignorePermissions = (keepRoute & 4) != 0;
820 SUMOVehicleClass vClass = ignorePermissions ? SVC_IGNORING : p->getVClass();
821 Position pos(x, y);
822#ifdef DEBUG_MOVEXY
823 const double origAngle = angle;
824#endif
825 // angle must be in [0,360] because it will be compared against those returned by naviDegree()
826 // angle set to INVALID_DOUBLE_VALUE is ignored in the evaluated and later set to the angle of the matched lane
827 if (angle != INVALID_DOUBLE_VALUE) {
828 while (angle >= 360.) {
829 angle -= 360.;
830 }
831 while (angle < 0.) {
832 angle += 360.;
833 }
834 }
835 Position currentPos = p->getPosition();
836#ifdef DEBUG_MOVEXY
837 std::cout << std::endl << "begin person " << p->getID() << " lanePos:" << p->getEdgePos() << " edge:" << Named::getIDSecure(p->getEdge()) << "\n";
838 std::cout << " want pos:" << pos << " edgeID:" << edgeID << " origAngle:" << origAngle << " angle:" << angle << " keepRoute:" << keepRoute << std::endl;
839#endif
840
841 ConstMSEdgeVector edges;
842 MSLane* lane = nullptr;
843 double lanePos;
844 double lanePosLat = 0;
845 double bestDistance = std::numeric_limits<double>::max();
846 int routeOffset = 0;
847 bool found = false;
848 double maxRouteDistance = matchThreshold;
849
851 ev.push_back(p->getEdge());
852 int routeIndex = 0;
853 MSLane* currentLane = const_cast<MSLane*>(getSidewalk<MSEdge, MSLane>(p->getEdge()));
854 switch (p->getStageType(0)) {
857 assert(s != 0);
858 ev = s->getEdges();
859 routeIndex = (int)(s->getRouteStep() - s->getRoute().begin());
860 }
861 break;
862 default:
863 break;
864 }
865 if (doKeepRoute) {
866 // case a): vehicle is on its earlier route
867 // we additionally assume it is moving forward (SUMO-limit);
868 // note that the route ("edges") is not changed in this case
870 ev, routeIndex, vClass, true,
871 bestDistance, &lane, lanePos, routeOffset);
872 } else {
873 double speed = pos.distanceTo2D(p->getPosition()); // !!!veh->getSpeed();
874 found = Helper::moveToXYMap(pos, maxRouteDistance, mayLeaveNetwork, edgeID, angle,
875 speed, ev, routeIndex, currentLane, p->getEdgePos(), currentLane != nullptr,
876 vClass, true,
877 bestDistance, &lane, lanePos, routeOffset, edges);
878 if (edges.size() != 0 && ev.size() > 1) {
879 // try to rebuild the route
880 const MSEdge* origEdge = p->getEdge();
881 assert(lane != nullptr);
882 const MSJunction* originalTarget = nullptr;
883 if (origEdge->isNormal()) {
884 if (routeIndex == 0) {
885 if (origEdge->getToJunction() == ev[1]->getToJunction() || origEdge->getToJunction() == ev[1]->getFromJunction()) {
886 originalTarget = origEdge->getToJunction();
887 } else {
888 originalTarget = origEdge->getFromJunction();
889 }
890 } else {
891 if (origEdge->getToJunction() == ev[routeIndex - 1]->getToJunction() || origEdge->getToJunction() == ev[routeIndex - 1]->getFromJunction()) {
892 originalTarget = origEdge->getFromJunction();
893 } else {
894 originalTarget = origEdge->getToJunction();
895 }
896 }
897 } else {
898 originalTarget = origEdge->getToJunction();
899 assert(originalTarget == origEdge->getFromJunction());
900 }
901 const MSEdge* newEdge = edges[0];
902 if (edges[0]->getFromJunction() == originalTarget || edges[0]->getToJunction() == originalTarget) {
903 edges = ev;
904 edges[routeIndex] = newEdge;
905 }
906 }
907 }
908 if ((found && bestDistance <= maxRouteDistance) || mayLeaveNetwork) {
909 // compute lateral offset
910 if (found) {
911 const double perpDist = lane->getShape().distance2D(pos, false);
912 if (perpDist != GeomHelper::INVALID_OFFSET) {
913 lanePosLat = perpDist;
914 if (!mayLeaveNetwork) {
915 lanePosLat = MIN2(lanePosLat, 0.5 * (lane->getWidth() + p->getVehicleType().getWidth()));
916 }
917 // figure out whether the offset is to the left or to the right
918 PositionVector tmp = lane->getShape();
919 try {
920 tmp.move2side(-lanePosLat); // moved to left
921 } catch (ProcessError&) {
922 WRITE_WARNING("Could not determine position on lane '" + lane->getID() + " at lateral position " + toString(-lanePosLat) + ".");
923 }
924 //std::cout << " lane=" << lane->getID() << " posLat=" << lanePosLat << " shape=" << lane->getShape() << " tmp=" << tmp << " tmpDist=" << tmp.distance2D(pos) << "\n";
925 if (tmp.distance2D(pos) > perpDist) {
926 lanePosLat = -lanePosLat;
927 }
928 }
929 }
930 if (found && !mayLeaveNetwork && MSGlobals::gLateralResolution < 0) {
931 // mapped position may differ from pos
932 pos = lane->geometryPositionAtOffset(lanePos, -lanePosLat);
933 }
934 assert((found && lane != 0) || (!found && lane == 0));
935 switch (p->getStageType(0)) {
937 if (angle == INVALID_DOUBLE_VALUE) {
938 // walking angle cannot be deduced from road angle so we always use the last pos
940 }
941 break;
942 }
945 if (p->getNumRemainingStages() <= 1 || p->getStageType(1) != MSStageType::WALKING) {
946 // insert walking stage after the current stage
947 ConstMSEdgeVector route({p->getEdge()});
948 const double departPos = p->getCurrentStage()->getArrivalPos();
949 p->appendStage(new MSPerson::MSPersonStage_Walking(p->getID(), route, nullptr, -1, -1, departPos, departPos, MSPModel::UNSPECIFIED_POS_LAT), 1);
950 }
951 // abort waiting stage and proceed to walking stage
952 p->removeStage(0);
953 assert(p->getStageType(0) == MSStageType::WALKING);
954 if (angle == INVALID_DOUBLE_VALUE) {
955 if (lane != nullptr && !lane->getEdge().isWalkingArea()) {
956 angle = GeomHelper::naviDegree(lane->getShape().rotationAtOffset(lanePos));
957 } else {
958 // compute angle outside road network or on walkingarea from old and new position
960 }
961 }
962 break;
963 }
964 default:
965 throw TraCIException("Command moveToXY is not supported for person '" + personID + "' while " + p->getCurrentStageDescription() + ".");
966 }
967 Helper::setRemoteControlled(p, pos, lane, lanePos, lanePosLat, angle, routeOffset, edges, MSNet::getInstance()->getCurrentTimeStep());
968 } else {
969 if (lane == nullptr) {
970 throw TraCIException("Could not map person '" + personID + "' no road found within " + toString(maxRouteDistance) + "m.");
971 } else {
972 throw TraCIException("Could not map person '" + personID + "' distance to road is " + toString(bestDistance) + ".");
973 }
974 }
975}
976
977
980void
981Person::setParameter(const std::string& personID, const std::string& key, const std::string& value) {
982 MSTransportable* p = getPerson(personID);
983 if (StringUtils::startsWith(key, "device.")) {
984 throw TraCIException("Person '" + personID + "' does not support device parameters\n");
985 } else if (StringUtils::startsWith(key, "laneChangeModel.")) {
986 throw TraCIException("Person '" + personID + "' does not support laneChangeModel parameters\n");
987 } else if (StringUtils::startsWith(key, "carFollowModel.")) {
988 throw TraCIException("Person '" + personID + "' does not support carFollowModel parameters\n");
989 } else if (StringUtils::startsWith(key, "junctionModel.")) {
990 try {
991 // use the whole key (including junctionModel prefix)
992 p->setJunctionModelParameter(key, value);
993 } catch (InvalidArgument& e) {
994 // error message includes id since it is also used for xml input
995 throw TraCIException(e.what());
996 }
997 } else if (StringUtils::startsWith(key, "has.") && StringUtils::endsWith(key, ".device")) {
998 throw TraCIException("Person '" + personID + "' does not support chanigng device status\n");
999 } else {
1000 ((SUMOVehicleParameter&)p->getParameter()).setParameter(key, value);
1001 }
1002}
1003
1004
1005void
1006Person::setLength(const std::string& personID, double length) {
1007 getPerson(personID)->getSingularType().setLength(length);
1008}
1009
1010
1011void
1012Person::setMaxSpeed(const std::string& personID, double speed) {
1013 getPerson(personID)->getSingularType().setMaxSpeed(speed);
1014}
1015
1016
1017void
1018Person::setVehicleClass(const std::string& personID, const std::string& clazz) {
1019 getPerson(personID)->getSingularType().setVClass(getVehicleClassID(clazz));
1020}
1021
1022
1023void
1024Person::setShapeClass(const std::string& personID, const std::string& clazz) {
1025 getPerson(personID)->getSingularType().setShape(getVehicleShapeID(clazz));
1026}
1027
1028
1029void
1030Person::setEmissionClass(const std::string& personID, const std::string& clazz) {
1031 getPerson(personID)->getSingularType().setEmissionClass(PollutantsInterface::getClassByName(clazz));
1032}
1033
1034
1035void
1036Person::setWidth(const std::string& personID, double width) {
1037 getPerson(personID)->getSingularType().setWidth(width);
1038}
1039
1040
1041void
1042Person::setHeight(const std::string& personID, double height) {
1043 getPerson(personID)->getSingularType().setHeight(height);
1044}
1045
1046
1047void
1048Person::setMinGap(const std::string& personID, double minGap) {
1049 getPerson(personID)->getSingularType().setMinGap(minGap);
1050}
1051
1052
1053void
1054Person::setAccel(const std::string& personID, double accel) {
1055 getPerson(personID)->getSingularType().setAccel(accel);
1056}
1057
1058
1059void
1060Person::setDecel(const std::string& personID, double decel) {
1061 getPerson(personID)->getSingularType().setDecel(decel);
1062}
1063
1064
1065void
1066Person::setEmergencyDecel(const std::string& personID, double decel) {
1067 getPerson(personID)->getSingularType().setEmergencyDecel(decel);
1068}
1069
1070
1071void
1072Person::setApparentDecel(const std::string& personID, double decel) {
1073 getPerson(personID)->getSingularType().setApparentDecel(decel);
1074}
1075
1076
1077void
1078Person::setImperfection(const std::string& personID, double imperfection) {
1079 getPerson(personID)->getSingularType().setImperfection(imperfection);
1080}
1081
1082
1083void
1084Person::setTau(const std::string& personID, double tau) {
1085 getPerson(personID)->getSingularType().setTau(tau);
1086}
1087
1088
1089void
1090Person::setMinGapLat(const std::string& personID, double minGapLat) {
1091 getPerson(personID)->getSingularType().setMinGapLat(minGapLat);
1092}
1093
1094
1095void
1096Person::setMaxSpeedLat(const std::string& personID, double speed) {
1097 getPerson(personID)->getSingularType().setMaxSpeedLat(speed);
1098}
1099
1100
1101void
1102Person::setLateralAlignment(const std::string& personID, const std::string& latAlignment) {
1103 double lao;
1105 if (SUMOVTypeParameter::parseLatAlignment(latAlignment, lao, lad)) {
1106 getPerson(personID)->getSingularType().setPreferredLateralAlignment(lad, lao);
1107 } else {
1108 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)");
1109 }
1110}
1111
1112
1113void
1114Person::setSpeedFactor(const std::string& personID, double factor) {
1115 getPerson(personID)->setChosenSpeedFactor(factor);
1116}
1117
1118
1119void
1120Person::setActionStepLength(const std::string& personID, double actionStepLength, bool resetActionOffset) {
1121 getPerson(personID)->getSingularType().setActionStepLength(SUMOVehicleParserHelper::processActionStepLength(actionStepLength), resetActionOffset);
1122}
1123
1124void
1125Person::remove(const std::string& personID, char /*reason*/) {
1126 MSPerson* person = getPerson(personID);
1127 // remove all stages after the current and then abort the current stage
1128 // (without adding a zero-length waiting stage)
1129 while (person->getNumRemainingStages() > 1) {
1130 person->removeStage(1);
1131 }
1132 person->removeStage(0, false);
1133}
1134
1135void
1136Person::setColor(const std::string& personID, const TraCIColor& c) {
1137 const SUMOVehicleParameter& p = getPerson(personID)->getParameter();
1138 p.color.set((unsigned char)c.r, (unsigned char)c.g, (unsigned char)c.b, (unsigned char)c.a);
1140}
1141
1142
1144
1145
1146MSPerson*
1147Person::getPerson(const std::string& personID) {
1148 return Helper::getPerson(personID);
1149}
1150
1151
1152void
1153Person::storeShape(const std::string& id, PositionVector& shape) {
1154 shape.push_back(getPerson(id)->getPosition());
1155}
1156
1157
1158std::shared_ptr<VariableWrapper>
1159Person::makeWrapper() {
1160 return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);
1161}
1162
1163
1164bool
1165Person::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper, tcpip::Storage* paramData) {
1166 switch (variable) {
1167 case TRACI_ID_LIST:
1168 return wrapper->wrapStringList(objID, variable, getIDList());
1169 case ID_COUNT:
1170 return wrapper->wrapInt(objID, variable, getIDCount());
1171 case VAR_POSITION:
1172 return wrapper->wrapPosition(objID, variable, getPosition(objID));
1173 case VAR_POSITION3D:
1174 return wrapper->wrapPosition(objID, variable, getPosition(objID, true));
1175 case VAR_ANGLE:
1176 return wrapper->wrapDouble(objID, variable, getAngle(objID));
1177 case VAR_SLOPE:
1178 return wrapper->wrapDouble(objID, variable, getSlope(objID));
1179 case VAR_SPEED:
1180 return wrapper->wrapDouble(objID, variable, getSpeed(objID));
1181 case VAR_ROAD_ID:
1182 return wrapper->wrapString(objID, variable, getRoadID(objID));
1183 case VAR_LANE_ID:
1184 return wrapper->wrapString(objID, variable, getLaneID(objID));
1185 case VAR_LANEPOSITION:
1186 return wrapper->wrapDouble(objID, variable, getLanePosition(objID));
1187 case VAR_COLOR:
1188 return wrapper->wrapColor(objID, variable, getColor(objID));
1189 case VAR_WAITING_TIME:
1190 return wrapper->wrapDouble(objID, variable, getWaitingTime(objID));
1191 case VAR_TYPE:
1192 return wrapper->wrapString(objID, variable, getTypeID(objID));
1193 case VAR_SPEED_FACTOR:
1194 return wrapper->wrapDouble(objID, variable, getSpeedFactor(objID));
1195 case VAR_NEXT_EDGE:
1196 return wrapper->wrapString(objID, variable, getNextEdge(objID));
1198 return wrapper->wrapInt(objID, variable, getRemainingStages(objID));
1199 case VAR_VEHICLE:
1200 return wrapper->wrapString(objID, variable, getVehicle(objID));
1202 paramData->readUnsignedByte();
1203 return wrapper->wrapString(objID, variable, getParameter(objID, paramData->readString()));
1205 paramData->readUnsignedByte();
1206 return wrapper->wrapStringPair(objID, variable, getParameterWithKey(objID, paramData->readString()));
1208 // we cannot use the general fall through here because we do not have an object id
1209 return false;
1210 default:
1211 return libsumo::VehicleType::handleVariable(getTypeID(objID), variable, wrapper, paramData);
1212 }
1213}
1214
1215
1216}
1217
1218
1219/****************************************************************************/
long long int SUMOTime
Definition: GUI.h:36
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:74
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:265
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:71
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:169
virtual std::vector< const Reservation * > getRunningReservations()
retrieve all reservations that were already dispatched and are still active
Definition: MSDispatch.cpp:179
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
const PositionVector & getShape() const
Returns this lane's shape.
Definition: MSLane.h:506
static bool dictionary(const std::string &id, MSLane *lane)
Static (sic!) container methods {.
Definition: MSLane.cpp:2199
double interpolateLanePosToGeometryPos(double lanePos) const
Definition: MSLane.h:527
MSEdge & getEdge() const
Returns the lane's edge.
Definition: MSLane.h:713
double getWidth() const
Returns the lane's width.
Definition: MSLane.h:590
const Position geometryPositionAtOffset(double offset, double lateralOffset=0) const
Definition: MSLane.h:533
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:321
MSStoppingPlace * getStoppingPlace(const std::string &id, const SumoXMLTag category) const
Returns the named stopping place of the given category.
Definition: MSNet.cpp:1287
MSPedestrianRouter & getPedestrianRouter(const int rngIndex, const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:1417
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:379
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:1096
static const double SIDEWALK_OFFSET
the offset for computing person positions when walking on edges without a sidewalk
Definition: MSPModel.h:125
static const double UNSPECIFIED_POS_LAT
the default lateral offset for persons when starting a walk
Definition: MSPModel.h:128
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:581
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:174
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:252
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:262
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:60
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:374
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:1706
static MSPerson * getPerson(const std::string &id)
Definition: Helper.cpp:488
static void setRemoteControlled(MSVehicle *v, Position xyPos, MSLane *l, double pos, double posLat, double angle, int edgeOffset, ConstMSEdgeVector route, SUMOTime t)
Definition: Helper.cpp:1373
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:1413
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:301
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 STAGE_WAITING
std::map< std::string, libsumo::TraCIResults > SubscriptionResults
{object->{variable->value}}
Definition: TraCIDefs.h:300
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