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