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