LCOV - code coverage report
Current view: top level - src/microsim/output - MSMeanData_Net.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 88.3 % 274 242
Test Date: 2026-10-12 15:53:19 Functions: 94.4 % 18 17

            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      8338774 : MSMeanData_Net::MSLaneMeanDataValues::MSLaneMeanDataValues(MSLane* const lane,
      58              :         const double length,
      59              :         const bool doAdd,
      60      8338774 :         const MSMeanData_Net* parent)
      61              :     : MSMeanData::MeanDataValues(lane, length, doAdd, parent),
      62      8338774 :       nVehDeparted(0), nVehArrived(0), nVehEntered(0), nVehLeft(0),
      63      8338774 :       nVehVaporized(0), nVehTeleported(0), waitSeconds(0), timeLoss(0),
      64      8338774 :       nVehLaneChangeFrom(0), nVehLaneChangeTo(0),
      65      8338774 :       frontSampleSeconds(0), frontTravelledDistance(0),
      66      8338774 :       vehLengthSum(0), occupationSum(0),
      67      8338774 :       minimalVehicleLength(INVALID_DOUBLE),
      68      8338774 :       myParent(parent) {}
      69              : 
      70              : 
      71     16674207 : MSMeanData_Net::MSLaneMeanDataValues::~MSLaneMeanDataValues() {
      72     16674207 : }
      73              : 
      74              : 
      75              : void
      76     16956500 : MSMeanData_Net::MSLaneMeanDataValues::reset(bool) {
      77     16956500 :     nVehDeparted = 0;
      78     16956500 :     nVehArrived = 0;
      79     16956500 :     nVehEntered = 0;
      80     16956500 :     nVehLeft = 0;
      81     16956500 :     nVehVaporized = 0;
      82     16956500 :     nVehTeleported = 0;
      83     16956500 :     nVehLaneChangeFrom = 0;
      84     16956500 :     nVehLaneChangeTo = 0;
      85     16956500 :     sampleSeconds = 0.;
      86     16956500 :     travelledDistance = 0;
      87     16956500 :     waitSeconds = 0;
      88     16956500 :     timeLoss = 0;
      89     16956500 :     frontSampleSeconds = 0;
      90     16956500 :     frontTravelledDistance = 0;
      91     16956500 :     vehLengthSum = 0;
      92     16956500 :     occupationSum = 0;
      93     16956500 :     minimalVehicleLength = INVALID_DOUBLE;
      94     16956500 :     resetTime = SIMSTEP;
      95     16956500 : }
      96              : 
      97              : 
      98              : void
      99      8681305 : MSMeanData_Net::MSLaneMeanDataValues::addTo(MSMeanData::MeanDataValues& val) const {
     100              :     MSLaneMeanDataValues& v = (MSLaneMeanDataValues&) val;
     101      8681305 :     v.nVehDeparted += nVehDeparted;
     102      8681305 :     v.nVehArrived += nVehArrived;
     103      8681305 :     v.nVehEntered += nVehEntered;
     104      8681305 :     v.nVehLeft += nVehLeft;
     105      8681305 :     v.nVehVaporized += nVehVaporized;
     106      8681305 :     v.nVehTeleported += nVehTeleported;
     107      8681305 :     v.nVehLaneChangeFrom += nVehLaneChangeFrom;
     108      8681305 :     v.nVehLaneChangeTo += nVehLaneChangeTo;
     109      8681305 :     v.sampleSeconds += sampleSeconds;
     110      8681305 :     v.travelledDistance += travelledDistance;
     111      8681305 :     v.waitSeconds += waitSeconds;
     112      8681305 :     v.timeLoss += timeLoss;
     113      8681305 :     v.frontSampleSeconds += frontSampleSeconds;
     114      8681305 :     v.frontTravelledDistance += frontTravelledDistance;
     115      8681305 :     v.vehLengthSum += vehLengthSum;
     116      8681305 :     v.occupationSum += occupationSum;
     117      8681305 :     if (v.minimalVehicleLength == INVALID_DOUBLE) {
     118      8579550 :         v.minimalVehicleLength = minimalVehicleLength;
     119              :     } else {
     120       197420 :         v.minimalVehicleLength = MIN2(minimalVehicleLength, v.minimalVehicleLength);
     121              :     }
     122      8681305 :     if (mySubData != nullptr) {
     123          280 :         mySubData->addTo(*val.getSubData());
     124              :     }
     125      8681305 : }
     126              : 
     127              : 
     128              : void
     129    418783854 : MSMeanData_Net::MSLaneMeanDataValues::notifyMoveInternal(
     130              :     const SUMOTrafficObject& veh, const double frontOnLane,
     131              :     const double timeOnLane, const double /* meanSpeedFrontOnLane */,
     132              :     const double meanSpeedVehicleOnLane,
     133              :     const double travelledDistanceFrontOnLane,
     134              :     const double travelledDistanceVehicleOnLane,
     135              :     const double meanLengthOnLane) {
     136              : #ifdef DEBUG_OCCUPANCY
     137              :     if (DEBUG_COND2) {
     138              :         std::cout << SIMTIME << "\n  MSMeanData_Net::MSLaneMeanDataValues::notifyMoveInternal()\n"
     139              :                   << "  veh '" << veh.getID() << "' on edge '" << veh.getEdge()->getID() << "'"
     140              :                   << ", timeOnLane=" << timeOnLane
     141              :                   << ", meanSpeedVehicleOnLane=" << meanSpeedVehicleOnLane
     142              :                   << ",\ntravelledDistanceFrontOnLane=" << travelledDistanceFrontOnLane
     143              :                   << ", travelledDistanceVehicleOnLane=" << travelledDistanceVehicleOnLane
     144              :                   << ", meanLengthOnLane=" << meanLengthOnLane
     145              :                   << std::endl;
     146              :     }
     147              : #endif
     148    418783854 :     if (myParent != nullptr && !myParent->vehicleApplies(veh)) {
     149              :         return;
     150              :     }
     151    418741534 :     sampleSeconds += timeOnLane;
     152    418741534 :     travelledDistance += travelledDistanceVehicleOnLane;
     153    418741534 :     vehLengthSum += veh.getVehicleType().getLength() * timeOnLane;
     154    418741534 :     if (MSGlobals::gUseMesoSim) {
     155              :         // For the mesosim case no information on whether the vehicle was occupying
     156              :         // the lane with its whole length is available. We assume the whole length
     157              :         // Therefore this increment is taken out with more information on the vehicle movement.
     158     10369893 :         occupationSum += veh.getVehicleType().getLength() * timeOnLane;
     159              :     } else {
     160              :         // for the microsim case more elaborate calculation of the average length on the lane,
     161              :         // is taken out in notifyMove(), refs #153
     162    408371641 :         occupationSum += meanLengthOnLane * TS;
     163              :     }
     164    418741534 :     if (!veh.isStopped()) {
     165    402694144 :         if (myParent != nullptr && (meanSpeedVehicleOnLane < myParent->myHaltSpeed
     166    341326257 :                                     || (myParent->myHaltSpeedRel > 0 && meanSpeedVehicleOnLane / veh.getCurrentEdge()->getSpeedLimit(veh.getVClass()) < myParent->myHaltSpeedRel))) {
     167     61311113 :             waitSeconds += timeOnLane;
     168    341383031 :         } else if (MSGlobals::gUseMesoSim) {
     169     10313454 :             waitSeconds += STEPS2TIME(veh.getWaitingTime());
     170              :         }
     171    402694144 :         const double vmax = veh.getLane() == nullptr ? veh.getEdge()->getVehicleMaxSpeed(&veh) : veh.getLane()->getVehicleMaxSpeed(&veh);
     172    402694144 :         if (vmax > 0) {
     173    803601614 :             timeLoss += timeOnLane * MAX2(0.0, vmax - meanSpeedVehicleOnLane) / vmax;
     174              :         }
     175              :     }
     176    418741534 :     frontSampleSeconds += frontOnLane;
     177    418741534 :     frontTravelledDistance += travelledDistanceFrontOnLane;
     178    418741534 :     if (minimalVehicleLength == INVALID_DOUBLE) {
     179       699802 :         minimalVehicleLength = veh.getVehicleType().getLengthWithGap();
     180              :     } else {
     181    834649297 :         minimalVehicleLength = MIN2(minimalVehicleLength, veh.getVehicleType().getLengthWithGap());
     182              :     }
     183              : #ifdef DEBUG_OCCUPANCY2
     184              :     // refs #3265
     185              :     std::cout << SIMTIME << "ID: " << getDescription() << " minVehicleLength=" << minimalVehicleLength << std::endl;
     186              : #endif
     187              : }
     188              : 
     189              : 
     190              : bool
     191     27581350 : MSMeanData_Net::MSLaneMeanDataValues::notifyLeave(SUMOTrafficObject& veh, double /*lastPos*/, MSMoveReminder::Notification reason, const MSLane* /* enteredLane */) {
     192     27581350 :     if ((myParent == nullptr || myParent->vehicleApplies(veh)) && (
     193     18432587 :                 getLane() == nullptr || !veh.isVehicle() || getLane() == static_cast<MSVehicle&>(veh).getLane())) {
     194              : #ifdef HAVE_FOX
     195     23161158 :         ScopedLocker<> lock(myNotificationMutex, MSGlobals::gNumSimThreads > 1);
     196              : #endif
     197     23161158 :         if (MSGlobals::gUseMesoSim) {
     198      9148607 :             removeFromVehicleUpdateValues(veh);
     199              :         }
     200     23161158 :         if (reason == MSMoveReminder::NOTIFICATION_ARRIVED) {
     201      3013901 :             ++nVehArrived;
     202     20147257 :         } else if (reason == MSMoveReminder::NOTIFICATION_LANE_CHANGE) {
     203       132539 :             ++nVehLaneChangeFrom;
     204     20014718 :         } else if (myParent == nullptr || reason != MSMoveReminder::NOTIFICATION_SEGMENT) {
     205     12123372 :             ++nVehLeft;
     206     12123372 :             if (reason == MSMoveReminder::NOTIFICATION_TELEPORT || reason == MSMoveReminder::NOTIFICATION_TELEPORT_ARRIVED) {
     207         6936 :                 ++nVehTeleported;
     208     12116436 :             } else if (reason >= MSMoveReminder::NOTIFICATION_VAPORIZED_CALIBRATOR) {
     209        70356 :                 ++nVehVaporized;
     210              :             }
     211              :         }
     212              :     }
     213     27581350 :     if (MSGlobals::gUseMesoSim || !veh.isVehicle()) {
     214              :         // only microsim vehicles keep the reminder until their back has fully left the edge/lane
     215      9162331 :         return false;
     216              :     }
     217     18419019 :     return reason == MSMoveReminder::NOTIFICATION_JUNCTION;
     218              : }
     219              : 
     220              : 
     221              : bool
     222     24189711 : MSMeanData_Net::MSLaneMeanDataValues::notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane) {
     223              : #ifdef DEBUG_NOTIFY_ENTER
     224              :     std::cout << "\n" << SIMTIME << " MSMeanData_Net::MSLaneMeanDataValues: veh '" << veh.getID() << "' enters lane '" << enteredLane->getID() << "'" << std::endl;
     225              : #else
     226              :     UNUSED_PARAMETER(enteredLane);
     227              : #endif
     228     24189711 :     if (myParent == nullptr || myParent->vehicleApplies(veh)) {
     229     23272096 :         if (getLane() == nullptr || !veh.isVehicle() || getLane() == static_cast<MSVehicle&>(veh).getLane()) {
     230              : #ifdef HAVE_FOX
     231     23263256 :             ScopedLocker<> lock(myNotificationMutex, MSGlobals::gNumSimThreads > 1);
     232              : #endif
     233     23263256 :             if (reason == MSMoveReminder::NOTIFICATION_DEPARTED) {
     234      3193299 :                 ++nVehDeparted;
     235     20069957 :             } else if (reason == MSMoveReminder::NOTIFICATION_LANE_CHANGE) {
     236       132199 :                 ++nVehLaneChangeTo;
     237     19937758 :             } else if (myParent == nullptr || reason != MSMoveReminder::NOTIFICATION_SEGMENT) {
     238     12076601 :                 ++nVehEntered;
     239              :             }
     240              :         }
     241     23272096 :         return true;
     242              :     }
     243              :     return false;
     244              : }
     245              : 
     246              : 
     247              : bool
     248     22491197 : MSMeanData_Net::MSLaneMeanDataValues::isEmpty() const {
     249     21828929 :     return sampleSeconds == 0 && nVehDeparted == 0 && nVehArrived == 0 && nVehEntered == 0
     250     44319678 :            && nVehLeft == 0 && nVehVaporized == 0 && nVehTeleported == 0 && nVehLaneChangeFrom == 0 && nVehLaneChangeTo == 0;
     251              : }
     252              : 
     253              : double
     254       966492 : MSMeanData_Net::MSLaneMeanDataValues::getOccupancy(SUMOTime period, int numLanes) const {
     255       966492 :     return occupationSum / STEPS2TIME(period) / myLaneLength / (double)numLanes * 100.;
     256              : }
     257              : 
     258              : void
     259       966370 : MSMeanData_Net::MSLaneMeanDataValues::write(OutputDevice& dev, const SumoXMLAttrMask& attributeMask, const SUMOTime period,
     260              :         const int numLanes, const double speedLimit, const double defaultTravelTime, const int numVehicles) const {
     261              : 
     262       966370 :     double density = frontSampleSeconds / STEPS2TIME(period) * 1000. / myLaneLength;
     263       966370 :     double overlapDensity = sampleSeconds / STEPS2TIME(period) * 1000. / myLaneLength;
     264       966370 :     if (MSGlobals::gLateralResolution < 0) {
     265              :         // avoid exceeding upper bound
     266       912331 :         density = MIN2(density, 1000 * (double)numLanes / MAX2(minimalVehicleLength, NUMERICAL_EPS));
     267       910717 :         overlapDensity = MIN2(overlapDensity, 1000 * (double)numLanes / MAX2(minimalVehicleLength, NUMERICAL_EPS));
     268              :     }
     269       966370 :     const double laneDensity = density / (double)numLanes;
     270       966370 :     const double occupancy = getOccupancy(period, numLanes);
     271              : #ifdef DEBUG_OCCUPANCY2
     272              :     // tests #3264
     273              :     if (occupancy > 100) {
     274              :         std::cout << SIMTIME << " Encountered bad occupancy: " << occupancy
     275              :                   << ", myLaneLength=" << myLaneLength << ", period=" << STEPS2TIME(period) << ", occupationSum=" << occupationSum
     276              :                   << std::endl;
     277              :     }
     278              :     // refs #3265
     279              :     std::cout << SIMTIME << "ID: " << getDescription() << " minVehicleLength=" << minimalVehicleLength
     280              :               << "\ndensity=" << density << "\n";
     281              : #endif
     282              : 
     283       966370 :     if (myParent == nullptr) {
     284        10045 :         const double speed = sampleSeconds == 0 ? 0. : travelledDistance / sampleSeconds;
     285        10045 :         const double frontSpeed = frontSampleSeconds == 0 ? 0. : frontTravelledDistance / frontSampleSeconds;
     286        10045 :         dev.writeOptionalAttr(SUMO_ATTR_DENSITY, density, attributeMask, sampleSeconds == 0);
     287        10045 :         dev.writeOptionalAttr(SUMO_ATTR_LANEDENSITY, laneDensity, attributeMask, sampleSeconds == 0);
     288        10045 :         dev.writeOptionalAttr(SUMO_ATTR_OCCUPANCY, occupancy, attributeMask, sampleSeconds == 0);
     289        10045 :         dev.writeOptionalAttr(SUMO_ATTR_WAITINGTIME, waitSeconds, attributeMask, sampleSeconds == 0);
     290        10045 :         dev.writeOptionalAttr(SUMO_ATTR_TIMELOSS, timeLoss, attributeMask, sampleSeconds == 0);
     291        10045 :         dev.writeOptionalAttr(SUMO_ATTR_SPEED, speed, attributeMask, sampleSeconds == 0);
     292        10045 :         dev.writeOptionalAttr(SUMO_ATTR_SPEEDREL, speedLimit == 0. || sampleSeconds == 0 ? 0. : travelledDistance / sampleSeconds / speedLimit,
     293        10045 :                               attributeMask, sampleSeconds == 0);
     294        10045 :         dev.writeOptionalAttr(SUMO_ATTR_DEPARTED, nVehDeparted, attributeMask);
     295        10045 :         dev.writeOptionalAttr(SUMO_ATTR_ARRIVED, nVehArrived, attributeMask);
     296        10045 :         dev.writeOptionalAttr(SUMO_ATTR_ENTERED, nVehEntered, attributeMask);
     297        10045 :         dev.writeOptionalAttr(SUMO_ATTR_LEFT, nVehLeft, attributeMask);
     298        10045 :         dev.writeOptionalAttr(SUMO_ATTR_VAPORIZED, nVehVaporized, attributeMask, nVehVaporized == 0);
     299        10045 :         dev.writeOptionalAttr(SUMO_ATTR_TELEPORTED, nVehTeleported, attributeMask, nVehTeleported == 0);
     300        10045 :         dev.writeOptionalAttr(SUMO_ATTR_FLOW, density * frontSpeed * 3.6, attributeMask, frontSampleSeconds == 0);
     301        10045 :         dev.writeOptionalAttr(SUMO_ATTR_DISTANCE, frontTravelledDistance, attributeMask);
     302        20090 :         dev.closeTag();
     303              :         return;
     304              :     }
     305       956325 :     const bool haveSamples = sampleSeconds > myParent->myMinSamples;
     306       956325 :     const bool haveFrontSamples = frontSampleSeconds > myParent->myMinSamples;
     307       956325 :     const bool haveSamplesOrDefault = haveSamples || defaultTravelTime >= 0.;
     308              :     bool haveTravelTime = haveSamplesOrDefault;
     309       956325 :     double traveltime = myParent->myMaxTravelTime;
     310       956325 :     if (haveSamples) {
     311       624072 :         if (numVehicles > 0) {
     312          244 :             traveltime = sampleSeconds / numVehicles;
     313              :         } else {
     314              :             traveltime = myParent->myMaxTravelTime;
     315       623828 :             if (frontTravelledDistance > NUMERICAL_EPS) {
     316       853131 :                 traveltime = MIN2(traveltime, myLaneLength * frontSampleSeconds / frontTravelledDistance);
     317       197119 :             } else if (defaultTravelTime >= 0.) {
     318            0 :                 traveltime = defaultTravelTime;
     319              :             } else {
     320              :                 haveTravelTime = false;
     321              :             }
     322              :         }
     323       332253 :     } else if (defaultTravelTime >= 0.) {
     324         2638 :         traveltime = defaultTravelTime;
     325              :     }
     326       956325 :     dev.writeOptionalAttr(SUMO_ATTR_TRAVELTIME, traveltime, attributeMask, !haveTravelTime);
     327       956325 :     double overlapTraveltime = myParent->myMaxTravelTime;
     328       956325 :     if (travelledDistance > 0.) {
     329              :         // one vehicle has to drive lane length + vehicle length before it has left the lane
     330              :         // thus we need to scale with an extended length, approximated by lane length + average vehicle length
     331       858667 :         overlapTraveltime = MIN2(overlapTraveltime, (myLaneLength + vehLengthSum / sampleSeconds) * sampleSeconds / travelledDistance);
     332              :     }
     333       956325 :     dev.writeOptionalAttr(SUMO_ATTR_OVERLAPTRAVELTIME, overlapTraveltime, attributeMask, !haveSamples || numVehicles > 0);
     334       956325 :     dev.writeOptionalAttr(SUMO_ATTR_DENSITY, density, attributeMask, !haveSamples || numVehicles > 0);
     335       956325 :     dev.writeOptionalAttr(SUMO_ATTR_OVERLAPDENSITY, overlapDensity, attributeMask, sampleSeconds == 0);
     336       956325 :     dev.writeOptionalAttr(SUMO_ATTR_LANEDENSITY, laneDensity, attributeMask, !haveSamples || numVehicles > 0);
     337       956325 :     dev.writeOptionalAttr(SUMO_ATTR_OCCUPANCY, occupancy, attributeMask, !haveSamples || numVehicles > 0);
     338       956325 :     dev.writeOptionalAttr(SUMO_ATTR_WAITINGTIME, waitSeconds, attributeMask, !haveSamples);
     339       956325 :     dev.writeOptionalAttr(SUMO_ATTR_TIMELOSS, timeLoss, attributeMask, !haveSamples);
     340       956325 :     double speed = 0.;
     341              :     double frontSpeed = 0.;
     342       956325 :     if (haveSamples) {
     343       624072 :         speed = travelledDistance / sampleSeconds;
     344       332253 :     } else if (defaultTravelTime > 0.) {
     345         2638 :         speed = myLaneLength / defaultTravelTime;
     346              :     }
     347       956325 :     if (haveFrontSamples) {
     348       583399 :         frontSpeed = frontTravelledDistance / frontSampleSeconds;
     349       372926 :     } else if (defaultTravelTime > 0.) {
     350         2638 :         frontSpeed = myLaneLength / defaultTravelTime;
     351              :     }
     352       956325 :     dev.writeOptionalAttr(SUMO_ATTR_SPEED, speed, attributeMask, !haveSamplesOrDefault);
     353       956325 :     dev.writeOptionalAttr(SUMO_ATTR_SPEEDREL, speedLimit == 0. ? 0. : speed / speedLimit, attributeMask, !haveSamplesOrDefault);
     354       956325 :     dev.writeOptionalAttr(SUMO_ATTR_DEPARTED, nVehDeparted, attributeMask);
     355       956325 :     dev.writeOptionalAttr(SUMO_ATTR_ARRIVED, nVehArrived, attributeMask);
     356       956325 :     dev.writeOptionalAttr(SUMO_ATTR_ENTERED, nVehEntered, attributeMask);
     357       956325 :     dev.writeOptionalAttr(SUMO_ATTR_LEFT, nVehLeft, attributeMask);
     358       956325 :     dev.writeOptionalAttr(SUMO_ATTR_LANECHANGEDFROM, nVehLaneChangeFrom, attributeMask);
     359       956325 :     dev.writeOptionalAttr(SUMO_ATTR_LANECHANGEDTO, nVehLaneChangeTo, attributeMask);
     360       956325 :     dev.writeOptionalAttr(SUMO_ATTR_VAPORIZED, nVehVaporized, attributeMask, nVehVaporized == 0);
     361       956325 :     dev.writeOptionalAttr(SUMO_ATTR_TELEPORTED, nVehTeleported, attributeMask, nVehTeleported == 0);
     362       956325 :     dev.writeOptionalAttr(SUMO_ATTR_FLOW, density * frontSpeed * 3.6, attributeMask, !haveSamples || numVehicles == 0);
     363       956325 :     dev.writeOptionalAttr(SUMO_ATTR_DISTANCE, frontTravelledDistance, attributeMask);
     364              : }
     365              : 
     366              : 
     367              : double
     368         8524 : MSMeanData_Net::MSLaneMeanDataValues::getAttributeValue(SumoXMLAttr a,
     369              :         const SUMOTime period, const double numLanes, const double speedLimit) const {
     370              :     /// @todo: remove redundancy in derived values (density, laneDensity)
     371         8524 :     switch (a) {
     372          576 :         case SUMO_ATTR_DENSITY:
     373          576 :             return MIN2(frontSampleSeconds / STEPS2TIME(period) * (double) 1000 / myLaneLength,
     374          576 :                         1000. * numLanes / MAX2(minimalVehicleLength, NUMERICAL_EPS));
     375          576 :         case SUMO_ATTR_LANEDENSITY: {
     376          576 :             const double density = MIN2(frontSampleSeconds / STEPS2TIME(period) * (double) 1000 / myLaneLength,
     377          576 :                                         1000. * numLanes / MAX2(minimalVehicleLength, NUMERICAL_EPS));
     378          576 :             return density / numLanes;
     379              :         }
     380            0 :         case SUMO_ATTR_OVERLAPDENSITY: {
     381            0 :             const double overlapDensity = MIN2(sampleSeconds / STEPS2TIME(period) * (double) 1000 / myLaneLength,
     382            0 :                                                1000. * numLanes / MAX2(minimalVehicleLength, NUMERICAL_EPS));
     383            0 :             return overlapDensity / numLanes;
     384              :         }
     385            0 :         case SUMO_ATTR_OCCUPANCY:
     386            0 :             return occupationSum / STEPS2TIME(period) / myLaneLength / numLanes * (double) 1000;
     387          576 :         case SUMO_ATTR_WAITINGTIME:
     388          576 :             return waitSeconds;
     389          576 :         case SUMO_ATTR_TIMELOSS:
     390          576 :             return timeLoss;
     391          576 :         case SUMO_ATTR_SPEED:
     392          576 :             return travelledDistance / sampleSeconds;
     393          576 :         case SUMO_ATTR_SPEEDREL:
     394          576 :             return speedLimit == 0. ? 0. : travelledDistance / sampleSeconds / speedLimit;
     395          576 :         case SUMO_ATTR_DEPARTED:
     396          576 :             return nVehDeparted;
     397          576 :         case SUMO_ATTR_ARRIVED:
     398          576 :             return nVehArrived;
     399          576 :         case SUMO_ATTR_ENTERED:
     400          576 :             return nVehEntered;
     401          576 :         case SUMO_ATTR_LEFT:
     402          576 :             return nVehLeft;
     403            0 :         case SUMO_ATTR_VAPORIZED:
     404            0 :             return nVehVaporized;
     405            0 :         case SUMO_ATTR_TELEPORTED:
     406            0 :             return nVehTeleported;
     407         2188 :         case SUMO_ATTR_FLOW: {
     408         2188 :             const double density = MIN2(frontSampleSeconds / STEPS2TIME(period) * (double) 1000 / myLaneLength,
     409         2188 :                                         1000. * numLanes / MAX2(minimalVehicleLength, NUMERICAL_EPS));
     410         2188 :             const double speed = frontTravelledDistance / frontSampleSeconds;
     411         2188 :             return density * speed * 3.6;
     412              :         }
     413          576 :         case SUMO_ATTR_DISTANCE:
     414          576 :             return frontTravelledDistance;
     415              :         default:
     416              :             return 0;
     417              :     }
     418              : }
     419              : 
     420              : 
     421              : // ---------------------------------------------------------------------------
     422              : // MSMeanData_Net - methods
     423              : // ---------------------------------------------------------------------------
     424        22984 : MSMeanData_Net::MSMeanData_Net(const std::string& id,
     425              :                                const SUMOTime dumpBegin,
     426              :                                const SUMOTime dumpEnd, const bool useLanes,
     427              :                                const std::string& excludeEmpty,
     428              :                                const bool withInternal,
     429              :                                const bool trackVehicles,
     430              :                                const int detectPersons,
     431              :                                const double maxTravelTime,
     432              :                                const double minSamples,
     433              :                                const double haltSpeed,
     434              :                                const double haltSpeedRel,
     435              :                                const std::string& vTypes,
     436              :                                const std::string& writeAttributes,
     437              :                                const std::vector<MSEdge*>& edges,
     438        22984 :                                AggregateType aggregate) :
     439              :     MSMeanData(id, dumpBegin, dumpEnd, useLanes, excludeEmpty,
     440              :                withInternal, trackVehicles, detectPersons, maxTravelTime, minSamples, vTypes, writeAttributes, edges, aggregate),
     441        22984 :     myHaltSpeed(haltSpeed),
     442        22984 :     myHaltSpeedRel(haltSpeedRel)
     443        22984 : { }
     444              : 
     445              : 
     446        44949 : MSMeanData_Net::~MSMeanData_Net() {}
     447              : 
     448              : 
     449              : MSMeanData::MeanDataValues*
     450      8336500 : MSMeanData_Net::createValues(MSLane* const lane, const double length, const bool doAdd) const {
     451      8336500 :     return new MSLaneMeanDataValues(lane, length, doAdd, this);
     452              : }
     453              : 
     454              : 
     455              : std::vector<std::string>
     456            0 : MSMeanData_Net::getAttributeNames() const {
     457              :     std::vector<std::string> result;
     458            0 :     result.push_back(toString(SUMO_ATTR_DENSITY));
     459            0 :     result.push_back(toString(SUMO_ATTR_LANEDENSITY));
     460            0 :     result.push_back(toString(SUMO_ATTR_OVERLAPDENSITY));
     461            0 :     result.push_back(toString(SUMO_ATTR_OCCUPANCY));
     462            0 :     result.push_back(toString(SUMO_ATTR_WAITINGTIME));
     463            0 :     result.push_back(toString(SUMO_ATTR_TIMELOSS));
     464            0 :     result.push_back(toString(SUMO_ATTR_SPEED));
     465            0 :     result.push_back(toString(SUMO_ATTR_SPEEDREL));
     466            0 :     result.push_back(toString(SUMO_ATTR_DEPARTED));
     467            0 :     result.push_back(toString(SUMO_ATTR_ARRIVED));
     468            0 :     result.push_back(toString(SUMO_ATTR_ENTERED));
     469            0 :     result.push_back(toString(SUMO_ATTR_LEFT));
     470            0 :     result.push_back(toString(SUMO_ATTR_LANECHANGEDFROM));
     471            0 :     result.push_back(toString(SUMO_ATTR_LANECHANGEDTO));
     472            0 :     result.push_back(toString(SUMO_ATTR_VAPORIZED));
     473            0 :     result.push_back(toString(SUMO_ATTR_TELEPORTED));
     474            0 :     result.push_back(toString(SUMO_ATTR_FLOW));
     475            0 :     result.push_back(toString(SUMO_ATTR_DISTANCE));
     476            0 :     return result;
     477            0 : }
     478              : 
     479              : 
     480              : bool
     481          101 : MSMeanData_Net::supports(const SumoXMLAttrMask& attributeMask) {
     482              :     return
     483          101 :         attributeMask.test(SUMO_ATTR_DENSITY) ||
     484          101 :         attributeMask.test(SUMO_ATTR_LANEDENSITY) ||
     485          101 :         attributeMask.test(SUMO_ATTR_OVERLAPDENSITY) ||
     486          101 :         attributeMask.test(SUMO_ATTR_OCCUPANCY) ||
     487          101 :         attributeMask.test(SUMO_ATTR_WAITINGTIME) ||
     488          101 :         attributeMask.test(SUMO_ATTR_TIMELOSS) ||
     489           77 :         attributeMask.test(SUMO_ATTR_SPEED) ||
     490           77 :         attributeMask.test(SUMO_ATTR_SPEEDREL) ||
     491           77 :         attributeMask.test(SUMO_ATTR_DEPARTED) ||
     492           44 :         attributeMask.test(SUMO_ATTR_ARRIVED) ||
     493           44 :         attributeMask.test(SUMO_ATTR_ENTERED) ||
     494           26 :         attributeMask.test(SUMO_ATTR_LEFT) ||
     495           10 :         attributeMask.test(SUMO_ATTR_LANECHANGEDFROM) ||
     496           10 :         attributeMask.test(SUMO_ATTR_LANECHANGEDTO) ||
     497           10 :         attributeMask.test(SUMO_ATTR_VAPORIZED) ||
     498           10 :         attributeMask.test(SUMO_ATTR_TELEPORTED) ||
     499          111 :         attributeMask.test(SUMO_ATTR_FLOW) ||
     500          101 :         attributeMask.test(SUMO_ATTR_DISTANCE);
     501              : }
     502              : 
     503              : 
     504              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1