LCOV - code coverage report
Current view: top level - src/microsim/output - MSStopOut.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 91.0 % 89 81
Test Date: 2024-11-20 15:55:46 Functions: 100.0 % 12 12

            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    MSStopOut.cpp
      15              : /// @author  Jakob Erdmann
      16              : /// @date    Wed, 21.12.2016
      17              : ///
      18              : // Ouput information about planned vehicle stop
      19              : /****************************************************************************/
      20              : #include <config.h>
      21              : 
      22              : #include <utils/vehicle/SUMOVehicle.h>
      23              : #include <utils/options/OptionsCont.h>
      24              : #include <utils/common/MsgHandler.h>
      25              : #include <microsim/MSNet.h>
      26              : #include <microsim/MSEdge.h>
      27              : #include <microsim/MSLane.h>
      28              : #include <microsim/MSGlobals.h>
      29              : #include <microsim/MSParkingArea.h>
      30              : #include <microsim/MSStoppingPlace.h>
      31              : #include <microsim/MSVehicleType.h>
      32              : #include <microsim/trigger/MSChargingStation.h>
      33              : #include <microsim/trigger/MSOverheadWire.h>
      34              : #include "MSStopOut.h"
      35              : 
      36              : 
      37              : // ---------------------------------------------------------------------------
      38              : // static initialisation methods
      39              : // ---------------------------------------------------------------------------
      40              : MSStopOut* MSStopOut::myInstance = nullptr;
      41              : 
      42              : void
      43        42345 : MSStopOut::init() {
      44        84690 :     if (OptionsCont::getOptions().isSet("stop-output")) {
      45         1227 :         myInstance = new MSStopOut(OutputDevice::getDeviceByOption("stop-output"));
      46              :     }
      47        42345 : }
      48              : 
      49              : void
      50        40212 : MSStopOut::cleanup() {
      51        40212 :     delete myInstance;
      52        40212 :     myInstance = nullptr;
      53        40212 : }
      54              : 
      55              : // ===========================================================================
      56              : // method definitions
      57              : // ===========================================================================
      58         1227 : MSStopOut::MSStopOut(OutputDevice& dev) :
      59         1227 :     myDevice(dev) {
      60         1227 : }
      61              : 
      62         2444 : MSStopOut::~MSStopOut() {}
      63              : 
      64              : 
      65              : void
      66         5024 : MSStopOut::stopStarted(const SUMOVehicle* veh, int numPersons, int numContainers, SUMOTime time) {
      67              :     assert(veh != nullptr);
      68              :     if (myStopped.count(veh) != 0) {
      69            0 :         WRITE_WARNINGF(TL("Vehicle '%' stops on edge '%', time=% without ending the previous stop."),
      70              :                        veh->getID(), veh->getEdge()->getID(), time2string(time));
      71              :     }
      72         5024 :     myStopped.emplace(veh, StopInfo(numPersons, numContainers));
      73         5024 : }
      74              : 
      75              : void
      76         2488 : MSStopOut::loadedPersons(const SUMOVehicle* veh, int n) {
      77              :     // ignore triggered vehicles
      78         2488 :     if (veh->hasDeparted()) {
      79              :         if (myStopped.count(veh) == 0) {
      80            0 :             WRITE_WARNINGF(TL("Vehicle '%' loads persons on edge '%', time=% without starting the stop."),
      81              :                            veh->getID(), veh->getEdge()->getID(), time2string(SIMSTEP));
      82              :         } else {
      83         2427 :             myStopped.find(veh)->second.loadedPersons += n;
      84              :         }
      85              :     }
      86         2488 : }
      87              : 
      88              : void
      89         1590 : MSStopOut::unloadedPersons(const SUMOVehicle* veh, int n) {
      90              :     if (myStopped.count(veh) == 0) {
      91            0 :         WRITE_WARNINGF(TL("Vehicle '%' unloads persons on edge '%', time=% without starting the stop."),
      92              :                        veh->getID(), veh->getEdge()->getID(), time2string(SIMSTEP));
      93              :     } else {
      94         1590 :         myStopped.find(veh)->second.unloadedPersons += n;
      95              :     }
      96         1590 : }
      97              : 
      98              : void
      99          187 : MSStopOut::loadedContainers(const SUMOVehicle* veh, int n) {
     100              :     // ignore triggered vehicles
     101          187 :     if (veh->hasDeparted()) {
     102              :         if (myStopped.count(veh) == 0) {
     103            0 :             WRITE_WARNINGF(TL("Vehicle '%' loads container on edge '%', time=% without starting the stop."),
     104              :                            veh->getID(), veh->getEdge()->getID(), time2string(SIMSTEP));
     105              :         } else {
     106          173 :             myStopped.find(veh)->second.loadedContainers += n;
     107              :         }
     108              :     }
     109          187 : }
     110              : 
     111              : void
     112          138 : MSStopOut::unloadedContainers(const SUMOVehicle* veh, int n) {
     113              :     if (myStopped.count(veh) == 0) {
     114            0 :         WRITE_WARNINGF(TL("Vehicle '%' unloads container on edge '%', time=% without starting the stop."),
     115              :                        veh->getID(), veh->getEdge()->getID(), time2string(SIMSTEP));
     116              :     } else {
     117          138 :         myStopped.find(veh)->second.unloadedContainers += n;
     118              :     }
     119          138 : }
     120              : 
     121              : void
     122         4895 : MSStopOut::stopEnded(const SUMOVehicle* veh, const SUMOVehicleParameter::Stop& stop, const std::string& laneOrEdgeID, bool simEnd) {
     123              :     assert(veh != nullptr);
     124              :     if (myStopped.count(veh) == 0) {
     125            0 :         WRITE_WARNINGF(TL("Vehicle '%' ends stop on edge '%', time=% without entering the stop."),
     126              :                        veh->getID(), veh->getEdge()->getID(), time2string(SIMSTEP));
     127            0 :         return;
     128              :     }
     129              :     const StopInfo& si = myStopped.find(veh)->second;
     130         4895 :     double delay = -1;
     131         4895 :     double arrivalDelay = -1;
     132         4895 :     if (stop.until >= 0 && !simEnd) {
     133          970 :         delay = STEPS2TIME(SIMSTEP - stop.until);
     134              :     }
     135         4895 :     if (stop.arrival >= 0) {
     136          240 :         arrivalDelay = STEPS2TIME(stop.started - stop.arrival);
     137              :     }
     138         4895 :     myDevice.openTag("stopinfo");
     139         4895 :     myDevice.writeAttr(SUMO_ATTR_ID, veh->getID());
     140         4895 :     myDevice.writeAttr(SUMO_ATTR_TYPE, veh->getVehicleType().getID());
     141         4895 :     if (MSGlobals::gUseMesoSim) {
     142          829 :         myDevice.writeAttr(SUMO_ATTR_EDGE, laneOrEdgeID);
     143              :     } else {
     144         4066 :         myDevice.writeAttr(SUMO_ATTR_LANE, laneOrEdgeID);
     145              :     }
     146         4895 :     myDevice.writeAttr(SUMO_ATTR_POSITION, veh->getPositionOnLane());
     147         4895 :     myDevice.writeAttr(SUMO_ATTR_PARKING, stop.parking);
     148         4895 :     myDevice.writeAttr(SUMO_ATTR_STARTED, time2string(stop.started));
     149         4895 :     myDevice.writeAttr(SUMO_ATTR_ENDED, simEnd ? "-1" : time2string(SIMSTEP));
     150         4895 :     if (stop.until >= 0) {
     151         1940 :         myDevice.writeAttr("delay", delay);
     152              :     }
     153         4895 :     if (stop.arrival >= 0) {
     154          240 :         myDevice.writeAttr(SUMO_ATTR_ARRIVALDELAY, arrivalDelay);
     155              :     }
     156         4895 :     if (stop.busstop != "") {
     157         1821 :         myDevice.writeAttr(SUMO_ATTR_BUS_STOP, stop.busstop);
     158              :     }
     159         4895 :     if (stop.containerstop != "") {
     160           16 :         myDevice.writeAttr(SUMO_ATTR_CONTAINER_STOP, stop.containerstop);
     161              :     }
     162         4895 :     if (stop.parkingarea != "") {
     163         1763 :         myDevice.writeAttr(SUMO_ATTR_PARKING_AREA, stop.parkingarea);
     164              :     }
     165         4895 :     if (stop.chargingStation != "") {
     166           64 :         myDevice.writeAttr(SUMO_ATTR_CHARGING_STATION, stop.chargingStation);
     167              :     }
     168         4895 :     if (stop.overheadWireSegment != "") {
     169            0 :         myDevice.writeAttr(SUMO_ATTR_OVERHEAD_WIRE_SEGMENT, stop.overheadWireSegment);
     170              :     }
     171         4895 :     if (stop.tripId != "") {
     172           31 :         myDevice.writeAttr(SUMO_ATTR_TRIP_ID, stop.tripId);
     173              :     }
     174         4895 :     if (stop.line != "") {
     175           11 :         myDevice.writeAttr(SUMO_ATTR_LINE, stop.line);
     176              :     }
     177         4895 :     if (stop.split != "") {
     178           44 :         myDevice.writeAttr(SUMO_ATTR_SPLIT, stop.split);
     179              :     }
     180         4895 :     if (MSGlobals::gUseStopEnded) {
     181           60 :         myDevice.writeAttr(SUMO_ATTR_USED_ENDED, stop.ended >= 0);
     182              :     }
     183         4895 :     myDevice.writeAttr("initialPersons", si.initialNumPersons);
     184         4895 :     myDevice.writeAttr("loadedPersons", si.loadedPersons);
     185         4895 :     myDevice.writeAttr("unloadedPersons", si.unloadedPersons);
     186         4895 :     myDevice.writeAttr("initialContainers", si.initialNumContainers);
     187         4895 :     myDevice.writeAttr("loadedContainers", si.loadedContainers);
     188         4895 :     myDevice.writeAttr("unloadedContainers", si.unloadedContainers);
     189         9790 :     myDevice.closeTag();
     190              :     myStopped.erase(veh);
     191              : }
     192              : 
     193              : void
     194          111 : MSStopOut::generateOutputForUnfinished() {
     195         1327 :     while (!myStopped.empty()) {
     196              :         const auto& item = *myStopped.begin();
     197         1216 :         const SUMOVehicle* veh = item.first;
     198         1216 :         const SUMOVehicleParameter::Stop* stop = veh->getNextStopParameter();
     199              :         assert(stop != nullptr);
     200         1216 :         const std::string laneOrEdgeID = MSGlobals::gUseMesoSim ? veh->getEdge()->getID() : Named::getIDSecure(veh->getLane());
     201              :         // erases item from myStopped
     202         1216 :         stopEnded(veh, *stop, laneOrEdgeID, true);
     203              :     }
     204          111 : }
     205              : 
     206              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1