SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MSMeanData_Net.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 // Network state mean data collector for edges/lanes
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
11 // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <microsim/MSEdgeControl.h>
33 #include <microsim/MSEdge.h>
34 #include <microsim/MSLane.h>
35 #include <microsim/MSVehicle.h>
36 #include <utils/common/SUMOTime.h>
37 #include <utils/common/ToString.h>
39 #include "MSMeanData_Net.h"
40 #include <limits>
41 
42 #ifdef HAVE_INTERNAL
43 #include <microsim/MSGlobals.h>
44 #include <mesosim/MELoop.h>
45 #include <mesosim/MESegment.h>
46 #endif
47 
48 #ifdef CHECK_MEMORY_LEAKS
49 #include <foreign/nvwa/debug_new.h>
50 #endif // CHECK_MEMORY_LEAKS
51 
52 
53 // ===========================================================================
54 // method definitions
55 // ===========================================================================
56 // ---------------------------------------------------------------------------
57 // MSMeanData_Net::MSLaneMeanDataValues - methods
58 // ---------------------------------------------------------------------------
60  const SUMOReal length,
61  const bool doAdd,
62  const std::set<std::string>* const vTypes,
63  const MSMeanData_Net* parent)
64  : MSMeanData::MeanDataValues(lane, length, doAdd, vTypes),
65  nVehDeparted(0), nVehArrived(0), nVehEntered(0), nVehLeft(0),
66  nVehVaporized(0), waitSeconds(0),
67  nVehLaneChangeFrom(0), nVehLaneChangeTo(0),
68  vehLengthSum(0), myParent(parent) {}
69 
70 
72 }
73 
74 
75 void
77  nVehDeparted = 0;
78  nVehArrived = 0;
79  nVehEntered = 0;
80  nVehLeft = 0;
81  nVehVaporized = 0;
82  nVehLaneChangeFrom = 0;
83  nVehLaneChangeTo = 0;
84  sampleSeconds = 0.;
85  travelledDistance = 0;
86  waitSeconds = 0;
87  vehLengthSum = 0;
88 }
89 
90 
91 void
94  v.nVehDeparted += nVehDeparted;
95  v.nVehArrived += nVehArrived;
96  v.nVehEntered += nVehEntered;
97  v.nVehLeft += nVehLeft;
98  v.nVehVaporized += nVehVaporized;
99  v.nVehLaneChangeFrom += nVehLaneChangeFrom;
100  v.nVehLaneChangeTo += nVehLaneChangeTo;
101  v.sampleSeconds += sampleSeconds;
102  v.travelledDistance += travelledDistance;
103  v.waitSeconds += waitSeconds;
104  v.vehLengthSum += vehLengthSum;
105 }
106 
107 
108 void
110  sampleSeconds += timeOnLane;
111  travelledDistance += speed * timeOnLane;
112  vehLengthSum += veh.getVehicleType().getLength() * timeOnLane;
113  if (myParent != 0 && speed < myParent->myHaltSpeed) {
114  waitSeconds += timeOnLane;
115  }
116 }
117 
118 
119 bool
121  if (vehicleApplies(veh) && (getLane() == 0 || getLane() == static_cast<MSVehicle&>(veh).getLane())) {
122 #ifdef HAVE_INTERNAL
124  myLastVehicleUpdateValues.erase(&veh);
125  }
126 #endif
127  if (reason == MSMoveReminder::NOTIFICATION_ARRIVED) {
128  ++nVehArrived;
129  } else if (reason == MSMoveReminder::NOTIFICATION_LANE_CHANGE) {
130  ++nVehLaneChangeFrom;
131  } else if (myParent == 0 || reason != MSMoveReminder::NOTIFICATION_SEGMENT) {
132  ++nVehLeft;
134  ++nVehVaporized;
135  }
136  }
137  }
138 #ifdef HAVE_INTERNAL
140  return false;
141  }
142 #endif
143  return reason == MSMoveReminder::NOTIFICATION_JUNCTION;
144 }
145 
146 
147 bool
149  if (vehicleApplies(veh)) {
150  if (getLane() == 0 || getLane() == static_cast<MSVehicle&>(veh).getLane()) {
152  ++nVehDeparted;
153  } else if (reason == MSMoveReminder::NOTIFICATION_LANE_CHANGE) {
154  ++nVehLaneChangeTo;
155  } else if (myParent == 0 || reason != MSMoveReminder::NOTIFICATION_SEGMENT) {
156  ++nVehEntered;
157  }
158  }
159  return true;
160  }
161  return false;
162 }
163 
164 
165 bool
167  return sampleSeconds == 0 && nVehDeparted == 0 && nVehArrived == 0 && nVehEntered == 0
168  && nVehLeft == 0 && nVehVaporized == 0 && nVehLaneChangeFrom == 0 && nVehLaneChangeTo == 0;
169 }
170 
171 
172 void
174  const SUMOReal numLanes, const SUMOReal defaultTravelTime, const int numVehicles) const {
175  if (myParent == 0) {
176  if (sampleSeconds > 0) {
177  dev << "\" density=\"" << sampleSeconds / STEPS2TIME(period) *(SUMOReal) 1000 / myLaneLength <<
178  "\" occupancy=\"" << vehLengthSum / STEPS2TIME(period) / myLaneLength / numLanes *(SUMOReal) 100 <<
179  "\" waitingTime=\"" << waitSeconds <<
180  "\" speed=\"" << travelledDistance / sampleSeconds;
181  }
182  dev << "\" departed=\"" << nVehDeparted <<
183  "\" arrived=\"" << nVehArrived <<
184  "\" entered=\"" << nVehEntered <<
185  "\" left=\"" << nVehLeft << "\"";
186  if (nVehVaporized > 0) {
187  dev << " vaporized=\"" << nVehVaporized << "\"";
188  }
189  dev.closeTag();
190  return;
191  }
192  if (sampleSeconds > myParent->myMinSamples) {
193  SUMOReal traveltime = myParent->myMaxTravelTime;
194  if (travelledDistance > 0.f) {
195  traveltime = MIN2(traveltime, myLaneLength * sampleSeconds / travelledDistance);
196  }
197  if (numVehicles > 0) {
198  dev << "\" traveltime=\"" << sampleSeconds / numVehicles <<
199  "\" waitingTime=\"" << waitSeconds <<
200  "\" speed=\"" << travelledDistance / sampleSeconds;
201  } else {
202  dev << "\" traveltime=\"" << traveltime <<
203  "\" density=\"" << sampleSeconds / STEPS2TIME(period) *(SUMOReal) 1000 / myLaneLength <<
204  "\" occupancy=\"" << vehLengthSum / STEPS2TIME(period) / myLaneLength / numLanes *(SUMOReal) 100 <<
205  "\" waitingTime=\"" << waitSeconds <<
206  "\" speed=\"" << travelledDistance / sampleSeconds;
207  }
208  } else if (defaultTravelTime >= 0.) {
209  dev << "\" traveltime=\"" << defaultTravelTime <<
210  "\" speed=\"" << myLaneLength / defaultTravelTime;
211  }
212  dev << "\" departed=\"" << nVehDeparted <<
213  "\" arrived=\"" << nVehArrived <<
214  "\" entered=\"" << nVehEntered <<
215  "\" left=\"" << nVehLeft <<
216  "\" laneChangedFrom=\"" << nVehLaneChangeFrom <<
217  "\" laneChangedTo=\"" << nVehLaneChangeTo << "\"";
218  if (nVehVaporized > 0) {
219  dev << " vaporized=\"" << nVehVaporized << "\"";
220  }
221  dev.closeTag();
222 }
223 
224 // ---------------------------------------------------------------------------
225 // MSMeanData_Net - methods
226 // ---------------------------------------------------------------------------
227 MSMeanData_Net::MSMeanData_Net(const std::string& id,
228  const SUMOTime dumpBegin,
229  const SUMOTime dumpEnd, const bool useLanes,
230  const bool withEmpty, const bool printDefaults,
231  const bool withInternal,
232  const bool trackVehicles,
233  const SUMOReal maxTravelTime,
234  const SUMOReal minSamples,
235  const SUMOReal haltSpeed,
236  const std::set<std::string> vTypes)
237  : MSMeanData(id, dumpBegin, dumpEnd, useLanes, withEmpty, printDefaults,
238  withInternal, trackVehicles, maxTravelTime, minSamples, vTypes),
239  myHaltSpeed(haltSpeed) {
240 }
241 
242 
244 
245 
247 MSMeanData_Net::createValues(MSLane* const lane, const SUMOReal length, const bool doAdd) const {
248  return new MSLaneMeanDataValues(lane, length, doAdd, &myVehicleTypes, this);
249 }
250 
251 
252 /****************************************************************************/
253 
Data collector for edges/lanes.
Definition: MSMeanData.h:66
virtual ~MSLaneMeanDataValues()
Destructor.
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.
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:180
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.
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:420
Data structure for mean (aggregated) edge/lane values.
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:63
Data structure for mean (aggregated) edge/lane values.
Definition: MSMeanData.h:75
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:57
const SUMOReal myHaltSpeed
the minimum sample seconds
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:70
Network state mean data collector for edges/lanes.
bool closeTag()
Closes the most recently opened tag.
#define SUMOReal
Definition: config.h:221
static const bool gUseMesoSim
Definition: MSGlobals.h:95
void reset(bool afterWrite=false)
Resets values so they may be used for the next interval.
Representation of a lane in the micro simulation.
Definition: MSLane.h:73
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle&#39;s type.