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_MESOSIM
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), myParent(parent),
65  nVehDeparted(0), nVehArrived(0), nVehEntered(0), nVehLeft(0),
66  nVehLaneChangeFrom(0), nVehLaneChangeTo(0), waitSeconds(0), vehLengthSum(0) {}
67 
68 
70 }
71 
72 
73 void
75  nVehDeparted = 0;
76  nVehArrived = 0;
77  nVehEntered = 0;
78  nVehLeft = 0;
79  nVehLaneChangeFrom = 0;
80  nVehLaneChangeTo = 0;
81  sampleSeconds = 0.;
82  travelledDistance = 0;
83  waitSeconds = 0;
84  vehLengthSum = 0;
85 }
86 
87 
88 void
91  v.nVehDeparted += nVehDeparted;
92  v.nVehArrived += nVehArrived;
93  v.nVehEntered += nVehEntered;
94  v.nVehLeft += nVehLeft;
95  v.nVehLaneChangeFrom += nVehLaneChangeFrom;
96  v.nVehLaneChangeTo += nVehLaneChangeTo;
97  v.sampleSeconds += sampleSeconds;
98  v.travelledDistance += travelledDistance;
99  v.waitSeconds += waitSeconds;
100  v.vehLengthSum += vehLengthSum;
101 }
102 
103 
104 void
106  sampleSeconds += timeOnLane;
107  travelledDistance += speed * timeOnLane;
108  vehLengthSum += veh.getVehicleType().getLength() * timeOnLane;
109  if (myParent != 0 && speed < myParent->myHaltSpeed) {
110  waitSeconds += timeOnLane;
111  }
112 }
113 
114 
115 bool
117  if (vehicleApplies(veh) && (getLane() == 0 || getLane() == static_cast<MSVehicle&>(veh).getLane())) {
118 #ifdef HAVE_MESOSIM
120  myLastVehicleUpdateValues.erase(&veh);
121  }
122 #endif
123  if (reason == MSMoveReminder::NOTIFICATION_ARRIVED) {
124  ++nVehArrived;
125  } else if (reason == MSMoveReminder::NOTIFICATION_LANE_CHANGE) {
126  ++nVehLaneChangeFrom;
127  } else if (myParent == 0 || reason != MSMoveReminder::NOTIFICATION_SEGMENT) {
128  ++nVehLeft;
129  }
130  }
131 #ifdef HAVE_MESOSIM
133  return false;
134  }
135 #endif
136  return reason == MSMoveReminder::NOTIFICATION_JUNCTION;
137 }
138 
139 
140 bool
142  if (vehicleApplies(veh)) {
143  if (getLane() == 0 || getLane() == static_cast<MSVehicle&>(veh).getLane()) {
145  ++nVehDeparted;
146  } else if (reason == MSMoveReminder::NOTIFICATION_LANE_CHANGE) {
147  ++nVehLaneChangeTo;
148  } else if (myParent == 0 || reason != MSMoveReminder::NOTIFICATION_SEGMENT) {
149  ++nVehEntered;
150  }
151  }
152  return true;
153  }
154  return false;
155 }
156 
157 
158 bool
160  return sampleSeconds == 0 && nVehDeparted == 0 && nVehArrived == 0 && nVehEntered == 0 && nVehLeft == 0 && nVehLaneChangeFrom == 0 && nVehLaneChangeTo == 0;
161 }
162 
163 
164 void
166  const SUMOReal numLanes, const SUMOReal defaultTravelTime, const int numVehicles) const {
167  if (myParent == 0) {
168  if (sampleSeconds > 0) {
169  dev << "\" density=\"" << sampleSeconds / STEPS2TIME(period) *(SUMOReal) 1000 / myLaneLength <<
170  "\" occupancy=\"" << vehLengthSum / STEPS2TIME(period) / myLaneLength / numLanes *(SUMOReal) 100 <<
171  "\" waitingTime=\"" << waitSeconds <<
172  "\" speed=\"" << travelledDistance / sampleSeconds;
173  }
174  dev << "\" departed=\"" << nVehDeparted <<
175  "\" arrived=\"" << nVehArrived <<
176  "\" entered=\"" << nVehEntered <<
177  "\" left=\"" << nVehLeft << "\"";
178  dev.closeTag(true);
179  return;
180  }
181  if (sampleSeconds > myParent->myMinSamples) {
182  SUMOReal traveltime = myParent->myMaxTravelTime;
183  if (travelledDistance > 0.f) {
184  traveltime = MIN2(traveltime, myLaneLength * sampleSeconds / travelledDistance);
185  }
186  if (numVehicles > 0) {
187  dev << "\" traveltime=\"" << sampleSeconds / numVehicles <<
188  "\" waitingTime=\"" << waitSeconds <<
189  "\" speed=\"" << travelledDistance / sampleSeconds;
190  } else {
191  dev << "\" traveltime=\"" << traveltime <<
192  "\" density=\"" << sampleSeconds / STEPS2TIME(period) *(SUMOReal) 1000 / myLaneLength <<
193  "\" occupancy=\"" << vehLengthSum / STEPS2TIME(period) / myLaneLength / numLanes *(SUMOReal) 100 <<
194  "\" waitingTime=\"" << waitSeconds <<
195  "\" speed=\"" << travelledDistance / sampleSeconds;
196  }
197  } else if (defaultTravelTime >= 0.) {
198  dev << "\" traveltime=\"" << defaultTravelTime <<
199  "\" speed=\"" << myLaneLength / defaultTravelTime;
200  }
201  dev << "\" departed=\"" << nVehDeparted <<
202  "\" arrived=\"" << nVehArrived <<
203  "\" entered=\"" << nVehEntered <<
204  "\" left=\"" << nVehLeft <<
205  "\" laneChangedFrom=\"" << nVehLaneChangeFrom <<
206  "\" laneChangedTo=\"" << nVehLaneChangeTo << "\"";
207  dev.closeTag(true);
208 }
209 
210 // ---------------------------------------------------------------------------
211 // MSMeanData_Net - methods
212 // ---------------------------------------------------------------------------
213 MSMeanData_Net::MSMeanData_Net(const std::string& id,
214  const SUMOTime dumpBegin,
215  const SUMOTime dumpEnd, const bool useLanes,
216  const bool withEmpty, const bool printDefaults,
217  const bool withInternal,
218  const bool trackVehicles,
219  const SUMOReal maxTravelTime,
220  const SUMOReal minSamples,
221  const SUMOReal haltSpeed,
222  const std::set<std::string> vTypes)
223  : MSMeanData(id, dumpBegin, dumpEnd, useLanes, withEmpty, printDefaults,
224  withInternal, trackVehicles, maxTravelTime, minSamples, vTypes),
225  myHaltSpeed(haltSpeed) {
226 }
227 
228 
230 
231 
233 MSMeanData_Net::createValues(MSLane* const lane, const SUMOReal length, const bool doAdd) const {
234  return new MSLaneMeanDataValues(lane, length, doAdd, &myVehicleTypes, this);
235 }
236 
237 
238 /****************************************************************************/
239