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 /****************************************************************************/
9 // Network state mean data collector for edges/lanes
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
12 // Copyright (C) 2004-2014 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;
83  nVehLaneChangeFrom = 0;
84  nVehLaneChangeTo = 0;
85  sampleSeconds = 0.;
86  travelledDistance = 0;
87  waitSeconds = 0;
88  vehLengthSum = 0;
89 }
90 
91 
92 void
95  v.nVehDeparted += nVehDeparted;
96  v.nVehArrived += nVehArrived;
97  v.nVehEntered += nVehEntered;
98  v.nVehLeft += nVehLeft;
99  v.nVehVaporized += nVehVaporized;
100  v.nVehLaneChangeFrom += nVehLaneChangeFrom;
101  v.nVehLaneChangeTo += nVehLaneChangeTo;
102  v.sampleSeconds += sampleSeconds;
103  v.travelledDistance += travelledDistance;
104  v.waitSeconds += waitSeconds;
105  v.vehLengthSum += vehLengthSum;
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  myLastVehicleUpdateValues.erase(&veh);
126  }
127 #endif
128  if (reason == MSMoveReminder::NOTIFICATION_ARRIVED) {
129  ++nVehArrived;
130  } else if (reason == MSMoveReminder::NOTIFICATION_LANE_CHANGE) {
131  ++nVehLaneChangeFrom;
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) {
155  ++nVehLaneChangeTo;
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  }
189  if (sampleSeconds > myParent->myMinSamples) {
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