LCOV - code coverage report
Current view: top level - src/microsim/output - MSMeanData_Amitran.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 95.9 % 73 70
Test Date: 2024-12-21 15:45:41 Functions: 100.0 % 17 17

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2001-2024 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_Amitran.cpp
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Michael Behrisch
      17              : /// @date    Mon, 10.05.2004
      18              : ///
      19              : // Network state mean data collector for edges/lanes
      20              : /****************************************************************************/
      21              : #include <config.h>
      22              : 
      23              : #include <microsim/MSEdgeControl.h>
      24              : #include <microsim/MSEdge.h>
      25              : #include <microsim/MSLane.h>
      26              : #include <microsim/MSVehicle.h>
      27              : #include <utils/common/SUMOTime.h>
      28              : #include <utils/common/ToString.h>
      29              : #include <utils/iodevices/OutputDevice.h>
      30              : #include "MSMeanData_Amitran.h"
      31              : #include <limits>
      32              : 
      33              : 
      34              : // ===========================================================================
      35              : // method definitions
      36              : // ===========================================================================
      37              : // ---------------------------------------------------------------------------
      38              : // MSMeanData_Amitran::MSLaneMeanDataValues - methods
      39              : // ---------------------------------------------------------------------------
      40         2432 : MSMeanData_Amitran::MSLaneMeanDataValues::MSLaneMeanDataValues(MSLane* const lane,
      41              :         const double length,
      42              :         const bool doAdd,
      43         2432 :         const MSMeanData_Amitran* parent)
      44         2432 :     : MSMeanData::MeanDataValues(lane, length, doAdd, parent), amount(0) {}
      45              : 
      46              : 
      47         4864 : MSMeanData_Amitran::MSLaneMeanDataValues::~MSLaneMeanDataValues() {
      48         4864 : }
      49              : 
      50              : 
      51              : void
      52         4560 : MSMeanData_Amitran::MSLaneMeanDataValues::reset(bool) {
      53         4560 :     amount = 0;
      54              :     typedAmount.clear();
      55              :     typedSamples.clear();
      56              :     typedTravelDistance.clear();
      57         4560 :     resetTime = SIMSTEP;
      58         4560 : }
      59              : 
      60              : 
      61              : void
      62         3360 : MSMeanData_Amitran::MSLaneMeanDataValues::addTo(MSMeanData::MeanDataValues& val) const {
      63              :     MSLaneMeanDataValues& v = (MSLaneMeanDataValues&) val;
      64         3360 :     v.amount += amount;
      65         3360 :     v.sampleSeconds += sampleSeconds;
      66         3360 :     v.travelledDistance += travelledDistance;
      67         6016 :     for (std::map<const MSVehicleType*, int>::const_iterator it = typedAmount.begin(); it != typedAmount.end(); ++it) {
      68         2656 :         v.typedAmount[it->first] += it->second;
      69              :     }
      70         6152 :     for (std::map<const MSVehicleType*, double>::const_iterator it = typedSamples.begin(); it != typedSamples.end(); ++it) {
      71         2792 :         v.typedSamples[it->first] += it->second;
      72              :     }
      73         6152 :     for (std::map<const MSVehicleType*, double>::const_iterator it = typedTravelDistance.begin(); it != typedTravelDistance.end(); ++it) {
      74         2792 :         v.typedTravelDistance[it->first] += it->second;
      75              :     }
      76         3360 : }
      77              : 
      78              : 
      79              : void
      80      1771972 : MSMeanData_Amitran::MSLaneMeanDataValues::notifyMoveInternal(const SUMOTrafficObject& veh, const double /* frontOnLane */, const double timeOnLane, const double /*meanSpeedFrontOnLane*/, const double /*meanSpeedVehicleOnLane*/, const double /*travelledDistanceFrontOnLane*/, const double travelledDistanceVehicleOnLane, const double /* meanLengthOnLane */) {
      81      1771972 :     sampleSeconds += timeOnLane;
      82      1771972 :     travelledDistance += travelledDistanceVehicleOnLane;
      83      1771972 :     typedSamples[&veh.getVehicleType()] += timeOnLane;
      84      1771972 :     typedTravelDistance[&veh.getVehicleType()] += travelledDistanceVehicleOnLane;
      85      1771972 : }
      86              : 
      87              : 
      88              : bool
      89       117552 : MSMeanData_Amitran::MSLaneMeanDataValues::notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* /* enteredLane */) {
      90       117552 :     if (myParent->vehicleApplies(veh)) {
      91       117552 :         if (getLane() == nullptr || getLane() == static_cast<MSVehicle&>(veh).getLane()) {
      92       117552 :             if (reason == MSMoveReminder::NOTIFICATION_DEPARTED || reason == MSMoveReminder::NOTIFICATION_JUNCTION) {
      93        62184 :                 ++amount;
      94        62184 :                 typedAmount[&veh.getVehicleType()]++;
      95              :             }
      96              :         }
      97       117552 :         return true;
      98              :     }
      99              :     return false;
     100              : }
     101              : 
     102              : 
     103              : bool
     104         2448 : MSMeanData_Amitran::MSLaneMeanDataValues::isEmpty() const {
     105         2448 :     return sampleSeconds == 0 && amount == 0;
     106              : }
     107              : 
     108              : 
     109              : void
     110         2720 : MSMeanData_Amitran::MSLaneMeanDataValues::write(OutputDevice& dev, long long int attributeMask, const SUMOTime /* period */,
     111              :         const int /* numLanes */, const double /*speedLimit*/, const double defaultTravelTime, const int /* numVehicles */) const {
     112              :     int averageSpeed;
     113         2720 :     if (sampleSeconds > 0) {
     114         2720 :         averageSpeed = int(100 * travelledDistance / sampleSeconds);
     115            0 :     } else if (defaultTravelTime >= 0.) {
     116            0 :         averageSpeed = int(100 * myLaneLength / defaultTravelTime);
     117              :     } else {
     118            0 :         averageSpeed = -1;
     119              :     }
     120         2720 :     dev.writeOptionalAttr(SUMO_ATTR_AMOUNT, amount, attributeMask);
     121         2720 :     dev.writeOptionalAttr(SUMO_ATTR_AVERAGESPEED, averageSpeed, attributeMask);
     122              : 
     123         2720 :     if (myParent->isTyped()) {
     124         1152 :         for (std::map<const MSVehicleType*, int>::const_iterator it = typedAmount.begin(); it != typedAmount.end(); ++it) {
     125         1152 :             dev.openTag("actorConfig");
     126          576 :             const int typedAvgSpeed = int(100 * typedTravelDistance.find(it->first)->second / typedSamples.find(it->first)->second);
     127          576 :             dev.writeAttr(SUMO_ATTR_ID, it->first->getNumericalID());
     128          576 :             dev.writeOptionalAttr(SUMO_ATTR_AMOUNT, it->second, attributeMask);
     129          576 :             dev.writeOptionalAttr(SUMO_ATTR_AVERAGESPEED, typedAvgSpeed, attributeMask);
     130         1152 :             dev.closeTag();
     131              :         }
     132              :     }
     133         2720 :     dev.closeTag();
     134         2720 : }
     135              : 
     136              : // ---------------------------------------------------------------------------
     137              : // MSMeanData_Amitran - methods
     138              : // ---------------------------------------------------------------------------
     139           24 : MSMeanData_Amitran::MSMeanData_Amitran(const std::string& id,
     140              :                                        const SUMOTime dumpBegin,
     141              :                                        const SUMOTime dumpEnd, const bool useLanes,
     142              :                                        const bool withEmpty, const bool printDefaults,
     143              :                                        const bool withInternal,
     144              :                                        const bool trackVehicles,
     145              :                                        const int detectPersons,
     146              :                                        const double maxTravelTime,
     147              :                                        const double minSamples,
     148              :                                        const double haltSpeed,
     149              :                                        const std::string& vTypes,
     150              :                                        const std::string& writeAttributes,
     151              :                                        const std::vector<MSEdge*>& edges,
     152           24 :                                        bool aggregate) :
     153              :     MSMeanData(id, dumpBegin, dumpEnd, useLanes, withEmpty, printDefaults,
     154              :                withInternal, trackVehicles, detectPersons, maxTravelTime, minSamples, vTypes, writeAttributes, edges, aggregate),
     155           24 :     myHaltSpeed(haltSpeed) {
     156           24 : }
     157              : 
     158              : 
     159           48 : MSMeanData_Amitran::~MSMeanData_Amitran() {}
     160              : 
     161              : 
     162              : void
     163           24 : MSMeanData_Amitran::writeXMLDetectorProlog(OutputDevice& dev) const {
     164           48 :     dev.writeXMLHeader("linkData", "amitran/linkdata.xsd");
     165           24 : }
     166              : 
     167              : 
     168              : std::string
     169         3024 : MSMeanData_Amitran::getEdgeID(const MSEdge* const edge) {
     170         3024 :     return toString(edge->getNumericalID());
     171              : }
     172              : 
     173              : 
     174              : void
     175          252 : MSMeanData_Amitran::openInterval(OutputDevice& dev, const SUMOTime startTime, const SUMOTime stopTime) {
     176          252 :     const int duration = int(1000 * STEPS2TIME(stopTime - startTime) + 0.5);
     177          252 :     dev.openTag(SUMO_TAG_TIMESLICE).writeAttr(SUMO_ATTR_STARTTIME, int(1000 * STEPS2TIME(startTime) + 0.5)).writeAttr(SUMO_ATTR_DURATION, duration);
     178          252 : }
     179              : 
     180              : 
     181              : bool
     182         3024 : MSMeanData_Amitran::writePrefix(OutputDevice& dev, const MeanDataValues& values, const SumoXMLTag /* tag */, const std::string id) const {
     183         3024 :     if (myDumpEmpty || !values.isEmpty()) {
     184         2720 :         dev.openTag("link").writeAttr(SUMO_ATTR_ID, id);
     185         2720 :         return true;
     186              :     }
     187              :     return false;
     188              : }
     189              : 
     190              : 
     191              : MSMeanData::MeanDataValues*
     192         2432 : MSMeanData_Amitran::createValues(MSLane* const lane, const double length, const bool doAdd) const {
     193         2432 :     return new MSLaneMeanDataValues(lane, length, doAdd, this);
     194              : }
     195              : 
     196              : 
     197              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1