SUMO - Simulation of Urban MObility
MSMeanData.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // Data collector for edges/lanes
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
13 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <limits>
35 #include <microsim/MSEdgeControl.h>
36 #include <microsim/MSEdge.h>
37 #include <microsim/MSLane.h>
38 #include <microsim/MSVehicle.h>
40 #include <microsim/MSNet.h>
41 #include <utils/common/SUMOTime.h>
42 #include <utils/common/ToString.h>
44 #include "MSMeanData_Amitran.h"
45 #include "MSMeanData.h"
46 
47 #include <microsim/MSGlobals.h>
48 #include <mesosim/MESegment.h>
49 #include <mesosim/MELoop.h>
50 
51 
52 // ===========================================================================
53 // method definitions
54 // ===========================================================================
55 // ---------------------------------------------------------------------------
56 // MSMeanData::MeanDataValues - methods
57 // ---------------------------------------------------------------------------
59  MSLane* const lane, const double length, const bool doAdd,
60  const MSMeanData* const parent) :
61  MSMoveReminder("meandata_" + (lane == 0 ? "NULL" : lane->getID()), lane, doAdd),
62  myParent(parent),
63  myLaneLength(length),
64  sampleSeconds(0),
65  travelledDistance(0) {}
66 
67 
69 }
70 
71 
72 bool
74  UNUSED_PARAMETER(reason);
75  return myParent == 0 || myParent->vehicleApplies(veh);
76 }
77 
78 
79 bool
80 MSMeanData::MeanDataValues::notifyMove(SUMOVehicle& veh, double oldPos, double newPos, double newSpeed) {
81  // if the vehicle has arrived, the reminder must be kept so it can be
82  // notified of the arrival subsequently
83  const double oldSpeed = veh.getPreviousSpeed();
84  double enterSpeed = MSGlobals::gSemiImplicitEulerUpdate ? newSpeed : oldSpeed; // NOTE: For the euler update, the vehicle is assumed to travel at constant speed for the whole time step
85  double leaveSpeed = newSpeed, leaveSpeedFront = newSpeed;
86 
87  // These values will be further decreased below
88  double timeOnLane = TS;
89  double frontOnLane = oldPos > myLaneLength ? 0. : TS;
90  bool ret = true;
91 
92  // Treat the case that the vehicle entered the lane in the last step
93  if (oldPos < 0 && newPos >= 0) {
94  // Vehicle was not on this lane in the last time step
95  const double timeBeforeEnter = MSCFModel::passingTime(oldPos, 0, newPos, oldSpeed, newSpeed);
96  timeOnLane = TS - timeBeforeEnter;
97  frontOnLane = timeOnLane;
98  enterSpeed = MSCFModel::speedAfterTime(timeBeforeEnter, oldSpeed, newPos - oldPos);
99  }
100 
101  // Treat the case that the vehicle's back left the lane in the last step
102  const double oldBackPos = oldPos - veh.getVehicleType().getLength();
103  const double newBackPos = newPos - veh.getVehicleType().getLength();
104  if (newBackPos > myLaneLength // vehicle's back has left the lane
105  && oldBackPos <= myLaneLength) { // and hasn't left the lane before, XXX: this shouldn't occur, should it? For instance, in the E2 code this is not checked (Leo)
106  assert(!MSGlobals::gSemiImplicitEulerUpdate || newSpeed != 0); // how could it move across the lane boundary otherwise
107 
108  // (Leo) vehicle left this lane (it can also have skipped over it in one time step -> therefore we use "timeOnLane -= ..." and ( ... - timeOnLane) below)
109  const double timeBeforeLeave = MSCFModel::passingTime(oldBackPos, myLaneLength, newBackPos, oldSpeed, newSpeed);
110  const double timeAfterLeave = TS - timeBeforeLeave;
111  timeOnLane -= timeAfterLeave;
112  leaveSpeed = MSCFModel::speedAfterTime(timeBeforeLeave, oldSpeed, newPos - oldPos);
113  // XXX: Do we really need this? Why would this "reduce rounding errors"? (Leo) Refs. #2579
114  if (fabs(timeOnLane) < NUMERICAL_EPS) { // reduce rounding errors
115  timeOnLane = 0.;
116  }
117  ret = veh.hasArrived();
118  }
119 
120 
121  // Treat the case that the vehicle's front left the lane in the last step
122  if (newPos > myLaneLength && oldPos <= myLaneLength) {
123  // vehicle's front has left the lane and has not left before
124  assert(!MSGlobals::gSemiImplicitEulerUpdate || newSpeed != 0);
125  const double timeBeforeLeave = MSCFModel::passingTime(oldPos, myLaneLength, newPos, oldSpeed, newSpeed);
126  const double timeAfterLeave = TS - timeBeforeLeave;
127  frontOnLane -= timeAfterLeave;
128  // XXX: Do we really need this? Why would this "reduce rounding errors"? (Leo) Refs. #2579
129  if (fabs(frontOnLane) < NUMERICAL_EPS) { // reduce rounding errors
130  frontOnLane = 0.;
131  }
132  leaveSpeedFront = MSCFModel::speedAfterTime(timeBeforeLeave, oldSpeed, newPos - oldPos);
133  }
134 
135  if (timeOnLane < 0) {
136  WRITE_ERROR("Negative vehicle step fraction for '" + veh.getID() + "' on lane '" + getLane()->getID() + "'.");
137  return veh.hasArrived();
138  }
139  if (timeOnLane == 0) {
140  return veh.hasArrived();
141  }
142 
143  // XXX: use this, when #2556 is fixed! Refs. #2575
144 // const double travelledDistanceFrontOnLane = MIN2(newPos, myLaneLength) - MAX2(oldPos, 0.);
145 // const double travelledDistanceVehicleOnLane = MIN2(newPos, myLaneLength) - MAX2(oldPos, 0.) + MIN2(MAX2(0., newPos-myLaneLength), veh.getVehicleType().getLength());
146  // XXX: #2556 fixed for ballistic update
147  const double travelledDistanceFrontOnLane = MSGlobals::gSemiImplicitEulerUpdate ? frontOnLane * newSpeed
148  : MAX2(0., MIN2(newPos, myLaneLength) - MAX2(oldPos, 0.));
149  const double travelledDistanceVehicleOnLane = MSGlobals::gSemiImplicitEulerUpdate ? timeOnLane * newSpeed
150  : MIN2(newPos, myLaneLength) - MAX2(oldPos, 0.) + MIN2(MAX2(0., newPos - myLaneLength), veh.getVehicleType().getLength());
151 // // XXX: no fix
152 // const double travelledDistanceFrontOnLane = frontOnLane*newSpeed;
153 // const double travelledDistanceVehicleOnLane = timeOnLane*newSpeed;
154 
155  notifyMoveInternal(veh, frontOnLane, timeOnLane, (enterSpeed + leaveSpeedFront) / 2., (enterSpeed + leaveSpeed) / 2., travelledDistanceFrontOnLane, travelledDistanceVehicleOnLane);
156 // notifyMoveInternal(veh, frontOnLane, timeOnLane, newSpeed, newSpeed, travelledDistanceFrontOnLane, travelledDistanceVehicleOnLane);
157  return ret;
158 }
159 
160 
161 bool
162 MSMeanData::MeanDataValues::notifyLeave(SUMOVehicle& /*veh*/, double /*lastPos*/, MSMoveReminder::Notification reason, const MSLane* /* enteredLane */) {
164  return false; // reminder is re-added on every segment (@recheck for performance)
165  }
166  return reason == MSMoveReminder::NOTIFICATION_JUNCTION;
167 }
168 
169 
170 bool
172  return sampleSeconds == 0;
173 }
174 
175 
176 void
178 }
179 
180 
181 double
183  return sampleSeconds;
184 }
185 
186 
187 // ---------------------------------------------------------------------------
188 // MSMeanData::MeanDataValueTracker - methods
189 // ---------------------------------------------------------------------------
191  const double length,
192  const MSMeanData* const parent)
193  : MSMeanData::MeanDataValues(lane, length, true, parent) {
194  myCurrentData.push_back(new TrackerEntry(parent->createValues(lane, length, false)));
195 }
196 
197 
199  std::list<TrackerEntry*>::iterator i;
200  for (i = myCurrentData.begin(); i != myCurrentData.end(); i++) {
201  delete *i;
202  }
203 
204  // FIXME: myTrackedData may still hold some undeleted TrackerEntries. When to delete those? (Leo), refers to #2251
205  // code below fails
206 
207 // std::map<SUMOVehicle*, TrackerEntry*>::iterator j;
208 // for(j=myTrackedData.begin(); j!=myTrackedData.end();j++){
209 // delete j->second;
210 // }
211 }
212 
213 
214 void
216  if (afterWrite) {
217  if (myCurrentData.begin() != myCurrentData.end()) {
218  myCurrentData.pop_front();
219  }
220  } else {
222  }
223 }
224 
225 
226 void
228  myCurrentData.front()->myValues->addTo(val);
229 }
230 
231 
232 void
233 MSMeanData::MeanDataValueTracker::notifyMoveInternal(const SUMOVehicle& veh, const double frontOnLane, const double timeOnLane, const double meanSpeedFrontOnLane, const double meanSpeedVehicleOnLane, const double travelledDistanceFrontOnLane, const double travelledDistanceVehicleOnLane) {
234  myTrackedData[&veh]->myValues->notifyMoveInternal(veh, frontOnLane, timeOnLane, meanSpeedFrontOnLane, meanSpeedVehicleOnLane, travelledDistanceFrontOnLane, travelledDistanceVehicleOnLane);
235 }
236 
237 
238 bool
239 MSMeanData::MeanDataValueTracker::notifyLeave(SUMOVehicle& veh, double lastPos, MSMoveReminder::Notification reason, const MSLane* /* enteredLane */) {
240  if (myParent == 0 || reason != MSMoveReminder::NOTIFICATION_SEGMENT) {
241  myTrackedData[&veh]->myNumVehicleLeft++;
242  }
243  return myTrackedData[&veh]->myValues->notifyLeave(veh, lastPos, reason);
244 }
245 
246 
247 bool
249  if (reason == MSMoveReminder::NOTIFICATION_SEGMENT) {
250  return true;
251  }
252  if (myParent->vehicleApplies(veh) && myTrackedData.find(&veh) == myTrackedData.end()) {
253  myTrackedData[&veh] = myCurrentData.back();
254  myTrackedData[&veh]->myNumVehicleEntered++;
255  if (!myTrackedData[&veh]->myValues->notifyEnter(veh, reason)) {
256  myTrackedData[&veh]->myNumVehicleLeft++;
257  myTrackedData.erase(&veh);
258  return false;
259  }
260  return true;
261  }
262  return false;
263 }
264 
265 
266 bool
268  return myCurrentData.front()->myValues->isEmpty();
269 }
270 
271 
272 void
274  const SUMOTime period,
275  const double numLanes,
276  const double defaultTravelTime,
277  const int /*numVehicles*/) const {
278  myCurrentData.front()->myValues->write(dev, period, numLanes,
279  defaultTravelTime,
280  myCurrentData.front()->myNumVehicleEntered);
281 }
282 
283 
284 int
286  int result = 0;
287  for (std::list<TrackerEntry*>::const_iterator it = myCurrentData.begin(); it != myCurrentData.end(); ++it) {
288  if ((*it)->myNumVehicleEntered == (*it)->myNumVehicleLeft) {
289  result++;
290  } else {
291  break;
292  }
293  }
294  return result;
295 }
296 
297 
298 double
300  return myCurrentData.front()->myValues->getSamples();
301 }
302 
303 
304 // ---------------------------------------------------------------------------
305 // MSMeanData - methods
306 // ---------------------------------------------------------------------------
307 MSMeanData::MSMeanData(const std::string& id,
308  const SUMOTime dumpBegin, const SUMOTime dumpEnd,
309  const bool useLanes, const bool withEmpty,
310  const bool printDefaults, const bool withInternal, const bool trackVehicles,
311  const double maxTravelTime,
312  const double minSamples,
313  const std::string& vTypes) :
314  MSDetectorFileOutput(id, vTypes),
315  myMinSamples(minSamples),
316  myMaxTravelTime(maxTravelTime),
317  myDumpEmpty(withEmpty),
318  myAmEdgeBased(!useLanes),
319  myDumpBegin(dumpBegin),
320  myDumpEnd(dumpEnd),
321  myPrintDefaults(printDefaults),
322  myDumpInternal(withInternal),
323  myTrackVehicles(trackVehicles) {
324 }
325 
326 
327 void
330  for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) {
331  const MSEdge::EdgeBasicFunction efun = (*e)->getPurpose();
334  myEdges.push_back(*e);
335  myMeasures.push_back(std::vector<MeanDataValues*>());
336  const std::vector<MSLane*>& lanes = (*e)->getLanes();
338  MeanDataValues* data;
339  if (myTrackVehicles) {
340  data = new MeanDataValueTracker(0, lanes[0]->getLength(), this);
341  } else {
342  data = createValues(0, lanes[0]->getLength(), false);
343  }
344  data->setDescription("meandata_" + (*e)->getID());
345  myMeasures.back().push_back(data);
347  while (s != 0) {
348  s->addDetector(data);
349  s->prepareDetectorForWriting(*data);
350  s = s->getNextSegment();
351  }
352  data->reset();
353  data->reset(true);
354  continue;
355  }
357  myMeasures.back().push_back(new MeanDataValueTracker(0, lanes[0]->getLength(), this));
358  }
359  for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
360  if (myTrackVehicles) {
361  if (myAmEdgeBased) {
362  (*lane)->addMoveReminder(myMeasures.back().back());
363  } else {
364  myMeasures.back().push_back(new MeanDataValueTracker(*lane, (*lane)->getLength(), this));
365  }
366  } else {
367  myMeasures.back().push_back(createValues(*lane, (*lane)->getLength(), true));
368  }
369  }
370  }
371  }
372 }
373 
374 
376  for (std::vector<std::vector<MeanDataValues*> >::const_iterator i = myMeasures.begin(); i != myMeasures.end(); ++i) {
377  for (std::vector<MeanDataValues*>::const_iterator j = (*i).begin(); j != (*i).end(); ++j) {
378  delete *j;
379  }
380  }
381 }
382 
383 
384 void
386  UNUSED_PARAMETER(stopTime);
388  MSEdgeVector::iterator edge = myEdges.begin();
389  for (std::vector<std::vector<MeanDataValues*> >::const_iterator i = myMeasures.begin(); i != myMeasures.end(); ++i, ++edge) {
391  MeanDataValues* data = i->front();
392  while (s != 0) {
393  s->prepareDetectorForWriting(*data);
394  s = s->getNextSegment();
395  }
396  data->reset();
397  }
398  return;
399  }
400  for (std::vector<std::vector<MeanDataValues*> >::const_iterator i = myMeasures.begin(); i != myMeasures.end(); ++i) {
401  for (std::vector<MeanDataValues*>::const_iterator j = (*i).begin(); j != (*i).end(); ++j) {
402  (*j)->reset();
403  }
404  }
405 }
406 
407 
408 std::string
409 MSMeanData::getEdgeID(const MSEdge* const edge) {
410  return edge->getID();
411 }
412 
413 
414 void
416  const std::vector<MeanDataValues*>& edgeValues,
417  MSEdge* edge, SUMOTime startTime, SUMOTime stopTime) {
420  MeanDataValues* data = edgeValues.front();
421  while (s != 0) {
422  s->prepareDetectorForWriting(*data);
423  s = s->getNextSegment();
424  }
425  if (writePrefix(dev, *data, SUMO_TAG_EDGE, getEdgeID(edge))) {
426  data->write(dev, stopTime - startTime,
427  (double)edge->getLanes().size(),
428  myPrintDefaults ? edge->getLength() / edge->getSpeedLimit() : -1.);
429  }
430  data->reset(true);
431  return;
432  }
433  std::vector<MeanDataValues*>::const_iterator lane;
434  if (!myAmEdgeBased) {
435  bool writeCheck = myDumpEmpty;
436  if (!writeCheck) {
437  for (lane = edgeValues.begin(); lane != edgeValues.end(); ++lane) {
438  if (!(*lane)->isEmpty()) {
439  writeCheck = true;
440  break;
441  }
442  }
443  }
444  if (writeCheck) {
446  }
447  for (lane = edgeValues.begin(); lane != edgeValues.end(); ++lane) {
448  MeanDataValues& meanData = **lane;
449  if (writePrefix(dev, meanData, SUMO_TAG_LANE, meanData.getLane()->getID())) {
450  meanData.write(dev, stopTime - startTime, 1.f, myPrintDefaults ? meanData.getLane()->getLength() / meanData.getLane()->getSpeedLimit() : -1.);
451  }
452  meanData.reset(true);
453  }
454  if (writeCheck) {
455  dev.closeTag();
456  }
457  } else {
458  if (myTrackVehicles) {
459  MeanDataValues& meanData = **edgeValues.begin();
460  if (writePrefix(dev, meanData, SUMO_TAG_EDGE, edge->getID())) {
461  meanData.write(dev, stopTime - startTime, (double)edge->getLanes().size(), myPrintDefaults ? edge->getLength() / edge->getSpeedLimit() : -1.);
462  }
463  meanData.reset(true);
464  } else {
465  MeanDataValues* sumData = createValues(0, edge->getLength(), false);
466  for (lane = edgeValues.begin(); lane != edgeValues.end(); ++lane) {
467  MeanDataValues& meanData = **lane;
468  meanData.addTo(*sumData);
469  meanData.reset();
470  }
471  if (writePrefix(dev, *sumData, SUMO_TAG_EDGE, getEdgeID(edge))) {
472  sumData->write(dev, stopTime - startTime, (double)edge->getLanes().size(), myPrintDefaults ? edge->getLength() / edge->getSpeedLimit() : -1.);
473  }
474  delete sumData;
475  }
476  }
477 }
478 
479 
480 void
481 MSMeanData::openInterval(OutputDevice& dev, const SUMOTime startTime, const SUMOTime stopTime) {
484 }
485 
486 
487 bool
488 MSMeanData::writePrefix(OutputDevice& dev, const MeanDataValues& values, const SumoXMLTag tag, const std::string id) const {
489  if (myDumpEmpty || !values.isEmpty()) {
490  dev.openTag(tag).writeAttr(SUMO_ATTR_ID, id).writeAttr("sampledSeconds", values.getSamples());
491  return true;
492  }
493  return false;
494 }
495 
496 
497 void
499  SUMOTime startTime, SUMOTime stopTime) {
500  // check whether this dump shall be written for the current time
501  int numReady = myDumpBegin < stopTime && myDumpEnd - DELTA_T >= startTime ? 1 : 0;
502  if (myTrackVehicles && myDumpBegin < stopTime) {
503  myPendingIntervals.push_back(std::make_pair(startTime, stopTime));
504  numReady = (int)myPendingIntervals.size();
505  for (std::vector<std::vector<MeanDataValues*> >::const_iterator i = myMeasures.begin(); i != myMeasures.end(); ++i) {
506  for (std::vector<MeanDataValues*>::const_iterator j = (*i).begin(); j != (*i).end(); ++j) {
507  numReady = MIN2(numReady, ((MeanDataValueTracker*)*j)->getNumReady());
508  if (numReady == 0) {
509  break;
510  }
511  }
512  if (numReady == 0) {
513  break;
514  }
515  }
516  }
517  if (numReady == 0 || myTrackVehicles) {
518  resetOnly(stopTime);
519  }
520  while (numReady-- > 0) {
521  if (!myPendingIntervals.empty()) {
522  startTime = myPendingIntervals.front().first;
523  stopTime = myPendingIntervals.front().second;
524  myPendingIntervals.pop_front();
525  }
526  openInterval(dev, startTime, stopTime);
527  MSEdgeVector::iterator edge = myEdges.begin();
528  for (std::vector<std::vector<MeanDataValues*> >::const_iterator i = myMeasures.begin(); i != myMeasures.end(); ++i, ++edge) {
529  writeEdge(dev, (*i), *edge, startTime, stopTime);
530  }
531  dev.closeTag();
532  }
533 }
534 
535 
536 void
538  dev.writeXMLHeader("meandata", "meandata_file.xsd");
539 }
540 
541 
542 void
544  if (step + DELTA_T == myDumpBegin) {
545  init();
546  }
547 }
548 
549 
550 /****************************************************************************/
551 
static double speedAfterTime(const double t, const double oldSpeed, const double dist)
Calculates the speed after a time t [0,TS] given the initial speed and the distance traveled in an i...
Definition: MSCFModel.cpp:444
MESegment * getNextSegment() const
Returns the following segment on the same edge (0 if it is the last).
Definition: MESegment.h:157
Data collector for edges/lanes.
Definition: MSMeanData.h:67
virtual ~MeanDataValueTracker()
Destructor.
Definition: MSMeanData.cpp:198
const MSLane * getLane() const
Returns the lane the reminder works on.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:256
SumoXMLTag
Numbers representing SUMO-XML - element names.
MESegment * getSegmentForEdge(const MSEdge &e, double pos=0)
Get the segment for a given edge at a given position.
Definition: MELoop.cpp:289
std::vector< std::vector< MeanDataValues * > > myMeasures
Value collectors; sorted by edge, then by lane.
Definition: MSMeanData.h:435
begin/end of the description of a single lane
const bool myDumpInternal
Whether internal lanes/edges shall be written.
Definition: MSMeanData.h:454
MeanDataValueTracker(MSLane *const lane, const double length, const MSMeanData *const parent)
Constructor.
Definition: MSMeanData.cpp:190
virtual bool notifyEnter(SUMOVehicle &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Called if the vehicle enters the reminder&#39;s lane.
Definition: MSMeanData.cpp:73
bool vehicleApplies(const SUMOVehicle &veh) const
Checks whether the detector measures vehicles of the given type.
double getSamples() const
Returns the number of collected sample seconds.
Definition: MSMeanData.cpp:299
const SUMOTime myDumpEnd
Definition: MSMeanData.h:445
const double myMaxTravelTime
the maximum travel time to write
Definition: MSMeanData.h:432
virtual void notifyMoveInternal(const SUMOVehicle &veh, const double frontOnLane, const double timeOnLane, const double meanSpeedFrontOnLane, const double meanSpeedVehicleOnLane, const double travelledDistanceFrontOnLane, const double travelledDistanceVehicleOnLane)
Internal notification about the vehicle moves.
The vehicle arrived at a junction.
MSLane *const myLane
Lane on which the reminder works.
bool isEmpty() const
Returns whether any data was collected.
Definition: MSMeanData.cpp:267
Notification
Definition of a vehicle state.
virtual void write(OutputDevice &dev, const SUMOTime period, const double numLanes, const double defaultTravelTime, const int numVehicles=-1) const =0
Writes output values into the given stream.
weights: time range begin
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:192
std::map< const SUMOVehicle *, TrackerEntry * > myTrackedData
The map of vehicles to data entries.
Definition: MSMeanData.h:289
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:158
T MAX2(T a, T b)
Definition: StdDefs.h:70
virtual bool isEmpty() const
Returns whether any data was collected.
Definition: MSMeanData.cpp:171
SUMOTime DELTA_T
Definition: SUMOTime.cpp:40
double getLength() const
Returns the lane&#39;s length.
Definition: MSLane.h:484
void notifyMoveInternal(const SUMOVehicle &veh, const double frontOnLane, const double timeOnLane, const double meanSpeedFrontOnLane, const double meanSpeedVehicleOnLane, const double travelledDistanceFrontOnLane, const double travelledDistanceVehicleOnLane)
Internal notification about the vehicle moves.
Definition: MSMeanData.cpp:233
The vehicle changes the segment (meso only)
const std::string & getID() const
Returns the id.
Definition: Named.h:66
#define TS
Definition: SUMOTime.h:52
EdgeBasicFunction
Defines possible edge types.
Definition: MSEdge.h:89
double getLength() const
return the length of the edge
Definition: MSEdge.h:586
double getSpeedLimit() const
Returns the speed limit of the edge The speed limit of the first lane is retured; should probably be...
Definition: MSEdge.cpp:824
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:38
std::list< TrackerEntry * > myCurrentData
The currently active meandata "intervals".
Definition: MSMeanData.h:292
virtual MSMeanData::MeanDataValues * createValues(MSLane *const lane, const double length, const bool doAdd) const =0
Create an instance of MeanDataValues.
void addTo(MSMeanData::MeanDataValues &val) const
Add the values of this to the given one and store them there.
Definition: MSMeanData.cpp:227
bool notifyMove(SUMOVehicle &veh, double oldPos, double newPos, double newSpeed)
Checks whether the reminder still has to be notified about the vehicle moves.
Definition: MSMeanData.cpp:80
A road/street connecting two junctions.
Definition: MSEdge.h:80
bool notifyEnter(SUMOVehicle &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Computes current values and adds them to their sums.
Definition: MSMeanData.cpp:248
const bool myPrintDefaults
Whether empty lanes/edges shall be written.
Definition: MSMeanData.h:451
Representation of a vehicle.
Definition: SUMOVehicle.h:67
bool notifyLeave(SUMOVehicle &veh, double lastPos, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Called if the vehicle leaves the reminder&#39;s lane.
Definition: MSMeanData.cpp:239
Data structure for mean (aggregated) edge/lane values.
Definition: MSMeanData.h:76
bool writeXMLHeader(const std::string &rootElement, const std::string &schemaFile, std::map< SumoXMLAttr, std::string > attrs=std::map< SumoXMLAttr, std::string >())
Writes an XML header with optional configuration.
Definition: MSMeanData.h:267
MSEdgeVector myEdges
The corresponding first edges.
Definition: MSMeanData.h:448
const bool myAmEdgeBased
Information whether the output shall be edge-based (not lane-based)
Definition: MSMeanData.h:442
double getSpeedLimit() const
Returns the lane&#39;s maximum allowed speed.
Definition: MSLane.h:476
#define STEPS2TIME(x)
Definition: SUMOTime.h:65
MSMeanData(const std::string &id, const SUMOTime dumpBegin, const SUMOTime dumpEnd, const bool useLanes, const bool withEmpty, const bool printDefaults, const bool withInternal, const bool trackVehicles, const double minSamples, const double maxTravelTime, const std::string &vTypes)
Constructor.
Definition: MSMeanData.cpp:307
T MIN2(T a, T b)
Definition: StdDefs.h:64
void addDetector(MSMoveReminder *data)
Adds a data collector for a detector to this segment.
Definition: MESegment.cpp:205
Something on a lane to be noticed about vehicle movement.
const SUMOTime myDumpBegin
The first and the last time step to write information (-1 indicates always)
Definition: MSMeanData.h:445
const double myLaneLength
The length of the lane / edge the data collector is on.
Definition: MSMeanData.h:175
virtual ~MSMeanData()
Destructor.
Definition: MSMeanData.cpp:375
const double myMinSamples
the minimum sample seconds
Definition: MSMeanData.h:429
virtual void addTo(MeanDataValues &val) const =0
Add the values of this to the given one and store them there.
begin/end of the description of an edge
virtual void openInterval(OutputDevice &dev, const SUMOTime startTime, const SUMOTime stopTime)
Writes the interval opener.
Definition: MSMeanData.cpp:481
void setDescription(const std::string &description)
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:206
static double passingTime(const double lastPos, const double passedPos, const double currentPos, const double lastSpeed, const double currentSpeed)
Calculates the time at which the position passedPosition has been passed In case of a ballistic updat...
Definition: MSCFModel.cpp:372
The edge is a pedestrian walking area (a special type of internal edge)
Definition: MSEdge.h:103
virtual ~MeanDataValues()
Destructor.
Definition: MSMeanData.cpp:68
std::string myID
The name of the object.
Definition: Named.h:136
const MSMeanData *const myParent
The meandata parent.
Definition: MSMeanData.h:172
void writeXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime)
Writes collected values into the given stream.
Definition: MSMeanData.cpp:498
virtual void reset(bool afterWrite=false)=0
Resets values so they may be used for the next interval.
std::list< std::pair< SUMOTime, SUMOTime > > myPendingIntervals
The intervals for which output still has to be generated (only in the tracking case) ...
Definition: MSMeanData.h:460
virtual bool hasArrived() const =0
Returns whether this vehicle has arrived.
virtual void writeXMLDetectorProlog(OutputDevice &dev) const
Opens the XML-output using "netstats" as root element.
Definition: MSMeanData.cpp:537
weights: time range end
A single mesoscopic segment (cell)
Definition: MESegment.h:57
virtual void update()
Called if a per timestep update is needed. Default does nothing.
Definition: MSMeanData.cpp:177
The edge is a pedestrian crossing (a special type of internal edge)
Definition: MSEdge.h:101
virtual bool writePrefix(OutputDevice &dev, const MeanDataValues &values, const SumoXMLTag tag, const std::string id) const
Checks for emptiness and writes prefix into the given stream.
Definition: MSMeanData.cpp:488
static MELoop * gMesoNet
mesoscopic simulation infrastructure
Definition: MSGlobals.h:113
double getLength() const
Get vehicle&#39;s length [m].
const MSEdgeVector & getEdges() const
Returns loaded edges.
virtual void detectorUpdate(const SUMOTime step)
Updates the detector.
Definition: MSMeanData.cpp:543
an aggreagated-output interval
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
virtual double getSamples() const
Returns the number of collected sample seconds.
Definition: MSMeanData.cpp:182
bool closeTag()
Closes the most recently opened tag.
static bool gSemiImplicitEulerUpdate
Definition: MSGlobals.h:63
MSEdgeControl & getEdgeControl()
Returns the edge control.
Definition: MSNet.h:353
long long int SUMOTime
Definition: TraCIDefs.h:52
#define NUMERICAL_EPS
Definition: config.h:151
void prepareDetectorForWriting(MSMoveReminder &data)
Updates data of a detector for all vehicle queues.
Definition: MESegment.cpp:247
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:77
void resetOnly(SUMOTime stopTime)
Resets network value in order to allow processing of the next interval.
Definition: MSMeanData.cpp:385
const bool myDumpEmpty
Whether empty lanes/edges shall be written.
Definition: MSMeanData.h:438
MeanDataValues(MSLane *const lane, const double length, const bool doAdd, const MSMeanData *const parent)
Constructor.
Definition: MSMeanData.cpp:58
void write(OutputDevice &dev, const SUMOTime period, const double numLanes, const double defaultTravelTime, const int numVehicles=-1) const
Writes output values into the given stream.
Definition: MSMeanData.cpp:273
The edge is an internal edge.
Definition: MSEdge.h:97
Data structure for mean (aggregated) edge/lane values for tracked vehicles.
Definition: MSMeanData.h:193
const bool myTrackVehicles
Whether vehicles are tracked.
Definition: MSMeanData.h:457
static bool gUseMesoSim
Definition: MSGlobals.h:98
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
void writeEdge(OutputDevice &dev, const std::vector< MeanDataValues *> &edgeValues, MSEdge *edge, SUMOTime startTime, SUMOTime stopTime)
Writes edge values into the given stream.
Definition: MSMeanData.cpp:415
virtual double getPreviousSpeed() const =0
Returns the vehicle&#39;s previous speed.
virtual const std::string & getID() const =0
Get the vehicle&#39;s ID.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
virtual std::string getEdgeID(const MSEdge *const edge)
Return the relevant edge id.
Definition: MSMeanData.cpp:409
virtual bool notifyLeave(SUMOVehicle &veh, double lastPos, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Called if the vehicle leaves the reminder&#39;s lane.
Definition: MSMeanData.cpp:162
Base of value-generating classes (detectors)
void init()
Adds the value collectors to all relevant edges.
Definition: MSMeanData.cpp:328
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle&#39;s type.
void reset(bool afterWrite)
Resets values so they may be used for the next interval.
Definition: MSMeanData.cpp:215