Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSStageDriving.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2025 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/****************************************************************************/
20// A stage performing the travelling by a transport system (cars, public transport)
21/****************************************************************************/
22#include <config.h>
23
29#include <microsim/MSEdge.h>
31#include <microsim/MSLane.h>
32#include <microsim/MSNet.h>
33#include <microsim/MSStop.h>
48
49
50// ===========================================================================
51// method definitions
52// ===========================================================================
53MSStageDriving::MSStageDriving(const MSEdge* origin, const MSEdge* destination,
54 MSStoppingPlace* toStop, const double arrivalPos, const double arrivalPosLat,
55 const std::vector<std::string>& lines, const std::string& group,
56 const std::string& intendedVeh, SUMOTime intendedDepart) :
57 MSStage(MSStageType::DRIVING, destination, toStop, arrivalPos, arrivalPosLat, group),
58 myOrigin(origin),
59 myLines(lines.begin(), lines.end()),
60 myVehicle(nullptr),
61 myVehicleID("NULL"),
64 myTimeLoss(-1),
65 myWaitingPos(-1),
67 myWaitingEdge(nullptr),
69 myOriginStop(nullptr),
70 myIntendedVehicleID(intendedVeh),
71 myIntendedDepart(intendedDepart),
72 myReservationCommand(nullptr) {
73}
74
75
79 std::vector<std::string>(myLines.begin(), myLines.end()),
81 clon->setParameters(*this);
82 return clon;
83}
84
85
87
88
89void
91 if (hasParameter("earliestPickupTime")) {
92 SUMOTime reservationTime = MSNet::getInstance()->getCurrentTimeStep();
93 if (hasParameter("reservationTime")) {
94 reservationTime = string2time(getParameter("reservationTime"));
95 }
96 SUMOTime earliestPickupTime = string2time(getParameter("earliestPickupTime"));
97 if (transportable->getNextStage(1) == this) {
98 // if the ride is the first stage use the departPos (there is a unvisible stop before)
99 myWaitingPos = transportable->getParameter().departPos;
100 } else {
101 // else use the middle of the edge, as also used as default for walk's arrivalPos
102 myWaitingPos = myOrigin->getLength() / 2;
103 }
104 myReservationCommand = new BookReservation(transportable, earliestPickupTime, this);
106 }
107}
108
109
110const MSEdge*
112 if (myVehicle != nullptr) {
113 if (myVehicle->getLane() != nullptr) {
114 return &myVehicle->getLane()->getEdge();
115 }
116 return myVehicle->getEdge();
117 } else if (myArrived >= 0) {
118 return myDestination;
119 } else {
120 return myWaitingEdge;
121 }
122}
123
124
125const MSEdge*
129
130
131double
133 if (isWaiting4Vehicle()) {
134 return myWaitingPos;
135 } else if (myArrived >= 0) {
136 return myArrivalPos;
137 } else {
138 // vehicle may already have passed the lane (check whether this is correct)
139 return MIN2(myVehicle->getPositionOnLane(), getEdge()->getLength());
140 }
141}
142
143int
145 if (isWaiting4Vehicle()) {
147 } else if (myArrived >= 0) {
149 } else {
150 return MSPModel::FORWARD;
151 }
152}
153
154const MSLane*
156 return myVehicle != nullptr ? myVehicle->getLane() : nullptr;
157}
158
159
162 if (isWaiting4Vehicle()) {
164 return myStopWaitPos;
165 }
168 } else if (myArrived >= 0) {
171 } else {
172 return myVehicle->getPosition();
173 }
174}
175
176
177double
179 if (isWaiting4Vehicle()) {
180 const double offset = myOriginStop == nullptr ? M_PI / 2 : myOriginStop->getAngle();
181 return getEdgeAngle(myWaitingEdge, myWaitingPos) + offset * (MSGlobals::gLefthand ? -1 : 1);
182 } else if (myArrived >= 0) {
184 } else {
185 MSVehicle* veh = dynamic_cast<MSVehicle*>(myVehicle);
186 if (veh != nullptr) {
187 return veh->getAngle();
188 } else {
189 return 0;
190 }
191 }
192}
193
194
195double
197 if (myVehicle != nullptr) {
198 // distance was previously set to driven distance upon embarking
199 return myVehicle->getOdometer() - myVehicleDistance;
200 }
201 return myVehicleDistance;
202}
203
204
205std::string
206MSStageDriving::getStageDescription(const bool isPerson) const {
207 return isWaiting4Vehicle() ? "waiting for " + joinToString(myLines, ",") : (isPerson ? "driving" : "transport");
208}
209
210
211std::string
212MSStageDriving::getStageSummary(const bool isPerson) const {
213 const std::string dest = (getDestinationStop() == nullptr ?
214 " edge '" + getDestination()->getID() + "'" :
215 " stop '" + getDestinationStop()->getID() + "'" + (
216 getDestinationStop()->getMyName() != "" ? " (" + getDestinationStop()->getMyName() + ")" : ""));
217 const std::string intended = myIntendedVehicleID != "" ?
218 " (vehicle " + myIntendedVehicleID + " at time=" + time2string(myIntendedDepart) + ")" :
219 "";
220 const std::string modeName = isPerson ? "driving" : "transported";
221 return isWaiting4Vehicle() ?
222 "waiting for " + joinToString(myLines, ",") + intended + " then " + modeName + " to " + dest :
223 modeName + " to " + dest;
224}
225
226
227void
228MSStageDriving::proceed(MSNet* net, MSTransportable* transportable, SUMOTime now, MSStage* previous) {
230 ? previous->getOriginStop()
231 : previous->getDestinationStop());
232 myWaitingSince = now;
233 const bool isPerson = transportable->isPerson();
235 && transportable->getCurrentStageIndex() == 1) {
236 // we are the first real stage (stage 0 is WAITING_FOR_DEPART)
237 const std::string vehID = *myLines.begin();
238 SUMOVehicle* startVeh = net->getVehicleControl().getVehicle(vehID);
239 if (startVeh == nullptr && net->hasFlow(vehID)) {
240 startVeh = net->getInsertionControl().getLastFlowVehicle(vehID);
241 }
242 if (startVeh == nullptr) {
243 throw ProcessError("Vehicle '" + vehID + "' not found for triggered departure of " +
244 (isPerson ? "person" : "container") + " '" + transportable->getID() + "'.");
245 }
246 if (transportable->isPerson()) {
247 const int pCap = startVeh->getVehicleType().getParameter().personCapacity;
248 if (startVeh->getPersonNumber() >= pCap) {
249 WRITE_WARNING(TLF("Vehicle '%' exceeds personCapacity % when placing triggered person '%', time=%",
250 startVeh->getID(), pCap, transportable->getID(), time2string(SIMSTEP)));
251 }
252 } else {
253 const int cCap = startVeh->getVehicleType().getParameter().containerCapacity;
254 if (startVeh->getContainerNumber() >= cCap) {
255 WRITE_WARNING(TLF("Vehicle '%' exceeds containerCapacity % when placing triggered container '%', time=%",
256 startVeh->getID(), cCap, transportable->getID(), time2string(SIMSTEP)));
257 }
258 }
259 myDeparted = now;
260 setVehicle(startVeh);
261 if (myOriginStop != nullptr) {
262 myOriginStop->removeTransportable(transportable);
263 }
264 myWaitingEdge = previous->getEdge();
266 myWaitingPos = previous->getEdgePos(now);
267 myVehicle->addTransportable(transportable);
268 return;
269 }
270 if (myOriginStop != nullptr) {
271 // the arrival stop may have an access point
272 myWaitingEdge = &myOriginStop->getLane().getEdge();
273 myStopWaitPos = myOriginStop->getWaitPosition(transportable);
274 myWaitingPos = myOriginStop->getWaitingPositionOnLane(transportable);
275 } else {
276 myWaitingEdge = previous->getEdge();
278 myWaitingPos = previous->getEdgePos(now);
279 }
280 if (myOrigin != nullptr && myOrigin != myWaitingEdge
281 && (myOriginStop == nullptr || myOriginStop->getAccessPos(myOrigin) < 0)) {
282 // transfer at junction (rather than access)
284 myWaitingPos = 0;
285 }
286 SUMOVehicle* const availableVehicle = myWaitingEdge->getWaitingVehicle(transportable, myWaitingPos);
287 const bool triggered = availableVehicle != nullptr &&
288 ((isPerson && availableVehicle->getParameter().departProcedure == DepartDefinition::TRIGGERED) ||
289 (!isPerson && availableVehicle->getParameter().departProcedure == DepartDefinition::CONTAINER_TRIGGERED));
290 if (triggered && !availableVehicle->hasDeparted()) {
291 setVehicle(availableVehicle);
292 if (myOriginStop != nullptr) {
293 myOriginStop->removeTransportable(transportable);
294 }
295 myVehicle->addTransportable(transportable);
298 } else {
299 registerWaiting(transportable, now);
300 }
301}
302
303
304void
306 // check if the ride can be conducted and reserve it
308 const MSEdge* to = getDestination();
309 double toPos = getArrivalPos();
310 if ((to->getPermissions() & SVC_TAXI) == 0 && getDestinationStop() != nullptr) {
311 // try to find usable access edge
312 for (const auto& access : getDestinationStop()->getAllAccessPos()) {
313 const MSEdge* accessEdge = &access.lane->getEdge();
314 if ((accessEdge->getPermissions() & SVC_TAXI) != 0) {
315 to = accessEdge;
316 toPos = access.endPos;
317 break;
318 }
319 }
320 }
321 if ((myWaitingEdge->getPermissions() & SVC_TAXI) == 0 && myOriginStop != nullptr) {
322 // try to find usable access edge
323 for (const auto& access : myOriginStop->getAllAccessPos()) {
324 const MSEdge* accessEdge = &access.lane->getEdge();
325 if ((accessEdge->getPermissions() & SVC_TAXI) != 0) {
326 myWaitingEdge = accessEdge;
328 myWaitingPos = access.endPos;
329 break;
330 }
331 }
332 }
333 // Create reservation only if not already created by previous reservationTime
334 if (myReservationCommand == nullptr) {
336 } else {
337 // update "fromPos" with current (new) value of myWaitingPos
339 }
340 }
341 if (transportable->isPerson()) {
343 } else {
345 }
346 myWaitingEdge->addTransportable(transportable);
347}
348
353
354
359
360
363 const SUMOTime departed = myDeparted >= 0 ? myDeparted : SIMSTEP;
364 return myWaitingSince >= 0 ? departed - myWaitingSince : SUMOTime_MAX;
365}
366
367
369MSStageDriving::getTimeLoss(const MSTransportable* /*transportable*/) const {
370 return myArrived >= 0 ? myTimeLoss : SUMOTime_MAX;
371}
372
373void
374MSStageDriving::tripInfoOutput(OutputDevice& os, const MSTransportable* const transportable) const {
376 const SUMOTime waitingTime = getWaitingTime();
377 const SUMOTime duration = myArrived - myDeparted;
379 os.openTag(transportable->isPerson() ? "ride" : "transport");
380 os.writeAttr("waitingTime", waitingTime != SUMOTime_MAX ? time2string(waitingTime) : "-1");
381 os.writeAttr("vehicle", myVehicleID);
382 os.writeAttr("depart", myDeparted >= 0 ? time2string(myDeparted) : "-1");
383 os.writeAttr("arrival", myArrived >= 0 ? time2string(myArrived) : "-1");
384 os.writeAttr("arrivalPos", myArrived >= 0 ? toString(getArrivalPos()) : "-1");
385 os.writeAttr("duration", myArrived >= 0 ? time2string(duration) :
386 (myDeparted >= 0 ? time2string(now - myDeparted) : "-1"));
387 os.writeAttr("routeLength", myArrived >= 0 || myVehicle != nullptr ? toString(getDistance()) : "-1");
388 os.writeAttr("timeLoss", myArrived >= 0 ? time2string(getTimeLoss(transportable)) : "-1");
389 os.closeTag();
390}
391
392
393void
394MSStageDriving::routeOutput(const bool isPerson, OutputDevice& os, const bool withRouteLength, const MSStage* const previous) const {
396 if (getFromEdge() != nullptr) {
397 os.writeAttr(SUMO_ATTR_FROM, getFromEdge()->getID());
398 } else if (previous != nullptr && previous->getStageType() == MSStageType::WAITING_FOR_DEPART) {
399 os.writeAttr(SUMO_ATTR_FROM, previous->getEdge()->getID());
400 }
401 os.writeAttr(SUMO_ATTR_TO, getDestination()->getID());
402 std::string comment = "";
403 if (myDestinationStop != nullptr) {
404 os.writeAttr(toString(myDestinationStop->getElement()), myDestinationStop->getID());
405 if (myDestinationStop->getMyName() != "") {
406 comment = " <!-- " + StringUtils::escapeXML(myDestinationStop->getMyName(), true) + " -->";
407 }
408 } else if (!unspecifiedArrivalPos()) {
410 }
411 if (myLines.size() > 1 || *myLines.begin() != LINE_ANY) {
412 // no need to write the default
414 }
415 if (myIntendedVehicleID != "") {
417 }
418 if (myIntendedDepart >= 0) {
420 }
421 if (withRouteLength) {
422 os.writeAttr("routeLength", myVehicleDistance);
423 }
424 if (OptionsCont::getOptions().getBool("vehroute-output.exit-times")) {
425 os.writeAttr("vehicle", myVehicleID);
428 }
429 if (OptionsCont::getOptions().getBool("vehroute-output.cost")) {
431 }
432 os.closeTag(comment);
433}
434
435
436bool
438 assert(myLines.size() > 0);
439 return (myLines.count(vehicle->getID()) > 0
440 || ((myLines.count(vehicle->getParameter().line) > 0
441 || myLines.count(LINE_ANY) > 0) &&
442 // even if the line matches we still have to check for stops (#14526)
443 (myDestinationStop == nullptr
444 ? vehicle->stopsAtEdge(myDestination)
445 : vehicle->stopsAt(myDestinationStop)))
446 || MSDevice_Taxi::compatibleLine(vehicle->getParameter().line, *myLines.begin()));
447}
448
449
450bool
452 return myVehicle == nullptr && myArrived < 0;
453}
454
455
460
461
462double
464 return myVehicle == nullptr ? 0 : myVehicle->getSpeed();
465}
466
467
470 ConstMSEdgeVector result;
471 result.push_back(getFromEdge());
472 result.push_back(getDestination());
473 return result;
474}
475
476
477double
481
482
483const std::string
484MSStageDriving::setArrived(MSNet* net, MSTransportable* transportable, SUMOTime now, const bool vehicleArrived) {
485 MSStage::setArrived(net, transportable, now, vehicleArrived);
486 if (myVehicle != nullptr) {
487 // distance was previously set to driven distance upon embarking
489 myTimeLoss = myVehicle->getTimeLoss() - myTimeLoss;
490 if (vehicleArrived) {
491 myArrivalPos = myVehicle->getArrivalPos();
492 } else {
493 myArrivalPos = myVehicle->getPositionOnLane();
494 }
495 const MSStoppingPlace* const stop = getDestinationStop();
496 if (stop != nullptr) {
498 for (const auto& access : stop->getAllAccessPos()) {
499 if (access.exit != exit) {
500 exit = access.exit;
501 break;
502 }
503 }
505 MSVehicle* train = dynamic_cast<MSVehicle*>(myVehicle);
506 if (train != nullptr) {
507 MSTrainHelper trainHelper = MSTrainHelper(train);
508 const MSLane* const lane = myVehicle->getLane();
509 if (OptionsCont::getOptions().getString("pedestrian.model") != "jupedsim") {
510 trainHelper.computeDoorPositions();
511 const std::vector<MSTrainHelper::Carriage*>& carriages = trainHelper.getCarriages();
512 const int randomCarriageIx = RandHelper::rand(trainHelper.getNumCarriages() - trainHelper.getFirstPassengerCarriage()) + trainHelper.getFirstPassengerCarriage();
513 const MSTrainHelper::Carriage* randomCarriage = carriages[randomCarriageIx];
514 const int randomDoorIx = RandHelper::rand(trainHelper.getCarriageDoors());
515 Position randomDoor = randomCarriage->doorPositions[randomDoorIx];
516 // Jitter the position before projection because of possible train curvature.
517 Position direction = randomCarriage->front - randomCarriage->back;
518 direction.norm2D();
519 const double doorWidth = train->getVehicleType().getParameter().carriageDoorWidth;
520 randomDoor.add(direction * RandHelper::rand(-0.5 * doorWidth, 0.5 * doorWidth));
521 // Project onto the lane.
522 myArrivalPos = lane->getShape().nearest_offset_to_point2D(randomDoor);
524 myArrivalPos = MIN2(MAX2(0., myArrivalPos), myVehicle->getEdge()->getLength());
525 } else {
526 std::vector<Position>& unboardingPositions = static_cast<MSDevice_Transportable*>(train->getDevice(typeid(MSDevice_Transportable)))->getUnboardingPositions();
527 if (unboardingPositions.empty()) {
528 const MSVehicleType* defaultPedestrianType = MSNet::getInstance()->getVehicleControl().getVType(DEFAULT_PEDTYPE_ID, nullptr, true);
529 const double defaultPassengerRadius = MAX2(defaultPedestrianType->getLength(), defaultPedestrianType->getWidth()) / 2.;
530 trainHelper.computeUnboardingPositions(defaultPassengerRadius, unboardingPositions);
531 }
532 // Random shuffling of the positions has already been done in the train helper.
533 const Position availableUnboardingPosition = unboardingPositions.back();
534 unboardingPositions.pop_back();
535 const Position arrivalPos = lane->getShape().transformToVectorCoordinates(availableUnboardingPosition);
536 myArrivalPos = arrivalPos.x();
537 myArrivalPosLat = arrivalPos.y();
538 }
539 }
540 }
541 }
542 } else {
543 myVehicleDistance = -1.;
544 myTimeLoss = -1;
545 }
546 myVehicle = nullptr; // avoid dangling pointer after vehicle arrival
547 return "";
548}
549
550
551void
553 myVehicle = v;
554 if (myVehicle != nullptr) {
555 myVehicleID = v->getID();
559 if (myVehicle->hasDeparted()) {
560 myVehicleDistance = myVehicle->getOdometer();
561 myTimeLoss = myVehicle->getTimeLoss();
562 } else {
563 // it probably got triggered by the person
565 myTimeLoss = 0;
566 }
567 }
568}
569
570
571void
573 myDestinationStop = nullptr;
574 if (myVehicle != nullptr) {
575 // jumping out of a moving vehicle!
576 myVehicle->removeTransportable(t);
577 myDestination = myVehicle->getLane() == nullptr ? myVehicle->getEdge() : &myVehicle->getLane()->getEdge();
578 myArrivalPos = myVehicle->getPositionOnLane();
579 // myVehicleDistance and myTimeLoss are updated in subsequent call to setArrived
580 } else {
581 MSTransportableControl& tc = (t->isPerson() ?
582 MSNet::getInstance()->getPersonControl() :
583 MSNet::getInstance()->getContainerControl());
589 }
590}
591
592
593std::string
595 return isWaiting4Vehicle() ? ("waiting for " + joinToString(myLines, ",")
596 + " at " + (myOriginStop == nullptr
597 ? ("edge '" + myWaitingEdge->getID() + "'")
598 : (toString(myOriginStop->getElement()) + " '" + myOriginStop->getID() + "'"))
599 ) : "";
600}
601
602
603bool
605 const MSEdge* stopEdge = stop.getEdge();
606 bool canLeave = false;
607 if (t->getDestination() == stopEdge) {
608 // if this is the last stage, we can use the arrivalPos of the person
609 const bool unspecifiedAP = unspecifiedArrivalPos() && (
611 const double arrivalPos = (unspecifiedArrivalPos()
613 SUMO_ATTR_ARRIVALPOS, t->getID(), true)
614 : getArrivalPos());
615 if (unspecifiedAP || stop.isInRange(arrivalPos, veh.getLength() + MSGlobals::gStopTolerance)) {
616 canLeave = true;
617 }
618 }
619 if (myDestinationStop != nullptr) {
620 if (!canLeave) {
621 // check with more tolerance due to busStop size and also check
622 // access edges
623 const double accessPos = myDestinationStop->getAccessPos(veh.getEdge());
624 if (accessPos >= 0) {
625 double tolerance = veh.getLength() + MSGlobals::gStopTolerance;
626 if (&myDestinationStop->getLane().getEdge() == veh.getEdge()) {
627 // accessPos is in the middle of the stop
628 tolerance += (myDestinationStop->getEndLanePosition() - myDestinationStop->getBeginLanePosition()) / 2;
629 }
630 canLeave = stop.isInRange(accessPos, tolerance);
631 }
632 }
633 }
634 return canLeave;
635}
636
637
638void
639MSStageDriving::saveState(std::ostringstream& out) {
640 const bool hasVehicle = myVehicle != nullptr;
641 out << " " << myWaitingSince << " " << myTimeLoss << " " << myArrived << " " << hasVehicle;
642 if (hasVehicle) {
643 out << " " << myDeparted << " " << myVehicle->getID() << " " << myVehicleDistance;
644 }
645}
646
647
648void
649MSStageDriving::loadState(MSTransportable* transportable, std::istringstream& state) {
650 bool hasVehicle;
651 state >> myWaitingSince >> myTimeLoss >> myArrived >> hasVehicle;
652 if (hasVehicle) {
653 std::string vehID;
654 state >> myDeparted >> vehID;
656 setVehicle(startVeh);
657 myVehicle->addTransportable(transportable);
658 state >> myVehicleDistance;
659 } else {
660 // there should always be at least one prior WAITING_FOR_DEPART stage
661 MSStage* previous = transportable->getNextStage(-1);
663 ? previous->getOriginStop()
664 : previous->getDestinationStop());
665 if (myOriginStop != nullptr) {
666 // the arrival stop may have an access point
667 myOriginStop->addTransportable(transportable);
668 myWaitingEdge = &myOriginStop->getLane().getEdge();
669 myStopWaitPos = myOriginStop->getWaitPosition(transportable);
670 myWaitingPos = myOriginStop->getWaitingPositionOnLane(transportable);
671 } else {
672 myWaitingEdge = previous->getEdge();
674 myWaitingPos = previous->getArrivalPos();
675 }
676 registerWaiting(transportable, SIMSTEP);
677 }
678}
679
680// ---------------------------------------------------------------------------
681// MSStageDriving::BookReservation method definitions
682// ---------------------------------------------------------------------------
685 MSDevice_Taxi::addReservation(myTransportable, myStage->getLines(), currentTime, currentTime, myEarliestPickupTime,
686 myStage->myOrigin, myStage->myWaitingPos, myStage->myOriginStop, myStage->getDestination(), myStage->getArrivalPos(), myStage->myDestinationStop, myStage->myGroup);
687 // do not repeat if execution fails
688 return 0;
689}
690
691/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
std::vector< const MSEdge * > ConstMSEdgeVector
Definition MSEdge.h:74
MSStageType
Definition MSStage.h:55
@ WAITING_FOR_DEPART
Definition MSStage.h:56
std::vector< const MSEdge * > ConstMSEdgeVector
#define WRITE_WARNING(msg)
Definition MsgHandler.h:286
#define TLF(string,...)
Definition MsgHandler.h:306
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition SUMOTime.cpp:46
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:91
#define SIMSTEP
Definition SUMOTime.h:61
#define SUMOTime_MAX
Definition SUMOTime.h:34
const std::string DEFAULT_PEDTYPE_ID
@ SVC_IGNORING
vehicles ignoring classes
@ SVC_TAXI
vehicle is a taxi
const std::string LINE_ANY
const long long int VEHPARS_ARRIVALPOS_SET
@ CONTAINER_TRIGGERED
The departure is container triggered.
@ TRIGGERED
The departure is person triggered.
@ SUMO_TAG_TRANSPORT
@ SUMO_TAG_RIDE
@ SUMO_ATTR_LINES
@ SUMO_ATTR_DEPART
@ SUMO_ATTR_STARTED
@ SUMO_ATTR_ARRIVALPOS
@ SUMO_ATTR_ENDED
@ SUMO_ATTR_COST
@ SUMO_ATTR_TO
@ SUMO_ATTR_FROM
@ SUMO_ATTR_INTENDED
T MIN2(T a, T b)
Definition StdDefs.h:80
T MAX2(T a, T b)
Definition StdDefs.h:86
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition ToString.h:289
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
MSDevice * getDevice(const std::type_info &type) const
Returns a device of the given type if it exists, nullptr otherwise.
static void updateReservationFromPos(MSTransportable *person, const std::set< std::string > &lines, const MSEdge *from, double fromPos, const MSEdge *to, double toPos, const std::string &group, double newFromPos)
update reservation's fromPos due to pre-booking
static void addReservation(MSTransportable *person, const std::set< std::string > &lines, SUMOTime reservationTime, SUMOTime pickupTime, SUMOTime earliestPickupTime, const MSEdge *from, double fromPos, const MSStoppingPlace *fromStop, const MSEdge *to, double toPos, const MSStoppingPlace *toStop, const std::string &group)
add new reservation
static void removeReservation(MSTransportable *person, const std::set< std::string > &lines, const MSEdge *from, double fromPos, const MSEdge *to, double toPos, const std::string &group)
retract reservation
static bool isReservation(const std::set< std::string > &lines)
whether the given lines description is a taxi call
bool compatibleLine(const Reservation *res)
whether the given reservation is compatible with the taxi line
std::vector< Position > & getUnboardingPositions()
static void addRideTransportData(const bool isPerson, const double distance, const SUMOTime duration, const SUMOVehicleClass vClass, const std::string &line, const SUMOTime waitingTime)
record tripinfo data for rides and transports
A road/street connecting two junctions.
Definition MSEdge.h:77
SVCPermissions getPermissions() const
Returns the combined permissions of all lanes of this edge.
Definition MSEdge.h:657
double getLength() const
return the length of the edge
Definition MSEdge.h:693
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
static double gStopTolerance
The tolerance to apply when matching waiting persons and vehicles.
Definition MSGlobals.h:168
static bool gLefthand
Whether lefthand-drive is being simulated.
Definition MSGlobals.h:174
SUMOVehicle * getLastFlowVehicle(const std::string &id) const
return the last vehicle for the given flow
void add(SUMOVehicle *veh)
Adds a single vehicle for departure.
Representation of a lane in the micro simulation.
Definition MSLane.h:84
double interpolateGeometryPosToLanePos(double geometryPos) const
Definition MSLane.h:566
virtual const PositionVector & getShape(bool) const
Definition MSLane.h:294
The simulated network and simulation perfomer.
Definition MSNet.h:89
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:186
MSEventControl * getBeginOfTimestepEvents()
Returns the event control for events executed at the begin of a time step.
Definition MSNet.h:485
virtual MSTransportableControl & getContainerControl()
Returns the container control.
Definition MSNet.cpp:1265
bool hasFlow(const std::string &id) const
return whether the given flow is known
Definition MSNet.cpp:434
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition MSNet.h:334
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition MSNet.h:445
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition MSNet.h:392
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition MSNet.cpp:1256
static const int FORWARD
Definition MSPModel.h:54
static const int UNDEFINED_DIRECTION
Definition MSPModel.h:56
SUMOTime execute(SUMOTime currentTime)
Executes the command.
bool isWaiting4Vehicle() const
Whether the person waits for a vehicle.
MSStage * clone() const
MSStoppingPlace * myOriginStop
the stop at which this ride starts (or nullptr)
const MSEdge * getEdge() const
Returns the current edge.
void loadState(MSTransportable *transportable, std::istringstream &state)
Reconstructs the current state.
SUMOTime getWaitingTime() const
void proceed(MSNet *net, MSTransportable *transportable, SUMOTime now, MSStage *previous)
proceeds to this stage
std::string myVehicleID
cached vehicle data for output after the vehicle has been removed
virtual ~MSStageDriving()
destructor
Position myStopWaitPos
ConstMSEdgeVector getEdges() const
the edges of the current stage
std::string getWaitingDescription() const
Return where the person waits and for what.
const std::string setArrived(MSNet *net, MSTransportable *transportable, SUMOTime now, const bool vehicleArrived)
marks arrival time and records driven distance
std::string myIntendedVehicleID
double getEdgePos(SUMOTime now) const
double getAngle(SUMOTime now) const
returns the angle of the transportable
void registerWaiting(MSTransportable *transportable, SUMOTime now)
brief register waiting person (on proceed or loadState)
void init(MSTransportable *transportable)
initialization, e.g. for param-related events
MSStageDriving(const MSEdge *origin, const MSEdge *destination, MSStoppingPlace *toStop, const double arrivalPos, const double arrivalPosLat, const std::vector< std::string > &lines, const std::string &group="", const std::string &intendedVeh="", SUMOTime intendedDepart=-1)
constructor
SUMOTime getTimeLoss(const MSTransportable *transportable) const
double getSpeed() const
the speed of the transportable
bool canLeaveVehicle(const MSTransportable *t, const SUMOVehicle &veh, const MSStop &stop)
checks whether the person may exit at the current vehicle position
bool isWaitingFor(const SUMOVehicle *vehicle) const
Whether the person waits for the given vehicle.
Position getPosition(SUMOTime now) const
returns the position of the transportable
void tripInfoOutput(OutputDevice &os, const MSTransportable *const transportable) const
Called on writing tripinfo output.
BookReservation * myReservationCommand
const MSEdge * myOrigin
the origin edge
const MSLane * getLane() const
Returns the current lane (if applicable).
SUMOVehicleClass myVehicleVClass
std::string getStageDescription(const bool isPerson) const
return (brief) string representation of the current stage
void routeOutput(const bool isPerson, OutputDevice &os, const bool withRouteLength, const MSStage *const previous) const
Called on writing vehroute output.
const MSEdge * getFromEdge() const
SUMOTime myWaitingSince
The time since which this person is waiting for a ride.
std::string myVehicleLine
void saveState(std::ostringstream &out)
Saves the current state into the given stream.
const MSEdge * myWaitingEdge
SUMOTime myIntendedDepart
std::string getStageSummary(const bool isPerson) const
return string summary of the current stage
void setVehicle(SUMOVehicle *v)
std::string myVehicleType
double getDistance() const
get travel distance in this stage
SUMOTime getDuration() const
const std::set< std::string > myLines
the lines to choose from
SUMOTime myTimeLoss
While driving, this is the timeLoss of the vehicle when the ride started, after arrival this is the t...
const std::set< std::string > & getLines() const
double getArrivalPos() const
return default value for undefined arrivalPos
SUMOTime getTravelTime() const
SUMOVehicle * myVehicle
The taken vehicle.
void abort(MSTransportable *t)
abort this stage (TraCI)
int getDirection() const
Return the movement directon on the edge.
const MSEdge * getDestination() const
returns the destination edge
Definition MSStage.cpp:65
double myArrivalPosLat
the lateral position at which we want to arrive
Definition MSStage.h:311
virtual double getEdgePos(SUMOTime now) const
Definition MSStage.cpp:83
virtual double getArrivalPos() const
Definition MSStage.h:97
MSStoppingPlace * myDestinationStop
the stop to reach by getting transported (if any)
Definition MSStage.h:305
virtual MSStoppingPlace * getOriginStop() const
returns the origin stop (if any). only needed for MSStageTrip
Definition MSStage.h:93
const std::string myGroup
The id of the group of transportables traveling together.
Definition MSStage.h:323
virtual const std::string setArrived(MSNet *net, MSTransportable *transportable, SUMOTime now, const bool vehicleArrived)
logs end of the step
Definition MSStage.cpp:160
double getCosts() const
Returns the costs of the stage.
Definition MSStage.h:271
MSStoppingPlace * getDestinationStop() const
returns the destination stop (if any)
Definition MSStage.h:88
bool unspecifiedArrivalPos() const
Definition MSStage.cpp:197
MSStageType getStageType() const
Definition MSStage.h:138
MSStage(const MSStageType type, const MSEdge *destination, MSStoppingPlace *toStop, const double arrivalPos, const double arrivalPosLat=0.0, const std::string &group="")
constructor
Definition MSStage.cpp:47
SUMOTime myArrived
the time at which this stage ended
Definition MSStage.h:317
double getEdgeAngle(const MSEdge *e, double at) const
get angle of the edge at a certain position
Definition MSStage.cpp:182
virtual const MSEdge * getEdge() const
Returns the current edge.
Definition MSStage.cpp:71
static const double ROADSIDE_OFFSET
the offset for computing positions when standing at an edge
Definition MSStage.h:334
double myArrivalPos
the longitudinal position at which we want to arrive
Definition MSStage.h:308
Position getEdgePosition(const MSEdge *e, double at, double offset) const
get position on edge e at length at with orthogonal offset
Definition MSStage.cpp:171
const MSEdge * myDestination
the next edge to reach by getting transported
Definition MSStage.h:302
SUMOTime myDeparted
the time at which this stage started
Definition MSStage.h:314
bool isInRange(const double pos, const double tolerance) const
whether the stop is in range of the given position
Definition MSStop.cpp:182
const MSEdge * getEdge() const
Definition MSStop.cpp:54
A lane area vehicles can halt at.
const std::vector< Access > & getAllAccessPos() const
lanes and positions connected to this stop
const std::string & getMyName() const
A class that helps computing positions of a train's carriages and additional structures.
void computeDoorPositions()
compute door positions on demand and fills the carriage structures
const std::vector< Carriage * > & getCarriages() const
void computeUnboardingPositions(double passengerRadius, std::vector< Position > &unboardingPositions)
compute unboarding positions on demand and fills the carriage structures
int getNumCarriages() const
int getCarriageDoors() const
int getFirstPassengerCarriage() const
void abortWaitingForVehicle(MSTransportable *t)
let the given transportable abort waiting for a vehicle (when removing stage via TraCI)
void addWaiting(const MSEdge *edge, MSTransportable *person)
adds a transportable to the list of transportables waiting for a vehicle on the specified edge
const MSEdge * getDestination() const
Returns the current destination.
MSStage * getNextStage(int offset) const
Return the next (or previous) stage denoted by the offset.
int getNumRemainingStages() const
Return the number of remaining stages (including the current).
bool isPerson() const override
Whether it is a person.
int getCurrentStageIndex() const
Return the index of the current stage.
const SUMOVehicleParameter & getParameter() const override
Returns the vehicle's parameter (including departure definition).
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
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.
void handleTriggeredDepart(SUMOVehicle *v, bool add)
register / unregister depart-triggered vehicles with edges
Representation of a vehicle in the micro simulation.
Definition MSVehicle.h:77
double getAngle() const
Returns the vehicle's direction in radians.
Definition MSVehicle.h:735
The car-following model and parameter.
double getWidth() const
Get the width which vehicles of this class shall have when being drawn.
const std::string & getID() const
Returns the name of the vehicle type.
double getLength() const
Get vehicle's length [m].
const SUMOVTypeParameter & getParameter() const
const std::string & getID() const
Returns the id.
Definition Named.h:74
static OptionsCont & getOptions()
Retrieves the options.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
bool hasParameter(const std::string &key) const
Returns whether the parameter is set.
void setParameters(const Parameterised &params)
set the given key/value map in map<string, string> format
virtual const std::string getParameter(const std::string &key, const std::string defaultValue="") const
Returns the value for a given key.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
static const Position INVALID
used to indicate that a position is valid
Definition Position.h:323
void norm2D()
Normalizes the given vector.
Definition Position.h:179
double x() const
Returns the x-position.
Definition Position.h:52
void add(const Position &pos)
Adds the given position to this one.
Definition Position.h:129
double y() const
Returns the y-position.
Definition Position.h:57
double nearest_offset_to_point2D(const Position &p, bool perpendicular=true) const
return the nearest offest to point 2D
Position transformToVectorCoordinates(const Position &p, bool extend=false) const
return position p within the length-wise coordinate system defined by this position vector....
static double rand(SumoRNG *rng=nullptr)
Returns a random real number in [0, 1).
virtual const MSVehicleType & getVehicleType() const =0
Returns the object's "vehicle" type.
virtual const SUMOVehicleParameter & getParameter() const =0
Returns the vehicle's parameter (including departure definition).
virtual SUMOVehicleClass getVClass() const =0
Returns the object's access class.
virtual const MSEdge * getEdge() const =0
Returns the edge the object is currently at.
int personCapacity
The person capacity of the vehicle.
int containerCapacity
The container capacity of the vehicle.
double carriageDoorWidth
the width of the carriage doors
Representation of a vehicle.
Definition SUMOVehicle.h:62
virtual bool stopsAtEdge(const MSEdge *edge) const =0
Returns whether the vehicle stops at the given edge.
virtual bool stopsAt(MSStoppingPlace *stop) const =0
Returns whether the vehicle stops at the given stopping place.
virtual int getPersonNumber() const =0
Returns the number of persons.
virtual bool hasDeparted() const =0
Returns whether this vehicle has departed.
virtual double getLength() const =0
Returns the vehicles's length.
virtual int getContainerNumber() const =0
Returns the number of containers.
bool wasSet(long long int what) const
Returns whether the given parameter was set.
double departPos
(optional) The position the vehicle shall depart from
double arrivalPos
(optional) The position the vehicle shall arrive on
static double interpretEdgePos(double pos, double maximumValue, SumoXMLAttr attr, const std::string &id, bool silent=false)
Interprets negative edge positions and fits them onto a given edge.
DepartDefinition departProcedure
Information how the vehicle shall choose the depart time.
std::string line
The vehicle's line (mainly for public transport).
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.
#define M_PI
Definition odrSpiral.cpp:45
std::vector< Position > doorPositions