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.sourceforge.net/
11 // Copyright (C) 2001-2012 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), nVehLaneChangeFrom(0), nVehLaneChangeTo(0),
67  waitSeconds(0), 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;
81  nVehLaneChangeFrom = 0;
82  nVehLaneChangeTo = 0;
83  sampleSeconds = 0.;
84  travelledDistance = 0;
85  waitSeconds = 0;
86  vehLengthSum = 0;
87 }
88 
89 
90 void
93  v.nVehDeparted += nVehDeparted;
94  v.nVehArrived += nVehArrived;
95  v.nVehEntered += nVehEntered;
96  v.nVehLeft += nVehLeft;
97  v.nVehVaporized += nVehVaporized;
98  v.nVehLaneChangeFrom += nVehLaneChangeFrom;
99  v.nVehLaneChangeTo += nVehLaneChangeTo;
100  v.sampleSeconds += sampleSeconds;
101  v.travelledDistance += travelledDistance;
102  v.waitSeconds += waitSeconds;
103  v.vehLengthSum += vehLengthSum;
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())) {
121 #ifdef HAVE_INTERNAL
123  myLastVehicleUpdateValues.erase(&veh);
124  }
125 #endif
126  if (reason == MSMoveReminder::NOTIFICATION_ARRIVED) {
127  ++nVehArrived;
128  } else if (reason == MSMoveReminder::NOTIFICATION_LANE_CHANGE) {
129  ++nVehLaneChangeFrom;
130  } else if (myParent == 0 || reason != MSMoveReminder::NOTIFICATION_SEGMENT) {
131  ++nVehLeft;
133  ++nVehVaporized;
134  }
135  }
136  }
137 #ifdef HAVE_INTERNAL
139  return false;
140  }
141 #endif
142  return reason == MSMoveReminder::NOTIFICATION_JUNCTION;
143 }
144 
145 
146 bool
148  if (vehicleApplies(veh)) {
149  if (getLane() == 0 || getLane() == static_cast<MSVehicle&>(veh).getLane()) {
151  ++nVehDeparted;
152  } else if (reason == MSMoveReminder::NOTIFICATION_LANE_CHANGE) {
153  ++nVehLaneChangeTo;
154  } else if (myParent == 0 || reason != MSMoveReminder::NOTIFICATION_SEGMENT) {
155  ++nVehEntered;
156  }
157  }
158  return true;
159  }
160  return false;
161 }
162 
163 
164 bool
166  return sampleSeconds == 0 && nVehDeparted == 0 && nVehArrived == 0 && nVehEntered == 0
167  && nVehLeft == 0 && nVehVaporized == 0 && nVehLaneChangeFrom == 0 && nVehLaneChangeTo == 0;
168 }
169 
170 
171 void
173  const SUMOReal numLanes, const SUMOReal defaultTravelTime, const int numVehicles) const {
174  if (myParent == 0) {
175  if (sampleSeconds > 0) {
176  dev << "\" density=\"" << sampleSeconds / STEPS2TIME(period) *(SUMOReal) 1000 / myLaneLength <<
177  "\" occupancy=\"" << vehLengthSum / STEPS2TIME(period) / myLaneLength / numLanes *(SUMOReal) 100 <<
178  "\" waitingTime=\"" << waitSeconds <<
179  "\" speed=\"" << travelledDistance / sampleSeconds;
180  }
181  dev << "\" departed=\"" << nVehDeparted <<
182  "\" arrived=\"" << nVehArrived <<
183  "\" entered=\"" << nVehEntered <<
184  "\" left=\"" << nVehLeft << "\"";
185  if (nVehVaporized > 0) {
186  dev << " vaporized=\"" << nVehVaporized << "\"";
187  }
188  dev.closeTag(true);
189  return;
190  }
191  if (sampleSeconds > myParent->myMinSamples) {
192  SUMOReal traveltime = myParent->myMaxTravelTime;
193  if (travelledDistance > 0.f) {
194  traveltime = MIN2(traveltime, myLaneLength * sampleSeconds / travelledDistance);
195  }
196  if (numVehicles > 0) {
197  dev << "\" traveltime=\"" << sampleSeconds / numVehicles <<
198  "\" waitingTime=\"" << waitSeconds <<
199  "\" speed=\"" << travelledDistance / sampleSeconds;
200  } else {
201  dev << "\" traveltime=\"" << traveltime <<
202  "\" density=\"" << sampleSeconds / STEPS2TIME(period) *(SUMOReal) 1000 / myLaneLength <<
203  "\" occupancy=\"" << vehLengthSum / STEPS2TIME(period) / myLaneLength / numLanes *(SUMOReal) 100 <<
204  "\" waitingTime=\"" << waitSeconds <<
205  "\" speed=\"" << travelledDistance / sampleSeconds;
206  }
207  } else if (defaultTravelTime >= 0.) {
208  dev << "\" traveltime=\"" << defaultTravelTime <<
209  "\" speed=\"" << myLaneLength / defaultTravelTime;
210  }
211  dev << "\" departed=\"" << nVehDeparted <<
212  "\" arrived=\"" << nVehArrived <<
213  "\" entered=\"" << nVehEntered <<
214  "\" left=\"" << nVehLeft <<
215  "\" laneChangedFrom=\"" << nVehLaneChangeFrom <<
216  "\" laneChangedTo=\"" << nVehLaneChangeTo << "\"";
217  if (nVehVaporized > 0) {
218  dev << " vaporized=\"" << nVehVaporized << "\"";
219  }
220  dev.closeTag(true);
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::set<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, &myVehicleTypes, this);
248 }
249 
250 
251 /****************************************************************************/
252