Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2004-2025 German Aerospace Center (DLR) and others.
4 : // This program and the accompanying materials are made available under the
5 : // terms of the Eclipse Public License 2.0 which is available at
6 : // https://www.eclipse.org/legal/epl-2.0/
7 : // This Source Code may also be made available under the following Secondary
8 : // Licenses when the conditions for such availability set forth in the Eclipse
9 : // Public License 2.0 are satisfied: GNU General Public License, version 2
10 : // or later which is available at
11 : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 : /****************************************************************************/
14 : /// @file MSMeanData_Net.cpp
15 : /// @author Daniel Krajzewicz
16 : /// @author Michael Behrisch
17 : /// @author Jakob Erdmann
18 : /// @date Mon, 10.05.2004
19 : ///
20 : // Network state mean data collector for edges/lanes
21 : /****************************************************************************/
22 : #include <config.h>
23 :
24 : #ifdef HAVE_FOX
25 : #include <utils/common/ScopedLocker.h>
26 : #endif
27 : #include <utils/common/SUMOTime.h>
28 : #include <utils/common/ToString.h>
29 : #include <utils/iodevices/OutputDevice.h>
30 : #include <microsim/MSEdgeControl.h>
31 : #include <microsim/MSEdge.h>
32 : #include <microsim/MSLane.h>
33 : #include <microsim/MSVehicle.h>
34 : #include <microsim/MSGlobals.h>
35 : #include <mesosim/MELoop.h>
36 : #include <mesosim/MESegment.h>
37 : #include "MSMeanData_Net.h"
38 :
39 :
40 : // ===========================================================================
41 : // debug constants
42 : // ===========================================================================
43 : //#define DEBUG_OCCUPANCY
44 : //#define DEBUG_OCCUPANCY2
45 : //#define DEBUG_NOTIFY_ENTER
46 : //#define DEBUG_COND (veh.getLane()->getID() == "")
47 : //#define DEBUG_COND (false)
48 : //#define DEBUG_COND2 (veh.getEdge()->getID() == "")
49 :
50 :
51 : // ===========================================================================
52 : // method definitions
53 : // ===========================================================================
54 : // ---------------------------------------------------------------------------
55 : // MSMeanData_Net::MSLaneMeanDataValues - methods
56 : // ---------------------------------------------------------------------------
57 8226263 : MSMeanData_Net::MSLaneMeanDataValues::MSLaneMeanDataValues(MSLane* const lane,
58 : const double length,
59 : const bool doAdd,
60 8226263 : const MSMeanData_Net* parent)
61 : : MSMeanData::MeanDataValues(lane, length, doAdd, parent),
62 8226263 : nVehDeparted(0), nVehArrived(0), nVehEntered(0), nVehLeft(0),
63 8226263 : nVehVaporized(0), nVehTeleported(0), waitSeconds(0), timeLoss(0),
64 8226263 : nVehLaneChangeFrom(0), nVehLaneChangeTo(0),
65 8226263 : frontSampleSeconds(0), frontTravelledDistance(0),
66 8226263 : vehLengthSum(0), occupationSum(0),
67 8226263 : minimalVehicleLength(INVALID_DOUBLE),
68 8226263 : myParent(parent) {}
69 :
70 :
71 16308555 : MSMeanData_Net::MSLaneMeanDataValues::~MSLaneMeanDataValues() {
72 16308555 : }
73 :
74 :
75 : void
76 16846325 : MSMeanData_Net::MSLaneMeanDataValues::reset(bool) {
77 16846325 : nVehDeparted = 0;
78 16846325 : nVehArrived = 0;
79 16846325 : nVehEntered = 0;
80 16846325 : nVehLeft = 0;
81 16846325 : nVehVaporized = 0;
82 16846325 : nVehTeleported = 0;
83 16846325 : nVehLaneChangeFrom = 0;
84 16846325 : nVehLaneChangeTo = 0;
85 16846325 : sampleSeconds = 0.;
86 16846325 : travelledDistance = 0;
87 16846325 : waitSeconds = 0;
88 16846325 : timeLoss = 0;
89 16846325 : frontSampleSeconds = 0;
90 16846325 : frontTravelledDistance = 0;
91 16846325 : vehLengthSum = 0;
92 16846325 : occupationSum = 0;
93 16846325 : minimalVehicleLength = INVALID_DOUBLE;
94 16846325 : resetTime = SIMSTEP;
95 16846325 : }
96 :
97 :
98 : void
99 8593291 : MSMeanData_Net::MSLaneMeanDataValues::addTo(MSMeanData::MeanDataValues& val) const {
100 : MSLaneMeanDataValues& v = (MSLaneMeanDataValues&) val;
101 8593291 : v.nVehDeparted += nVehDeparted;
102 8593291 : v.nVehArrived += nVehArrived;
103 8593291 : v.nVehEntered += nVehEntered;
104 8593291 : v.nVehLeft += nVehLeft;
105 8593291 : v.nVehVaporized += nVehVaporized;
106 8593291 : v.nVehTeleported += nVehTeleported;
107 8593291 : v.nVehLaneChangeFrom += nVehLaneChangeFrom;
108 8593291 : v.nVehLaneChangeTo += nVehLaneChangeTo;
109 8593291 : v.sampleSeconds += sampleSeconds;
110 8593291 : v.travelledDistance += travelledDistance;
111 8593291 : v.waitSeconds += waitSeconds;
112 8593291 : v.timeLoss += timeLoss;
113 8593291 : v.frontSampleSeconds += frontSampleSeconds;
114 8593291 : v.frontTravelledDistance += frontTravelledDistance;
115 8593291 : v.vehLengthSum += vehLengthSum;
116 8593291 : v.occupationSum += occupationSum;
117 8593291 : if (v.minimalVehicleLength == INVALID_DOUBLE) {
118 8500867 : v.minimalVehicleLength = minimalVehicleLength;
119 : } else {
120 178556 : v.minimalVehicleLength = MIN2(minimalVehicleLength, v.minimalVehicleLength);
121 : }
122 8593291 : }
123 :
124 :
125 : void
126 393361880 : MSMeanData_Net::MSLaneMeanDataValues::notifyMoveInternal(
127 : const SUMOTrafficObject& veh, const double frontOnLane,
128 : const double timeOnLane, const double /* meanSpeedFrontOnLane */,
129 : const double meanSpeedVehicleOnLane,
130 : const double travelledDistanceFrontOnLane,
131 : const double travelledDistanceVehicleOnLane,
132 : const double meanLengthOnLane) {
133 : #ifdef DEBUG_OCCUPANCY
134 : if (DEBUG_COND2) {
135 : std::cout << SIMTIME << "\n MSMeanData_Net::MSLaneMeanDataValues::notifyMoveInternal()\n"
136 : << " veh '" << veh.getID() << "' on edge '" << veh.getEdge()->getID() << "'"
137 : << ", timeOnLane=" << timeOnLane
138 : << ", meanSpeedVehicleOnLane=" << meanSpeedVehicleOnLane
139 : << ",\ntravelledDistanceFrontOnLane=" << travelledDistanceFrontOnLane
140 : << ", travelledDistanceVehicleOnLane=" << travelledDistanceVehicleOnLane
141 : << ", meanLengthOnLane=" << meanLengthOnLane
142 : << std::endl;
143 : }
144 : #endif
145 393361880 : if (myParent != nullptr && !myParent->vehicleApplies(veh)) {
146 : return;
147 : }
148 393319560 : sampleSeconds += timeOnLane;
149 393319560 : travelledDistance += travelledDistanceVehicleOnLane;
150 393319560 : vehLengthSum += veh.getVehicleType().getLength() * timeOnLane;
151 393319560 : if (MSGlobals::gUseMesoSim) {
152 : // For the mesosim case no information on whether the vehicle was occupying
153 : // the lane with its whole length is available. We assume the whole length
154 : // Therefore this increment is taken out with more information on the vehicle movement.
155 10274036 : occupationSum += veh.getVehicleType().getLength() * timeOnLane;
156 : } else {
157 : // for the microsim case more elaborate calculation of the average length on the lane,
158 : // is taken out in notifyMove(), refs #153
159 383045524 : occupationSum += meanLengthOnLane * TS;
160 : }
161 393319560 : if (!veh.isStopped()) {
162 377276253 : if (myParent != nullptr && meanSpeedVehicleOnLane < myParent->myHaltSpeed) {
163 52929738 : waitSeconds += timeOnLane;
164 324346515 : } else if (MSGlobals::gUseMesoSim) {
165 10228341 : waitSeconds += STEPS2TIME(veh.getWaitingTime());
166 : }
167 377276253 : const double vmax = veh.getLane() == nullptr ? veh.getEdge()->getVehicleMaxSpeed(&veh) : veh.getLane()->getVehicleMaxSpeed(&veh);
168 377276253 : if (vmax > 0) {
169 752802621 : timeLoss += timeOnLane * MAX2(0.0, vmax - meanSpeedVehicleOnLane) / vmax;
170 : }
171 : }
172 393319560 : frontSampleSeconds += frontOnLane;
173 393319560 : frontTravelledDistance += travelledDistanceFrontOnLane;
174 393319560 : if (minimalVehicleLength == INVALID_DOUBLE) {
175 696881 : minimalVehicleLength = veh.getVehicleType().getLengthWithGap();
176 : } else {
177 783798697 : minimalVehicleLength = MIN2(minimalVehicleLength, veh.getVehicleType().getLengthWithGap());
178 : }
179 : #ifdef DEBUG_OCCUPANCY2
180 : // refs #3265
181 : std::cout << SIMTIME << "ID: " << getDescription() << " minVehicleLength=" << minimalVehicleLength << std::endl;
182 : #endif
183 : }
184 :
185 :
186 : bool
187 25494533 : MSMeanData_Net::MSLaneMeanDataValues::notifyLeave(SUMOTrafficObject& veh, double /*lastPos*/, MSMoveReminder::Notification reason, const MSLane* /* enteredLane */) {
188 25494533 : if ((myParent == nullptr || myParent->vehicleApplies(veh)) && (
189 16434054 : getLane() == nullptr || !veh.isVehicle() || getLane() == static_cast<MSVehicle&>(veh).getLane())) {
190 : #ifdef HAVE_FOX
191 21372017 : ScopedLocker<> lock(myNotificationMutex, MSGlobals::gNumSimThreads > 1);
192 : #endif
193 21372017 : if (MSGlobals::gUseMesoSim) {
194 9060323 : removeFromVehicleUpdateValues(veh);
195 : }
196 21372017 : if (reason == MSMoveReminder::NOTIFICATION_ARRIVED) {
197 2478991 : ++nVehArrived;
198 18893026 : } else if (reason == MSMoveReminder::NOTIFICATION_LANE_CHANGE) {
199 132036 : ++nVehLaneChangeFrom;
200 18760990 : } else if (myParent == nullptr || reason != MSMoveReminder::NOTIFICATION_SEGMENT) {
201 10888435 : ++nVehLeft;
202 10888435 : if (reason == MSMoveReminder::NOTIFICATION_TELEPORT || reason == MSMoveReminder::NOTIFICATION_TELEPORT_ARRIVED) {
203 3969 : ++nVehTeleported;
204 10884466 : } else if (reason >= MSMoveReminder::NOTIFICATION_VAPORIZED_CALIBRATOR) {
205 70059 : ++nVehVaporized;
206 : }
207 : }
208 : }
209 25494533 : if (MSGlobals::gUseMesoSim) {
210 : return false;
211 : }
212 16425370 : return reason == MSMoveReminder::NOTIFICATION_JUNCTION;
213 : }
214 :
215 :
216 : bool
217 22522238 : MSMeanData_Net::MSLaneMeanDataValues::notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane) {
218 : #ifdef DEBUG_NOTIFY_ENTER
219 : std::cout << "\n" << SIMTIME << " MSMeanData_Net::MSLaneMeanDataValues: veh '" << veh.getID() << "' enters lane '" << enteredLane->getID() << "'" << std::endl;
220 : #else
221 : UNUSED_PARAMETER(enteredLane);
222 : #endif
223 22522238 : if (myParent == nullptr || myParent->vehicleApplies(veh)) {
224 21486457 : if (getLane() == nullptr || !veh.isVehicle() || getLane() == static_cast<MSVehicle&>(veh).getLane()) {
225 : #ifdef HAVE_FOX
226 21477617 : ScopedLocker<> lock(myNotificationMutex, MSGlobals::gNumSimThreads > 1);
227 : #endif
228 21477617 : if (reason == MSMoveReminder::NOTIFICATION_DEPARTED) {
229 2663422 : ++nVehDeparted;
230 18814195 : } else if (reason == MSMoveReminder::NOTIFICATION_LANE_CHANGE) {
231 131723 : ++nVehLaneChangeTo;
232 18682472 : } else if (myParent == nullptr || reason != MSMoveReminder::NOTIFICATION_SEGMENT) {
233 10840091 : ++nVehEntered;
234 : }
235 : }
236 21486457 : return true;
237 : }
238 : return false;
239 : }
240 :
241 :
242 : bool
243 22479566 : MSMeanData_Net::MSLaneMeanDataValues::isEmpty() const {
244 21821772 : return sampleSeconds == 0 && nVehDeparted == 0 && nVehArrived == 0 && nVehEntered == 0
245 44300890 : && nVehLeft == 0 && nVehVaporized == 0 && nVehTeleported == 0 && nVehLaneChangeFrom == 0 && nVehLaneChangeTo == 0;
246 : }
247 :
248 : double
249 899678 : MSMeanData_Net::MSLaneMeanDataValues::getOccupancy(SUMOTime period, int numLanes) const {
250 899678 : return occupationSum / STEPS2TIME(period) / myLaneLength / (double)numLanes * 100.;
251 : }
252 :
253 : void
254 899558 : MSMeanData_Net::MSLaneMeanDataValues::write(OutputDevice& dev, const SumoXMLAttrMask& attributeMask, const SUMOTime period,
255 : const int numLanes, const double speedLimit, const double defaultTravelTime, const int numVehicles) const {
256 :
257 899558 : double density = frontSampleSeconds / STEPS2TIME(period) * 1000. / myLaneLength;
258 899558 : double overlapDensity = sampleSeconds / STEPS2TIME(period) * 1000. / myLaneLength;
259 899558 : if (MSGlobals::gLateralResolution < 0) {
260 : // avoid exceeding upper bound
261 845757 : density = MIN2(density, 1000 * (double)numLanes / MAX2(minimalVehicleLength, NUMERICAL_EPS));
262 844959 : overlapDensity = MIN2(overlapDensity, 1000 * (double)numLanes / MAX2(minimalVehicleLength, NUMERICAL_EPS));
263 : }
264 899558 : const double laneDensity = density / (double)numLanes;
265 899558 : const double occupancy = getOccupancy(period, numLanes);
266 : #ifdef DEBUG_OCCUPANCY2
267 : // tests #3264
268 : if (occupancy > 100) {
269 : std::cout << SIMTIME << " Encountered bad occupancy: " << occupancy
270 : << ", myLaneLength=" << myLaneLength << ", period=" << STEPS2TIME(period) << ", occupationSum=" << occupationSum
271 : << std::endl;
272 : }
273 : // refs #3265
274 : std::cout << SIMTIME << "ID: " << getDescription() << " minVehicleLength=" << minimalVehicleLength
275 : << "\ndensity=" << density << "\n";
276 : #endif
277 :
278 899558 : if (myParent == nullptr) {
279 10036 : const double speed = sampleSeconds == 0 ? 0. : travelledDistance / sampleSeconds;
280 10036 : dev.writeOptionalAttr(SUMO_ATTR_DENSITY, density, attributeMask, sampleSeconds == 0);
281 10036 : dev.writeOptionalAttr(SUMO_ATTR_LANEDENSITY, laneDensity, attributeMask, sampleSeconds == 0);
282 10036 : dev.writeOptionalAttr(SUMO_ATTR_OCCUPANCY, occupancy, attributeMask, sampleSeconds == 0);
283 10036 : dev.writeOptionalAttr(SUMO_ATTR_WAITINGTIME, waitSeconds, attributeMask, sampleSeconds == 0);
284 10036 : dev.writeOptionalAttr(SUMO_ATTR_TIMELOSS, timeLoss, attributeMask, sampleSeconds == 0);
285 10036 : dev.writeOptionalAttr(SUMO_ATTR_SPEED, speed, attributeMask, sampleSeconds == 0);
286 10036 : dev.writeOptionalAttr(SUMO_ATTR_SPEEDREL, speedLimit == 0. || sampleSeconds == 0 ? 0. : travelledDistance / sampleSeconds / speedLimit,
287 10036 : attributeMask, sampleSeconds == 0);
288 10036 : dev.writeOptionalAttr(SUMO_ATTR_DEPARTED, nVehDeparted, attributeMask);
289 10036 : dev.writeOptionalAttr(SUMO_ATTR_ARRIVED, nVehArrived, attributeMask);
290 10036 : dev.writeOptionalAttr(SUMO_ATTR_ENTERED, nVehEntered, attributeMask);
291 10036 : dev.writeOptionalAttr(SUMO_ATTR_LEFT, nVehLeft, attributeMask);
292 10036 : dev.writeOptionalAttr(SUMO_ATTR_VAPORIZED, nVehVaporized, attributeMask, nVehVaporized == 0);
293 10036 : dev.writeOptionalAttr(SUMO_ATTR_TELEPORTED, nVehTeleported, attributeMask, nVehTeleported == 0);
294 10036 : dev.writeOptionalAttr(SUMO_ATTR_FLOW, density * speed * 3.6, attributeMask, sampleSeconds == 0);
295 20072 : dev.closeTag();
296 : return;
297 : }
298 889522 : const bool haveSamples = sampleSeconds > myParent->myMinSamples;
299 889522 : const bool haveSamplesOrDefault = haveSamples || defaultTravelTime >= 0.;
300 : bool haveTravelTime = haveSamplesOrDefault;
301 889522 : double traveltime = myParent->myMaxTravelTime;
302 889522 : if (haveSamples) {
303 620338 : if (numVehicles > 0) {
304 244 : traveltime = sampleSeconds / numVehicles;
305 : } else {
306 : traveltime = myParent->myMaxTravelTime;
307 620094 : if (frontTravelledDistance > NUMERICAL_EPS) {
308 847319 : traveltime = MIN2(traveltime, myLaneLength * frontSampleSeconds / frontTravelledDistance);
309 196331 : } else if (defaultTravelTime >= 0.) {
310 0 : traveltime = defaultTravelTime;
311 : } else {
312 : haveTravelTime = false;
313 : }
314 : }
315 269184 : } else if (defaultTravelTime >= 0.) {
316 1056 : traveltime = defaultTravelTime;
317 : }
318 889522 : dev.writeOptionalAttr(SUMO_ATTR_TRAVELTIME, traveltime, attributeMask, !haveTravelTime);
319 889522 : double overlapTraveltime = myParent->myMaxTravelTime;
320 889522 : if (travelledDistance > 0.) {
321 : // one vehicle has to drive lane length + vehicle length before it has left the lane
322 : // thus we need to scale with an extended length, approximated by lane length + average vehicle length
323 852199 : overlapTraveltime = MIN2(overlapTraveltime, (myLaneLength + vehLengthSum / sampleSeconds) * sampleSeconds / travelledDistance);
324 : }
325 889522 : dev.writeOptionalAttr(SUMO_ATTR_OVERLAPTRAVELTIME, overlapTraveltime, attributeMask, !haveSamples || numVehicles > 0);
326 889522 : dev.writeOptionalAttr(SUMO_ATTR_DENSITY, density, attributeMask, !haveSamples || numVehicles > 0);
327 889522 : dev.writeOptionalAttr(SUMO_ATTR_OVERLAPDENSITY, overlapDensity, attributeMask, sampleSeconds == 0);
328 889522 : dev.writeOptionalAttr(SUMO_ATTR_LANEDENSITY, laneDensity, attributeMask, !haveSamples || numVehicles > 0);
329 889522 : dev.writeOptionalAttr(SUMO_ATTR_OCCUPANCY, occupancy, attributeMask, !haveSamples || numVehicles > 0);
330 889522 : dev.writeOptionalAttr(SUMO_ATTR_WAITINGTIME, waitSeconds, attributeMask, !haveSamples);
331 889522 : dev.writeOptionalAttr(SUMO_ATTR_TIMELOSS, timeLoss, attributeMask, !haveSamples);
332 889522 : double speed = 0.;
333 889522 : if (haveSamples) {
334 620338 : speed = travelledDistance / sampleSeconds;
335 269184 : } else if (defaultTravelTime > 0.) {
336 1056 : speed = myLaneLength / defaultTravelTime;
337 : }
338 889522 : dev.writeOptionalAttr(SUMO_ATTR_SPEED, speed, attributeMask, !haveSamplesOrDefault);
339 889522 : dev.writeOptionalAttr(SUMO_ATTR_SPEEDREL, speedLimit == 0. ? 0. : speed / speedLimit, attributeMask, !haveSamplesOrDefault);
340 889522 : dev.writeOptionalAttr(SUMO_ATTR_DEPARTED, nVehDeparted, attributeMask);
341 889522 : dev.writeOptionalAttr(SUMO_ATTR_ARRIVED, nVehArrived, attributeMask);
342 889522 : dev.writeOptionalAttr(SUMO_ATTR_ENTERED, nVehEntered, attributeMask);
343 889522 : dev.writeOptionalAttr(SUMO_ATTR_LEFT, nVehLeft, attributeMask);
344 889522 : dev.writeOptionalAttr(SUMO_ATTR_LANECHANGEDFROM, nVehLaneChangeFrom, attributeMask);
345 889522 : dev.writeOptionalAttr(SUMO_ATTR_LANECHANGEDTO, nVehLaneChangeTo, attributeMask);
346 889522 : dev.writeOptionalAttr(SUMO_ATTR_VAPORIZED, nVehVaporized, attributeMask, nVehVaporized == 0);
347 889522 : dev.writeOptionalAttr(SUMO_ATTR_TELEPORTED, nVehTeleported, attributeMask, nVehTeleported == 0);
348 889522 : dev.writeOptionalAttr(SUMO_ATTR_FLOW, density * speed * 3.6, attributeMask, !haveSamples || numVehicles > 0);
349 1779044 : dev.closeTag();
350 : }
351 :
352 :
353 : double
354 0 : MSMeanData_Net::MSLaneMeanDataValues::getAttributeValue(SumoXMLAttr a,
355 : const SUMOTime period, const double numLanes, const double speedLimit) const {
356 : /// @todo: remove redundancy in derived values (density, laneDensity)
357 0 : switch (a) {
358 0 : case SUMO_ATTR_DENSITY:
359 0 : return MIN2(frontSampleSeconds / STEPS2TIME(period) * (double) 1000 / myLaneLength,
360 0 : 1000. * numLanes / MAX2(minimalVehicleLength, NUMERICAL_EPS));
361 0 : case SUMO_ATTR_LANEDENSITY: {
362 0 : const double density = MIN2(frontSampleSeconds / STEPS2TIME(period) * (double) 1000 / myLaneLength,
363 0 : 1000. * numLanes / MAX2(minimalVehicleLength, NUMERICAL_EPS));
364 0 : return density / numLanes;
365 : }
366 0 : case SUMO_ATTR_OVERLAPDENSITY: {
367 0 : const double overlapDensity = MIN2(sampleSeconds / STEPS2TIME(period) * (double) 1000 / myLaneLength,
368 0 : 1000. * numLanes / MAX2(minimalVehicleLength, NUMERICAL_EPS));
369 0 : return overlapDensity / numLanes;
370 : }
371 0 : case SUMO_ATTR_OCCUPANCY:
372 0 : return occupationSum / STEPS2TIME(period) / myLaneLength / numLanes * (double) 1000;
373 0 : case SUMO_ATTR_WAITINGTIME:
374 0 : return waitSeconds;
375 0 : case SUMO_ATTR_TIMELOSS:
376 0 : return timeLoss;
377 0 : case SUMO_ATTR_SPEED:
378 0 : return travelledDistance / sampleSeconds;
379 0 : case SUMO_ATTR_SPEEDREL:
380 0 : return speedLimit == 0. ? 0. : travelledDistance / sampleSeconds / speedLimit;
381 0 : case SUMO_ATTR_DEPARTED:
382 0 : return nVehDeparted;
383 0 : case SUMO_ATTR_ARRIVED:
384 0 : return nVehArrived;
385 0 : case SUMO_ATTR_ENTERED:
386 0 : return nVehEntered;
387 0 : case SUMO_ATTR_LEFT:
388 0 : return nVehLeft;
389 0 : case SUMO_ATTR_VAPORIZED:
390 0 : return nVehVaporized;
391 0 : case SUMO_ATTR_TELEPORTED:
392 0 : return nVehTeleported;
393 0 : case SUMO_ATTR_FLOW: {
394 0 : const double density = MIN2(sampleSeconds / STEPS2TIME(period) * (double) 1000 / myLaneLength,
395 0 : 1000. * numLanes / MAX2(minimalVehicleLength, NUMERICAL_EPS));
396 0 : const double speed = travelledDistance / sampleSeconds;
397 0 : return density * speed * 3.6;
398 : }
399 : default:
400 : return 0;
401 : }
402 : }
403 :
404 : // ---------------------------------------------------------------------------
405 : // MSMeanData_Net - methods
406 : // ---------------------------------------------------------------------------
407 20043 : MSMeanData_Net::MSMeanData_Net(const std::string& id,
408 : const SUMOTime dumpBegin,
409 : const SUMOTime dumpEnd, const bool useLanes,
410 : const bool withEmpty, const bool printDefaults,
411 : const bool withInternal,
412 : const bool trackVehicles,
413 : const int detectPersons,
414 : const double maxTravelTime,
415 : const double minSamples,
416 : const double haltSpeed,
417 : const std::string& vTypes,
418 : const std::string& writeAttributes,
419 : const std::vector<MSEdge*>& edges,
420 20043 : bool aggregate) :
421 : MSMeanData(id, dumpBegin, dumpEnd, useLanes, withEmpty, printDefaults,
422 : withInternal, trackVehicles, detectPersons, maxTravelTime, minSamples, vTypes, writeAttributes, edges, aggregate),
423 20043 : myHaltSpeed(haltSpeed)
424 20043 : { }
425 :
426 :
427 38858 : MSMeanData_Net::~MSMeanData_Net() {}
428 :
429 :
430 : MSMeanData::MeanDataValues*
431 8223594 : MSMeanData_Net::createValues(MSLane* const lane, const double length, const bool doAdd) const {
432 8223594 : return new MSLaneMeanDataValues(lane, length, doAdd, this);
433 : }
434 :
435 :
436 : std::vector<std::string>
437 0 : MSMeanData_Net::getAttributeNames() const {
438 : std::vector<std::string> result;
439 0 : result.push_back(toString(SUMO_ATTR_DENSITY));
440 0 : result.push_back(toString(SUMO_ATTR_LANEDENSITY));
441 0 : result.push_back(toString(SUMO_ATTR_OCCUPANCY));
442 0 : result.push_back(toString(SUMO_ATTR_WAITINGTIME));
443 0 : result.push_back(toString(SUMO_ATTR_TIMELOSS));
444 0 : result.push_back(toString(SUMO_ATTR_SPEED));
445 0 : result.push_back(toString(SUMO_ATTR_SPEEDREL));
446 0 : result.push_back(toString(SUMO_ATTR_DEPARTED));
447 0 : result.push_back(toString(SUMO_ATTR_ARRIVED));
448 0 : result.push_back(toString(SUMO_ATTR_ENTERED));
449 0 : result.push_back(toString(SUMO_ATTR_LEFT));
450 0 : result.push_back(toString(SUMO_ATTR_VAPORIZED));
451 0 : result.push_back(toString(SUMO_ATTR_TELEPORTED));
452 0 : result.push_back(toString(SUMO_ATTR_FLOW));
453 0 : return result;
454 0 : }
455 :
456 :
457 : double
458 0 : MSMeanData_Net::getAttributeValue(const MSLane* lane, SumoXMLAttr a, double defaultValue) const {
459 : double result = defaultValue;
460 0 : const std::vector<MeanDataValues*>* edgeValues = getEdgeValues(&lane->getEdge());
461 0 : if (edgeValues == nullptr) {
462 : return result;
463 : }
464 : MeanDataValues* values = nullptr;
465 0 : if (!myAmEdgeBased) {
466 0 : values = (*edgeValues)[lane->getIndex()];
467 : } else {
468 0 : MeanDataValues* sumData = createValues(nullptr, lane->getLength(), false);
469 0 : for (MeanDataValues* meanData : (*edgeValues)) {
470 0 : meanData->addTo(*sumData);
471 : }
472 : values = sumData;
473 : }
474 : const SUMOTime myLastResetTime = 0; // XXX store last reset time
475 0 : const SUMOTime period = SIMSTEP - myLastResetTime;
476 0 : result = values->getAttributeValue(a, period, lane->getEdge().getNumLanes(), lane->getSpeedLimit());
477 0 : if (myAmEdgeBased) {
478 0 : delete values;
479 : }
480 : return result;
481 : }
482 :
483 :
484 : /****************************************************************************/
|