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-2015 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 #ifdef HAVE_INTERNAL
44 #include <microsim/MSGlobals.h>
45 #include <mesosim/MELoop.h>
46 #include <mesosim/MESegment.h>
47 #endif
48 
49 #ifdef CHECK_MEMORY_LEAKS
50 #include <foreign/nvwa/debug_new.h>
51 #endif // CHECK_MEMORY_LEAKS
52 
53 
54 // ===========================================================================
55 // method definitions
56 // ===========================================================================
57 // ---------------------------------------------------------------------------
58 // MSMeanData_Net::MSLaneMeanDataValues - methods
59 // ---------------------------------------------------------------------------
61  const SUMOReal length,
62  const bool doAdd,
63  const std::set<std::string>* const vTypes,
64  const MSMeanData_Net* parent)
65  : MSMeanData::MeanDataValues(lane, length, doAdd, vTypes),
66  nVehDeparted(0), nVehArrived(0), nVehEntered(0), nVehLeft(0),
67  nVehVaporized(0), waitSeconds(0),
68  nVehLaneChangeFrom(0), nVehLaneChangeTo(0),
69  vehLengthSum(0), myParent(parent) {}
70 
71 
73 }
74 
75 
76 void
78  nVehDeparted = 0;
79  nVehArrived = 0;
80  nVehEntered = 0;
81  nVehLeft = 0;
82  nVehVaporized = 0;
84  nVehLaneChangeTo = 0;
85  sampleSeconds = 0.;
87  waitSeconds = 0;
88  vehLengthSum = 0;
89 }
90 
91 
92 void
98  v.nVehLeft += nVehLeft;
106 }
107 
108 
109 void
111  sampleSeconds += timeOnLane;
112  travelledDistance += speed * timeOnLane;
113  vehLengthSum += veh.getVehicleType().getLength() * timeOnLane;
114  if (myParent != 0 && speed < myParent->myHaltSpeed) {
115  waitSeconds += timeOnLane;
116  }
117 }
118 
119 
120 bool
122  if (vehicleApplies(veh) && (getLane() == 0 || getLane() == static_cast<MSVehicle&>(veh).getLane())) {
123 #ifdef HAVE_INTERNAL
125  removeFromVehicleUpdateValues(veh);
126  }
127 #endif
128  if (reason == MSMoveReminder::NOTIFICATION_ARRIVED) {
129  ++nVehArrived;
130  } else if (reason == MSMoveReminder::NOTIFICATION_LANE_CHANGE) {
132  } else if (myParent == 0 || reason != MSMoveReminder::NOTIFICATION_SEGMENT) {
133  ++nVehLeft;
135  ++nVehVaporized;
136  }
137  }
138  }
139 #ifdef HAVE_INTERNAL
141  return false;
142  }
143 #endif
144  return reason == MSMoveReminder::NOTIFICATION_JUNCTION;
145 }
146 
147 
148 bool
150  if (vehicleApplies(veh)) {
151  if (getLane() == 0 || getLane() == static_cast<MSVehicle&>(veh).getLane()) {
153  ++nVehDeparted;
154  } else if (reason == MSMoveReminder::NOTIFICATION_LANE_CHANGE) {
156  } else if (myParent == 0 || reason != MSMoveReminder::NOTIFICATION_SEGMENT) {
157  ++nVehEntered;
158  }
159  }
160  return true;
161  }
162  return false;
163 }
164 
165 
166 bool
168  return sampleSeconds == 0 && nVehDeparted == 0 && nVehArrived == 0 && nVehEntered == 0
169  && nVehLeft == 0 && nVehVaporized == 0 && nVehLaneChangeFrom == 0 && nVehLaneChangeTo == 0;
170 }
171 
172 
173 void
175  const SUMOReal numLanes, const SUMOReal defaultTravelTime, const int numVehicles) const {
176  if (myParent == 0) {
177  if (sampleSeconds > 0) {
178  dev.writeAttr("density", sampleSeconds / STEPS2TIME(period) * (SUMOReal) 1000 / myLaneLength)
179  .writeAttr("occupancy", vehLengthSum / STEPS2TIME(period) / myLaneLength / numLanes * (SUMOReal) 100)
180  .writeAttr("waitingTime", waitSeconds).writeAttr("speed", travelledDistance / sampleSeconds);
181  }
182  dev.writeAttr("departed", nVehDeparted).writeAttr("arrived", nVehArrived).writeAttr("entered", nVehEntered).writeAttr("left", nVehLeft);
183  if (nVehVaporized > 0) {
184  dev.writeAttr("vaporized", nVehVaporized);
185  }
186  dev.closeTag();
187  return;
188  }
190  SUMOReal traveltime = myParent->myMaxTravelTime;
191  if (travelledDistance > 0.f) {
192  traveltime = MIN2(traveltime, myLaneLength * sampleSeconds / travelledDistance);
193  }
194  if (numVehicles > 0) {
195  dev.writeAttr("traveltime", sampleSeconds / numVehicles).writeAttr("waitingTime", waitSeconds).writeAttr("speed", travelledDistance / sampleSeconds);
196  } else {
197  dev.writeAttr("traveltime", traveltime)
198  .writeAttr("density", sampleSeconds / STEPS2TIME(period) * (SUMOReal) 1000 / myLaneLength)
199  .writeAttr("occupancy", vehLengthSum / STEPS2TIME(period) / myLaneLength / numLanes * (SUMOReal) 100)
200  .writeAttr("waitingTime", waitSeconds).writeAttr("speed", travelledDistance / sampleSeconds);
201  }
202  } else if (defaultTravelTime >= 0.) {
203  dev.writeAttr("traveltime", defaultTravelTime).writeAttr("speed", myLaneLength / defaultTravelTime);
204  }
205  dev.writeAttr("departed", nVehDeparted).writeAttr("arrived", nVehArrived).writeAttr("entered", nVehEntered).writeAttr("left", nVehLeft)
206  .writeAttr("laneChangedFrom", nVehLaneChangeFrom).writeAttr("laneChangedTo", nVehLaneChangeTo);
207  if (nVehVaporized > 0) {
208  dev.writeAttr("vaporized", nVehVaporized);
209  }
210  dev.closeTag();
211 }
212 
213 // ---------------------------------------------------------------------------
214 // MSMeanData_Net - methods
215 // ---------------------------------------------------------------------------
216 MSMeanData_Net::MSMeanData_Net(const std::string& id,
217  const SUMOTime dumpBegin,
218  const SUMOTime dumpEnd, const bool useLanes,
219  const bool withEmpty, const bool printDefaults,
220  const bool withInternal,
221  const bool trackVehicles,
222  const SUMOReal maxTravelTime,
223  const SUMOReal minSamples,
224  const SUMOReal haltSpeed,
225  const std::set<std::string> vTypes)
226  : MSMeanData(id, dumpBegin, dumpEnd, useLanes, withEmpty, printDefaults,
227  withInternal, trackVehicles, maxTravelTime, minSamples, vTypes),
228  myHaltSpeed(haltSpeed) {
229 }
230 
231 
233 
234 
236 MSMeanData_Net::createValues(MSLane* const lane, const SUMOReal length, const bool doAdd) const {
237  return new MSLaneMeanDataValues(lane, length, doAdd, &myVehicleTypes, this);
238 }
239 
240 
241 /****************************************************************************/
242 
Data collector for edges/lanes.
Definition: MSMeanData.h:67
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:257
virtual ~MSLaneMeanDataValues()
Destructor.
const SUMOReal myLaneLength
The length of the lane / edge the data collector is on.
Definition: MSMeanData.h:173
MSLaneMeanDataValues(MSLane *const lane, const SUMOReal length, const bool doAdd, const std::set< std::string > *const vTypes=0, const MSMeanData_Net *parent=0)
Constructor.
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.
long long int SUMOTime
Definition: SUMOTime.h:43
unsigned nVehVaporized
The number of vehicles that left this lane within the sample interval.
The vehicle arrived at a junction.
SUMOReal travelledDistance
The sum of the distances the vehicles travelled.
Definition: MSMeanData.h:181
const SUMOReal myMaxTravelTime
the maximum travel time to write
Definition: MSMeanData.h:432
void addTo(MSMeanData::MeanDataValues &val) const
Add the values of this to the given one and store them there.
Notification
Definition of a vehicle state.
const MSMeanData_Net * myParent
The meandata parent.
SUMOReal getLength() const
Get vehicle&#39;s length [m].
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::set< std::string > vTypes)
Constructor.
The vehicle got vaporized.
The vehicle changes the segment (meso only)
unsigned nVehLaneChangeFrom
The number of vehicles that changed from this lane.
const std::set< std::string > myVehicleTypes
The vehicle types to look for (empty means all)
Definition: MSMeanData.h:435
Data structure for mean (aggregated) edge/lane values.
const MSLane * getLane() const
Returns the lane the reminder works on.
SUMOReal waitSeconds
The number of vehicle probes with small speed.
The vehicle changes lanes (micro only)
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:65
Data structure for mean (aggregated) edge/lane values.
Definition: MSMeanData.h:76
void notifyMoveInternal(SUMOVehicle &veh, SUMOReal timeOnLane, SUMOReal speed)
Internal notification about the vehicle moves.
unsigned nVehArrived
The number of vehicles that finished on the lane.
unsigned nVehLaneChangeTo
The number of vehicles that changed to this lane.
unsigned nVehEntered
The number of vehicles that entered this lane within the sample interval.
virtual ~MSMeanData_Net()
Destructor.
The vehicle arrived at its destination (is deleted)
#define STEPS2TIME(x)
Definition: SUMOTime.h:65
bool isEmpty() const
Returns whether any data was collected.
T MIN2(T a, T b)
Definition: StdDefs.h:73
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.
The vehicle has departed (was inserted into the network)
MSMeanData::MeanDataValues * createValues(MSLane *const lane, const SUMOReal length, const bool doAdd) const
Create an instance of MeanDataValues.
unsigned nVehLeft
The number of vehicles that left this lane within the sample interval.
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:214
static const bool gUseMesoSim
Definition: MSGlobals.h:102
void reset(bool afterWrite=false)
Resets values so they may be used for the next interval.
bool vehicleApplies(const SUMOVehicle &veh) const
Tests whether the vehicles type is to be regarded.
Definition: MSMeanData.cpp:124
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle&#39;s type.