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 std::set<std::string>* const vTypes,
62  const MSMeanData_Net* parent)
63  : MSMeanData::MeanDataValues(lane, length, doAdd, vTypes),
64  nVehDeparted(0), nVehArrived(0), nVehEntered(0), nVehLeft(0),
65  nVehVaporized(0), waitSeconds(0),
66  nVehLaneChangeFrom(0), nVehLaneChangeTo(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;
86  vehLengthSum = 0;
87 }
88 
89 
90 void
96  v.nVehLeft += nVehLeft;
104 }
105 
106 
107 void
109  sampleSeconds += timeOnLane;
110  travelledDistance += speed * timeOnLane;
111  vehLengthSum += veh.getVehicleType().getLength() * timeOnLane;
112  if (myParent != 0 && speed < myParent->myHaltSpeed) {
113  waitSeconds += timeOnLane;
114  }
115 }
116 
117 
118 bool
120  if (vehicleApplies(veh) && (getLane() == 0 || getLane() == static_cast<MSVehicle&>(veh).getLane())) {
123  }
124  if (reason == MSMoveReminder::NOTIFICATION_ARRIVED) {
125  ++nVehArrived;
126  } else if (reason == MSMoveReminder::NOTIFICATION_LANE_CHANGE) {
128  } else if (myParent == 0 || reason != MSMoveReminder::NOTIFICATION_SEGMENT) {
129  ++nVehLeft;
131  ++nVehVaporized;
132  }
133  }
134  }
136  return false;
137  }
138  return reason == MSMoveReminder::NOTIFICATION_JUNCTION;
139 }
140 
141 
142 bool
144  if (vehicleApplies(veh)) {
145  if (getLane() == 0 || getLane() == static_cast<MSVehicle&>(veh).getLane()) {
147  ++nVehDeparted;
148  } else if (reason == MSMoveReminder::NOTIFICATION_LANE_CHANGE) {
150  } else if (myParent == 0 || reason != MSMoveReminder::NOTIFICATION_SEGMENT) {
151  ++nVehEntered;
152  }
153  }
154  return true;
155  }
156  return false;
157 }
158 
159 
160 bool
162  return sampleSeconds == 0 && nVehDeparted == 0 && nVehArrived == 0 && nVehEntered == 0
163  && nVehLeft == 0 && nVehVaporized == 0 && nVehLaneChangeFrom == 0 && nVehLaneChangeTo == 0;
164 }
165 
166 
167 void
169  const SUMOReal numLanes, const SUMOReal defaultTravelTime, const int numVehicles) const {
170  if (myParent == 0) {
171  if (sampleSeconds > 0) {
172  dev.writeAttr("density", sampleSeconds / STEPS2TIME(period) * (SUMOReal) 1000 / myLaneLength)
173  .writeAttr("occupancy", vehLengthSum / STEPS2TIME(period) / myLaneLength / numLanes * (SUMOReal) 100)
174  .writeAttr("waitingTime", waitSeconds).writeAttr("speed", travelledDistance / sampleSeconds);
175  }
176  dev.writeAttr("departed", nVehDeparted).writeAttr("arrived", nVehArrived).writeAttr("entered", nVehEntered).writeAttr("left", nVehLeft);
177  if (nVehVaporized > 0) {
178  dev.writeAttr("vaporized", nVehVaporized);
179  }
180  dev.closeTag();
181  return;
182  }
184  SUMOReal traveltime = myParent->myMaxTravelTime;
185  if (travelledDistance > 0.f) {
186  traveltime = MIN2(traveltime, myLaneLength * sampleSeconds / travelledDistance);
187  }
188  if (numVehicles > 0) {
189  dev.writeAttr("traveltime", sampleSeconds / numVehicles).writeAttr("waitingTime", waitSeconds).writeAttr("speed", travelledDistance / sampleSeconds);
190  } else {
191  dev.writeAttr("traveltime", traveltime)
192  .writeAttr("density", sampleSeconds / STEPS2TIME(period) * (SUMOReal) 1000 / myLaneLength)
193  .writeAttr("occupancy", vehLengthSum / STEPS2TIME(period) / myLaneLength / numLanes * (SUMOReal) 100)
194  .writeAttr("waitingTime", waitSeconds).writeAttr("speed", travelledDistance / sampleSeconds);
195  }
196  } else if (defaultTravelTime >= 0.) {
197  dev.writeAttr("traveltime", defaultTravelTime).writeAttr("speed", myLaneLength / defaultTravelTime);
198  }
199  dev.writeAttr("departed", nVehDeparted).writeAttr("arrived", nVehArrived).writeAttr("entered", nVehEntered).writeAttr("left", nVehLeft)
200  .writeAttr("laneChangedFrom", nVehLaneChangeFrom).writeAttr("laneChangedTo", nVehLaneChangeTo);
201  if (nVehVaporized > 0) {
202  dev.writeAttr("vaporized", nVehVaporized);
203  }
204  dev.closeTag();
205 }
206 
207 // ---------------------------------------------------------------------------
208 // MSMeanData_Net - methods
209 // ---------------------------------------------------------------------------
210 MSMeanData_Net::MSMeanData_Net(const std::string& id,
211  const SUMOTime dumpBegin,
212  const SUMOTime dumpEnd, const bool useLanes,
213  const bool withEmpty, const bool printDefaults,
214  const bool withInternal,
215  const bool trackVehicles,
216  const SUMOReal maxTravelTime,
217  const SUMOReal minSamples,
218  const SUMOReal haltSpeed,
219  const std::set<std::string> vTypes)
220  : MSMeanData(id, dumpBegin, dumpEnd, useLanes, withEmpty, printDefaults,
221  withInternal, trackVehicles, maxTravelTime, minSamples, vTypes),
222  myHaltSpeed(haltSpeed) {
223 }
224 
225 
227 
228 
230 MSMeanData_Net::createValues(MSLane* const lane, const SUMOReal length, const bool doAdd) const {
231  return new MSLaneMeanDataValues(lane, length, doAdd, &myVehicleTypes, this);
232 }
233 
234 
235 /****************************************************************************/
236 
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
void removeFromVehicleUpdateValues(SUMOVehicle &veh)
const SUMOReal myMaxTravelTime
the maximum travel time to write
Definition: MSMeanData.h:437
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:440
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:69
const SUMOReal myHaltSpeed
the minimum sample seconds
const SUMOReal myMinSamples
the minimum sample seconds
Definition: MSMeanData.h:434
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:213
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:120
static bool gUseMesoSim
Definition: MSGlobals.h:87
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle&#39;s type.