LCOV - code coverage report
Current view: top level - src/microsim/output - MSAmitranTrajectories.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 28 29 96.6 %
Date: 2024-05-06 15:32:35 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /****************************************************************************/
       2             : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3             : // Copyright (C) 2014-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    MSAmitranTrajectories.cpp
      15             : /// @author  Michael Behrisch
      16             : /// @date    13.03.2014
      17             : ///
      18             : // Realises dumping the complete network state
      19             : /****************************************************************************/
      20             : #include <config.h>
      21             : 
      22             : #include <microsim/MSVehicleControl.h>
      23             : #include <microsim/MSEdge.h>
      24             : #include <microsim/MSLane.h>
      25             : #include <microsim/MSNet.h>
      26             : #include <microsim/MSVehicle.h>
      27             : #include <microsim/MSGlobals.h>
      28             : #include <utils/iodevices/OutputDevice.h>
      29             : #include <utils/emissions/PollutantsInterface.h>
      30             : #include "MSAmitranTrajectories.h"
      31             : 
      32             : // ===========================================================================
      33             : // static member definitions
      34             : // ===========================================================================
      35             : std::set<std::string> MSAmitranTrajectories::myWrittenTypes;
      36             : std::map<std::string, int> MSAmitranTrajectories::myWrittenVehicles;
      37             : 
      38             : 
      39             : // ===========================================================================
      40             : // method definitions
      41             : // ===========================================================================
      42             : void
      43        1620 : MSAmitranTrajectories::write(OutputDevice& of, const SUMOTime timestep) {
      44        1620 :     MSVehicleControl& vc = MSNet::getInstance()->getVehicleControl();
      45        4122 :     for (MSVehicleControl::constVehIt v = vc.loadedVehBegin(); v != vc.loadedVehEnd(); ++v) {
      46        2502 :         writeVehicle(of, *v->second, timestep);
      47             :     }
      48        1620 : }
      49             : 
      50             : 
      51             : void
      52        2502 : MSAmitranTrajectories::writeVehicle(OutputDevice& of, const SUMOVehicle& veh, const SUMOTime timestep) {
      53        2502 :     if (veh.isOnRoad()) {
      54        2448 :         const std::string& type = veh.getVehicleType().getID();
      55             :         if (myWrittenTypes.count(type) == 0) {
      56          12 :             of.openTag(SUMO_TAG_ACTORCONFIG).writeAttr(SUMO_ATTR_ID, veh.getVehicleType().getNumericalID());
      57          12 :             const SUMOEmissionClass c = veh.getVehicleType().getEmissionClass();
      58          12 :             if (c != 0) {
      59          12 :                 of.writeAttr(SUMO_ATTR_VEHICLECLASS, PollutantsInterface::getAmitranVehicleClass(c));
      60          24 :                 of.writeAttr("fuel", PollutantsInterface::getFuel(c));
      61          24 :                 of.writeAttr(SUMO_ATTR_EMISSIONCLASS, "Euro" + toString(PollutantsInterface::getEuroClass(c)));
      62          12 :                 const double weight = PollutantsInterface::getWeight(c);
      63          12 :                 if (weight > 0.) {
      64           0 :                     of.writeAttr(SUMO_ATTR_WEIGHT, int(weight / 10. + 0.5));
      65             :                 }
      66             :             }
      67          24 :             of.writeAttr(SUMO_ATTR_REF, type).closeTag();
      68             :             myWrittenTypes.insert(type);
      69             :         }
      70             :         if (myWrittenVehicles.count(veh.getID()) == 0) {
      71          60 :             const int index = (int)myWrittenVehicles.size();
      72          60 :             of.openTag(SUMO_TAG_VEHICLE).writeAttr(SUMO_ATTR_ID, index)
      73          60 :             .writeAttr(SUMO_ATTR_ACTORCONFIG, veh.getVehicleType().getNumericalID())
      74         120 :             .writeAttr(SUMO_ATTR_STARTTIME, STEPS2MS(veh.getDeparture()));
      75          60 :             of.writeAttr(SUMO_ATTR_REF, veh.getID()).closeTag();
      76          60 :             myWrittenVehicles[veh.getID()] = index;
      77             :         }
      78        2448 :         of.openTag(SUMO_TAG_MOTIONSTATE).writeAttr(SUMO_ATTR_VEHICLE, myWrittenVehicles[veh.getID()])
      79        2448 :         .writeAttr(SUMO_ATTR_SPEED, int(100.*veh.getSpeed() + 0.5))
      80             :         .writeAttr(SUMO_ATTR_TIME, STEPS2MS(timestep))
      81        2448 :         .writeAttr(SUMO_ATTR_ACCELERATION, int(1000.*veh.getAcceleration() + 0.5));
      82        4896 :         of.closeTag();
      83             :     }
      84        2502 : }
      85             : 
      86             : 
      87             : /****************************************************************************/

Generated by: LCOV version 1.14