Eclipse SUMO - Simulation of Urban MObility
MSDevice_Tripinfo.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2009-2022 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 /****************************************************************************/
21 // A device which collects info on the vehicle trip
22 /****************************************************************************/
23 #include <config.h>
24 
25 #include <microsim/MSGlobals.h>
26 #include <microsim/MSNet.h>
27 #include <microsim/MSLane.h>
28 #include <microsim/MSEdge.h>
29 #include <microsim/MSVehicle.h>
31 #include <mesosim/MEVehicle.h>
35 #include "MSDevice_Vehroutes.h"
36 #include "MSDevice_Tripinfo.h"
37 
38 #define NOT_ARRIVED TIME2STEPS(-1)
39 
40 
41 // ===========================================================================
42 // static members
43 // ===========================================================================
44 std::set<const MSDevice_Tripinfo*, ComparatorNumericalIdLess> MSDevice_Tripinfo::myPendingOutput;
45 
55 
62 
67 std::vector<int> MSDevice_Tripinfo::myRideCount({0, 0});
68 std::vector<int> MSDevice_Tripinfo::myRideBusCount({0, 0});
69 std::vector<int> MSDevice_Tripinfo::myRideRailCount({0, 0});
70 std::vector<int> MSDevice_Tripinfo::myRideTaxiCount({0, 0});
71 std::vector<int> MSDevice_Tripinfo::myRideBikeCount({0, 0});
72 std::vector<int> MSDevice_Tripinfo::myRideAbortCount({0, 0});
73 std::vector<double> MSDevice_Tripinfo::myTotalRideWaitingTime({0., 0.});
74 std::vector<double> MSDevice_Tripinfo::myTotalRideRouteLength({0., 0.});
75 std::vector<SUMOTime> MSDevice_Tripinfo::myTotalRideDuration({0, 0});
76 
77 // ===========================================================================
78 // method definitions
79 // ===========================================================================
80 // ---------------------------------------------------------------------------
81 // static initialisation methods
82 // ---------------------------------------------------------------------------
83 void
85  oc.addOptionSubTopic("Tripinfo Device");
86  insertDefaultAssignmentOptions("tripinfo", "Tripinfo Device", oc);
87 }
88 
89 
90 void
91 MSDevice_Tripinfo::buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into) {
93  const bool enableByOutputOption = oc.isSet("tripinfo-output") || oc.getBool("duration-log.statistics");
94  if (equippedByDefaultAssignmentOptions(oc, "tripinfo", v, enableByOutputOption)) {
95  MSDevice_Tripinfo* device = new MSDevice_Tripinfo(v, "tripinfo_" + v.getID());
96  into.push_back(device);
97  myPendingOutput.insert(device);
98  }
99 }
100 
101 
102 // ---------------------------------------------------------------------------
103 // MSDevice_Tripinfo-methods
104 // ---------------------------------------------------------------------------
105 MSDevice_Tripinfo::MSDevice_Tripinfo(SUMOVehicle& holder, const std::string& id) :
106  MSVehicleDevice(holder, id),
107  myDepartLane(""),
108  myDepartSpeed(-1),
109  myDepartPosLat(0),
110  myWaitingTime(0),
111  myAmWaiting(false),
112  myWaitingCount(0),
113  myStoppingTime(0),
114  myParkingStarted(-1),
115  myArrivalTime(NOT_ARRIVED),
116  myArrivalLane(""),
117  myArrivalPos(-1),
118  myArrivalPosLat(0.),
119  myArrivalSpeed(-1),
120  myArrivalReason(MSMoveReminder::NOTIFICATION_ARRIVED),
121  myMesoTimeLoss(0),
122  myRouteLength(0.) {
123 }
124 
125 
127  // ensure clean up for vaporized vehicles which do not generate output
128  myPendingOutput.erase(this);
129 }
130 
131 void
133  myVehicleCount = 0;
134  myTotalRouteLength = 0;
135  myTotalSpeed = 0;
136  myTotalDuration = 0;
137  myTotalWaitingTime = 0;
138  myTotalTimeLoss = 0;
139  myTotalDepartDelay = 0;
141 
142  myBikeCount = 0;
144  myTotalBikeSpeed = 0;
148 
149  myWalkCount = 0;
153 
154  myRideCount = {0, 0};
155  myRideBusCount = {0, 0};
156  myRideRailCount = {0, 0};
157  myRideTaxiCount = {0, 0};
158  myRideBikeCount = {0, 0};
159  myRideAbortCount = {0, 0};
160  myTotalRideWaitingTime = {0., 0.};
161  myTotalRideRouteLength = {0., 0.};
162  myTotalRideDuration = {0, 0};
163 }
164 
165 bool
167  if (veh.isVehicle()) {
169  if (!myAmWaiting) {
170  myWaitingCount++;
171  myAmWaiting = true;
172  }
173  }
174  return true;
175 }
176 
177 
178 bool
180  double /*newPos*/, double newSpeed) {
181  if (veh.isStopped()) {
183  } else if (newSpeed <= SUMO_const_haltingSpeed) {
185  if (!myAmWaiting) {
186  myWaitingCount++;
187  myAmWaiting = true;
188  }
189  } else {
190  myAmWaiting = false;
191  }
192  return true;
193 }
194 
195 
196 void
198  const double /* frontOnLane */,
199  const double timeOnLane,
200  const double /* meanSpeedFrontOnLane */,
201  const double meanSpeedVehicleOnLane,
202  const double /* travelledDistanceFrontOnLane */,
203  const double /* travelledDistanceVehicleOnLane */,
204  const double /* meanLengthOnLane */) {
205 
206  // called by meso
207  const double vmax = veh.getEdge()->getVehicleMaxSpeed(&veh);
208  if (vmax > 0) {
209  myMesoTimeLoss += TIME2STEPS(timeOnLane * (vmax - meanSpeedVehicleOnLane) / vmax);
210  }
211  myWaitingTime += veh.getWaitingTime();
212 }
213 
214 void
216  if (myParkingStarted >= 0) {
218  myParkingStarted = -1;
219  }
220 }
221 
222 bool
225  if (!MSGlobals::gUseMesoSim) {
226  myDepartLane = static_cast<MSVehicle&>(veh).getLane()->getID();
227  myDepartPosLat = static_cast<MSVehicle&>(veh).getLateralPositionOnLane();
228  }
229  myDepartSpeed = veh.getSpeed();
231  } else if (reason == MSMoveReminder::NOTIFICATION_PARKING) {
232  // notifyMove is not called while parking
233  // @note insertion delay when resuming after parking is included
235  }
236  return true;
237 }
238 
239 
240 bool
242  MSMoveReminder::Notification reason, const MSLane* /* enteredLane */) {
243  if (reason >= MSMoveReminder::NOTIFICATION_ARRIVED) {
245  myArrivalReason = reason;
246  if (!MSGlobals::gUseMesoSim) {
247  myArrivalLane = static_cast<MSVehicle&>(veh).getLane()->getID();
248  myArrivalPosLat = static_cast<MSVehicle&>(veh).getLateralPositionOnLane();
249  }
250  // @note vehicle may have moved past its arrivalPos during the last step
251  // due to non-zero arrivalspeed but we consider it as arrived at the desired position
252  // However, vaporization may happen anywhere (via TraCI)
254  // vaporized
256  } else {
258  }
259  myArrivalSpeed = veh.getSpeed();
261  } else if (reason == MSMoveReminder::NOTIFICATION_PARKING) {
263  } else if (reason == NOTIFICATION_JUNCTION || reason == NOTIFICATION_TELEPORT) {
266  } else {
267  const MSLane* lane = static_cast<MSVehicle&>(veh).getLane();
268  if (lane != nullptr) {
269  myRouteLength += lane->getLength();
270  }
271  }
272  }
273  return true;
274 }
275 
276 
277 void
279  const SUMOTime timeLoss = MSGlobals::gUseMesoSim ? myMesoTimeLoss : static_cast<MSVehicle&>(myHolder).getTimeLoss();
280  const double routeLength = myRouteLength + (myArrivalTime == NOT_ARRIVED ? myHolder.getPositionOnLane() : myArrivalPos);
281  SUMOTime duration = 0;
282  if (myHolder.hasDeparted()) {
284  if (myHolder.getVClass() == SVC_BICYCLE) {
285  myBikeCount++;
286  myTotalBikeRouteLength += routeLength;
287  myTotalBikeSpeed += routeLength / STEPS2TIME(duration);
288  myTotalBikeDuration += duration;
290  myTotalBikeTimeLoss += timeLoss;
291  } else {
292  myVehicleCount++;
293  myTotalRouteLength += routeLength;
294  myTotalSpeed += routeLength / STEPS2TIME(duration);
295  myTotalDuration += duration;
297  myTotalTimeLoss += timeLoss;
298  }
300  }
301 
302  myPendingOutput.erase(this);
303  if (tripinfoOut == nullptr) {
304  return;
305  }
306  // write
307  OutputDevice& os = *tripinfoOut;
308  os.openTag("tripinfo").writeAttr("id", myHolder.getID());
309  os.writeAttr("depart", myHolder.hasDeparted() ? time2string(myHolder.getDeparture()) : "-1");
310  os.writeAttr("departLane", myDepartLane);
311  os.writeAttr("departPos", myHolder.getDepartPos());
313  os.writeAttr("departPosLat", myDepartPosLat);
314  }
315  os.writeAttr("departSpeed", myDepartSpeed);
316  SUMOTime departDelay = myHolder.getDepartDelay();
317  const SUMOVehicleParameter& param = myHolder.getParameter();
318  if (!myHolder.hasDeparted()) {
319  assert(param.depart <= SIMSTEP || param.departProcedure != DEPART_GIVEN);
320  departDelay = SIMSTEP - param.depart;
321  }
322  os.writeAttr("departDelay", time2string(departDelay));
323  os.writeAttr("arrival", time2string(myArrivalTime));
324  os.writeAttr("arrivalLane", myArrivalLane);
325  os.writeAttr("arrivalPos", myArrivalPos);
327  os.writeAttr("arrivalPosLat", myArrivalPosLat);
328  }
329  os.writeAttr("arrivalSpeed", myArrivalSpeed);
330  os.writeAttr("duration", time2string(duration));
331  os.writeAttr("routeLength", routeLength);
332  os.writeAttr("waitingTime", time2string(myWaitingTime));
333  os.writeAttr("waitingCount", myWaitingCount);
334  os.writeAttr("stopTime", time2string(myStoppingTime));
335  os.writeAttr("timeLoss", time2string(timeLoss));
336  os.writeAttr("rerouteNo", myHolder.getNumberReroutes());
337  os.writeAttr("devices", toString(myHolder.getDevices()));
338  os.writeAttr("vType", myHolder.getVehicleType().getID());
339  os.writeAttr("speedFactor", myHolder.getChosenSpeedFactor());
340  std::string vaporized;
341  switch (myArrivalReason) {
343  vaporized = "calibrator";
344  break;
346  vaporized = "gui";
347  break;
349  vaporized = "collision";
350  break;
352  vaporized = "vaporizer";
353  break;
355  vaporized = "traci";
356  break;
358  vaporized = "teleport";
359  break;
360  default:
362  (param.arrivalEdge >= 0 && myHolder.getRoutePosition() >= param.arrivalEdge)) {
363  vaporized = "";
364  } else {
365  vaporized = "end";
366  }
367  break;
368  }
369  os.writeAttr("vaporized", vaporized);
370  // cannot close tag because emission device output might follow
371 }
372 
373 
374 void
376  MSNet* net = MSNet::getInstance();
377  OutputDevice* tripinfoOut = (OptionsCont::getOptions().isSet("tripinfo-output") ?
378  &OutputDevice::getDeviceByOption("tripinfo-output") : nullptr);
381  const bool writeUndeparted = OptionsCont::getOptions().getBool("tripinfo-output.write-undeparted");
382  const SUMOTime t = net->getCurrentTimeStep();
383  while (myPendingOutput.size() > 0) {
384  const MSDevice_Tripinfo* d = *myPendingOutput.begin();
385  const bool departed = d->myHolder.hasDeparted();
386  const bool departDelayed = d->myHolder.getParameter().depart <= t;
387  if (!departed && departDelayed) {
390  }
391  if (departed || (writeUndeparted && departDelayed)) {
392  const_cast<MSDevice_Tripinfo*>(d)->updateParkingStopTime();
393  d->generateOutput(tripinfoOut);
394  if (tripinfoOut != nullptr) {
395  for (MSVehicleDevice* const dev : d->myHolder.getDevices()) {
396  if (typeid(*dev) == typeid(MSDevice_Tripinfo) || typeid(*dev) == typeid(MSDevice_Vehroutes)) {
397  // tripinfo is special and vehroute has it's own write-unfinished option
398  continue;
399  }
400  dev->generateOutput(tripinfoOut);
401  }
402  OutputDevice::getDeviceByOption("tripinfo-output").closeTag();
403  }
404  } else {
405  myPendingOutput.erase(d);
406  }
407  }
408  // unfinished persons
409  if (net->hasPersons()) {
411  while (pc.loadedBegin() != pc.loadedEnd()) {
412  pc.erase(pc.loadedBegin()->second);
413  }
414  }
415 
416 }
417 
418 
419 void
420 MSDevice_Tripinfo::addPedestrianData(double walkLength, SUMOTime walkDuration, SUMOTime walkTimeLoss) {
421  myWalkCount++;
422  myTotalWalkRouteLength += walkLength;
423  myTotalWalkDuration += walkDuration;
424  myTotalWalkTimeLoss += walkTimeLoss;
425 }
426 
427 
428 void
429 MSDevice_Tripinfo::addRideTransportData(const bool isPerson, const double distance, const SUMOTime duration,
430  const SUMOVehicleClass vClass, const std::string& line, const SUMOTime waitingTime) {
431  const int index = isPerson ? 0 : 1;
432  myRideCount[index]++;
433  if (duration > 0) {
434  myTotalRideWaitingTime[index] += waitingTime;
435  myTotalRideRouteLength[index] += distance;
436  myTotalRideDuration[index] += duration;
437  if (vClass == SVC_BICYCLE) {
438  myRideBikeCount[index]++;
439  } else if (!line.empty()) {
440  if (isRailway(vClass)) {
441  myRideRailCount[index]++;
442  } else if (vClass == SVC_TAXI) {
443  myRideTaxiCount[index]++;
444  } else {
445  // some kind of road vehicle
446  myRideBusCount[index]++;
447  }
448  }
449  } else {
450  myRideAbortCount[index]++;
451  }
452 }
453 
454 
455 std::string
457  std::ostringstream msg;
458  msg.setf(msg.fixed);
459  msg.precision(gPrecision);
460  if (myBikeCount == 0 || myVehicleCount > 0) {
461  if (myBikeCount > 0) {
462  msg << "Statistics (avg of " << myVehicleCount << "):\n";
463  } else {
464  msg << "Statistics (avg):\n";
465  }
466  msg << " RouteLength: " << getAvgRouteLength() << "\n"
467  << " Speed: " << getAvgTripSpeed() << "\n"
468  << " Duration: " << getAvgDuration() << "\n"
469  << " WaitingTime: " << getAvgWaitingTime() << "\n"
470  << " TimeLoss: " << getAvgTimeLoss() << "\n";
471  }
472  if (myBikeCount > 0) {
473  msg << "Bike Statistics (avg of " << myBikeCount << "):\n"
474  << " RouteLength: " << getAvgBikeRouteLength() << "\n"
475  << " Speed: " << getAvgBikeTripSpeed() << "\n"
476  << " Duration: " << getAvgBikeDuration() << "\n"
477  << " WaitingTime: " << getAvgBikeWaitingTime() << "\n"
478  << " TimeLoss: " << getAvgBikeTimeLoss() << "\n";
479  if (myVehicleCount > 0) {
480  msg << "Statistics (avg of " << (myVehicleCount + myBikeCount) << "):\n";
481  }
482  }
483  msg << " DepartDelay: " << getAvgDepartDelay() << "\n";
484  if (myWaitingDepartDelay >= 0) {
485  msg << " DepartDelayWaiting: " << STEPS2TIME(myWaitingDepartDelay / MAX2(1.0, (double)myUndepartedVehicleCount)) << "\n";
486  }
487  if (myWalkCount > 0) {
488  msg << "Pedestrian Statistics (avg of " << myWalkCount << " walks):\n"
489  << " RouteLength: " << getAvgWalkRouteLength() << "\n"
490  << " Duration: " << getAvgWalkDuration() << "\n"
491  << " TimeLoss: " << getAvgWalkTimeLoss() << "\n";
492  }
493  printRideStatistics(msg, "Ride", "rides", 0);
494  printRideStatistics(msg, "Transport", "transports", 1);
495  return msg.str();
496 }
497 
498 void
499 MSDevice_Tripinfo::printRideStatistics(std::ostringstream& msg, const std::string& category, const std::string& modeName, const int index) {
500  if (myRideCount[index] > 0) {
501  msg << category << " Statistics (avg of " << myRideCount[index] << " " << modeName << "):\n";
502  msg << " WaitingTime: " << STEPS2TIME(myTotalRideWaitingTime[index] / myRideCount[index]) << "\n";
503  msg << " RouteLength: " << myTotalRideRouteLength[index] / myRideCount[index] << "\n";
504  msg << " Duration: " << STEPS2TIME(myTotalRideDuration[index] / myRideCount[index]) << "\n";
505  if (myRideBusCount[index] > 0) {
506  msg << " Bus: " << myRideBusCount[index] << "\n";
507  }
508  if (myRideRailCount[index] > 0) {
509  msg << " Train: " << myRideRailCount[index] << "\n";
510  }
511  if (myRideTaxiCount[index] > 0) {
512  msg << " Taxi: " << myRideTaxiCount[index] << "\n";
513  }
514  if (myRideBikeCount[index] > 0) {
515  msg << " Bike: " << myRideBikeCount[index] << "\n";
516  }
517  if (myRideAbortCount[index] > 0) {
518  msg << " Aborted: " << myRideAbortCount[index] << "\n";
519  }
520  }
521 
522 }
523 
524 
525 void
528  od.openTag("vehicleTripStatistics");
529  od.writeAttr("routeLength", getAvgRouteLength());
530  od.writeAttr("speed", getAvgTripSpeed());
531  od.writeAttr("duration", getAvgDuration());
532  od.writeAttr("waitingTime", getAvgWaitingTime());
533  od.writeAttr("timeLoss", getAvgTimeLoss());
534  od.writeAttr("departDelay", getAvgDepartDelay());
535  od.writeAttr("departDelayWaiting", myWaitingDepartDelay >= 0 ? STEPS2TIME(myWaitingDepartDelay / MAX2(1.0, (double)myUndepartedVehicleCount)) : -1);
536  od.writeAttr("totalTravelTime", time2string(myTotalDuration));
538  od.writeAttr("totalDepartDelay", time2string(totalDepartDelay));
539  od.closeTag();
540  if (myBikeCount > 0) {
541  od.openTag("bikeTripStatistics");
542  od.writeAttr("count", myBikeCount);
543  od.writeAttr("routeLength", getAvgBikeRouteLength());
544  od.writeAttr("speed", getAvgBikeTripSpeed());
545  od.writeAttr("duration", getAvgBikeDuration());
546  od.writeAttr("waitingTime", getAvgBikeWaitingTime());
547  od.writeAttr("timeLoss", getAvgBikeTimeLoss());
548  od.writeAttr("totalTravelTime", time2string(myTotalBikeDuration));
549  od.closeTag();
550  }
551  od.openTag("pedestrianStatistics");
552  od.writeAttr("number", myWalkCount);
553  od.writeAttr("routeLength", getAvgWalkRouteLength());
554  od.writeAttr("duration", getAvgWalkDuration());
555  od.writeAttr("timeLoss", getAvgWalkTimeLoss());
556  od.closeTag();
557  writeRideStatistics(od, "rideStatistics", 0);
558  writeRideStatistics(od, "transportStatistics", 1);
559 }
560 
561 void
562 MSDevice_Tripinfo::writeRideStatistics(OutputDevice& od, const std::string& category, const int index) {
563  od.openTag(category);
564  od.writeAttr("number", myRideCount[index]);
565  if (myRideCount[index] > 0) {
566  od.writeAttr("waitingTime", STEPS2TIME(myTotalRideWaitingTime[index] / myRideCount[index]));
567  od.writeAttr("routeLength", myTotalRideRouteLength[index] / myRideCount[index]);
568  od.writeAttr("duration", STEPS2TIME(myTotalRideDuration[index] / myRideCount[index]));
569  od.writeAttr("bus", myRideBusCount[index]);
570  od.writeAttr("train", myRideRailCount[index]);
571  od.writeAttr("taxi", myRideTaxiCount[index]);
572  od.writeAttr("bike", myRideBikeCount[index]);
573  od.writeAttr("aborted", myRideAbortCount[index]);
574  }
575  od.closeTag();
576 }
577 
578 
579 double
581  if (myVehicleCount > 0) {
583  } else {
584  return 0;
585  }
586 }
587 
588 double
590  if (myVehicleCount > 0) {
591  return myTotalSpeed / myVehicleCount;
592  } else {
593  return 0;
594  }
595 }
596 
597 double
599  if (myVehicleCount > 0) {
600  return STEPS2TIME(myTotalDuration / (double)myVehicleCount);
601  } else {
602  return 0;
603  }
604 }
605 
606 double
608  if (myVehicleCount > 0) {
609  return STEPS2TIME(myTotalWaitingTime / (double)myVehicleCount);
610  } else {
611  return 0;
612  }
613 }
614 
615 
616 double
618  if (myVehicleCount > 0) {
619  return STEPS2TIME(myTotalTimeLoss / (double)myVehicleCount);
620  } else {
621  return 0;
622  }
623 }
624 
625 
626 double
628  if (myVehicleCount > 0) {
629  return STEPS2TIME(myTotalDepartDelay / (double)myVehicleCount);
630  } else {
631  return 0;
632  }
633 }
634 
635 double
637  if (myBikeCount > 0) {
639  } else {
640  return 0;
641  }
642 }
643 
644 double
646  if (myBikeCount > 0) {
647  return myTotalBikeSpeed / myBikeCount;
648  } else {
649  return 0;
650  }
651 }
652 
653 double
655  if (myBikeCount > 0) {
656  return STEPS2TIME(myTotalBikeDuration / (double)myBikeCount);
657  } else {
658  return 0;
659  }
660 }
661 
662 double
664  if (myBikeCount > 0) {
666  } else {
667  return 0;
668  }
669 }
670 
671 
672 double
674  if (myBikeCount > 0) {
675  return STEPS2TIME(myTotalBikeTimeLoss / (double)myBikeCount);
676  } else {
677  return 0;
678  }
679 }
680 
681 
682 
683 double
685  if (myWalkCount > 0) {
687  } else {
688  return 0;
689  }
690 }
691 
692 double
694  if (myWalkCount > 0) {
695  return STEPS2TIME(myTotalWalkDuration / (double)myWalkCount);
696  } else {
697  return 0;
698  }
699 }
700 
701 
702 double
704  if (myWalkCount > 0) {
705  return STEPS2TIME(myTotalWalkTimeLoss / (double)myWalkCount);
706  } else {
707  return 0;
708  }
709 }
710 
711 
712 double
714  if (myRideCount[0] > 0) {
716  } else {
717  return 0;
718  }
719 }
720 
721 double
723  if (myRideCount[0] > 0) {
725  } else {
726  return 0;
727  }
728 }
729 
730 double
732  if (myRideCount[0] > 0) {
733  return myTotalRideRouteLength[0] / myRideCount[0];
734  } else {
735  return 0;
736  }
737 }
738 
739 
740 void
742  if (myHolder.hasDeparted()) {
744  out.writeAttr(SUMO_ATTR_ID, getID());
745  std::ostringstream internals;
746  if (!MSGlobals::gUseMesoSim) {
747  internals << myDepartLane << " " << myDepartPosLat << " ";
748  }
749  internals << myDepartSpeed << " " << myRouteLength << " " << myWaitingTime << " " << myAmWaiting << " " << myWaitingCount << " ";
750  internals << myStoppingTime << " " << myParkingStarted;
751  out.writeAttr(SUMO_ATTR_STATE, internals.str());
752  out.closeTag();
753  }
754 }
755 
756 
757 void
759  std::istringstream bis(attrs.getString(SUMO_ATTR_STATE));
760  if (!MSGlobals::gUseMesoSim) {
761  bis >> myDepartLane >> myDepartPosLat;
762  }
765 }
766 
767 
768 /****************************************************************************/
#define NOT_ARRIVED
SUMOTime DELTA_T
Definition: SUMOTime.cpp:37
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
#define STEPS2TIME(x)
Definition: SUMOTime.h:53
#define SIMSTEP
Definition: SUMOTime.h:59
#define TIME2STEPS(x)
Definition: SUMOTime.h:55
long long int SUMOTime
Definition: SUMOTime.h:32
bool isRailway(SVCPermissions permissions)
Returns whether an edge with the given permission is a railway edge.
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_BICYCLE
vehicle is a bicycle
@ SVC_TAXI
vehicle is a taxi
@ DEPART_GIVEN
The time is given.
@ SUMO_TAG_DEVICE
@ SUMO_ATTR_ID
@ SUMO_ATTR_STATE
The state of a link.
int gPrecision
the precision for floating point outputs
Definition: StdDefs.cpp:25
const double SUMO_const_haltingSpeed
the speed threshold at which vehicles are considered as halting
Definition: StdDefs.h:61
T MAX2(T a, T b)
Definition: StdDefs.h:80
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
A device which collects info on the vehicle trip (mainly on departure and arrival)
bool notifyEnter(SUMOTrafficObject &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Saves departure info on insertion.
static SUMOTime myTotalDepartDelay
static long myVehicleCount
global tripinfo statistics
double myDepartSpeed
The speed on departure.
static std::vector< int > myRideAbortCount
static double getAvgBikeTripSpeed()
static void writeStatistics(OutputDevice &od)
write statistic output to (xml) file
void saveState(OutputDevice &out) const
Saves the state of the device.
SUMOTime myArrivalTime
The vehicle's arrival time.
SUMOTime myWaitingTime
The overall waiting time.
void loadState(const SUMOSAXAttributes &attrs)
Loads the state of the device from the given description.
static std::set< const MSDevice_Tripinfo *, ComparatorNumericalIdLess > myPendingOutput
devices which may still need to produce output
static SUMOTime myTotalBikeDuration
static SUMOTime myTotalWalkTimeLoss
static long myUndepartedVehicleCount
static double getAvgRideWaitingTime()
SUMOTime myParkingStarted
The time when parking started.
static double getAvgBikeDuration()
static double getAvgWalkRouteLength()
std::string myArrivalLane
The lane the vehicle arrived at.
MSDevice_Tripinfo(SUMOVehicle &holder, const std::string &id)
Constructor.
static double getAvgTimeLoss()
static void printRideStatistics(std::ostringstream &msg, const std::string &category, const std::string &modeName, const int index)
double myArrivalSpeed
The speed when arriving.
static double getAvgRideRouteLength()
static double getAvgBikeTimeLoss()
~MSDevice_Tripinfo()
Destructor.
static SUMOTime myTotalTimeLoss
static double getAvgRideDuration()
static std::vector< int > myRideRailCount
static double getAvgDepartDelay()
static double myTotalBikeRouteLength
static double myTotalSpeed
static double getAvgBikeRouteLength()
static std::vector< SUMOTime > myTotalRideDuration
static SUMOTime myTotalBikeTimeLoss
static double getAvgTripSpeed()
static double getAvgRouteLength()
accessors for GUINet-Parameters
static std::vector< double > myTotalRideWaitingTime
void updateParkingStopTime()
update stopping time after parking
static SUMOTime myTotalDuration
static SUMOTime myTotalWalkDuration
static std::string printStatistics()
get statistics for printing to stdout
static void generateOutputForUnfinished()
generate output for vehicles which are still in the network
static double myTotalBikeSpeed
static double getAvgWaitingTime()
static void addPedestrianData(double walkLength, SUMOTime walkDuration, SUMOTime walkTimeLoss)
record tripinfo data for pedestrians
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed)
Checks for waiting steps when the vehicle moves.
std::string myDepartLane
The lane the vehicle departed at.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
static void writeRideStatistics(OutputDevice &od, const std::string &category, const int index)
double myRouteLength
The route length.
static SUMOTime myTotalWaitingTime
static double myTotalRouteLength
static double getAvgBikeWaitingTime()
double myArrivalPosLat
The lateral position on the lane the vehicle arrived at.
static long myBikeCount
separate values for bicycles
static double getAvgDuration()
static SUMOTime myTotalBikeWaitingTime
static void cleanup()
resets counters
int myWaitingCount
The overall number of unintended stops.
SUMOTime myStoppingTime
The overall intentional stopping time.
bool notifyLeave(SUMOTrafficObject &veh, double lastPos, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Saves arrival info.
void generateOutput(OutputDevice *tripinfoOut) const
Called on writing tripinfo output.
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
static std::vector< int > myRideCount
bool notifyIdle(SUMOTrafficObject &veh)
record idling as waiting time - cf issue 2233
static double getAvgWalkDuration()
SUMOTime myMesoTimeLoss
The time loss when compared to the desired and allowed speed.
static std::vector< int > myRideBusCount
double myDepartPosLat
The lateral depart position.
bool myAmWaiting
Whether the vehicle is currently waiting.
double myArrivalPos
The position on the lane the vehicle arrived at.
void notifyMoveInternal(const SUMOTrafficObject &veh, const double frontOnLane, const double timeOnLane, const double meanSpeedFrontOnLane, const double meanSpeedVehicleOnLane, const double travelledDistanceFrontOnLane, const double travelledDistanceVehicleOnLane, const double)
Internal notification about the vehicle moves, see MSMoveReminder::notifyMoveInternal()
static std::vector< int > myRideTaxiCount
static std::vector< int > myRideBikeCount
MSMoveReminder::Notification myArrivalReason
The reason for vehicle arrival.
static double getAvgWalkTimeLoss()
static double myTotalWalkRouteLength
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_Tripinfo-options.
static SUMOTime myWaitingDepartDelay
static std::vector< double > myTotalRideRouteLength
A device which collects info on the vehicle trip (mainly on departure and arrival)
static void insertDefaultAssignmentOptions(const std::string &deviceName, const std::string &optionsTopic, OptionsCont &oc, const bool isPerson=false)
Adds common command options that allow to assign devices to vehicles.
Definition: MSDevice.cpp:137
static bool equippedByDefaultAssignmentOptions(const OptionsCont &oc, const std::string &deviceName, DEVICEHOLDER &v, bool outputOptionSet, const bool isPerson=false)
Determines whether a vehicle should get a certain device.
Definition: MSDevice.h:205
double getLength() const
return the length of the edge
Definition: MSEdge.h:641
double getVehicleMaxSpeed(const SUMOTrafficObject *const veh) const
Returns the maximum speed the vehicle may use on this edge.
Definition: MSEdge.cpp:1002
static bool gUseMesoSim
Definition: MSGlobals.h:94
static double gLateralResolution
Definition: MSGlobals.h:88
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
double getLength() const
Returns the lane's length.
Definition: MSLane.h:541
Something on a lane to be noticed about vehicle movement.
const MSLane * getLane() const
Returns the lane the reminder works on.
Notification
Definition of a vehicle state.
@ NOTIFICATION_VAPORIZED_TRACI
The vehicle got removed via TraCI.
@ NOTIFICATION_ARRIVED
The vehicle arrived at its destination (is deleted)
@ NOTIFICATION_TELEPORT_ARRIVED
The vehicle was teleported out of the net.
@ NOTIFICATION_VAPORIZED_CALIBRATOR
The vehicle got removed by a calibrator.
@ NOTIFICATION_VAPORIZED_GUI
The vehicle got removed via the GUI.
@ NOTIFICATION_DEPARTED
The vehicle has departed (was inserted into the network)
@ NOTIFICATION_VAPORIZED_VAPORIZER
The vehicle got vaporized with a vaporizer.
@ NOTIFICATION_JUNCTION
The vehicle arrived at a junction.
@ NOTIFICATION_PARKING
The vehicle starts or ends parking.
@ NOTIFICATION_VAPORIZED_COLLISION
The vehicle got removed by a collision.
@ NOTIFICATION_TELEPORT
The vehicle is being teleported.
The simulated network and simulation perfomer.
Definition: MSNet.h:88
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:174
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:318
bool hasPersons() const
Returns whether persons are simulated.
Definition: MSNet.h:393
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:1059
const MSEdge * getLastEdge() const
returns the destination edge
Definition: MSRoute.cpp:87
constVehIt loadedBegin() const
Returns the begin of the internal transportables map.
constVehIt loadedEnd() const
Returns the end of the internal transportables map.
virtual void erase(MSTransportable *transportable)
removes a single transportable
Abstract in-vehicle device.
SUMOVehicle & myHolder
The vehicle that stores the device.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:75
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:90
const std::string & getID() const
Returns the id.
Definition: Named.h:74
A storage for options typed value containers)
Definition: OptionsCont.h:89
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:248
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
void setPrecision(int precision=gPrecision)
Sets the precision or resets it to default.
Encapsulated SAX-Attributes.
virtual std::string getString(int id) const =0
Returns the string-value of the named (by its enum-value) attribute.
Representation of a vehicle, person, or container.
virtual SUMOTime getWaitingTime() const =0
virtual bool isVehicle() const
Whether it is a vehicle.
virtual double getChosenSpeedFactor() const =0
virtual double getSpeed() const =0
Returns the object's current speed.
virtual bool isStopped() const =0
Returns whether the object is at a stop.
virtual const MSVehicleType & getVehicleType() const =0
Returns the object's "vehicle" type.
virtual SUMOVehicleClass getVClass() const =0
Returns the object's access class.
virtual const SUMOVehicleParameter & getParameter() const =0
Returns the vehicle's parameter (including departure definition)
virtual const MSEdge * getEdge() const =0
Returns the edge the object is currently at.
virtual double getPositionOnLane() const =0
Get the object's position along the lane.
Representation of a vehicle.
Definition: SUMOVehicle.h:60
virtual const MSRoute & getRoute() const =0
Returns the current route.
virtual SUMOTime getDeparture() const =0
Returns this vehicle's real departure time.
virtual bool hasDeparted() const =0
Returns whether this vehicle has departed.
virtual int getNumberReroutes() const =0
Returns the number of new routes this vehicle got.
virtual double getArrivalPos() const =0
Returns this vehicle's desired arrivalPos for its current route (may change on reroute)
virtual double getDepartPos() const =0
Returns this vehicle's real departure position.
virtual SUMOTime getDepartDelay() const =0
virtual int getRoutePosition() const =0
return index of edge within route
virtual const std::vector< MSVehicleDevice * > & getDevices() const =0
Returns this vehicle's devices.
Structure representing possible vehicle parameter.
DepartDefinition departProcedure
Information how the vehicle shall choose the depart time.
int arrivalEdge
(optional) The final edge within the route of the vehicle