SUMO - Simulation of Urban MObility
MSTransportable.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // The common superclass for modelling transportable objects like persons and containers
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
27 #include <utils/geom/GeomHelper.h>
31 #include "MSEdge.h"
32 #include "MSLane.h"
33 #include "MSNet.h"
35 #include "MSVehicleControl.h"
36 #include "MSTransportableControl.h"
37 #include "MSTransportable.h"
38 
39 /* -------------------------------------------------------------------------
40 * static member definitions
41 * ----------------------------------------------------------------------- */
42 const double MSTransportable::ROADSIDE_OFFSET(3);
43 
44 
45 // ===========================================================================
46 // method definitions
47 // ===========================================================================
48 /* -------------------------------------------------------------------------
49  * MSTransportable::Stage - methods
50  * ----------------------------------------------------------------------- */
51 MSTransportable::Stage::Stage(const MSEdge* destination, MSStoppingPlace* toStop, const double arrivalPos, StageType type)
52  : myDestination(destination), myDestinationStop(toStop), myArrivalPos(arrivalPos), myDeparted(-1), myArrived(-1), myType(type) {}
53 
55 
56 const MSEdge*
58  return myDestination;
59 }
60 
61 
62 const MSEdge*
64  return myDestination;
65 }
66 
67 
68 const MSEdge*
70  return myDestination;
71 }
72 
73 
74 double
76  return myArrivalPos;
77 }
78 
79 
82  return 0;
83 }
84 
85 
86 double
88  return 0.;
89 }
90 
91 
94  ConstMSEdgeVector result;
95  result.push_back(getDestination());
96  return result;
97 }
98 
99 
100 void
102  if (myDeparted < 0) {
103  myDeparted = now;
104  }
105 }
106 
107 void
108 MSTransportable::Stage::setArrived(MSNet* /* net */, MSTransportable* /* transportable */, SUMOTime now) {
109  myArrived = now;
110 }
111 
112 bool
113 MSTransportable::Stage::isWaitingFor(const std::string& /*line*/) const {
114  return false;
115 }
116 
117 Position
118 MSTransportable::Stage::getEdgePosition(const MSEdge* e, double at, double offset) const {
119  return getLanePosition(e->getLanes()[0], at, offset);
120 }
121 
122 Position
123 MSTransportable::Stage::getLanePosition(const MSLane* lane, double at, double offset) const {
124  return lane->getShape().positionAtOffset(lane->interpolateLanePosToGeometryPos(at), offset);
125 }
126 
127 double
128 MSTransportable::Stage::getEdgeAngle(const MSEdge* e, double at) const {
129  return e->getLanes()[0]->getShape().rotationAtOffset(at);
130 }
131 
132 
133 /* -------------------------------------------------------------------------
134 * MSTransportable::Stage_Trip - methods
135 * ----------------------------------------------------------------------- */
136 MSTransportable::Stage_Trip::Stage_Trip(const MSEdge* origin, const MSEdge* destination, MSStoppingPlace* toStop, const SUMOTime duration, const SVCPermissions modeSet,
137  const std::string& vTypes, const double speed, const double walkFactor, const double departPosLat, const bool hasArrivalPos, const double arrivalPos) :
138  MSTransportable::Stage(destination, toStop, arrivalPos, TRIP),
139  myOrigin(origin),
140  myDuration(duration),
141  myModeSet(modeSet),
142  myVTypes(vTypes),
143  mySpeed(speed),
144  myWalkFactor(walkFactor),
145  myDepartPosLat(departPosLat),
146  myHaveArrivalPos(hasArrivalPos) {
147 }
148 
149 
151 
152 
153 Position
155  throw ProcessError("Should not get here!");
156 }
157 
158 
159 double
161  throw ProcessError("Should not get here!");
162 }
163 
164 
165 const MSEdge*
167  return myOrigin;
168 }
169 
170 
171 double
173  return myDepartPos;
174 }
175 
176 
177 void
179  MSTransportable::Stage::setArrived(net, transportable, now);
180  MSVehicleControl& vehControl = net->getVehicleControl();
181  std::vector<SUMOVehicleParameter*> pars;
182  for (StringTokenizer st(myVTypes); st.hasNext();) {
183  pars.push_back(new SUMOVehicleParameter());
184  pars.back()->vtypeid = st.next();
185  pars.back()->parametersSet |= VEHPARS_VTYPE_SET;
186  pars.back()->departProcedure = DEPART_TRIGGERED;
187  pars.back()->id = transportable->getID() + "_" + toString(pars.size() - 1);
188  }
189  if (pars.empty()) {
190  if ((myModeSet & SVC_PASSENGER) != 0) {
191  pars.push_back(new SUMOVehicleParameter());
192  pars.back()->id = transportable->getID() + "_0";
193  pars.back()->departProcedure = DEPART_TRIGGERED;
194  } else if ((myModeSet & SVC_BICYCLE) != 0) {
195  pars.push_back(new SUMOVehicleParameter());
196  pars.back()->vtypeid = DEFAULT_BIKETYPE_ID;
197  pars.back()->id = transportable->getID() + "_b0";
198  pars.back()->departProcedure = DEPART_TRIGGERED;
199  } else {
200  // allow shortcut via busStop even when not intending to ride
201  pars.push_back(nullptr);
202  }
203  }
204  MSTransportable::Stage* previous;
205  if (transportable->getNumStages() == transportable->getNumRemainingStages()) { // this is a difficult way to check that we are the first stage
206  myDepartPos = transportable->getParameter().departPos;
207  if (transportable->getParameter().departPosProcedure == DEPART_POS_RANDOM) {
209  }
210  previous = new MSTransportable::Stage_Waiting(myOrigin, -1, transportable->getParameter().depart, myDepartPos, "start", true);
211  } else {
212  previous = transportable->getNextStage(-1);
213  myDepartPos = previous->getArrivalPos();
214  }
215  // TODO This works currently only for a single vehicle type
216  for (SUMOVehicleParameter* vehPar : pars) {
217  SUMOVehicle* vehicle = nullptr;
218  if (vehPar != nullptr) {
219  MSVehicleType* type = vehControl.getVType(vehPar->vtypeid);
220  if (type->getVehicleClass() != SVC_IGNORING && (myOrigin->getPermissions() & type->getVehicleClass()) == 0) {
221  WRITE_WARNING("Ignoring vehicle type '" + type->getID() + "' when routing person '" + transportable->getID() + "' because it is not allowed on the start edge.");
222  } else {
223  const MSRoute* const routeDummy = new MSRoute(vehPar->id, ConstMSEdgeVector({ myOrigin }), false, nullptr, std::vector<SUMOVehicleParameter::Stop>());
224  vehicle = vehControl.buildVehicle(vehPar, routeDummy, type, !MSGlobals::gCheckRoutes);
225  }
226  }
227  bool carUsed = false;
228  std::vector<MSNet::MSIntermodalRouter::TripItem> result;
229  int stageIndex = 1;
230  if (net->getIntermodalRouter().compute(myOrigin, myDestination, previous->getArrivalPos(), myArrivalPos, myDestinationStop == nullptr ? "" : myDestinationStop->getID(),
231  transportable->getVehicleType().getMaxSpeed() * myWalkFactor, vehicle, myModeSet, transportable->getParameter().depart, result)) {
232  for (std::vector<MSNet::MSIntermodalRouter::TripItem>::iterator it = result.begin(); it != result.end(); ++it) {
233  if (!it->edges.empty()) {
235  double localArrivalPos = bs != nullptr ? bs->getAccessPos(it->edges.back()) : it->edges.back()->getLength() / 2.;
236  if (it + 1 == result.end() && myHaveArrivalPos) {
237  localArrivalPos = myArrivalPos;
238  }
239  if (it->line == "") {
240  double depPos = previous->getArrivalPos();
241  if (previous->getDestinationStop() != nullptr) {
242  depPos = previous->getDestinationStop()->getAccessPos(it->edges.front());
243  } else if (previous->getEdge() != it->edges.front()) {
244 // if (previous->getEdge()->getToJunction() == it->edges.front()->getToJunction()) {
245 // depPos = it->edges.front()->getLength();
246 // } else {
247  depPos = 0.;
248 // }
249  }
250  previous = new MSPerson::MSPersonStage_Walking(transportable->getID(), it->edges, bs, myDuration, mySpeed, depPos, localArrivalPos, myDepartPosLat);
251  transportable->appendStage(previous, stageIndex++);
252  } else if (vehicle != nullptr && it->line == vehicle->getID()) {
253  if (bs == nullptr && it + 1 != result.end()) {
254  // we have no defined endpoint and are in the middle of the trip, drive as far as possible
255  localArrivalPos = it->edges.back()->getLength();
256  }
257  previous = new MSPerson::MSPersonStage_Driving(it->edges.back(), bs, localArrivalPos, std::vector<std::string>({ it->line }));
258  transportable->appendStage(previous, stageIndex++);
259  vehicle->replaceRouteEdges(it->edges, -1, 0, "person:" + transportable->getID(), true);
260  vehicle->setArrivalPos(localArrivalPos);
261  vehControl.addVehicle(vehPar->id, vehicle);
262  carUsed = true;
263  } else {
264  previous = new MSPerson::MSPersonStage_Driving(it->edges.back(), bs, localArrivalPos, std::vector<std::string>({ it->line }), it->intended, TIME2STEPS(it->depart));
265  transportable->appendStage(previous, stageIndex++);
266  }
267  }
268  }
269  } else {
271  const std::string error = "No connection found between '" + myOrigin->getID() + "' and '" + (myDestinationStop != nullptr ? myDestinationStop->getID() : myDestination->getID()) + "' for person '" + transportable->getID() + "'.";
272  throw ProcessError(error);
273  } else {
274  // pedestrian will teleport
275  transportable->appendStage(new MSPerson::MSPersonStage_Walking(transportable->getID(), ConstMSEdgeVector({ myOrigin, myDestination }), myDestinationStop, myDuration, mySpeed, previous->getArrivalPos(), myArrivalPos, myDepartPosLat), stageIndex++);
276  }
277  }
278  if (vehicle != nullptr && !carUsed) {
279  vehControl.deleteVehicle(vehicle, true);
280  }
281  }
282 }
283 
284 
285 void
286 MSTransportable::Stage_Trip::proceed(MSNet* net, MSTransportable* transportable, SUMOTime now, Stage* /* previous */) {
287  // just skip the stage, every interesting happens in setArrived
288  transportable->proceed(net, now);
289 }
290 
291 
292 void
294 }
295 
296 
297 void
298 MSTransportable::Stage_Trip::routeOutput(OutputDevice&, const bool /* withRouteLength */) const {
299 }
300 
301 
302 void
304 }
305 
306 
307 void
309 }
310 
311 
312 std::string
314  return "trip from '" + myOrigin->getID() + "' to '" + getDestination()->getID() + "'";
315 }
316 
317 
318 /* -------------------------------------------------------------------------
319 * MSTransportable::Stage_Waiting - methods
320 * ----------------------------------------------------------------------- */
322  SUMOTime duration, SUMOTime until, double pos, const std::string& actType,
323  const bool initial) :
324  MSTransportable::Stage(destination, nullptr, SUMOVehicleParameter::interpretEdgePos(
325  pos, destination->getLength(), SUMO_ATTR_DEPARTPOS, "stopping at " + destination->getID()),
326  initial ? WAITING_FOR_DEPART : WAITING),
327  myWaitingDuration(duration),
328  myWaitingUntil(until),
329  myActType(actType) {
330 }
331 
332 
334 
335 
336 SUMOTime
338  return myWaitingUntil;
339 }
340 
341 
342 Position
345  ROADSIDE_OFFSET * (MSNet::getInstance()->lefthand() ? -1 : 1));
346 }
347 
348 
349 double
351  return getEdgeAngle(myDestination, myArrivalPos) + M_PI / 2 * (MSNet::getInstance()->lefthand() ? -1 : 1);
352 }
353 
354 
355 void
357  myDeparted = now;
358  const SUMOTime until = MAX3(now, now + myWaitingDuration, myWaitingUntil);
359  if (dynamic_cast<MSPerson*>(transportable) != nullptr) {
360  previous->getEdge()->addPerson(transportable);
361  net->getPersonControl().setWaitEnd(until, transportable);
362  } else {
363  previous->getEdge()->addContainer(transportable);
364  net->getContainerControl().setWaitEnd(until, transportable);
365  }
366 }
367 
368 
369 void
371  if (myType != WAITING_FOR_DEPART) {
372  os.openTag("stop");
373  os.writeAttr("duration", time2string(myArrived - myDeparted));
374  os.writeAttr("arrival", time2string(myArrived));
375  os.writeAttr("arrivalPos", toString(myArrivalPos));
376  os.writeAttr("actType", toString(myActType));
377  os.closeTag();
378  }
379 }
380 
381 
382 void
383 MSTransportable::Stage_Waiting::routeOutput(OutputDevice& os, const bool /* withRouteLength */) const {
384  if (myType != WAITING_FOR_DEPART) {
385  // lane index is arbitrary
386  os.openTag("stop").writeAttr(SUMO_ATTR_LANE, getDestination()->getID() + "_0");
387  if (myWaitingDuration >= 0) {
389  }
390  if (myWaitingUntil >= 0) {
392  }
393  os.closeTag();
394  }
395 }
396 
397 
398 void
400  os.openTag("event").writeAttr("time", time2string(t)).writeAttr("type", "actstart " + myActType)
401  .writeAttr("agent", p.getID()).writeAttr("link", getEdge()->getID()).closeTag();
402 }
403 
404 
405 void
407  os.openTag("event").writeAttr("time", time2string(t)).writeAttr("type", "actend " + myActType).writeAttr("agent", p.getID())
408  .writeAttr("link", getEdge()->getID()).closeTag();
409 }
410 
411 
412 SUMOTime
414  return now - myDeparted;
415 }
416 
417 
418 void
420  MSTransportableControl& tc = (dynamic_cast<MSPerson*>(t) != nullptr ?
423  tc.abortWaiting(t);
424 }
425 
426 
427 std::string
429  std::string timeInfo;
430  if (myWaitingUntil >= 0) {
431  timeInfo += " until " + time2string(myWaitingUntil);
432  }
433  if (myWaitingDuration >= 0) {
434  timeInfo += " duration " + time2string(myWaitingDuration);
435  }
436  return "stopping at edge '" + getDestination()->getID() + "' " + timeInfo + " (" + myActType + ")";
437 }
438 
439 
440 /* -------------------------------------------------------------------------
441 * MSTransportable::Stage_Driving - methods
442 * ----------------------------------------------------------------------- */
444  MSStoppingPlace* toStop, const double arrivalPos, const std::vector<std::string>& lines,
445  const std::string& intendedVeh, SUMOTime intendedDepart) :
446  MSTransportable::Stage(destination, toStop, arrivalPos, DRIVING),
447  myLines(lines.begin(), lines.end()),
448  myVehicle(nullptr),
449  myVehicleID("NULL"),
450  myVehicleDistance(-1.),
451  myWaitingEdge(nullptr),
452  myStopWaitPos(Position::INVALID),
453  myIntendedVehicleID(intendedVeh),
454  myIntendedDepart(intendedDepart) {
455 }
456 
457 
459 
460 const MSEdge*
462  if (myVehicle != nullptr) {
463  if (myVehicle->getLane() != nullptr) {
464  return &myVehicle->getLane()->getEdge();
465  }
466  return myVehicle->getEdge();
467  }
468  return myWaitingEdge;
469 }
470 
471 
472 const MSEdge*
474  return myWaitingEdge;
475 }
476 
477 
478 double
480  if (isWaiting4Vehicle()) {
481  return myWaitingPos;
482  }
483  // vehicle may already have passed the lane (check whether this is correct)
485 }
486 
487 
488 Position
490  if (isWaiting4Vehicle()) {
492  return myStopWaitPos;
493  }
495  ROADSIDE_OFFSET * (MSNet::getInstance()->lefthand() ? -1 : 1));
496  }
497  return myVehicle->getPosition();
498 }
499 
500 
501 double
503  if (!isWaiting4Vehicle()) {
504  MSVehicle* veh = dynamic_cast<MSVehicle*>(myVehicle);
505  if (veh != nullptr) {
506  return veh->getAngle();
507  } else {
508  return 0;
509  }
510  }
511  return getEdgeAngle(myWaitingEdge, myWaitingPos) + M_PI / 2. * (MSNet::getInstance()->lefthand() ? -1 : 1);
512 }
513 
514 
515 bool
516 MSTransportable::Stage_Driving::isWaitingFor(const std::string& line) const {
517  return myLines.count(line) > 0;
518 }
519 
520 
521 bool
523  return myVehicle == nullptr;
524 }
525 
526 
527 SUMOTime
529  return isWaiting4Vehicle() ? now - myWaitingSince : 0;
530 }
531 
532 
533 double
535  return isWaiting4Vehicle() ? 0 : myVehicle->getSpeed();
536 }
537 
538 
541  ConstMSEdgeVector result;
542  result.push_back(getFromEdge());
543  result.push_back(getDestination());
544  return result;
545 }
546 
547 void
549  MSTransportable::Stage::setArrived(net, transportable, now);
550  if (myVehicle != nullptr) {
551  // distance was previously set to driven distance upon embarking
555  if (myVehicle->isStopped()) {
557  }
558  } else {
559  myVehicleDistance = -1.;
560  }
561 }
562 
563 void
565  myVehicle = v;
566  myVehicleID = v->getID();
568  myVehicleVClass = v->getVClass();
572 }
573 
574 void
576  myDestination = newDestination;
577  myDestinationStop = newDestStop;
578  if (newDestStop != nullptr) {
579  myArrivalPos = (newDestStop->getBeginLanePosition() + newDestStop->getEndLanePosition()) / 2;
580  }
581 }
582 
583 
584 void
586  if (myVehicle != nullptr) {
587  // jumping out of a moving vehicle!
588  dynamic_cast<MSVehicle*>(myVehicle)->removeTransportable(t);
589  }
590 }
591 
592 
593 std::string
595  return isWaiting4Vehicle() ? ("waiting for " + joinToString(myLines, ",")
596  + " at " + (myDestinationStop == nullptr
597  ? ("edge '" + myWaitingEdge->getID() + "'")
598  : ("busStop '" + myDestinationStop->getID() + "'"))
599  ) : "";
600 }
601 
602 
603 void
605  os.openTag("event").writeAttr("time", time2string(t)).writeAttr("type", "arrival").writeAttr("agent", p.getID()).writeAttr("link", getEdge()->getID()).closeTag();
606 }
607 
608 
609 void
611  os.openTag("event").writeAttr("time", time2string(t)).writeAttr("type", "arrival").writeAttr("agent", p.getID()).writeAttr("link", getEdge()->getID()).closeTag();
612 }
613 
614 
615 
616 /* -------------------------------------------------------------------------
617  * MSTransportable - methods
618  * ----------------------------------------------------------------------- */
620  : myParameter(pars), myVType(vtype), myPlan(plan) {
621  myStep = myPlan->begin();
622 }
623 
624 
626  if (myPlan != nullptr) {
627  for (MSTransportablePlan::const_iterator i = myPlan->begin(); i != myPlan->end(); ++i) {
628  delete *i;
629  }
630  delete myPlan;
631  myPlan = nullptr;
632  }
633  delete myParameter;
634  if (myVType->isVehicleSpecific()) {
636  }
637 }
638 
639 const std::string&
641  return myParameter->id;
642 }
643 
644 SUMOTime
646  return myParameter->depart;
647 }
648 
649 void
651  (*myStep)->setDeparted(now);
652 }
653 
654 double
656  return (*myStep)->getEdgePos(MSNet::getInstance()->getCurrentTimeStep());
657 }
658 
659 Position
661  return (*myStep)->getPosition(MSNet::getInstance()->getCurrentTimeStep());
662 }
663 
664 double
666  return (*myStep)->getAngle(MSNet::getInstance()->getCurrentTimeStep());
667 }
668 
669 double
671  return STEPS2TIME((*myStep)->getWaitingTime(MSNet::getInstance()->getCurrentTimeStep()));
672 }
673 
674 double
676  return (*myStep)->getSpeed();
677 }
678 
679 
680 int
682  return (int)(myPlan->end() - myStep);
683 }
684 
685 int
687  return (int)myPlan->size();
688 }
689 
690 void
692  // myStep is invalidated upon modifying myPlan
693  const int stepIndex = (int)(myStep - myPlan->begin());
694  if (next < 0) {
695  myPlan->push_back(stage);
696  } else {
697  if (stepIndex + next > (int)myPlan->size()) {
698  throw ProcessError("invalid index '" + toString(next) + "' for inserting new stage into plan of '" + getID() + "'");
699  }
700  myPlan->insert(myPlan->begin() + stepIndex + next, stage);
701  }
702  myStep = myPlan->begin() + stepIndex;
703 }
704 
705 
706 void
708  assert(myStep + next < myPlan->end());
709  assert(next >= 0);
710  if (next > 0) {
711  // myStep is invalidated upon modifying myPlan
712  int stepIndex = (int)(myStep - myPlan->begin());
713  delete *(myStep + next);
714  myPlan->erase(myStep + next);
715  myStep = myPlan->begin() + stepIndex;
716  } else {
717  if (myStep + 1 == myPlan->end()) {
718  // stay in the simulation until the start of simStep to allow appending new stages (at the correct position)
719  appendStage(new Stage_Waiting(getEdge(), 0, 0, getEdgePos(), "last stage removed", false));
720  }
721  (*myStep)->abort(this);
722  proceed(MSNet::getInstance(), MSNet::getInstance()->getCurrentTimeStep());
723  }
724 }
725 
726 
727 void
729  for (MSTransportablePlan::const_iterator i = myPlan->begin(); i != myPlan->end(); ++i) {
730  (*i)->setSpeed(speed);
731  }
732 }
733 
734 
735 void
737  if (myVType->isVehicleSpecific()) {
739  }
740  myVType = type;
741 }
742 
743 
746  if (myVType->isVehicleSpecific()) {
747  return *myVType;
748  }
749  MSVehicleType* type = myVType->buildSingularType(myVType->getID() + "@" + getID());
750  replaceVehicleType(type);
751  return *type;
752 }
753 
754 
757  PositionVector centerLine;
758  const Position p = getPosition();
759  const double angle = getAngle();
760  const double length = getVehicleType().getLength();
761  const Position back = p + Position(-cos(angle) * length, -sin(angle) * length);
762  centerLine.push_back(p);
763  centerLine.push_back(back);
764  centerLine.move2side(0.5 * getVehicleType().getWidth());
765  PositionVector result = centerLine;
766  centerLine.move2side(-getVehicleType().getWidth());
767  result.append(centerLine.reverse(), POSITION_EPS);
768  //std::cout << " transp=" << getID() << " p=" << p << " angle=" << GeomHelper::naviDegree(angle) << " back=" << back << " result=" << result << "\n";
769  return result;
770 }
771 
772 
773 std::string
774 MSTransportable::getStageSummary(int stageIndex) const {
775  assert(stageIndex < (int)myPlan->size());
776  assert(stageIndex >= 0);
777  return (*myPlan)[stageIndex]->getStageSummary();
778 }
779 
780 
781 bool
783  return myStep == myPlan->end();
784 }
785 
786 
787 void
789  // check whether the transportable was riding to the orignal stop
790  // @note: parkingArea can currently not be set as myDestinationStop so we
791  // check for stops on the edge instead
792  assert(getCurrentStageType() == DRIVING);
793  if (getDestination() == &orig->getLane().getEdge()) {
794  Stage_Driving* stage = dynamic_cast<Stage_Driving*>(*myStep);
795  assert(stage != 0);
796  assert(stage->getVehicle() != 0);
797  // adapt plan
798  stage->setDestination(&replacement->getLane().getEdge(), replacement);
799  if (myStep + 1 == myPlan->end()) {
800  return;
801  }
802  // if the next step is a walk, adapt the route
803  // TODO Should we also reroute when the walk has a fixed edge list or only trips?
804  Stage* nextStage = *(myStep + 1);
805  if (nextStage->getStageType() == TRIP) {
806  dynamic_cast<MSTransportable::Stage_Trip*>(nextStage)->setOrigin(stage->getDestination());
807  }
808  }
809 }
810 
811 
812 /****************************************************************************/
virtual void beginEventOutput(const MSTransportable &p, SUMOTime t, OutputDevice &os) const
Called for writing the events output.
The departure is person triggered.
void abortWaiting(MSTransportable *t)
aborts waiting stage of transportable
bool compute(const E *from, const E *to, const double departPos, const double arrivalPos, const std::string stopID, const double speed, const V *const vehicle, const SVCPermissions modeSet, const SUMOTime msTime, std::vector< TripItem > &into, const double externalFactor=0.)
Builds the route between the given edges using the minimum effort at the given time The definition of...
virtual void proceed(MSNet *net, MSTransportable *transportable, SUMOTime now, Stage *previous)
proceeds to the next step
double getAccessPos(const MSEdge *edge) const
the position on the given edge which is connected to this stop, -1 on failure
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:256
void abort(MSTransportable *)
abort this stage (TraCI)
virtual void proceed(MSNet *net, MSTransportable *transportable, SUMOTime now, Stage *previous)
proceeds to the next step
Stage(const MSEdge *destination, MSStoppingPlace *toStop, const double arrivalPos, StageType type)
constructor
std::string getStageSummary() const
return string summary of the current stage
Stage_Waiting(const MSEdge *destination, SUMOTime duration, SUMOTime until, double pos, const std::string &actType, const bool initial)
constructor
MSEdge & getEdge() const
Returns the lane&#39;s edge.
Definition: MSLane.h:640
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:79
virtual void deleteVehicle(SUMOVehicle *v, bool discard=false)
Deletes the vehicle.
long long int SUMOTime
Definition: SUMOTime.h:36
double getBeginLanePosition() const
Returns the begin position of this stop.
std::string getWaitingDescription() const
Return where the person waits and for what.
std::string myActType
The type of activity.
double getAngle(SUMOTime now) const
returns the angle of the transportable
double getAngle() const
Returns the vehicle&#39;s direction in radians.
Definition: MSVehicle.h:685
virtual const MSEdge * getFromEdge() const
void append(const PositionVector &v, double sameThreshold=2.0)
virtual void setArrived(MSNet *net, MSTransportable *transportable, SUMOTime now)
logs end of the step
const MSEdge * getEdge() const
Returns the current edge.
const SVCPermissions myModeSet
The allowed modes of transportation.
MSStoppingPlace * getStoppingPlace(const std::string &id, const SumoXMLTag category) const
Returns the named stopping place of the given category.
Definition: MSNet.cpp:869
virtual const MSRoute & getRoute() const =0
Returns the current route.
A lane area vehicles can halt at.
void setSpeed(double speed)
sets the walking speed (ignored in other stages)
virtual double getEdgePos() const
Return the position on the edge.
double getAngle(SUMOTime now) const
returns the angle of the transportable
bool hasArrived() const
return whether the person has reached the end of its plan
PositionVector getBoundingBox() const
return the bounding box of the person
virtual bool isWaitingFor(const std::string &line) const
Whether the transportable waits for a vehicle of the line specified.
const MSEdge * getDestination() const
returns the destination edge
vehicle is a bicycle
void abort(MSTransportable *)
abort this stage (TraCI)
virtual const MSEdge * getEdge() const
Returns the current edge.
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
const MSEdge * getEdge() const
Returns the current edge.
virtual double getEdgePos(SUMOTime now) const
static double rand(std::mt19937 *rng=0)
Returns a random real number in [0, 1)
Definition: RandHelper.h:61
virtual const MSEdge * getEdge() const =0
Returns the edge the vehicle is currently at.
#define INVALID
virtual void beginEventOutput(const MSTransportable &p, SUMOTime t, OutputDevice &os) const
Called for writing the events output.
MSIntermodalRouter & getIntermodalRouter(const int routingMode=0, const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:944
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:65
void setWaitEnd(SUMOTime time, MSTransportable *transportable)
sets the arrival time for a waiting transportable
ConstMSEdgeVector getEdges() const
the edges of the current stage
virtual MSLane * getLane() const =0
Returns the lane the vehicle is on.
Position getPosition(SUMOTime now) const
returns the position of the transportable
double getEdgePos(SUMOTime now) const
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:162
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:165
const PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:456
const std::set< std::string > myLines
the lines to choose from
double getSpeed() const
the speed of the transportable
PositionVector reverse() const
reverse position vector
const std::string DEFAULT_BIKETYPE_ID
virtual bool addVehicle(const std::string &id, SUMOVehicle *v)
Tries to insert the vehicle into the internal vehicle container.
virtual void beginEventOutput(const MSTransportable &p, SUMOTime t, OutputDevice &os) const
Called for writing the events output.
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:72
virtual bool proceed(MSNet *net, SUMOTime time)=0
SUMOTime myDuration
the time the trip should take (applies to only walking)
const std::string & getID() const
Returns the id.
Definition: Named.h:78
#define TIME2STEPS(x)
Definition: SUMOTime.h:60
Position getLanePosition(const MSLane *lane, double at, double offset) const
get position on lane at length at with orthogonal offset
virtual double getSpeed() const
the current speed of the transportable
const MSEdge * myDestination
the next edge to reach by getting transported
MSStoppingPlace * myDestinationStop
the stop to reach by getting transported (if any)
const SUMOVehicleParameter & getParameter() const
MSTransportablePlan::iterator myStep
the iterator over the route
double getEdgePos(SUMOTime now) const
double getLength() const
return the length of the edge
Definition: MSEdge.h:568
The position is chosen randomly.
const MSEdge * getFromEdge() const
int getNumRemainingStages() const
Return the number of remaining stages (including the current)
T MAX3(T a, T b, T c)
Definition: StdDefs.h:90
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:241
The simulated network and simulation perfomer.
Definition: MSNet.h:84
The car-following model and parameter.
Definition: MSVehicleType.h:66
bool isVehicleSpecific() const
Returns whether this type belongs to a single vehicle only (was modified)
void setArrived(MSNet *net, MSTransportable *transportable, SUMOTime now)
marks arrival time and records driven distance
Stage_Trip(const MSEdge *origin, const MSEdge *destination, MSStoppingPlace *toStop, const SUMOTime duration, const SVCPermissions modeSet, const std::string &vTypes, const double speed, const double walkFactor, const double departPosLat, const bool hasArrivalPos, const double arrivalPos)
constructor
virtual MSTransportableControl & getContainerControl()
Returns the container control.
Definition: MSNet.cpp:784
const SUMOVehicleParameter * myParameter
the plan of the transportable
void removeStage(int next)
removes the nth next stage
std::string getStageSummary() const
return string summary of the current stage
bool isWaiting4Vehicle() const
Whether the person waits for a vehicle.
SUMOTime myWaitingSince
The time since which this person is waiting for a ride.
MSVehicleType & getSingularType()
Replaces the current vehicle type with a new one used by this vehicle only.
A road/street connecting two junctions.
Definition: MSEdge.h:75
double myDepartPos
The depart position.
const double myWalkFactor
The factor to apply to walking durations.
std::vector< MSTransportable::Stage * > MSTransportablePlan
the structure holding the plan of a transportable
double getEndLanePosition() const
Returns the end position of this stop.
virtual SUMOVehicleClass getVClass() const =0
Returns the vehicle&#39;s access class.
virtual ConstMSEdgeVector getEdges() const
the edges of the current stage
MSTransportable::Stage * getNextStage(int next) const
Return the current stage.
virtual SUMOTime getWaitingTime(SUMOTime now) const
the time this transportable spent waiting
MSVehicleType * myVType
This transportable&#39;s type. (mainly used for drawing related information Note sure if it is really nec...
SUMOTime myArrived
the time at which this stage ended
virtual void setArrived(MSNet *net, MSTransportable *transportable, SUMOTime now)
logs end of the step
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
SUMOTime myDeparted
the time at which this stage started
void setDeparted(SUMOTime now)
logs depart time of the current stage
Representation of a vehicle.
Definition: SUMOVehicle.h:60
static bool gCheckRoutes
Definition: MSGlobals.h:79
DepartPosDefinition departPosProcedure
Information how the vehicle shall choose the departure position.
MSVehicleType * buildSingularType(const std::string &id) const
Duplicates the microsim vehicle type giving the newly created type the given id, marking it as vehicl...
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:776
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
SUMOTime getDesiredDepart() const
Returns the desired departure time.
A list of positions.
Position getPosition(SUMOTime now) const
returns the position of the transportable
virtual double getAngle() const
return the current angle of the transportable
virtual void addPerson(MSTransportable *p) const
Definition: MSEdge.h:595
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:316
virtual ~Stage_Trip()
destructor
void removeVType(const MSVehicleType *vehType)
virtual ~MSTransportable()
destructor
SUMOTime getWaitingTime(SUMOTime now) const
time spent waiting for a ride
SUMOTime depart
The vehicle&#39;s departure time.
#define STEPS2TIME(x)
Definition: SUMOTime.h:58
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:263
double getArrivalPos() const
double getMaxSpeed() const
Get vehicle&#39;s maximum speed [m/s].
T MIN2(T a, T b)
Definition: StdDefs.h:70
std::string myVehicleID
cached vehicle data for output after the vehicle has been removed
#define POSITION_EPS
Definition: config.h:172
const std::string & getID() const
returns the id of the transportable
void setDestination(const MSEdge *newDestination, MSStoppingPlace *newDestStop)
const double mySpeed
The walking speed.
virtual ~Stage_Driving()
destructor
SUMOTime myWaitingUntil
the time until the person is waiting
SUMOVehicle * myVehicle
The taken vehicle.
Position getPosition(SUMOTime now) const
returns the position of the transportable
std::string getStageSummary(int stageIndex) const
return textual summary for the given stage
virtual void endEventOutput(const MSTransportable &p, SUMOTime t, OutputDevice &os) const
Called for writing the events output (end of an action)
bool lefthand() const
return whether the network was built for lefthand traffic
Definition: MSNet.h:615
void move2side(double amount)
move position vector to side using certain ammount
vehicle is a passenger car (a "normal" car)
std::string line
The vehicle&#39;s line (mainly for public transport)
Position getEdgePosition(const MSEdge *e, double at, double offset) const
get position on edge e at length at with orthogonal offset
virtual void endEventOutput(const MSTransportable &p, SUMOTime t, OutputDevice &os) const
Called for writing the events output (end of an action)
MSVehicleType * getVType(const std::string &id=DEFAULT_VTYPE_ID, std::mt19937 *rng=0)
Returns the named vehicle type or a sample from the named distribution.
virtual double getSpeed() const
the speed of the transportable
MSStoppingPlace * getDestinationStop() const
returns the destination stop (if any)
void appendStage(Stage *stage, int next=-1)
Appends the given stage to the current plan.
virtual double getDepartPos() const =0
Returns this vehicle&#39;s real departure position.
double getAngle(SUMOTime now) const
returns the angle of the transportable
void rerouteParkingArea(MSStoppingPlace *orig, MSStoppingPlace *replacement)
adapt plan when the vehicle reroutes and now stops at replacement instead of orig ...
double departPos
(optional) The position the vehicle shall depart from
StageType myType
The type of this stage.
virtual void tripInfoOutput(OutputDevice &os, const MSTransportable *const transportable) const
Called on writing tripinfo output.
Structure representing possible vehicle parameter.
MSTransportable(const SUMOVehicleParameter *pars, MSVehicleType *vtype, MSTransportablePlan *plan)
constructor
virtual void addContainer(MSTransportable *container) const
Add a container to myContainers.
Definition: MSEdge.h:607
#define M_PI
Definition: odrSpiral.cpp:40
virtual Position getPosition() const
Return the Network coordinate of the transportable.
Stage_Driving(const MSEdge *destination, MSStoppingPlace *toStop, const double arrivalPos, const std::vector< std::string > &lines, const std::string &intendedVeh="", SUMOTime intendedDepart=-1)
constructor
virtual double getPositionOnLane() const =0
Get the vehicle&#39;s position along the lane.
virtual const SUMOVehicleParameter & getParameter() const =0
Returns the vehicle&#39;s parameter (including departure definition)
virtual void endEventOutput(const MSTransportable &p, SUMOTime t, OutputDevice &os) const
Called for writing the events output (end of an action)
SUMOVehicle * getVehicle() const
Whether the transportable waits for a vehicle.
StageType getStageType() const
double interpolateLanePosToGeometryPos(double lanePos) const
Definition: MSLane.h:472
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:94
virtual void tripInfoOutput(OutputDevice &os, const MSTransportable *const transportable) const
Called on writing tripinfo output.
virtual void routeOutput(OutputDevice &os, const bool withRouteLength) const
Called on writing vehroute output.
static const double ROADSIDE_OFFSET
the offset for computing positions when standing at an edge
const MSEdge * myOrigin
the origin edge
void replaceVehicleType(MSVehicleType *type)
Replaces the current vehicle type by the one given.
virtual Position getPosition(const double offset=0) const =0
Return current position (x/y, cartesian)
double getLength() const
Get vehicle&#39;s length [m].
SUMOTime getWaitingTime(SUMOTime now) const
the time this transportable spent waiting
const std::string myVTypes
The possible vehicles to use.
const int VEHPARS_VTYPE_SET
double getEdgeAngle(const MSEdge *e, double at) const
get angle of the edge at a certain position
const MSVehicleType & getVehicleType() const
virtual double getWaitingSeconds() const
the time this transportable spent waiting in seconds
virtual bool isStopped() const =0
Returns whether the vehicle is at a stop.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
void setDeparted(SUMOTime now)
logs end of the step
const double myDepartPosLat
The lateral depart position.
const MSEdge * getDestination() const
Returns the current destination.
MSTransportablePlan * myPlan
the plan of the transportable
virtual ~Stage_Waiting()
destructor
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:70
The class responsible for building and deletion of vehicles.
SVCPermissions getPermissions() const
Definition: MSEdge.h:532
virtual ~Stage()
destructor
const bool myHaveArrivalPos
whether an arrivalPos was in the input
virtual SUMOVehicle * buildVehicle(SUMOVehicleParameter *defs, const MSRoute *route, MSVehicleType *type, const bool ignoreStopErrors, const bool fromRouteFile=true)
Builds a vehicle, increases the number of built vehicles.
const MSLane & getLane() const
Returns the lane this stop is located at.
virtual const ConstMSEdgeVector::const_iterator & getCurrentRouteEdge() const =0
Returns an iterator pointing to the current edge in this vehicles route.
const MSEdge * getEdge() const
Returns the current edge.
virtual void routeOutput(OutputDevice &os, const bool withRouteLength) const
Called on writing vehroute output.
bool isWaitingFor(const std::string &line) const
Whether the person waits for a vehicle of the line specified.
virtual double getSpeed() const =0
Returns the vehicle&#39;s current speed.
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
Representation of a lane in the micro simulation.
Definition: MSLane.h:78
virtual const std::string & getID() const =0
Get the vehicle&#39;s ID.
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition: ToString.h:237
vehicles ignoring classes
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
SUMOVehicleClass getVehicleClass() const
Get this vehicle type&#39;s vehicle class.
SUMOTime myWaitingDuration
the time the person is waiting
int getNumStages() const
Return the total number stages in this persons plan.
std::string id
The vehicle&#39;s id.
static const Position INVALID
used to indicate that a position is valid
Definition: Position.h:285
double myArrivalPos
the position at which we want to arrive
StageType getCurrentStageType() const
the current stage type of the transportable
double getDistanceBetween(double fromPos, double toPos, const MSEdge *fromEdge, const MSEdge *toEdge, bool includeInternal=true, int routePosition=0) const
Compute the distance between 2 given edges on this route, including the length of internal lanes...
Definition: MSRoute.cpp:277