SUMO - Simulation of Urban MObility
MSMeanData_Net.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // Network state mean data collector for edges/lanes
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2004-2016 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <microsim/MSEdgeControl.h>
34 #include <microsim/MSEdge.h>
35 #include <microsim/MSLane.h>
36 #include <microsim/MSVehicle.h>
37 #include <utils/common/SUMOTime.h>
38 #include <utils/common/ToString.h>
40 #include "MSMeanData_Net.h"
41 #include <limits>
42 
43 #include <microsim/MSGlobals.h>
44 #include <mesosim/MELoop.h>
45 #include <mesosim/MESegment.h>
46 
47 #ifdef CHECK_MEMORY_LEAKS
48 #include <foreign/nvwa/debug_new.h>
49 #endif // CHECK_MEMORY_LEAKS
50 
51 
52 // ===========================================================================
53 // method definitions
54 // ===========================================================================
55 // ---------------------------------------------------------------------------
56 // MSMeanData_Net::MSLaneMeanDataValues - methods
57 // ---------------------------------------------------------------------------
59  const SUMOReal length,
60  const bool doAdd,
61  const MSMeanData_Net* parent)
62  : MSMeanData::MeanDataValues(lane, length, doAdd, parent),
63  nVehDeparted(0), nVehArrived(0), nVehEntered(0), nVehLeft(0),
64  nVehVaporized(0), waitSeconds(0),
65  nVehLaneChangeFrom(0), nVehLaneChangeTo(0),
66  frontSampleSeconds(0), frontTravelledDistance(0),
67  vehLengthSum(0), myParent(parent) {}
68 
69 
71 }
72 
73 
74 void
76  nVehDeparted = 0;
77  nVehArrived = 0;
78  nVehEntered = 0;
79  nVehLeft = 0;
80  nVehVaporized = 0;
82  nVehLaneChangeTo = 0;
83  sampleSeconds = 0.;
85  waitSeconds = 0;
88  vehLengthSum = 0;
89 }
90 
91 
92 void
98  v.nVehLeft += nVehLeft;
108 }
109 
110 
111 void
112 MSMeanData_Net::MSLaneMeanDataValues::notifyMoveInternal(const SUMOVehicle& veh, const SUMOReal frontOnLane, const SUMOReal timeOnLane, const SUMOReal /*meanSpeedFrontOnLane*/, const SUMOReal meanSpeedVehicleOnLane, const SUMOReal travelledDistanceFrontOnLane, const SUMOReal travelledDistanceVehicleOnLane) {
113  sampleSeconds += timeOnLane;
114  travelledDistance += travelledDistanceVehicleOnLane;
115  vehLengthSum += veh.getVehicleType().getLength() * timeOnLane;
116  // XXX: recheck, which value to use here for the speed. (Leo) Refs. #2579
117  if (myParent != 0 && meanSpeedVehicleOnLane < myParent->myHaltSpeed) {
118  waitSeconds += timeOnLane;
119  }
120  frontSampleSeconds += frontOnLane;
121  frontTravelledDistance += travelledDistanceFrontOnLane;
122 }
123 
124 
125 bool
127  if ((myParent == 0 || myParent->vehicleApplies(veh)) && (getLane() == 0 || getLane() == static_cast<MSVehicle&>(veh).getLane())) {
130  }
131  if (reason == MSMoveReminder::NOTIFICATION_ARRIVED) {
132  ++nVehArrived;
133  } else if (reason == MSMoveReminder::NOTIFICATION_LANE_CHANGE) {
135  } else if (myParent == 0 || reason != MSMoveReminder::NOTIFICATION_SEGMENT) {
136  ++nVehLeft;
138  ++nVehVaporized;
139  }
140  }
141  }
143  return false;
144  }
145  return reason == MSMoveReminder::NOTIFICATION_JUNCTION;
146 }
147 
148 
149 bool
151  if (myParent == 0 || myParent->vehicleApplies(veh)) {
152  if (getLane() == 0 || getLane() == static_cast<MSVehicle&>(veh).getLane()) {
154  ++nVehDeparted;
155  } else if (reason == MSMoveReminder::NOTIFICATION_LANE_CHANGE) {
157  } else if (myParent == 0 || reason != MSMoveReminder::NOTIFICATION_SEGMENT) {
158  ++nVehEntered;
159  }
160  }
161  return true;
162  }
163  return false;
164 }
165 
166 
167 bool
169  return sampleSeconds == 0 && nVehDeparted == 0 && nVehArrived == 0 && nVehEntered == 0
170  && nVehLeft == 0 && nVehVaporized == 0 && nVehLaneChangeFrom == 0 && nVehLaneChangeTo == 0;
171 }
172 
173 
174 void
176  const SUMOReal numLanes, const SUMOReal defaultTravelTime, const int numVehicles) const {
177  if (myParent == 0) {
178  if (sampleSeconds > 0) {
179  dev.writeAttr("density", sampleSeconds / STEPS2TIME(period) * (SUMOReal) 1000 / myLaneLength)
180  .writeAttr("occupancy", vehLengthSum / STEPS2TIME(period) / myLaneLength / numLanes * (SUMOReal) 100)
181  .writeAttr("waitingTime", waitSeconds).writeAttr("speed", travelledDistance / sampleSeconds);
182  }
183  dev.writeAttr("departed", nVehDeparted).writeAttr("arrived", nVehArrived).writeAttr("entered", nVehEntered).writeAttr("left", nVehLeft);
184  if (nVehVaporized > 0) {
185  dev.writeAttr("vaporized", nVehVaporized);
186  }
187  dev.closeTag();
188  return;
189  }
191  SUMOReal overlapTraveltime = myParent->myMaxTravelTime;
192  if (travelledDistance > 0.f) {
193  // one vehicle has to drive lane length + vehicle length before it has left the lane
194  // thus we need to scale with an extended length, approximated by lane length + average vehicle length
195  overlapTraveltime = MIN2(overlapTraveltime, (myLaneLength + vehLengthSum / sampleSeconds) * sampleSeconds / travelledDistance);
196  }
197  if (numVehicles > 0) {
198  dev.writeAttr("traveltime", sampleSeconds / numVehicles).writeAttr("waitingTime", waitSeconds).writeAttr("speed", travelledDistance / sampleSeconds);
199  } else {
200  SUMOReal traveltime = myParent->myMaxTravelTime;
201  if (frontTravelledDistance > 0.f) {
202  traveltime = MIN2(traveltime, myLaneLength * frontSampleSeconds / frontTravelledDistance);
203  dev.writeAttr("traveltime", traveltime);
204  } else if (defaultTravelTime >= 0.) {
205  dev.writeAttr("traveltime", defaultTravelTime);
206  }
207  dev.writeAttr("overlapTraveltime", overlapTraveltime)
208  .writeAttr("density", sampleSeconds / STEPS2TIME(period) * (SUMOReal) 1000 / myLaneLength)
209  .writeAttr("occupancy", vehLengthSum / STEPS2TIME(period) / myLaneLength / numLanes * (SUMOReal) 100)
210  .writeAttr("waitingTime", waitSeconds).writeAttr("speed", travelledDistance / sampleSeconds);
211  }
212  } else if (defaultTravelTime >= 0.) {
213  dev.writeAttr("traveltime", defaultTravelTime).writeAttr("speed", myLaneLength / defaultTravelTime);
214  }
215  dev.writeAttr("departed", nVehDeparted).writeAttr("arrived", nVehArrived).writeAttr("entered", nVehEntered).writeAttr("left", nVehLeft)
216  .writeAttr("laneChangedFrom", nVehLaneChangeFrom).writeAttr("laneChangedTo", nVehLaneChangeTo);
217  if (nVehVaporized > 0) {
218  dev.writeAttr("vaporized", nVehVaporized);
219  }
220  dev.closeTag();
221 }
222 
223 // ---------------------------------------------------------------------------
224 // MSMeanData_Net - methods
225 // ---------------------------------------------------------------------------
226 MSMeanData_Net::MSMeanData_Net(const std::string& id,
227  const SUMOTime dumpBegin,
228  const SUMOTime dumpEnd, const bool useLanes,
229  const bool withEmpty, const bool printDefaults,
230  const bool withInternal,
231  const bool trackVehicles,
232  const SUMOReal maxTravelTime,
233  const SUMOReal minSamples,
234  const SUMOReal haltSpeed,
235  const std::string& vTypes)
236  : MSMeanData(id, dumpBegin, dumpEnd, useLanes, withEmpty, printDefaults,
237  withInternal, trackVehicles, maxTravelTime, minSamples, vTypes),
238  myHaltSpeed(haltSpeed) {
239 }
240 
241 
243 
244 
246 MSMeanData_Net::createValues(MSLane* const lane, const SUMOReal length, const bool doAdd) const {
247  return new MSLaneMeanDataValues(lane, length, doAdd, this);
248 }
249 
250 
251 /****************************************************************************/
252 
Data collector for edges/lanes.
Definition: MSMeanData.h:67
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:257
int nVehEntered
The number of vehicles that entered this lane within the sample interval.
virtual ~MSLaneMeanDataValues()
Destructor.
const SUMOReal myLaneLength
The length of the lane / edge the data collector is on.
Definition: MSMeanData.h:175
MSMeanData::MeanDataValues * createValues(MSLane *const lane, const SUMOReal length, const bool doAdd) const
Create an instance of MeanDataValues.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:82
long long int SUMOTime
Definition: SUMOTime.h:43
MSLaneMeanDataValues(MSLane *const lane, const SUMOReal length, const bool doAdd, const MSMeanData_Net *parent)
Constructor.
int nVehVaporized
The number of vehicles that left this lane within the sample interval.
bool vehicleApplies(const SUMOVehicle &veh) const
Checks whether the detector measures vehicles of the given type.
The vehicle arrived at a junction.
SUMOReal travelledDistance
The sum of the distances the vehicles travelled.
Definition: MSMeanData.h:183
void removeFromVehicleUpdateValues(SUMOVehicle &veh)
const SUMOReal myMaxTravelTime
the maximum travel time to write
Definition: MSMeanData.h:432
Notification
Definition of a vehicle state.
const MSMeanData_Net * myParent
The meandata parent.
SUMOReal getLength() const
Get vehicle&#39;s length [m].
The vehicle got vaporized.
The vehicle changes the segment (meso only)
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.
SUMOReal frontSampleSeconds
The number of vehicle probes regarding the vehicle front.
Data structure for mean (aggregated) edge/lane values.
SUMOReal waitSeconds
The number of vehicle probes with small speed.
The vehicle changes lanes (micro only) XXX: What if a vehicle changes lanes and passes a junction sim...
int nVehLaneChangeTo
The number of vehicles that changed to this lane.
SUMOReal vehLengthSum
The sum of the lengths the vehicles had.
bool notifyEnter(SUMOVehicle &veh, MSMoveReminder::Notification reason)
Computes current values and adds them to their sums.
Representation of a vehicle.
Definition: SUMOVehicle.h:66
Data structure for mean (aggregated) edge/lane values.
Definition: MSMeanData.h:76
virtual ~MSMeanData_Net()
Destructor.
The vehicle arrived at its destination (is deleted)
#define STEPS2TIME(x)
Definition: SUMOTime.h:65
T MIN2(T a, T b)
Definition: StdDefs.h:69
const SUMOReal myHaltSpeed
the minimum sample seconds
const SUMOReal myMinSamples
the minimum sample seconds
Definition: MSMeanData.h:429
bool notifyLeave(SUMOVehicle &veh, SUMOReal lastPos, MSMoveReminder::Notification reason)
Called if the vehicle leaves the reminder&#39;s lane.
int nVehLeft
The number of vehicles that left this lane within the sample interval.
int nVehArrived
The number of vehicles that finished on the lane.
MSMeanData_Net(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 maxTravelTime, const SUMOReal minSamples, const SUMOReal haltSpeed, const std::string &vTypes)
Constructor.
The vehicle has departed (was inserted into the network)
SUMOReal frontTravelledDistance
The travelled distance regarding the vehicle front.
int nVehLaneChangeFrom
The number of vehicles that changed from this lane.
void addTo(MSMeanData::MeanDataValues &val) const
Add the values of this to the given one and store them there.
bool isEmpty() const
Returns whether any data was collected.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
Network state mean data collector for edges/lanes.
bool closeTag()
Closes the most recently opened tag.
#define SUMOReal
Definition: config.h:213
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.
void reset(bool afterWrite=false)
Resets values so they may be used for the next interval.
static bool gUseMesoSim
Definition: MSGlobals.h:95
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle&#39;s type.