Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2004-2026 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 8328905 : MSMeanData_Net::MSLaneMeanDataValues::MSLaneMeanDataValues(MSLane* const lane,
58 : const double length,
59 : const bool doAdd,
60 8328905 : const MSMeanData_Net* parent)
61 : : MSMeanData::MeanDataValues(lane, length, doAdd, parent),
62 8328905 : nVehDeparted(0), nVehArrived(0), nVehEntered(0), nVehLeft(0),
63 8328905 : nVehVaporized(0), nVehTeleported(0), waitSeconds(0), timeLoss(0),
64 8328905 : nVehLaneChangeFrom(0), nVehLaneChangeTo(0),
65 8328905 : frontSampleSeconds(0), frontTravelledDistance(0),
66 8328905 : vehLengthSum(0), occupationSum(0),
67 8328905 : minimalVehicleLength(INVALID_DOUBLE),
68 8328905 : myParent(parent) {}
69 :
70 :
71 16654469 : MSMeanData_Net::MSLaneMeanDataValues::~MSLaneMeanDataValues() {
72 16654469 : }
73 :
74 :
75 : void
76 16950792 : MSMeanData_Net::MSLaneMeanDataValues::reset(bool) {
77 16950792 : nVehDeparted = 0;
78 16950792 : nVehArrived = 0;
79 16950792 : nVehEntered = 0;
80 16950792 : nVehLeft = 0;
81 16950792 : nVehVaporized = 0;
82 16950792 : nVehTeleported = 0;
83 16950792 : nVehLaneChangeFrom = 0;
84 16950792 : nVehLaneChangeTo = 0;
85 16950792 : sampleSeconds = 0.;
86 16950792 : travelledDistance = 0;
87 16950792 : waitSeconds = 0;
88 16950792 : timeLoss = 0;
89 16950792 : frontSampleSeconds = 0;
90 16950792 : frontTravelledDistance = 0;
91 16950792 : vehLengthSum = 0;
92 16950792 : occupationSum = 0;
93 16950792 : minimalVehicleLength = INVALID_DOUBLE;
94 16950792 : resetTime = SIMSTEP;
95 16950792 : }
96 :
97 :
98 : void
99 8660990 : MSMeanData_Net::MSLaneMeanDataValues::addTo(MSMeanData::MeanDataValues& val) const {
100 : MSLaneMeanDataValues& v = (MSLaneMeanDataValues&) val;
101 8660990 : v.nVehDeparted += nVehDeparted;
102 8660990 : v.nVehArrived += nVehArrived;
103 8660990 : v.nVehEntered += nVehEntered;
104 8660990 : v.nVehLeft += nVehLeft;
105 8660990 : v.nVehVaporized += nVehVaporized;
106 8660990 : v.nVehTeleported += nVehTeleported;
107 8660990 : v.nVehLaneChangeFrom += nVehLaneChangeFrom;
108 8660990 : v.nVehLaneChangeTo += nVehLaneChangeTo;
109 8660990 : v.sampleSeconds += sampleSeconds;
110 8660990 : v.travelledDistance += travelledDistance;
111 8660990 : v.waitSeconds += waitSeconds;
112 8660990 : v.timeLoss += timeLoss;
113 8660990 : v.frontSampleSeconds += frontSampleSeconds;
114 8660990 : v.frontTravelledDistance += frontTravelledDistance;
115 8660990 : v.vehLengthSum += vehLengthSum;
116 8660990 : v.occupationSum += occupationSum;
117 8660990 : if (v.minimalVehicleLength == INVALID_DOUBLE) {
118 8568934 : v.minimalVehicleLength = minimalVehicleLength;
119 : } else {
120 177770 : v.minimalVehicleLength = MIN2(minimalVehicleLength, v.minimalVehicleLength);
121 : }
122 8660990 : }
123 :
124 :
125 : void
126 416176745 : 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 416176745 : if (myParent != nullptr && !myParent->vehicleApplies(veh)) {
146 : return;
147 : }
148 416134425 : sampleSeconds += timeOnLane;
149 416134425 : travelledDistance += travelledDistanceVehicleOnLane;
150 416134425 : vehLengthSum += veh.getVehicleType().getLength() * timeOnLane;
151 416134425 : 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 10308538 : 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 405825887 : occupationSum += meanLengthOnLane * TS;
160 : }
161 416134425 : if (!veh.isStopped()) {
162 400087043 : if (myParent != nullptr && (meanSpeedVehicleOnLane < myParent->myHaltSpeed
163 340065942 : || (myParent->myHaltSpeedRel > 0 && meanSpeedVehicleOnLane / veh.getCurrentEdge()->getSpeedLimit(veh.getVClass()) < myParent->myHaltSpeedRel))) {
164 59964299 : waitSeconds += timeOnLane;
165 340122744 : } else if (MSGlobals::gUseMesoSim) {
166 10258859 : waitSeconds += STEPS2TIME(veh.getWaitingTime());
167 : }
168 400087043 : const double vmax = veh.getLane() == nullptr ? veh.getEdge()->getVehicleMaxSpeed(&veh) : veh.getLane()->getVehicleMaxSpeed(&veh);
169 400087043 : if (vmax > 0) {
170 798394856 : timeLoss += timeOnLane * MAX2(0.0, vmax - meanSpeedVehicleOnLane) / vmax;
171 : }
172 : }
173 416134425 : frontSampleSeconds += frontOnLane;
174 416134425 : frontTravelledDistance += travelledDistanceFrontOnLane;
175 416134425 : if (minimalVehicleLength == INVALID_DOUBLE) {
176 697225 : minimalVehicleLength = veh.getVehicleType().getLengthWithGap();
177 : } else {
178 829466301 : minimalVehicleLength = MIN2(minimalVehicleLength, veh.getVehicleType().getLengthWithGap());
179 : }
180 : #ifdef DEBUG_OCCUPANCY2
181 : // refs #3265
182 : std::cout << SIMTIME << "ID: " << getDescription() << " minVehicleLength=" << minimalVehicleLength << std::endl;
183 : #endif
184 : }
185 :
186 :
187 : bool
188 27393688 : MSMeanData_Net::MSLaneMeanDataValues::notifyLeave(SUMOTrafficObject& veh, double /*lastPos*/, MSMoveReminder::Notification reason, const MSLane* /* enteredLane */) {
189 27393688 : if ((myParent == nullptr || myParent->vehicleApplies(veh)) && (
190 18298619 : getLane() == nullptr || !veh.isVehicle() || getLane() == static_cast<MSVehicle&>(veh).getLane())) {
191 : #ifdef HAVE_FOX
192 22978080 : ScopedLocker<> lock(myNotificationMutex, MSGlobals::gNumSimThreads > 1);
193 : #endif
194 22978080 : if (MSGlobals::gUseMesoSim) {
195 9094913 : removeFromVehicleUpdateValues(veh);
196 : }
197 22978080 : if (reason == MSMoveReminder::NOTIFICATION_ARRIVED) {
198 2987729 : ++nVehArrived;
199 19990351 : } else if (reason == MSMoveReminder::NOTIFICATION_LANE_CHANGE) {
200 132676 : ++nVehLaneChangeFrom;
201 19857675 : } else if (myParent == nullptr || reason != MSMoveReminder::NOTIFICATION_SEGMENT) {
202 11998063 : ++nVehLeft;
203 11998063 : if (reason == MSMoveReminder::NOTIFICATION_TELEPORT || reason == MSMoveReminder::NOTIFICATION_TELEPORT_ARRIVED) {
204 6619 : ++nVehTeleported;
205 11991444 : } else if (reason >= MSMoveReminder::NOTIFICATION_VAPORIZED_CALIBRATOR) {
206 70303 : ++nVehVaporized;
207 : }
208 : }
209 : }
210 27393688 : if (MSGlobals::gUseMesoSim || !veh.isVehicle()) {
211 : // only microsim vehicles keep the reminder until their back has fully left the edge/lane
212 9108035 : return false;
213 : }
214 18285653 : return reason == MSMoveReminder::NOTIFICATION_JUNCTION;
215 : }
216 :
217 :
218 : bool
219 24004269 : MSMeanData_Net::MSLaneMeanDataValues::notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane) {
220 : #ifdef DEBUG_NOTIFY_ENTER
221 : std::cout << "\n" << SIMTIME << " MSMeanData_Net::MSLaneMeanDataValues: veh '" << veh.getID() << "' enters lane '" << enteredLane->getID() << "'" << std::endl;
222 : #else
223 : UNUSED_PARAMETER(enteredLane);
224 : #endif
225 24004269 : if (myParent == nullptr || myParent->vehicleApplies(veh)) {
226 23087144 : if (getLane() == nullptr || !veh.isVehicle() || getLane() == static_cast<MSVehicle&>(veh).getLane()) {
227 : #ifdef HAVE_FOX
228 23078304 : ScopedLocker<> lock(myNotificationMutex, MSGlobals::gNumSimThreads > 1);
229 : #endif
230 23078304 : if (reason == MSMoveReminder::NOTIFICATION_DEPARTED) {
231 3165539 : ++nVehDeparted;
232 19912765 : } else if (reason == MSMoveReminder::NOTIFICATION_LANE_CHANGE) {
233 132335 : ++nVehLaneChangeTo;
234 19780430 : } else if (myParent == nullptr || reason != MSMoveReminder::NOTIFICATION_SEGMENT) {
235 11950993 : ++nVehEntered;
236 : }
237 : }
238 23087144 : return true;
239 : }
240 : return false;
241 : }
242 :
243 :
244 : bool
245 22487989 : MSMeanData_Net::MSLaneMeanDataValues::isEmpty() const {
246 21826944 : return sampleSeconds == 0 && nVehDeparted == 0 && nVehArrived == 0 && nVehEntered == 0
247 44314485 : && nVehLeft == 0 && nVehVaporized == 0 && nVehTeleported == 0 && nVehLaneChangeFrom == 0 && nVehLaneChangeTo == 0;
248 : }
249 :
250 : double
251 962669 : MSMeanData_Net::MSLaneMeanDataValues::getOccupancy(SUMOTime period, int numLanes) const {
252 962669 : return occupationSum / STEPS2TIME(period) / myLaneLength / (double)numLanes * 100.;
253 : }
254 :
255 : void
256 962547 : MSMeanData_Net::MSLaneMeanDataValues::write(OutputDevice& dev, const SumoXMLAttrMask& attributeMask, const SUMOTime period,
257 : const int numLanes, const double speedLimit, const double defaultTravelTime, const int numVehicles) const {
258 :
259 962547 : double density = frontSampleSeconds / STEPS2TIME(period) * 1000. / myLaneLength;
260 962547 : double overlapDensity = sampleSeconds / STEPS2TIME(period) * 1000. / myLaneLength;
261 962547 : if (MSGlobals::gLateralResolution < 0) {
262 : // avoid exceeding upper bound
263 908105 : density = MIN2(density, 1000 * (double)numLanes / MAX2(minimalVehicleLength, NUMERICAL_EPS));
264 906904 : overlapDensity = MIN2(overlapDensity, 1000 * (double)numLanes / MAX2(minimalVehicleLength, NUMERICAL_EPS));
265 : }
266 962547 : const double laneDensity = density / (double)numLanes;
267 962547 : const double occupancy = getOccupancy(period, numLanes);
268 : #ifdef DEBUG_OCCUPANCY2
269 : // tests #3264
270 : if (occupancy > 100) {
271 : std::cout << SIMTIME << " Encountered bad occupancy: " << occupancy
272 : << ", myLaneLength=" << myLaneLength << ", period=" << STEPS2TIME(period) << ", occupationSum=" << occupationSum
273 : << std::endl;
274 : }
275 : // refs #3265
276 : std::cout << SIMTIME << "ID: " << getDescription() << " minVehicleLength=" << minimalVehicleLength
277 : << "\ndensity=" << density << "\n";
278 : #endif
279 :
280 962547 : if (myParent == nullptr) {
281 10045 : const double speed = sampleSeconds == 0 ? 0. : travelledDistance / sampleSeconds;
282 10045 : const double frontSpeed = frontSampleSeconds == 0 ? 0. : frontTravelledDistance / frontSampleSeconds;
283 10045 : dev.writeOptionalAttr(SUMO_ATTR_DENSITY, density, attributeMask, sampleSeconds == 0);
284 10045 : dev.writeOptionalAttr(SUMO_ATTR_LANEDENSITY, laneDensity, attributeMask, sampleSeconds == 0);
285 10045 : dev.writeOptionalAttr(SUMO_ATTR_OCCUPANCY, occupancy, attributeMask, sampleSeconds == 0);
286 10045 : dev.writeOptionalAttr(SUMO_ATTR_WAITINGTIME, waitSeconds, attributeMask, sampleSeconds == 0);
287 10045 : dev.writeOptionalAttr(SUMO_ATTR_TIMELOSS, timeLoss, attributeMask, sampleSeconds == 0);
288 10045 : dev.writeOptionalAttr(SUMO_ATTR_SPEED, speed, attributeMask, sampleSeconds == 0);
289 10045 : dev.writeOptionalAttr(SUMO_ATTR_SPEEDREL, speedLimit == 0. || sampleSeconds == 0 ? 0. : travelledDistance / sampleSeconds / speedLimit,
290 10045 : attributeMask, sampleSeconds == 0);
291 10045 : dev.writeOptionalAttr(SUMO_ATTR_DEPARTED, nVehDeparted, attributeMask);
292 10045 : dev.writeOptionalAttr(SUMO_ATTR_ARRIVED, nVehArrived, attributeMask);
293 10045 : dev.writeOptionalAttr(SUMO_ATTR_ENTERED, nVehEntered, attributeMask);
294 10045 : dev.writeOptionalAttr(SUMO_ATTR_LEFT, nVehLeft, attributeMask);
295 10045 : dev.writeOptionalAttr(SUMO_ATTR_VAPORIZED, nVehVaporized, attributeMask, nVehVaporized == 0);
296 10045 : dev.writeOptionalAttr(SUMO_ATTR_TELEPORTED, nVehTeleported, attributeMask, nVehTeleported == 0);
297 10045 : dev.writeOptionalAttr(SUMO_ATTR_FLOW, density * frontSpeed * 3.6, attributeMask, frontSampleSeconds == 0);
298 20090 : dev.closeTag();
299 : return;
300 : }
301 952502 : const bool haveSamples = sampleSeconds > myParent->myMinSamples;
302 952502 : const bool haveFrontSamples = frontSampleSeconds > myParent->myMinSamples;
303 952502 : const bool haveSamplesOrDefault = haveSamples || defaultTravelTime >= 0.;
304 : bool haveTravelTime = haveSamplesOrDefault;
305 952502 : double traveltime = myParent->myMaxTravelTime;
306 952502 : if (haveSamples) {
307 621645 : if (numVehicles > 0) {
308 241 : traveltime = sampleSeconds / numVehicles;
309 : } else {
310 : traveltime = myParent->myMaxTravelTime;
311 621404 : if (frontTravelledDistance > NUMERICAL_EPS) {
312 849930 : traveltime = MIN2(traveltime, myLaneLength * frontSampleSeconds / frontTravelledDistance);
313 196335 : } else if (defaultTravelTime >= 0.) {
314 0 : traveltime = defaultTravelTime;
315 : } else {
316 : haveTravelTime = false;
317 : }
318 : }
319 330857 : } else if (defaultTravelTime >= 0.) {
320 2638 : traveltime = defaultTravelTime;
321 : }
322 952502 : dev.writeOptionalAttr(SUMO_ATTR_TRAVELTIME, traveltime, attributeMask, !haveTravelTime);
323 952502 : double overlapTraveltime = myParent->myMaxTravelTime;
324 952502 : if (travelledDistance > 0.) {
325 : // one vehicle has to drive lane length + vehicle length before it has left the lane
326 : // thus we need to scale with an extended length, approximated by lane length + average vehicle length
327 854825 : overlapTraveltime = MIN2(overlapTraveltime, (myLaneLength + vehLengthSum / sampleSeconds) * sampleSeconds / travelledDistance);
328 : }
329 952502 : dev.writeOptionalAttr(SUMO_ATTR_OVERLAPTRAVELTIME, overlapTraveltime, attributeMask, !haveSamples || numVehicles > 0);
330 952502 : dev.writeOptionalAttr(SUMO_ATTR_DENSITY, density, attributeMask, !haveSamples || numVehicles > 0);
331 952502 : dev.writeOptionalAttr(SUMO_ATTR_OVERLAPDENSITY, overlapDensity, attributeMask, sampleSeconds == 0);
332 952502 : dev.writeOptionalAttr(SUMO_ATTR_LANEDENSITY, laneDensity, attributeMask, !haveSamples || numVehicles > 0);
333 952502 : dev.writeOptionalAttr(SUMO_ATTR_OCCUPANCY, occupancy, attributeMask, !haveSamples || numVehicles > 0);
334 952502 : dev.writeOptionalAttr(SUMO_ATTR_WAITINGTIME, waitSeconds, attributeMask, !haveSamples);
335 952502 : dev.writeOptionalAttr(SUMO_ATTR_TIMELOSS, timeLoss, attributeMask, !haveSamples);
336 952502 : double speed = 0.;
337 : double frontSpeed = 0.;
338 952502 : if (haveSamples) {
339 621645 : speed = travelledDistance / sampleSeconds;
340 330857 : } else if (defaultTravelTime > 0.) {
341 2638 : speed = myLaneLength / defaultTravelTime;
342 : }
343 952502 : if (haveFrontSamples) {
344 580972 : frontSpeed = frontTravelledDistance / frontSampleSeconds;
345 371530 : } else if (defaultTravelTime > 0.) {
346 2638 : frontSpeed = myLaneLength / defaultTravelTime;
347 : }
348 952502 : dev.writeOptionalAttr(SUMO_ATTR_SPEED, speed, attributeMask, !haveSamplesOrDefault);
349 952502 : dev.writeOptionalAttr(SUMO_ATTR_SPEEDREL, speedLimit == 0. ? 0. : speed / speedLimit, attributeMask, !haveSamplesOrDefault);
350 952502 : dev.writeOptionalAttr(SUMO_ATTR_DEPARTED, nVehDeparted, attributeMask);
351 952502 : dev.writeOptionalAttr(SUMO_ATTR_ARRIVED, nVehArrived, attributeMask);
352 952502 : dev.writeOptionalAttr(SUMO_ATTR_ENTERED, nVehEntered, attributeMask);
353 952502 : dev.writeOptionalAttr(SUMO_ATTR_LEFT, nVehLeft, attributeMask);
354 952502 : dev.writeOptionalAttr(SUMO_ATTR_LANECHANGEDFROM, nVehLaneChangeFrom, attributeMask);
355 952502 : dev.writeOptionalAttr(SUMO_ATTR_LANECHANGEDTO, nVehLaneChangeTo, attributeMask);
356 952502 : dev.writeOptionalAttr(SUMO_ATTR_VAPORIZED, nVehVaporized, attributeMask, nVehVaporized == 0);
357 952502 : dev.writeOptionalAttr(SUMO_ATTR_TELEPORTED, nVehTeleported, attributeMask, nVehTeleported == 0);
358 952502 : dev.writeOptionalAttr(SUMO_ATTR_FLOW, density * frontSpeed * 3.6, attributeMask, !haveSamples || numVehicles == 0);
359 1905004 : dev.closeTag();
360 : }
361 :
362 :
363 : double
364 0 : MSMeanData_Net::MSLaneMeanDataValues::getAttributeValue(SumoXMLAttr a,
365 : const SUMOTime period, const double numLanes, const double speedLimit) const {
366 : /// @todo: remove redundancy in derived values (density, laneDensity)
367 0 : switch (a) {
368 0 : case SUMO_ATTR_DENSITY:
369 0 : return MIN2(frontSampleSeconds / STEPS2TIME(period) * (double) 1000 / myLaneLength,
370 0 : 1000. * numLanes / MAX2(minimalVehicleLength, NUMERICAL_EPS));
371 0 : case SUMO_ATTR_LANEDENSITY: {
372 0 : const double density = MIN2(frontSampleSeconds / STEPS2TIME(period) * (double) 1000 / myLaneLength,
373 0 : 1000. * numLanes / MAX2(minimalVehicleLength, NUMERICAL_EPS));
374 0 : return density / numLanes;
375 : }
376 0 : case SUMO_ATTR_OVERLAPDENSITY: {
377 0 : const double overlapDensity = MIN2(sampleSeconds / STEPS2TIME(period) * (double) 1000 / myLaneLength,
378 0 : 1000. * numLanes / MAX2(minimalVehicleLength, NUMERICAL_EPS));
379 0 : return overlapDensity / numLanes;
380 : }
381 0 : case SUMO_ATTR_OCCUPANCY:
382 0 : return occupationSum / STEPS2TIME(period) / myLaneLength / numLanes * (double) 1000;
383 0 : case SUMO_ATTR_WAITINGTIME:
384 0 : return waitSeconds;
385 0 : case SUMO_ATTR_TIMELOSS:
386 0 : return timeLoss;
387 0 : case SUMO_ATTR_SPEED:
388 0 : return travelledDistance / sampleSeconds;
389 0 : case SUMO_ATTR_SPEEDREL:
390 0 : return speedLimit == 0. ? 0. : travelledDistance / sampleSeconds / speedLimit;
391 0 : case SUMO_ATTR_DEPARTED:
392 0 : return nVehDeparted;
393 0 : case SUMO_ATTR_ARRIVED:
394 0 : return nVehArrived;
395 0 : case SUMO_ATTR_ENTERED:
396 0 : return nVehEntered;
397 0 : case SUMO_ATTR_LEFT:
398 0 : return nVehLeft;
399 0 : case SUMO_ATTR_VAPORIZED:
400 0 : return nVehVaporized;
401 0 : case SUMO_ATTR_TELEPORTED:
402 0 : return nVehTeleported;
403 0 : case SUMO_ATTR_FLOW: {
404 0 : const double density = MIN2(frontSampleSeconds / STEPS2TIME(period) * (double) 1000 / myLaneLength,
405 0 : 1000. * numLanes / MAX2(minimalVehicleLength, NUMERICAL_EPS));
406 0 : const double speed = frontTravelledDistance / frontSampleSeconds;
407 0 : return density * speed * 3.6;
408 : }
409 : default:
410 : return 0;
411 : }
412 : }
413 :
414 : // ---------------------------------------------------------------------------
415 : // MSMeanData_Net - methods
416 : // ---------------------------------------------------------------------------
417 22938 : MSMeanData_Net::MSMeanData_Net(const std::string& id,
418 : const SUMOTime dumpBegin,
419 : const SUMOTime dumpEnd, const bool useLanes,
420 : const std::string& excludeEmpty,
421 : const bool withInternal,
422 : const bool trackVehicles,
423 : const int detectPersons,
424 : const double maxTravelTime,
425 : const double minSamples,
426 : const double haltSpeed,
427 : const double haltSpeedRel,
428 : const std::string& vTypes,
429 : const std::string& writeAttributes,
430 : const std::vector<MSEdge*>& edges,
431 22938 : AggregateType aggregate) :
432 : MSMeanData(id, dumpBegin, dumpEnd, useLanes, excludeEmpty,
433 : withInternal, trackVehicles, detectPersons, maxTravelTime, minSamples, vTypes, writeAttributes, edges, aggregate),
434 22938 : myHaltSpeed(haltSpeed),
435 22938 : myHaltSpeedRel(haltSpeedRel)
436 22938 : { }
437 :
438 :
439 44857 : MSMeanData_Net::~MSMeanData_Net() {}
440 :
441 :
442 : MSMeanData::MeanDataValues*
443 8326631 : MSMeanData_Net::createValues(MSLane* const lane, const double length, const bool doAdd) const {
444 8326631 : return new MSLaneMeanDataValues(lane, length, doAdd, this);
445 : }
446 :
447 :
448 : std::vector<std::string>
449 0 : MSMeanData_Net::getAttributeNames() const {
450 : std::vector<std::string> result;
451 0 : result.push_back(toString(SUMO_ATTR_DENSITY));
452 0 : result.push_back(toString(SUMO_ATTR_LANEDENSITY));
453 0 : result.push_back(toString(SUMO_ATTR_OCCUPANCY));
454 0 : result.push_back(toString(SUMO_ATTR_WAITINGTIME));
455 0 : result.push_back(toString(SUMO_ATTR_TIMELOSS));
456 0 : result.push_back(toString(SUMO_ATTR_SPEED));
457 0 : result.push_back(toString(SUMO_ATTR_SPEEDREL));
458 0 : result.push_back(toString(SUMO_ATTR_DEPARTED));
459 0 : result.push_back(toString(SUMO_ATTR_ARRIVED));
460 0 : result.push_back(toString(SUMO_ATTR_ENTERED));
461 0 : result.push_back(toString(SUMO_ATTR_LEFT));
462 0 : result.push_back(toString(SUMO_ATTR_VAPORIZED));
463 0 : result.push_back(toString(SUMO_ATTR_TELEPORTED));
464 0 : result.push_back(toString(SUMO_ATTR_FLOW));
465 0 : return result;
466 0 : }
467 :
468 :
469 : double
470 0 : MSMeanData_Net::getAttributeValue(const MSLane* lane, SumoXMLAttr a, double defaultValue) const {
471 : double result = defaultValue;
472 0 : const std::vector<MeanDataValues*>* edgeValues = getEdgeValues(&lane->getEdge());
473 0 : if (edgeValues == nullptr) {
474 : return result;
475 : }
476 : MeanDataValues* values = nullptr;
477 0 : if (!myAmEdgeBased) {
478 0 : values = (*edgeValues)[lane->getIndex()];
479 : } else {
480 0 : MeanDataValues* sumData = createValues(nullptr, lane->getLength(), false);
481 0 : for (MeanDataValues* meanData : (*edgeValues)) {
482 0 : meanData->addTo(*sumData);
483 : }
484 : values = sumData;
485 : }
486 : const SUMOTime myLastResetTime = 0; // XXX store last reset time
487 0 : const SUMOTime period = SIMSTEP - myLastResetTime;
488 0 : result = values->getAttributeValue(a, period, lane->getEdge().getNumLanes(), lane->getSpeedLimit());
489 0 : if (myAmEdgeBased) {
490 0 : delete values;
491 : }
492 : return result;
493 : }
494 :
495 :
496 : /****************************************************************************/
|