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