LCOV - code coverage report
Current view: top level - src/microsim/output - MSMeanData_Net.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 72.5 % 255 185
Test Date: 2025-12-06 15:35:27 Functions: 83.3 % 18 15

            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      8226912 : MSMeanData_Net::MSLaneMeanDataValues::MSLaneMeanDataValues(MSLane* const lane,
      58              :         const double length,
      59              :         const bool doAdd,
      60      8226912 :         const MSMeanData_Net* parent)
      61              :     : MSMeanData::MeanDataValues(lane, length, doAdd, parent),
      62      8226912 :       nVehDeparted(0), nVehArrived(0), nVehEntered(0), nVehLeft(0),
      63      8226912 :       nVehVaporized(0), nVehTeleported(0), waitSeconds(0), timeLoss(0),
      64      8226912 :       nVehLaneChangeFrom(0), nVehLaneChangeTo(0),
      65      8226912 :       frontSampleSeconds(0), frontTravelledDistance(0),
      66      8226912 :       vehLengthSum(0), occupationSum(0),
      67      8226912 :       minimalVehicleLength(INVALID_DOUBLE),
      68      8226912 :       myParent(parent) {}
      69              : 
      70              : 
      71     16309846 : MSMeanData_Net::MSLaneMeanDataValues::~MSLaneMeanDataValues() {
      72     16309846 : }
      73              : 
      74              : 
      75              : void
      76     16860744 : MSMeanData_Net::MSLaneMeanDataValues::reset(bool) {
      77     16860744 :     nVehDeparted = 0;
      78     16860744 :     nVehArrived = 0;
      79     16860744 :     nVehEntered = 0;
      80     16860744 :     nVehLeft = 0;
      81     16860744 :     nVehVaporized = 0;
      82     16860744 :     nVehTeleported = 0;
      83     16860744 :     nVehLaneChangeFrom = 0;
      84     16860744 :     nVehLaneChangeTo = 0;
      85     16860744 :     sampleSeconds = 0.;
      86     16860744 :     travelledDistance = 0;
      87     16860744 :     waitSeconds = 0;
      88     16860744 :     timeLoss = 0;
      89     16860744 :     frontSampleSeconds = 0;
      90     16860744 :     frontTravelledDistance = 0;
      91     16860744 :     vehLengthSum = 0;
      92     16860744 :     occupationSum = 0;
      93     16860744 :     minimalVehicleLength = INVALID_DOUBLE;
      94     16860744 :     resetTime = SIMSTEP;
      95     16860744 : }
      96              : 
      97              : 
      98              : void
      99      8613348 : MSMeanData_Net::MSLaneMeanDataValues::addTo(MSMeanData::MeanDataValues& val) const {
     100              :     MSLaneMeanDataValues& v = (MSLaneMeanDataValues&) val;
     101      8613348 :     v.nVehDeparted += nVehDeparted;
     102      8613348 :     v.nVehArrived += nVehArrived;
     103      8613348 :     v.nVehEntered += nVehEntered;
     104      8613348 :     v.nVehLeft += nVehLeft;
     105      8613348 :     v.nVehVaporized += nVehVaporized;
     106      8613348 :     v.nVehTeleported += nVehTeleported;
     107      8613348 :     v.nVehLaneChangeFrom += nVehLaneChangeFrom;
     108      8613348 :     v.nVehLaneChangeTo += nVehLaneChangeTo;
     109      8613348 :     v.sampleSeconds += sampleSeconds;
     110      8613348 :     v.travelledDistance += travelledDistance;
     111      8613348 :     v.waitSeconds += waitSeconds;
     112      8613348 :     v.timeLoss += timeLoss;
     113      8613348 :     v.frontSampleSeconds += frontSampleSeconds;
     114      8613348 :     v.frontTravelledDistance += frontTravelledDistance;
     115      8613348 :     v.vehLengthSum += vehLengthSum;
     116      8613348 :     v.occupationSum += occupationSum;
     117      8613348 :     if (v.minimalVehicleLength == INVALID_DOUBLE) {
     118      8520654 :         v.minimalVehicleLength = minimalVehicleLength;
     119              :     } else {
     120       179096 :         v.minimalVehicleLength = MIN2(minimalVehicleLength, v.minimalVehicleLength);
     121              :     }
     122      8613348 : }
     123              : 
     124              : 
     125              : void
     126    393388010 : 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    393388010 :     if (myParent != nullptr && !myParent->vehicleApplies(veh)) {
     146              :         return;
     147              :     }
     148    393345690 :     sampleSeconds += timeOnLane;
     149    393345690 :     travelledDistance += travelledDistanceVehicleOnLane;
     150    393345690 :     vehLengthSum += veh.getVehicleType().getLength() * timeOnLane;
     151    393345690 :     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     10274526 :         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    383071164 :         occupationSum += meanLengthOnLane * TS;
     160              :     }
     161    393345690 :     if (!veh.isStopped()) {
     162    377302401 :         if (myParent != nullptr && meanSpeedVehicleOnLane < myParent->myHaltSpeed) {
     163     53003220 :             waitSeconds += timeOnLane;
     164    324299181 :         } else if (MSGlobals::gUseMesoSim) {
     165     10228831 :             waitSeconds += STEPS2TIME(veh.getWaitingTime());
     166              :         }
     167    377302401 :         const double vmax = veh.getLane() == nullptr ? veh.getEdge()->getVehicleMaxSpeed(&veh) : veh.getLane()->getVehicleMaxSpeed(&veh);
     168    377302401 :         if (vmax > 0) {
     169    752854464 :             timeLoss += timeOnLane * MAX2(0.0, vmax - meanSpeedVehicleOnLane) / vmax;
     170              :         }
     171              :     }
     172    393345690 :     frontSampleSeconds += frontOnLane;
     173    393345690 :     frontTravelledDistance += travelledDistanceFrontOnLane;
     174    393345690 :     if (minimalVehicleLength == INVALID_DOUBLE) {
     175       696870 :         minimalVehicleLength = veh.getVehicleType().getLengthWithGap();
     176              :     } else {
     177    783851072 :         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     25488319 : MSMeanData_Net::MSLaneMeanDataValues::notifyLeave(SUMOTrafficObject& veh, double /*lastPos*/, MSMoveReminder::Notification reason, const MSLane* /* enteredLane */) {
     188     25488319 :     if ((myParent == nullptr || myParent->vehicleApplies(veh)) && (
     189     16427484 :                 getLane() == nullptr || !veh.isVehicle() || getLane() == static_cast<MSVehicle&>(veh).getLane())) {
     190              : #ifdef HAVE_FOX
     191     21365961 :         ScopedLocker<> lock(myNotificationMutex, MSGlobals::gNumSimThreads > 1);
     192              : #endif
     193     21365961 :         if (MSGlobals::gUseMesoSim) {
     194      9060679 :             removeFromVehicleUpdateValues(veh);
     195              :         }
     196     21365961 :         if (reason == MSMoveReminder::NOTIFICATION_ARRIVED) {
     197      2476031 :             ++nVehArrived;
     198     18889930 :         } else if (reason == MSMoveReminder::NOTIFICATION_LANE_CHANGE) {
     199       132203 :             ++nVehLaneChangeFrom;
     200     18757727 :         } else if (myParent == nullptr || reason != MSMoveReminder::NOTIFICATION_SEGMENT) {
     201     10885128 :             ++nVehLeft;
     202     10885128 :             if (reason == MSMoveReminder::NOTIFICATION_TELEPORT || reason == MSMoveReminder::NOTIFICATION_TELEPORT_ARRIVED) {
     203         4066 :                 ++nVehTeleported;
     204     10881062 :             } else if (reason >= MSMoveReminder::NOTIFICATION_VAPORIZED_CALIBRATOR) {
     205        70311 :                 ++nVehVaporized;
     206              :             }
     207              :         }
     208              :     }
     209     25488319 :     if (MSGlobals::gUseMesoSim) {
     210              :         return false;
     211              :     }
     212     16418800 :     return reason == MSMoveReminder::NOTIFICATION_JUNCTION;
     213              : }
     214              : 
     215              : 
     216              : bool
     217     22517762 : 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     22517762 :     if (myParent == nullptr || myParent->vehicleApplies(veh)) {
     224     21480644 :         if (getLane() == nullptr || !veh.isVehicle() || getLane() == static_cast<MSVehicle&>(veh).getLane()) {
     225              : #ifdef HAVE_FOX
     226     21471804 :             ScopedLocker<> lock(myNotificationMutex, MSGlobals::gNumSimThreads > 1);
     227              : #endif
     228     21471804 :             if (reason == MSMoveReminder::NOTIFICATION_DEPARTED) {
     229      2661356 :                 ++nVehDeparted;
     230     18810448 :             } else if (reason == MSMoveReminder::NOTIFICATION_LANE_CHANGE) {
     231       131885 :                 ++nVehLaneChangeTo;
     232     18678563 :             } else if (myParent == nullptr || reason != MSMoveReminder::NOTIFICATION_SEGMENT) {
     233     10836138 :                 ++nVehEntered;
     234              :             }
     235              :         }
     236     21480644 :         return true;
     237              :     }
     238              :     return false;
     239              : }
     240              : 
     241              : 
     242              : bool
     243     22480104 : MSMeanData_Net::MSLaneMeanDataValues::isEmpty() const {
     244     21822227 :     return sampleSeconds == 0 && nVehDeparted == 0 && nVehArrived == 0 && nVehEntered == 0
     245     44301883 :            && nVehLeft == 0 && nVehVaporized == 0 && nVehTeleported == 0 && nVehLaneChangeFrom == 0 && nVehLaneChangeTo == 0;
     246              : }
     247              : 
     248              : double
     249       899290 : MSMeanData_Net::MSLaneMeanDataValues::getOccupancy(SUMOTime period, int numLanes) const {
     250       899290 :     return occupationSum / STEPS2TIME(period) / myLaneLength / (double)numLanes * 100.;
     251              : }
     252              : 
     253              : void
     254       899170 : 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       899170 :     double density = frontSampleSeconds / STEPS2TIME(period) * 1000. / myLaneLength;
     258       899170 :     double overlapDensity = sampleSeconds / STEPS2TIME(period) * 1000. / myLaneLength;
     259       899170 :     if (MSGlobals::gLateralResolution < 0) {
     260              :         // avoid exceeding upper bound
     261       845357 :         density = MIN2(density, 1000 * (double)numLanes / MAX2(minimalVehicleLength, NUMERICAL_EPS));
     262       844559 :         overlapDensity = MIN2(overlapDensity, 1000 * (double)numLanes / MAX2(minimalVehicleLength, NUMERICAL_EPS));
     263              :     }
     264       899170 :     const double laneDensity = density / (double)numLanes;
     265       899170 :     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       899170 :     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       889134 :     const bool haveSamples = sampleSeconds > myParent->myMinSamples;
     300       889134 :     const bool haveFrontSamples = frontSampleSeconds > myParent->myMinSamples;
     301       889134 :     const bool haveSamplesOrDefault = haveSamples || defaultTravelTime >= 0.;
     302              :     bool haveTravelTime = haveSamplesOrDefault;
     303       889134 :     double traveltime = myParent->myMaxTravelTime;
     304       889134 :     if (haveSamples) {
     305       620263 :         if (numVehicles > 0) {
     306          244 :             traveltime = sampleSeconds / numVehicles;
     307              :         } else {
     308              :             traveltime = myParent->myMaxTravelTime;
     309       620019 :             if (frontTravelledDistance > NUMERICAL_EPS) {
     310       847169 :                 traveltime = MIN2(traveltime, myLaneLength * frontSampleSeconds / frontTravelledDistance);
     311       196331 :             } else if (defaultTravelTime >= 0.) {
     312            0 :                 traveltime = defaultTravelTime;
     313              :             } else {
     314              :                 haveTravelTime = false;
     315              :             }
     316              :         }
     317       268871 :     } else if (defaultTravelTime >= 0.) {
     318         1056 :         traveltime = defaultTravelTime;
     319              :     }
     320       889134 :     dev.writeOptionalAttr(SUMO_ATTR_TRAVELTIME, traveltime, attributeMask, !haveTravelTime);
     321       889134 :     double overlapTraveltime = myParent->myMaxTravelTime;
     322       889134 :     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       852049 :         overlapTraveltime = MIN2(overlapTraveltime, (myLaneLength + vehLengthSum / sampleSeconds) * sampleSeconds / travelledDistance);
     326              :     }
     327       889134 :     dev.writeOptionalAttr(SUMO_ATTR_OVERLAPTRAVELTIME, overlapTraveltime, attributeMask, !haveSamples || numVehicles > 0);
     328       889134 :     dev.writeOptionalAttr(SUMO_ATTR_DENSITY, density, attributeMask, !haveSamples || numVehicles > 0);
     329       889134 :     dev.writeOptionalAttr(SUMO_ATTR_OVERLAPDENSITY, overlapDensity, attributeMask, sampleSeconds == 0);
     330       889134 :     dev.writeOptionalAttr(SUMO_ATTR_LANEDENSITY, laneDensity, attributeMask, !haveSamples || numVehicles > 0);
     331       889134 :     dev.writeOptionalAttr(SUMO_ATTR_OCCUPANCY, occupancy, attributeMask, !haveSamples || numVehicles > 0);
     332       889134 :     dev.writeOptionalAttr(SUMO_ATTR_WAITINGTIME, waitSeconds, attributeMask, !haveSamples);
     333       889134 :     dev.writeOptionalAttr(SUMO_ATTR_TIMELOSS, timeLoss, attributeMask, !haveSamples);
     334       889134 :     double speed = 0.;
     335              :     double frontSpeed = 0.;
     336       889134 :     if (haveSamples) {
     337       620263 :         speed = travelledDistance / sampleSeconds;
     338       268871 :     } else if (defaultTravelTime > 0.) {
     339         1056 :         speed = myLaneLength / defaultTravelTime;
     340              :     }
     341       889134 :     if (haveFrontSamples) {
     342       579626 :         frontSpeed = frontTravelledDistance / frontSampleSeconds;
     343       309508 :     } else if (defaultTravelTime > 0.) {
     344         1056 :         frontSpeed = myLaneLength / defaultTravelTime;
     345              :     }
     346       889134 :     dev.writeOptionalAttr(SUMO_ATTR_SPEED, speed, attributeMask, !haveSamplesOrDefault);
     347       889134 :     dev.writeOptionalAttr(SUMO_ATTR_SPEEDREL, speedLimit == 0. ? 0. : speed / speedLimit, attributeMask, !haveSamplesOrDefault);
     348       889134 :     dev.writeOptionalAttr(SUMO_ATTR_DEPARTED, nVehDeparted, attributeMask);
     349       889134 :     dev.writeOptionalAttr(SUMO_ATTR_ARRIVED, nVehArrived, attributeMask);
     350       889134 :     dev.writeOptionalAttr(SUMO_ATTR_ENTERED, nVehEntered, attributeMask);
     351       889134 :     dev.writeOptionalAttr(SUMO_ATTR_LEFT, nVehLeft, attributeMask);
     352       889134 :     dev.writeOptionalAttr(SUMO_ATTR_LANECHANGEDFROM, nVehLaneChangeFrom, attributeMask);
     353       889134 :     dev.writeOptionalAttr(SUMO_ATTR_LANECHANGEDTO, nVehLaneChangeTo, attributeMask);
     354       889134 :     dev.writeOptionalAttr(SUMO_ATTR_VAPORIZED, nVehVaporized, attributeMask, nVehVaporized == 0);
     355       889134 :     dev.writeOptionalAttr(SUMO_ATTR_TELEPORTED, nVehTeleported, attributeMask, nVehTeleported == 0);
     356       889134 :     dev.writeOptionalAttr(SUMO_ATTR_FLOW, density * frontSpeed * 3.6, attributeMask, !haveSamples || numVehicles == 0);
     357      1778268 :     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        20056 : 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        20056 :                                AggregateType aggregate) :
     429              :     MSMeanData(id, dumpBegin, dumpEnd, useLanes, withEmpty, printDefaults,
     430              :                withInternal, trackVehicles, detectPersons, maxTravelTime, minSamples, vTypes, writeAttributes, edges, aggregate),
     431        20056 :     myHaltSpeed(haltSpeed)
     432        20056 : { }
     433              : 
     434              : 
     435        38877 : MSMeanData_Net::~MSMeanData_Net() {}
     436              : 
     437              : 
     438              : MSMeanData::MeanDataValues*
     439      8224231 : MSMeanData_Net::createValues(MSLane* const lane, const double length, const bool doAdd) const {
     440      8224231 :     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              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1