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