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-2026 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),
63 myTimeLoss(-1),
64 myWaitingPos(-1),
66 myWaitingEdge(origin),
68 myOriginStop(nullptr),
69 myIntendedVehicleID(intendedVeh),
70 myIntendedDepart(intendedDepart) {
71}
72
73
77 std::vector<std::string>(myLines.begin(), myLines.end()),
79 clon->setParameters(*this);
80 return clon;
81}
82
83
85
86
87void
89 if (hasParameter("earliestPickupTime")) {
90 SUMOTime reservationTime = MSNet::getInstance()->getCurrentTimeStep();
91 if (hasParameter("reservationTime")) {
92 reservationTime = string2time(getParameter("reservationTime"));
93 }
94 SUMOTime earliestPickupTime = string2time(getParameter("earliestPickupTime"));
95 if (transportable->getNextStage(1) == this) {
96 // if the ride is the first stage use the departPos (there is a unvisible stop before)
97 myWaitingPos = transportable->getParameter().departPos;
98 } else {
99 // else use the middle of the edge, as also used as default for walk's arrivalPos
100 myWaitingPos = myOrigin->getLength() / 2;
101 }
103 MSNet::getInstance()->getBeginOfTimestepEvents()->addEvent(new BookReservation(transportable, earliestPickupTime, this), reservationTime);
104 }
105}
106
107
108const MSEdge*
110 if (myVehicle != nullptr) {
111 if (myVehicle->getLane() != nullptr) {
112 return &myVehicle->getLane()->getEdge();
113 }
114 return myVehicle->getEdge();
115 } else if (myArrived >= 0) {
116 return myDestination;
117 } else {
118 return myWaitingEdge;
119 }
120}
121
122
123const MSEdge*
127
128
129double
131 if (isWaiting4Vehicle()) {
132 return myWaitingPos;
133 } else if (myArrived >= 0) {
134 return myArrivalPos;
135 } else {
136 // vehicle may already have passed the lane (check whether this is correct)
137 return MIN2(myVehicle->getPositionOnLane(), getEdge()->getLength());
138 }
139}
140
141int
143 if (isWaiting4Vehicle()) {
145 } else if (myArrived >= 0) {
147 } else {
148 return MSPModel::FORWARD;
149 }
150}
151
152const MSLane*
154 return myVehicle != nullptr ? myVehicle->getLane() : nullptr;
155}
156
157
160 if (isWaiting4Vehicle()) {
162 return myStopWaitPos;
163 }
166 } else if (myArrived >= 0) {
169 } else {
170 return myVehicle->getPosition();
171 }
172}
173
174
175double
177 if (isWaiting4Vehicle()) {
178 const double offset = myOriginStop == nullptr ? M_PI / 2 : myOriginStop->getAngle();
179 return getEdgeAngle(myWaitingEdge, myWaitingPos) + offset * (MSGlobals::gLefthand ? -1 : 1);
180 } else if (myArrived >= 0) {
182 } else {
183 MSVehicle* veh = dynamic_cast<MSVehicle*>(myVehicle);
184 if (veh != nullptr) {
185 return veh->getAngle();
186 } else {
187 return 0;
188 }
189 }
190}
191
192
193double
195 if (myVehicle != nullptr) {
196 // distance was previously set to driven distance upon embarking
197 return myVehicle->getOdometer() - myVehicleDistance;
198 }
199 return myVehicleDistance;
200}
201
202
203std::string
204MSStageDriving::getStageDescription(const bool isPerson) const {
205 return isWaiting4Vehicle() ? "waiting for " + joinToString(myLines, ",") : (isPerson ? "driving" : "transport");
206}
207
208
209std::string
210MSStageDriving::getStageSummary(const bool isPerson) const {
211 const std::string dest = (getDestinationStop() == nullptr ?
212 " edge '" + getDestination()->getID() + "'" :
213 " stop '" + getDestinationStop()->getID() + "'" + (
214 getDestinationStop()->getMyName() != "" ? " (" + getDestinationStop()->getMyName() + ")" : ""));
215 const std::string intended = myIntendedVehicleID != "" ?
216 " (vehicle " + myIntendedVehicleID + " at time=" + time2string(myIntendedDepart) + ")" :
217 "";
218 const std::string modeName = isPerson ? "driving" : "transported";
219 return isWaiting4Vehicle() ?
220 "waiting for " + joinToString(myLines, ",") + intended + " then " + modeName + " to " + dest :
221 modeName + " to " + dest;
222}
223
224
225void
226MSStageDriving::proceed(MSNet* net, MSTransportable* transportable, SUMOTime now, MSStage* previous) {
228 ? previous->getOriginStop()
229 : previous->getDestinationStop());
230 myWaitingSince = now;
231 const bool isPerson = transportable->isPerson();
233 && transportable->getCurrentStageIndex() == 1) {
234 // we are the first real stage (stage 0 is WAITING_FOR_DEPART)
235 const std::string vehID = *myLines.begin();
236 SUMOVehicle* startVeh = net->getVehicleControl().getVehicle(vehID);
237 if (startVeh == nullptr && net->hasFlow(vehID)) {
238 startVeh = net->getInsertionControl().getLastFlowVehicle(vehID);
239 }
240 if (startVeh == nullptr) {
241 throw ProcessError("Vehicle '" + vehID + "' not found for triggered departure of " +
242 (isPerson ? "person" : "container") + " '" + transportable->getID() + "'.");
243 }
244 if (transportable->isPerson()) {
245 const int pCap = startVeh->getVehicleType().getParameter().personCapacity;
246 if (startVeh->getPersonNumber() >= pCap) {
247 WRITE_WARNING(TLF("Vehicle '%' exceeds personCapacity % when placing triggered person '%', time=%",
248 startVeh->getID(), pCap, transportable->getID(), time2string(SIMSTEP)));
249 }
250 } else {
251 const int cCap = startVeh->getVehicleType().getParameter().containerCapacity;
252 if (startVeh->getContainerNumber() >= cCap) {
253 WRITE_WARNING(TLF("Vehicle '%' exceeds containerCapacity % when placing triggered container '%', time=%",
254 startVeh->getID(), cCap, transportable->getID(), time2string(SIMSTEP)));
255 }
256 }
257 myDeparted = now;
258 setVehicle(startVeh);
259 if (myOriginStop != nullptr) {
260 myOriginStop->removeTransportable(transportable);
261 }
262 myWaitingEdge = previous->getEdge();
264 myWaitingPos = previous->getEdgePos(now);
265 myVehicle->addTransportable(transportable);
266 return;
267 }
268 if (myOriginStop != nullptr) {
269 // the arrival stop may have an access point
270 myWaitingEdge = &myOriginStop->getLane().getEdge();
271 myStopWaitPos = myOriginStop->getWaitPosition(transportable);
272 myWaitingPos = myOriginStop->getWaitingPositionOnLane(transportable);
273 } else {
274 myWaitingEdge = previous->getEdge();
276 myWaitingPos = previous->getEdgePos(now);
277 }
278 if (myOrigin != nullptr && myOrigin != myWaitingEdge
279 && (myOriginStop == nullptr || myOriginStop->getAccessPos(myOrigin) < 0)) {
280 // transfer at junction (rather than access)
282 myWaitingPos = 0;
283 }
284 SUMOVehicle* const availableVehicle = myWaitingEdge->getWaitingVehicle(transportable, myWaitingPos);
285 const bool triggered = availableVehicle != nullptr &&
286 ((isPerson && availableVehicle->getParameter().departProcedure == DepartDefinition::TRIGGERED) ||
287 (!isPerson && availableVehicle->getParameter().departProcedure == DepartDefinition::CONTAINER_TRIGGERED));
288 if (triggered && !availableVehicle->hasDeparted()) {
289 setVehicle(availableVehicle);
290 if (myOriginStop != nullptr) {
291 myOriginStop->removeTransportable(transportable);
292 }
293 myVehicle->addTransportable(transportable);
296 } else {
297 registerWaiting(transportable, now);
298 }
299}
300
301
302void
304 // check if the ride can be conducted and reserve it
306 const MSEdge* to = getDestination();
307 double toPos = getArrivalPos();
308 if ((to->getPermissions() & SVC_TAXI) == 0 && getDestinationStop() != nullptr) {
309 // try to find usable access edge
310 for (const auto& access : getDestinationStop()->getAllAccessPos()) {
311 const MSEdge* accessEdge = &access.lane->getEdge();
312 if ((accessEdge->getPermissions() & SVC_TAXI) != 0) {
313 to = accessEdge;
314 toPos = access.endPos;
315 break;
316 }
317 }
318 }
319 if ((myWaitingEdge->getPermissions() & SVC_TAXI) == 0 && myOriginStop != nullptr) {
320 // try to find usable access edge
321 for (const auto& access : myOriginStop->getAllAccessPos()) {
322 const MSEdge* accessEdge = &access.lane->getEdge();
323 if ((accessEdge->getPermissions() & SVC_TAXI) != 0) {
324 myWaitingEdge = accessEdge;
326 myWaitingPos = access.endPos;
327 break;
328 }
329 }
330 }
331 // Create reservation only if not already created by previous reservationTime
334 } else {
335 // update "fromPos" with current (new) value of myWaitingPos
337 }
338 }
339 // check required for state-loading
340 if (myVehicle == nullptr) {
341 if (transportable->isPerson()) {
343 } else {
345 }
346 myWaitingEdge->addTransportable(transportable);
347 }
348}
349
354
355
360
361
364 const SUMOTime departed = myDeparted >= 0 ? myDeparted : SIMSTEP;
365 return myWaitingSince >= 0 ? departed - myWaitingSince : SUMOTime_MAX;
366}
367
368
370MSStageDriving::getTimeLoss(const MSTransportable* /*transportable*/) const {
371 return myArrived >= 0 ? myTimeLoss : SUMOTime_MAX;
372}
373
374void
375MSStageDriving::tripInfoOutput(OutputDevice& os, const MSTransportable* const transportable) const {
377 const SUMOTime waitingTime = getWaitingTime();
378 const SUMOTime duration = myArrived - myDeparted;
380 os.openTag(transportable->isPerson() ? "ride" : "transport");
381 os.writeAttr("waitingTime", waitingTime != SUMOTime_MAX ? time2string(waitingTime) : "-1");
382 os.writeAttr("vehicle", myVehicleID.empty() ? "NULL" : myVehicleID);
383 os.writeAttr("depart", myDeparted >= 0 ? time2string(myDeparted) : "-1");
384 os.writeAttr("arrival", myArrived >= 0 ? time2string(myArrived) : "-1");
385 os.writeAttr("arrivalPos", myArrived >= 0 ? toString(getArrivalPos()) : "-1");
386 os.writeAttr("duration", myArrived >= 0 ? time2string(duration) :
387 (myDeparted >= 0 ? time2string(now - myDeparted) : "-1"));
388 os.writeAttr(SUMO_ATTR_ROUTELENGTH, myArrived >= 0 || myVehicle != nullptr ? toString(getDistance()) : "-1");
389 os.writeAttr("timeLoss", myArrived >= 0 ? time2string(getTimeLoss(transportable)) : "-1");
390 os.closeTag();
391}
392
393
394void
395MSStageDriving::routeOutput(const bool isPerson, OutputDevice& os, const bool withRouteLength, const MSStage* const previous, const bool withTiming, const bool /*saveState*/) const {
397 if (getFromEdge() != nullptr) {
398 os.writeAttr(SUMO_ATTR_FROM, getFromEdge()->getID());
399 } else if (previous != nullptr && previous->getStageType() == MSStageType::WAITING_FOR_DEPART) {
400 os.writeAttr(SUMO_ATTR_FROM, previous->getEdge()->getID());
401 }
402 os.writeAttr(SUMO_ATTR_TO, getDestination()->getID());
403 std::string comment = "";
404 if (myDestinationStop != nullptr) {
405 os.writeAttr(toString(myDestinationStop->getElement()), myDestinationStop->getID());
406 if (myDestinationStop->getMyName() != "") {
407 comment = " <!-- " + StringUtils::escapeXML(myDestinationStop->getMyName(), true) + " -->";
408 }
409 } else if (!unspecifiedArrivalPos()) {
411 }
412 if (myLines.size() > 1 || *myLines.begin() != LINE_ANY) {
413 // no need to write the default
415 }
416 if (myIntendedVehicleID != "") {
418 }
419 if (myIntendedDepart >= 0) {
421 }
422 if (withRouteLength) {
423 os.writeAttr("routeLength", myVehicleDistance);
424 }
425 if (withTiming) {
426 os.writeAttr("vehicle", myVehicleID.empty() ? "NULL" : myVehicleID);
429 }
430 if (OptionsCont::getOptions().getBool("vehroute-output.cost")) {
432 }
433 os.closeTag(comment);
434}
435
436
437bool
439 assert(myLines.size() > 0);
440 return (myLines.count(vehicle->getID()) > 0
441 || ((myLines.count(vehicle->getParameter().line) > 0
442 || myLines.count(LINE_ANY) > 0) &&
443 // even if the line matches we still have to check for stops (#14526)
444 (myDestinationStop == nullptr
445 ? vehicle->stopsAtEdge(myDestination)
446 : vehicle->stopsAt(myDestinationStop)))
447 || MSDevice_Taxi::compatibleLine(vehicle->getParameter().line, *myLines.begin()));
448}
449
450
451bool
453 return myVehicle == nullptr && myArrived < 0;
454}
455
456
461
462
463double
465 return myVehicle == nullptr ? 0 : myVehicle->getSpeed();
466}
467
468
471 ConstMSEdgeVector result;
472 result.push_back(getFromEdge());
473 result.push_back(getDestination());
474 return result;
475}
476
477
478double
482
483
484const std::string
485MSStageDriving::setArrived(MSNet* net, MSTransportable* transportable, SUMOTime now, const bool vehicleArrived) {
486 MSStage::setArrived(net, transportable, now, vehicleArrived);
487 if (myVehicle != nullptr) {
488 // distance was previously set to driven distance upon embarking
490 myTimeLoss = myVehicle->getTimeLoss() - myTimeLoss;
491 if (vehicleArrived) {
492 myArrivalPos = myVehicle->getArrivalPos();
493 } else {
494 myArrivalPos = myVehicle->getPositionOnLane();
495 }
496 const MSStoppingPlace* const stop = getDestinationStop();
497 if (stop != nullptr) {
499 for (const auto& access : stop->getAllAccessPos()) {
500 if (access.exit != exit) {
501 exit = access.exit;
502 break;
503 }
504 }
506 MSVehicle* train = dynamic_cast<MSVehicle*>(myVehicle);
507 if (train != nullptr) {
508 MSTrainHelper trainHelper = MSTrainHelper(train);
509 const MSLane* const lane = myVehicle->getLane();
510 if (OptionsCont::getOptions().getString("pedestrian.model") != "jupedsim") {
511 trainHelper.computeDoorPositions();
512 const std::vector<MSTrainHelper::Carriage*>& carriages = trainHelper.getCarriages();
513 const int randomCarriageIx = RandHelper::rand(trainHelper.getNumCarriages() - trainHelper.getFirstPassengerCarriage()) + trainHelper.getFirstPassengerCarriage();
514 const MSTrainHelper::Carriage* randomCarriage = carriages[randomCarriageIx];
515 const int randomDoorIx = RandHelper::rand(trainHelper.getCarriageDoors());
516 Position randomDoor = randomCarriage->doorPositions[randomDoorIx];
517 // Jitter the position before projection because of possible train curvature.
518 Position direction = randomCarriage->front - randomCarriage->back;
519 direction.norm2D();
520 const double doorWidth = train->getVehicleType().getParameter().carriageDoorWidth;
521 randomDoor.add(direction * RandHelper::rand(-0.5 * doorWidth, 0.5 * doorWidth));
522 // Project onto the lane.
523 myArrivalPos = lane->getShape().nearest_offset_to_point2D(randomDoor);
525 myArrivalPos = MIN2(MAX2(0., myArrivalPos), myVehicle->getEdge()->getLength());
526 } else {
527 std::vector<Position>& unboardingPositions = static_cast<MSDevice_Transportable*>(train->getDevice(typeid(MSDevice_Transportable)))->getUnboardingPositions();
528 if (unboardingPositions.empty()) {
529 const MSVehicleType* defaultPedestrianType = MSNet::getInstance()->getVehicleControl().getVType(DEFAULT_PEDTYPE_ID, nullptr, true);
530 const double defaultPassengerRadius = MAX2(defaultPedestrianType->getLength(), defaultPedestrianType->getWidth()) / 2.;
531 trainHelper.computeUnboardingPositions(defaultPassengerRadius, unboardingPositions);
532 }
533 // Random shuffling of the positions has already been done in the train helper.
534 const Position availableUnboardingPosition = unboardingPositions.back();
535 unboardingPositions.pop_back();
536 const Position arrivalPos = lane->getShape().transformToVectorCoordinates(availableUnboardingPosition);
537 myArrivalPos = arrivalPos.x();
538 myArrivalPosLat = arrivalPos.y();
539 }
540 }
541 }
542 }
543 } else {
544 myVehicleDistance = -1.;
545 myTimeLoss = -1;
546 }
547 myVehicle = nullptr; // avoid dangling pointer after vehicle arrival
548 return "";
549}
550
551
552void
554 myVehicle = v;
555 if (myVehicle != nullptr) {
556 myVehicleID = v->getID();
560 if (myVehicle->hasDeparted()) {
561 myVehicleDistance = myVehicle->getOdometer();
562 myTimeLoss = myVehicle->getTimeLoss();
563 } else {
564 // it probably got triggered by the person
566 myTimeLoss = 0;
567 }
568 }
569}
570
571
572void
574 myDestinationStop = nullptr;
575 if (myVehicle != nullptr) {
576 // jumping out of a moving vehicle!
577 myVehicle->removeTransportable(t);
578 myDestination = myVehicle->getLane() == nullptr ? myVehicle->getEdge() : &myVehicle->getLane()->getEdge();
579 myArrivalPos = myVehicle->getPositionOnLane();
580 // myVehicleDistance and myTimeLoss are updated in subsequent call to setArrived
581 } else {
582 MSTransportableControl& tc = (t->isPerson() ?
583 MSNet::getInstance()->getPersonControl() :
584 MSNet::getInstance()->getContainerControl());
590 }
591}
592
593
594std::string
596 return isWaiting4Vehicle() ? ("waiting for " + joinToString(myLines, ",")
597 + " at " + (myOriginStop == nullptr
598 ? ("edge '" + myWaitingEdge->getID() + "'")
599 : (toString(myOriginStop->getElement()) + " '" + myOriginStop->getID() + "'"))
600 ) : "";
601}
602
603
604bool
606 const MSEdge* stopEdge = stop.getEdge();
607 bool canLeave = false;
608 if (t->getDestination() == stopEdge) {
609 // if this is the last stage, we can use the arrivalPos of the person
610 const bool unspecifiedAP = unspecifiedArrivalPos() && (
612 const double arrivalPos = (unspecifiedArrivalPos()
614 SUMO_ATTR_ARRIVALPOS, t->getID(), true)
615 : getArrivalPos());
616 if (unspecifiedAP || stop.isInRange(arrivalPos, veh.getLength() + MSGlobals::gStopTolerance)) {
617 canLeave = true;
618 }
619 }
620 if (myDestinationStop != nullptr) {
621 if (!canLeave) {
622 // check with more tolerance due to busStop size and also check
623 // access edges
624 const double accessPos = myDestinationStop->getAccessPos(veh.getEdge());
625 if (accessPos >= 0) {
626 double tolerance = veh.getLength() + MSGlobals::gStopTolerance;
627 if (&myDestinationStop->getLane().getEdge() == veh.getEdge()) {
628 // accessPos is in the middle of the stop
629 tolerance += (myDestinationStop->getEndLanePosition() - myDestinationStop->getBeginLanePosition()) / 2;
630 }
631 canLeave = stop.isInRange(accessPos, tolerance);
632 }
633 }
634 }
635 return canLeave;
636}
637
638
639void
640MSStageDriving::saveState(std::ostringstream& out, MSTransportable* transportable) {
641 const bool hasVehicle = myVehicle != nullptr;
642 out << " " << myWaitingSince << " " << myTimeLoss << " " << myArrived << " " << hasVehicle;
643 if (hasVehicle) {
644 out << " " << myDeparted << " " << myVehicle->getID() << " " << myVehicleDistance;
645 } else if (myOriginStop != nullptr) {
646 out.setf(std::ios::fixed, std::ios::floatfield);
647 out << std::setprecision(gPrecision);
648 out << " " << myOriginStop->checkWaitingSpot(transportable);
649 out << " " << myWaitingPos << " " << myStopWaitPos.x() << " " << myStopWaitPos.y();
650 }
651}
652
653
654void
655MSStageDriving::loadState(MSTransportable* transportable, std::istringstream& state) {
656 // there should always be at least one prior WAITING_FOR_DEPART stage
657 MSStage* previous = transportable->getNextStage(-1);
659 ? previous->getOriginStop()
660 : previous->getDestinationStop());
661 bool hasVehicle;
662 SUMOTime loadedTimeLoss;
663 state >> myWaitingSince >> loadedTimeLoss >> myArrived >> hasVehicle;
664 if (hasVehicle) {
665 std::string vehID;
666 state >> myDeparted >> vehID;
668 setVehicle(startVeh);
669 myTimeLoss = loadedTimeLoss;
670 myVehicle->addTransportable(transportable);
671 state >> myVehicleDistance;
672 } else if (myOriginStop != nullptr) {
673 int waitingSpot;
674 state >> waitingSpot;
675 state >> myWaitingPos;
676 double x, y;
677 state >> x;
678 state >> y;
679 myStopWaitPos = Position(x, y);
680 myOriginStop->addTransportable(transportable, waitingSpot);
681 myWaitingEdge = &myOriginStop->getLane().getEdge();
682 } else {
683 myWaitingEdge = previous->getEdge();
685 myWaitingPos = previous->getArrivalPos();
686 }
687 // running reservations will be converted in MSDevice_Taxi::addReservation
688 registerWaiting(transportable, myWaitingSince);
689}
690
691// ---------------------------------------------------------------------------
692// MSStageDriving::BookReservation method definitions
693// ---------------------------------------------------------------------------
696 MSDevice_Taxi::addReservation(myTransportable, myStage->getLines(), currentTime, currentTime, myEarliestPickupTime,
697 myStage->myOrigin, myStage->myWaitingPos, myStage->myOriginStop, myStage->getDestination(), myStage->getArrivalPos(), myStage->myDestinationStop, myStage->myGroup);
698 return 0; // do not repeat
699}
700
701/****************************************************************************/
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:64
#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_ROUTELENGTH
@ SUMO_ATTR_INTENDED
int gPrecision
the precision for floating point outputs
Definition StdDefs.cpp:27
const double INVALID_DOUBLE
invalid double
Definition StdDefs.h:68
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:314
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:49
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:658
double getLength() const
return the length of the edge
Definition MSEdge.h:694
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:567
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:199
MSEventControl * getBeginOfTimestepEvents()
Returns the event control for events executed at the begin of a time step.
Definition MSNet.h:495
virtual MSTransportableControl & getContainerControl()
Returns the container control.
Definition MSNet.cpp:1300
bool hasFlow(const std::string &id) const
return whether the given flow is known
Definition MSNet.cpp:455
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition MSNet.h:334
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition MSNet.h:455
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition MSNet.h:402
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition MSNet.cpp:1291
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.
void routeOutput(const bool isPerson, OutputDevice &os, const bool withRouteLength, const MSStage *const previous, const bool withTiming, const bool saveState=false) const
Called on writing vehroute output.
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
void saveState(std::ostringstream &out, MSTransportable *transportable)
Saves the current state into the given stream.
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.
const MSEdge * myOrigin
the origin edge
const MSLane * getLane() const
Returns the current lane (if applicable).
SUMOVehicleClass myVehicleVClass
double myReservationWaitingPos
std::string getStageDescription(const bool isPerson) const
return (brief) string representation of the current stage
const MSEdge * getFromEdge() const
SUMOTime myWaitingSince
The time since which this person is waiting for a ride.
std::string myVehicleLine
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:315
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:309
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:327
virtual const std::string setArrived(MSNet *net, MSTransportable *transportable, SUMOTime now, const bool vehicleArrived)
logs end of the step
Definition MSStage.cpp:167
double getCosts() const
Returns the costs of the stage.
Definition MSStage.h:275
MSStoppingPlace * getDestinationStop() const
returns the destination stop (if any)
Definition MSStage.h:88
bool unspecifiedArrivalPos() const
Definition MSStage.cpp:204
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:321
double getEdgeAngle(const MSEdge *e, double at) const
get angle of the edge at a certain position
Definition MSStage.cpp:189
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:338
double myArrivalPos
the longitudinal position at which we want to arrive
Definition MSStage.h:312
Position getEdgePosition(const MSEdge *e, double at, double offset) const
get position on edge e at length at with orthogonal offset
Definition MSStage.cpp:178
const MSEdge * myDestination
the next edge to reach by getting transported
Definition MSStage.h:306
SUMOTime myDeparted
the time at which this stage started
Definition MSStage.h:318
bool isInRange(const double pos, const double tolerance) const
whether the stop is in range of the given position
Definition MSStop.cpp:219
const MSEdge * getEdge() const
Definition MSStop.cpp:55
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:73
static OptionsCont & getOptions()
Retrieves the options.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const ATTR_TYPE &attr, const T &val, const bool isNull=false)
writes a named attribute
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 (normal) route 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:63
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