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 8308033 : MSMeanData_Net::MSLaneMeanDataValues::MSLaneMeanDataValues(MSLane* const lane,
58 : const double length,
59 : const bool doAdd,
60 8308033 : const MSMeanData_Net* parent)
61 : : MSMeanData::MeanDataValues(lane, length, doAdd, parent),
62 8308033 : nVehDeparted(0), nVehArrived(0), nVehEntered(0), nVehLeft(0),
63 8308033 : nVehVaporized(0), nVehTeleported(0), waitSeconds(0), timeLoss(0),
64 8308033 : nVehLaneChangeFrom(0), nVehLaneChangeTo(0),
65 8308033 : frontSampleSeconds(0), frontTravelledDistance(0),
66 8308033 : vehLengthSum(0), occupationSum(0),
67 8308033 : minimalVehicleLength(INVALID_DOUBLE),
68 8308033 : myParent(parent) {}
69 :
70 :
71 16470698 : MSMeanData_Net::MSLaneMeanDataValues::~MSLaneMeanDataValues() {
72 16470698 : }
73 :
74 :
75 : void
76 16926078 : MSMeanData_Net::MSLaneMeanDataValues::reset(bool) {
77 16926078 : nVehDeparted = 0;
78 16926078 : nVehArrived = 0;
79 16926078 : nVehEntered = 0;
80 16926078 : nVehLeft = 0;
81 16926078 : nVehVaporized = 0;
82 16926078 : nVehTeleported = 0;
83 16926078 : nVehLaneChangeFrom = 0;
84 16926078 : nVehLaneChangeTo = 0;
85 16926078 : sampleSeconds = 0.;
86 16926078 : travelledDistance = 0;
87 16926078 : waitSeconds = 0;
88 16926078 : timeLoss = 0;
89 16926078 : frontSampleSeconds = 0;
90 16926078 : frontTravelledDistance = 0;
91 16926078 : vehLengthSum = 0;
92 16926078 : occupationSum = 0;
93 16926078 : minimalVehicleLength = INVALID_DOUBLE;
94 16926078 : resetTime = SIMSTEP;
95 16926078 : }
96 :
97 :
98 : void
99 8646154 : MSMeanData_Net::MSLaneMeanDataValues::addTo(MSMeanData::MeanDataValues& val) const {
100 : MSLaneMeanDataValues& v = (MSLaneMeanDataValues&) val;
101 8646154 : v.nVehDeparted += nVehDeparted;
102 8646154 : v.nVehArrived += nVehArrived;
103 8646154 : v.nVehEntered += nVehEntered;
104 8646154 : v.nVehLeft += nVehLeft;
105 8646154 : v.nVehVaporized += nVehVaporized;
106 8646154 : v.nVehTeleported += nVehTeleported;
107 8646154 : v.nVehLaneChangeFrom += nVehLaneChangeFrom;
108 8646154 : v.nVehLaneChangeTo += nVehLaneChangeTo;
109 8646154 : v.sampleSeconds += sampleSeconds;
110 8646154 : v.travelledDistance += travelledDistance;
111 8646154 : v.waitSeconds += waitSeconds;
112 8646154 : v.timeLoss += timeLoss;
113 8646154 : v.frontSampleSeconds += frontSampleSeconds;
114 8646154 : v.frontTravelledDistance += frontTravelledDistance;
115 8646154 : v.vehLengthSum += vehLengthSum;
116 8646154 : v.occupationSum += occupationSum;
117 8646154 : if (v.minimalVehicleLength == INVALID_DOUBLE) {
118 8553551 : v.minimalVehicleLength = minimalVehicleLength;
119 : } else {
120 178913 : v.minimalVehicleLength = MIN2(minimalVehicleLength, v.minimalVehicleLength);
121 : }
122 8646154 : }
123 :
124 :
125 : void
126 418088945 : 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 418088945 : if (myParent != nullptr && !myParent->vehicleApplies(veh)) {
146 : return;
147 : }
148 418046625 : sampleSeconds += timeOnLane;
149 418046625 : travelledDistance += travelledDistanceVehicleOnLane;
150 418046625 : vehLengthSum += veh.getVehicleType().getLength() * timeOnLane;
151 418046625 : 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 10284544 : 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 407762081 : occupationSum += meanLengthOnLane * TS;
160 : }
161 418046625 : if (!veh.isStopped()) {
162 402001695 : if (myParent != nullptr && meanSpeedVehicleOnLane < myParent->myHaltSpeed) {
163 55842253 : waitSeconds += timeOnLane;
164 346159442 : } else if (MSGlobals::gUseMesoSim) {
165 10238849 : waitSeconds += STEPS2TIME(veh.getWaitingTime());
166 : }
167 402001695 : const double vmax = veh.getLane() == nullptr ? veh.getEdge()->getVehicleMaxSpeed(&veh) : veh.getLane()->getVehicleMaxSpeed(&veh);
168 402001695 : if (vmax > 0) {
169 802246435 : timeLoss += timeOnLane * MAX2(0.0, vmax - meanSpeedVehicleOnLane) / vmax;
170 : }
171 : }
172 418046625 : frontSampleSeconds += frontOnLane;
173 418046625 : frontTravelledDistance += travelledDistanceFrontOnLane;
174 418046625 : if (minimalVehicleLength == INVALID_DOUBLE) {
175 694781 : minimalVehicleLength = veh.getVehicleType().getLengthWithGap();
176 : } else {
177 833257408 : 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 29030840 : MSMeanData_Net::MSLaneMeanDataValues::notifyLeave(SUMOTrafficObject& veh, double /*lastPos*/, MSMoveReminder::Notification reason, const MSLane* /* enteredLane */) {
188 29030840 : if ((myParent == nullptr || myParent->vehicleApplies(veh)) && (
189 19960177 : getLane() == nullptr || !veh.isVehicle() || getLane() == static_cast<MSVehicle&>(veh).getLane())) {
190 : #ifdef HAVE_FOX
191 24360951 : ScopedLocker<> lock(myNotificationMutex, MSGlobals::gNumSimThreads > 1);
192 : #endif
193 24360951 : if (MSGlobals::gUseMesoSim) {
194 9070507 : removeFromVehicleUpdateValues(veh);
195 : }
196 24360951 : if (reason == MSMoveReminder::NOTIFICATION_ARRIVED) {
197 3474430 : ++nVehArrived;
198 20886521 : } else if (reason == MSMoveReminder::NOTIFICATION_LANE_CHANGE) {
199 131790 : ++nVehLaneChangeFrom;
200 20754731 : } else if (myParent == nullptr || reason != MSMoveReminder::NOTIFICATION_SEGMENT) {
201 12878856 : ++nVehLeft;
202 12878856 : if (reason == MSMoveReminder::NOTIFICATION_TELEPORT || reason == MSMoveReminder::NOTIFICATION_TELEPORT_ARRIVED) {
203 5235 : ++nVehTeleported;
204 12873621 : } else if (reason >= MSMoveReminder::NOTIFICATION_VAPORIZED_CALIBRATOR) {
205 70315 : ++nVehVaporized;
206 : }
207 : }
208 : }
209 29030840 : if (MSGlobals::gUseMesoSim) {
210 : return false;
211 : }
212 19951493 : return reason == MSMoveReminder::NOTIFICATION_JUNCTION;
213 : }
214 :
215 :
216 : bool
217 25474468 : 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 25474468 : if (myParent == nullptr || myParent->vehicleApplies(veh)) {
224 24467065 : if (getLane() == nullptr || !veh.isVehicle() || getLane() == static_cast<MSVehicle&>(veh).getLane()) {
225 : #ifdef HAVE_FOX
226 24458225 : ScopedLocker<> lock(myNotificationMutex, MSGlobals::gNumSimThreads > 1);
227 : #endif
228 24458225 : if (reason == MSMoveReminder::NOTIFICATION_DEPARTED) {
229 3647956 : ++nVehDeparted;
230 20810269 : } else if (reason == MSMoveReminder::NOTIFICATION_LANE_CHANGE) {
231 131426 : ++nVehLaneChangeTo;
232 20678843 : } else if (myParent == nullptr || reason != MSMoveReminder::NOTIFICATION_SEGMENT) {
233 12833142 : ++nVehEntered;
234 : }
235 : }
236 24467065 : return true;
237 : }
238 : return false;
239 : }
240 :
241 :
242 : bool
243 22480095 : MSMeanData_Net::MSLaneMeanDataValues::isEmpty() const {
244 21822227 : return sampleSeconds == 0 && nVehDeparted == 0 && nVehArrived == 0 && nVehEntered == 0
245 44301874 : && nVehLeft == 0 && nVehVaporized == 0 && nVehTeleported == 0 && nVehLaneChangeFrom == 0 && nVehLaneChangeTo == 0;
246 : }
247 :
248 : double
249 947548 : MSMeanData_Net::MSLaneMeanDataValues::getOccupancy(SUMOTime period, int numLanes) const {
250 947548 : return occupationSum / STEPS2TIME(period) / myLaneLength / (double)numLanes * 100.;
251 : }
252 :
253 : void
254 947428 : 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 947428 : double density = frontSampleSeconds / STEPS2TIME(period) * 1000. / myLaneLength;
258 947428 : double overlapDensity = sampleSeconds / STEPS2TIME(period) * 1000. / myLaneLength;
259 947428 : if (MSGlobals::gLateralResolution < 0) {
260 : // avoid exceeding upper bound
261 894034 : density = MIN2(density, 1000 * (double)numLanes / MAX2(minimalVehicleLength, NUMERICAL_EPS));
262 892817 : overlapDensity = MIN2(overlapDensity, 1000 * (double)numLanes / MAX2(minimalVehicleLength, NUMERICAL_EPS));
263 : }
264 947428 : const double laneDensity = density / (double)numLanes;
265 947428 : 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 947428 : if (myParent == nullptr) {
279 10036 : const double speed = sampleSeconds == 0 ? 0. : travelledDistance / sampleSeconds;
280 10036 : const double frontSpeed = frontSampleSeconds == 0 ? 0. : frontTravelledDistance / frontSampleSeconds;
281 10036 : dev.writeOptionalAttr(SUMO_ATTR_DENSITY, density, attributeMask, sampleSeconds == 0);
282 10036 : dev.writeOptionalAttr(SUMO_ATTR_LANEDENSITY, laneDensity, attributeMask, sampleSeconds == 0);
283 10036 : dev.writeOptionalAttr(SUMO_ATTR_OCCUPANCY, occupancy, attributeMask, sampleSeconds == 0);
284 10036 : dev.writeOptionalAttr(SUMO_ATTR_WAITINGTIME, waitSeconds, attributeMask, sampleSeconds == 0);
285 10036 : dev.writeOptionalAttr(SUMO_ATTR_TIMELOSS, timeLoss, attributeMask, sampleSeconds == 0);
286 10036 : dev.writeOptionalAttr(SUMO_ATTR_SPEED, speed, attributeMask, sampleSeconds == 0);
287 10036 : dev.writeOptionalAttr(SUMO_ATTR_SPEEDREL, speedLimit == 0. || sampleSeconds == 0 ? 0. : travelledDistance / sampleSeconds / speedLimit,
288 10036 : attributeMask, sampleSeconds == 0);
289 10036 : dev.writeOptionalAttr(SUMO_ATTR_DEPARTED, nVehDeparted, attributeMask);
290 10036 : dev.writeOptionalAttr(SUMO_ATTR_ARRIVED, nVehArrived, attributeMask);
291 10036 : dev.writeOptionalAttr(SUMO_ATTR_ENTERED, nVehEntered, attributeMask);
292 10036 : dev.writeOptionalAttr(SUMO_ATTR_LEFT, nVehLeft, attributeMask);
293 10036 : dev.writeOptionalAttr(SUMO_ATTR_VAPORIZED, nVehVaporized, attributeMask, nVehVaporized == 0);
294 10036 : dev.writeOptionalAttr(SUMO_ATTR_TELEPORTED, nVehTeleported, attributeMask, nVehTeleported == 0);
295 10036 : dev.writeOptionalAttr(SUMO_ATTR_FLOW, density * frontSpeed * 3.6, attributeMask, frontSampleSeconds == 0);
296 20072 : dev.closeTag();
297 : return;
298 : }
299 937392 : const bool haveSamples = sampleSeconds > myParent->myMinSamples;
300 937392 : const bool haveFrontSamples = frontSampleSeconds > myParent->myMinSamples;
301 937392 : const bool haveSamplesOrDefault = haveSamples || defaultTravelTime >= 0.;
302 : bool haveTravelTime = haveSamplesOrDefault;
303 937392 : double traveltime = myParent->myMaxTravelTime;
304 937392 : if (haveSamples) {
305 618315 : if (numVehicles > 0) {
306 244 : traveltime = sampleSeconds / numVehicles;
307 : } else {
308 : traveltime = myParent->myMaxTravelTime;
309 618071 : if (frontTravelledDistance > NUMERICAL_EPS) {
310 843283 : traveltime = MIN2(traveltime, myLaneLength * frontSampleSeconds / frontTravelledDistance);
311 196326 : } else if (defaultTravelTime >= 0.) {
312 0 : traveltime = defaultTravelTime;
313 : } else {
314 : haveTravelTime = false;
315 : }
316 : }
317 319077 : } else if (defaultTravelTime >= 0.) {
318 1056 : traveltime = defaultTravelTime;
319 : }
320 937392 : dev.writeOptionalAttr(SUMO_ATTR_TRAVELTIME, traveltime, attributeMask, !haveTravelTime);
321 937392 : double overlapTraveltime = myParent->myMaxTravelTime;
322 937392 : if (travelledDistance > 0.) {
323 : // one vehicle has to drive lane length + vehicle length before it has left the lane
324 : // thus we need to scale with an extended length, approximated by lane length + average vehicle length
325 848153 : overlapTraveltime = MIN2(overlapTraveltime, (myLaneLength + vehLengthSum / sampleSeconds) * sampleSeconds / travelledDistance);
326 : }
327 937392 : dev.writeOptionalAttr(SUMO_ATTR_OVERLAPTRAVELTIME, overlapTraveltime, attributeMask, !haveSamples || numVehicles > 0);
328 937392 : dev.writeOptionalAttr(SUMO_ATTR_DENSITY, density, attributeMask, !haveSamples || numVehicles > 0);
329 937392 : dev.writeOptionalAttr(SUMO_ATTR_OVERLAPDENSITY, overlapDensity, attributeMask, sampleSeconds == 0);
330 937392 : dev.writeOptionalAttr(SUMO_ATTR_LANEDENSITY, laneDensity, attributeMask, !haveSamples || numVehicles > 0);
331 937392 : dev.writeOptionalAttr(SUMO_ATTR_OCCUPANCY, occupancy, attributeMask, !haveSamples || numVehicles > 0);
332 937392 : dev.writeOptionalAttr(SUMO_ATTR_WAITINGTIME, waitSeconds, attributeMask, !haveSamples);
333 937392 : dev.writeOptionalAttr(SUMO_ATTR_TIMELOSS, timeLoss, attributeMask, !haveSamples);
334 937392 : double speed = 0.;
335 : double frontSpeed = 0.;
336 937392 : if (haveSamples) {
337 618315 : speed = travelledDistance / sampleSeconds;
338 319077 : } else if (defaultTravelTime > 0.) {
339 1056 : speed = myLaneLength / defaultTravelTime;
340 : }
341 937392 : if (haveFrontSamples) {
342 577681 : frontSpeed = frontTravelledDistance / frontSampleSeconds;
343 359711 : } else if (defaultTravelTime > 0.) {
344 1056 : frontSpeed = myLaneLength / defaultTravelTime;
345 : }
346 937392 : dev.writeOptionalAttr(SUMO_ATTR_SPEED, speed, attributeMask, !haveSamplesOrDefault);
347 937392 : dev.writeOptionalAttr(SUMO_ATTR_SPEEDREL, speedLimit == 0. ? 0. : speed / speedLimit, attributeMask, !haveSamplesOrDefault);
348 937392 : dev.writeOptionalAttr(SUMO_ATTR_DEPARTED, nVehDeparted, attributeMask);
349 937392 : dev.writeOptionalAttr(SUMO_ATTR_ARRIVED, nVehArrived, attributeMask);
350 937392 : dev.writeOptionalAttr(SUMO_ATTR_ENTERED, nVehEntered, attributeMask);
351 937392 : dev.writeOptionalAttr(SUMO_ATTR_LEFT, nVehLeft, attributeMask);
352 937392 : dev.writeOptionalAttr(SUMO_ATTR_LANECHANGEDFROM, nVehLaneChangeFrom, attributeMask);
353 937392 : dev.writeOptionalAttr(SUMO_ATTR_LANECHANGEDTO, nVehLaneChangeTo, attributeMask);
354 937392 : dev.writeOptionalAttr(SUMO_ATTR_VAPORIZED, nVehVaporized, attributeMask, nVehVaporized == 0);
355 937392 : dev.writeOptionalAttr(SUMO_ATTR_TELEPORTED, nVehTeleported, attributeMask, nVehTeleported == 0);
356 937392 : dev.writeOptionalAttr(SUMO_ATTR_FLOW, density * frontSpeed * 3.6, attributeMask, !haveSamples || numVehicles == 0);
357 1874784 : dev.closeTag();
358 : }
359 :
360 :
361 : double
362 0 : MSMeanData_Net::MSLaneMeanDataValues::getAttributeValue(SumoXMLAttr a,
363 : const SUMOTime period, const double numLanes, const double speedLimit) const {
364 : /// @todo: remove redundancy in derived values (density, laneDensity)
365 0 : switch (a) {
366 0 : case SUMO_ATTR_DENSITY:
367 0 : return MIN2(frontSampleSeconds / STEPS2TIME(period) * (double) 1000 / myLaneLength,
368 0 : 1000. * numLanes / MAX2(minimalVehicleLength, NUMERICAL_EPS));
369 0 : case SUMO_ATTR_LANEDENSITY: {
370 0 : const double density = MIN2(frontSampleSeconds / STEPS2TIME(period) * (double) 1000 / myLaneLength,
371 0 : 1000. * numLanes / MAX2(minimalVehicleLength, NUMERICAL_EPS));
372 0 : return density / numLanes;
373 : }
374 0 : case SUMO_ATTR_OVERLAPDENSITY: {
375 0 : const double overlapDensity = MIN2(sampleSeconds / STEPS2TIME(period) * (double) 1000 / myLaneLength,
376 0 : 1000. * numLanes / MAX2(minimalVehicleLength, NUMERICAL_EPS));
377 0 : return overlapDensity / numLanes;
378 : }
379 0 : case SUMO_ATTR_OCCUPANCY:
380 0 : return occupationSum / STEPS2TIME(period) / myLaneLength / numLanes * (double) 1000;
381 0 : case SUMO_ATTR_WAITINGTIME:
382 0 : return waitSeconds;
383 0 : case SUMO_ATTR_TIMELOSS:
384 0 : return timeLoss;
385 0 : case SUMO_ATTR_SPEED:
386 0 : return travelledDistance / sampleSeconds;
387 0 : case SUMO_ATTR_SPEEDREL:
388 0 : return speedLimit == 0. ? 0. : travelledDistance / sampleSeconds / speedLimit;
389 0 : case SUMO_ATTR_DEPARTED:
390 0 : return nVehDeparted;
391 0 : case SUMO_ATTR_ARRIVED:
392 0 : return nVehArrived;
393 0 : case SUMO_ATTR_ENTERED:
394 0 : return nVehEntered;
395 0 : case SUMO_ATTR_LEFT:
396 0 : return nVehLeft;
397 0 : case SUMO_ATTR_VAPORIZED:
398 0 : return nVehVaporized;
399 0 : case SUMO_ATTR_TELEPORTED:
400 0 : return nVehTeleported;
401 0 : case SUMO_ATTR_FLOW: {
402 0 : const double density = MIN2(frontSampleSeconds / STEPS2TIME(period) * (double) 1000 / myLaneLength,
403 0 : 1000. * numLanes / MAX2(minimalVehicleLength, NUMERICAL_EPS));
404 0 : const double speed = frontTravelledDistance / frontSampleSeconds;
405 0 : return density * speed * 3.6;
406 : }
407 : default:
408 : return 0;
409 : }
410 : }
411 :
412 : // ---------------------------------------------------------------------------
413 : // MSMeanData_Net - methods
414 : // ---------------------------------------------------------------------------
415 22541 : MSMeanData_Net::MSMeanData_Net(const std::string& id,
416 : const SUMOTime dumpBegin,
417 : const SUMOTime dumpEnd, const bool useLanes,
418 : const bool withEmpty, const bool printDefaults,
419 : const bool withInternal,
420 : const bool trackVehicles,
421 : const int detectPersons,
422 : const double maxTravelTime,
423 : const double minSamples,
424 : const double haltSpeed,
425 : const std::string& vTypes,
426 : const std::string& writeAttributes,
427 : const std::vector<MSEdge*>& edges,
428 22541 : AggregateType aggregate) :
429 : MSMeanData(id, dumpBegin, dumpEnd, useLanes, withEmpty, printDefaults,
430 : withInternal, trackVehicles, detectPersons, maxTravelTime, minSamples, vTypes, writeAttributes, edges, aggregate),
431 22541 : myHaltSpeed(haltSpeed)
432 22541 : { }
433 :
434 :
435 44009 : MSMeanData_Net::~MSMeanData_Net() {}
436 :
437 :
438 : MSMeanData::MeanDataValues*
439 8305795 : MSMeanData_Net::createValues(MSLane* const lane, const double length, const bool doAdd) const {
440 8305795 : return new MSLaneMeanDataValues(lane, length, doAdd, this);
441 : }
442 :
443 :
444 : std::vector<std::string>
445 0 : MSMeanData_Net::getAttributeNames() const {
446 : std::vector<std::string> result;
447 0 : result.push_back(toString(SUMO_ATTR_DENSITY));
448 0 : result.push_back(toString(SUMO_ATTR_LANEDENSITY));
449 0 : result.push_back(toString(SUMO_ATTR_OCCUPANCY));
450 0 : result.push_back(toString(SUMO_ATTR_WAITINGTIME));
451 0 : result.push_back(toString(SUMO_ATTR_TIMELOSS));
452 0 : result.push_back(toString(SUMO_ATTR_SPEED));
453 0 : result.push_back(toString(SUMO_ATTR_SPEEDREL));
454 0 : result.push_back(toString(SUMO_ATTR_DEPARTED));
455 0 : result.push_back(toString(SUMO_ATTR_ARRIVED));
456 0 : result.push_back(toString(SUMO_ATTR_ENTERED));
457 0 : result.push_back(toString(SUMO_ATTR_LEFT));
458 0 : result.push_back(toString(SUMO_ATTR_VAPORIZED));
459 0 : result.push_back(toString(SUMO_ATTR_TELEPORTED));
460 0 : result.push_back(toString(SUMO_ATTR_FLOW));
461 0 : return result;
462 0 : }
463 :
464 :
465 : double
466 0 : MSMeanData_Net::getAttributeValue(const MSLane* lane, SumoXMLAttr a, double defaultValue) const {
467 : double result = defaultValue;
468 0 : const std::vector<MeanDataValues*>* edgeValues = getEdgeValues(&lane->getEdge());
469 0 : if (edgeValues == nullptr) {
470 : return result;
471 : }
472 : MeanDataValues* values = nullptr;
473 0 : if (!myAmEdgeBased) {
474 0 : values = (*edgeValues)[lane->getIndex()];
475 : } else {
476 0 : MeanDataValues* sumData = createValues(nullptr, lane->getLength(), false);
477 0 : for (MeanDataValues* meanData : (*edgeValues)) {
478 0 : meanData->addTo(*sumData);
479 : }
480 : values = sumData;
481 : }
482 : const SUMOTime myLastResetTime = 0; // XXX store last reset time
483 0 : const SUMOTime period = SIMSTEP - myLastResetTime;
484 0 : result = values->getAttributeValue(a, period, lane->getEdge().getNumLanes(), lane->getSpeedLimit());
485 0 : if (myAmEdgeBased) {
486 0 : delete values;
487 : }
488 : return result;
489 : }
490 :
491 :
492 : /****************************************************************************/
|