LCOV - code coverage report
Current view: top level - src/microsim/output - MSFullExport.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 99.1 % 116 115
Test Date: 2025-11-13 15:38:19 Functions: 100.0 % 6 6

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2012-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    MSFullExport.cpp
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Mario Krumnow
      17              : /// @author  Michael Behrisch
      18              : /// @author  Jakob Erdmann
      19              : /// @date    2012-04-26
      20              : ///
      21              : // Dumping a hugh List of Parameters available in the Simulation
      22              : /****************************************************************************/
      23              : #include <config.h>
      24              : 
      25              : #include <utils/iodevices/OutputDevice.h>
      26              : #include <utils/emissions/PollutantsInterface.h>
      27              : #include <utils/emissions/HelpersHarmonoise.h>
      28              : #include <utils/geom/GeomHelper.h>
      29              : #include <microsim/MSEdge.h>
      30              : #include <microsim/MSEdgeControl.h>
      31              : #include <microsim/MSLane.h>
      32              : #include <microsim/MSNet.h>
      33              : #include <microsim/MSVehicle.h>
      34              : #include <microsim/MSVehicleControl.h>
      35              : #include <microsim/transportables/MSTransportableControl.h>
      36              : #include <microsim/transportables/MSTransportable.h>
      37              : #include <microsim/traffic_lights/MSTLLogicControl.h>
      38              : #include <microsim/traffic_lights/MSTrafficLightLogic.h>
      39              : #include "MSFullExport.h"
      40              : 
      41              : 
      42              : // ===========================================================================
      43              : // method definitions
      44              : // ===========================================================================
      45              : void
      46         1138 : MSFullExport::write(OutputDevice& of, SUMOTime timestep) {
      47         2276 :     of.openTag("data") << " timestep=\"" << time2string(timestep) << "\"";
      48         1138 :     writeVehicles(of);
      49         1138 :     if (MSNet::getInstance()->hasPersons()) {
      50           24 :         writePersons(of);
      51              :     }
      52         1138 :     writeEdge(of);
      53         1138 :     writeTLS(of, timestep);
      54         1138 :     of.closeTag();
      55         1138 : }
      56              : 
      57              : 
      58              : void
      59         1138 : MSFullExport::writeVehicles(OutputDevice& of) {
      60         1138 :     of.openTag("vehicles");
      61         1138 :     MSVehicleControl& vc = MSNet::getInstance()->getVehicleControl();
      62         1138 :     const bool hasEle = MSNet::getInstance()->hasElevation();
      63         2258 :     for (MSVehicleControl::constVehIt it = vc.loadedVehBegin(); it != vc.loadedVehEnd(); ++it) {
      64         1120 :         const SUMOVehicle* veh = it->second;
      65         1120 :         const MSVehicle* microVeh = dynamic_cast<const MSVehicle*>(veh);
      66         1120 :         if (veh->isOnRoad()) {
      67         1036 :             std::string fclass = veh->getVehicleType().getID();
      68         1036 :             fclass = fclass.substr(0, fclass.find_first_of("@"));
      69         1036 :             PollutantsInterface::Emissions emiss = PollutantsInterface::computeAll(
      70         1036 :                     veh->getVehicleType().getEmissionClass(), veh->getSpeed(),
      71         1036 :                     veh->getAcceleration(), veh->getSlope(),
      72         1036 :                     veh->getEmissionParameters());
      73         1036 :             of.openTag(SUMO_TAG_VEHICLE);
      74         1036 :             of.writeAttr(SUMO_ATTR_ID, veh->getID());
      75         1036 :             of.writeAttr(SUMO_ATTR_ECLASS, PollutantsInterface::getName(veh->getVehicleType().getEmissionClass()));
      76         1036 :             of.writeAttr(SUMO_ATTR_CO2, emiss.CO2);
      77         1036 :             of.writeAttr(SUMO_ATTR_CO, emiss.CO);
      78         1036 :             of.writeAttr(SUMO_ATTR_HC, emiss.HC);
      79         1036 :             of.writeAttr(SUMO_ATTR_NOX, emiss.NOx);
      80         1036 :             of.writeAttr(SUMO_ATTR_PMX, emiss.PMx);
      81         1036 :             of.writeAttr(SUMO_ATTR_FUEL, emiss.fuel);
      82         1036 :             of.writeAttr(SUMO_ATTR_ELECTRICITY, emiss.electricity);
      83         1036 :             of.writeAttr(SUMO_ATTR_NOISE, HelpersHarmonoise::computeNoise(veh->getVehicleType().getEmissionClass(), veh->getSpeed(), veh->getAcceleration()));
      84         1036 :             of.writeAttr(SUMO_ATTR_ROUTE, veh->getRoute().getID());
      85         1036 :             of.writeAttr(SUMO_ATTR_TYPE, fclass);
      86         1036 :             if (microVeh != nullptr) {
      87          688 :                 of.writeAttr(SUMO_ATTR_WAITING, microVeh->getWaitingSeconds());
      88          688 :                 of.writeAttr(SUMO_ATTR_LANE, microVeh->getLane()->getID());
      89              :             }
      90         1036 :             of.writeAttr(SUMO_ATTR_POSITION, veh->getPositionOnLane());
      91         1036 :             of.writeAttr(SUMO_ATTR_SPEED, veh->getSpeed());
      92         1036 :             of.writeAttr(SUMO_ATTR_ANGLE, GeomHelper::naviDegree(veh->getAngle()));
      93         1036 :             const Position pos = veh->getPosition();
      94         1036 :             of.writeAttr(SUMO_ATTR_X, pos.x());
      95         1036 :             of.writeAttr(SUMO_ATTR_Y, pos.y());
      96         1036 :             if (hasEle) {
      97          148 :                 of.writeAttr(SUMO_ATTR_Z, pos.z());
      98          148 :                 of.writeAttr(SUMO_ATTR_SLOPE, veh->getSlope());
      99              :             }
     100         2072 :             of.closeTag();
     101              :         }
     102              :     }
     103         1138 :     of.closeTag();
     104         1138 : }
     105              : 
     106              : void
     107           24 : MSFullExport::writePersons(OutputDevice& of) {
     108           24 :     MSTransportableControl& tc = MSNet::getInstance()->getPersonControl();
     109           24 :     const bool hasEle = MSNet::getInstance()->hasElevation();
     110           48 :     of.openTag("persons");
     111           48 :     for (auto it = tc.loadedBegin(); it != tc.loadedEnd(); ++it) {
     112           24 :         const MSTransportable* p = it->second;
     113           24 :         if (p->getCurrentStageType() != MSStageType::WAITING_FOR_DEPART) {
     114           24 :             const MSEdge* e = p->getEdge();
     115              :             const SUMOVehicle* v = p->getVehicle();
     116           24 :             Position pos = p->getPosition();
     117           24 :             of.openTag(SUMO_TAG_PERSON);
     118           24 :             of.writeAttr(SUMO_ATTR_ID, p->getID());
     119           24 :             of.writeAttr(SUMO_ATTR_X, pos.x());
     120           24 :             of.writeAttr(SUMO_ATTR_Y, pos.y());
     121           24 :             if (hasEle) {
     122            0 :                 of.writeAttr("z", pos.z());
     123              :             }
     124           24 :             of.writeAttr(SUMO_ATTR_ANGLE, GeomHelper::naviDegree(p->getAngle()));
     125           24 :             of.writeAttr(SUMO_ATTR_SPEED, p->getSpeed());
     126           24 :             of.writeAttr(SUMO_ATTR_POSITION, p->getEdgePos());
     127           24 :             of.writeAttr(SUMO_ATTR_EDGE, e->getID());
     128           24 :             of.writeAttr(SUMO_ATTR_SLOPE, e->getLanes()[0]->getShape().slopeDegreeAtOffset(p->getEdgePos()));
     129           36 :             of.writeAttr(SUMO_ATTR_VEHICLE, v == nullptr ? "" : v->getID());
     130           24 :             of.writeAttr(SUMO_ATTR_TYPE, p->getVehicleType().getID());
     131           24 :             of.writeAttr("stage", (int)p->getCurrentStageType());
     132           48 :             of.closeTag();
     133              :         }
     134              :     }
     135           24 :     of.closeTag();
     136           24 : }
     137              : 
     138              : void
     139         1138 : MSFullExport::writeEdge(OutputDevice& of) {
     140         1138 :     of.openTag("edges");
     141         1138 :     MSEdgeControl& ec = MSNet::getInstance()->getEdgeControl();
     142              :     const MSEdgeVector& edges = ec.getEdges();
     143        46282 :     for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) {
     144        45144 :         MSEdge& edge = **e;
     145        45144 :         if (!MSGlobals::gUsingInternalLanes && !edge.isNormal()) {
     146         7956 :             continue;
     147              :         }
     148        74376 :         of.openTag("edge").writeAttr("id", edge.getID()).writeAttr("traveltime", edge.getCurrentTravelTime());
     149              :         const std::vector<MSLane*>& lanes = edge.getLanes();
     150        83976 :         for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
     151        46788 :             writeLane(of, **lane);
     152              :         }
     153        74376 :         of.closeTag();
     154              :     }
     155         1138 :     of.closeTag();
     156         1138 : }
     157              : 
     158              : 
     159              : void
     160        46788 : MSFullExport::writeLane(OutputDevice& of, const MSLane& lane) {
     161        93576 :     of.openTag("lane").writeAttr("id", lane.getID()).writeAttr("CO", lane.getEmissions<PollutantsInterface::CO>()).writeAttr("CO2", lane.getEmissions<PollutantsInterface::CO2>());
     162        93576 :     of.writeAttr("NOx", lane.getEmissions<PollutantsInterface::NO_X>()).writeAttr("PMx", lane.getEmissions<PollutantsInterface::PM_X>()).writeAttr("HC", lane.getEmissions<PollutantsInterface::HC>());
     163        93576 :     of.writeAttr("noise", lane.getHarmonoise_NoiseEmissions()).writeAttr("fuel", lane.getEmissions<PollutantsInterface::FUEL>());
     164        93576 :     of.writeAttr("electricity", lane.getEmissions<PollutantsInterface::ELEC>()).writeAttr("maxspeed", lane.getSpeedLimit());
     165        93576 :     of.writeAttr("meanspeed", lane.getMeanSpeed()).writeAttr("occupancy", lane.getNettoOccupancy()).writeAttr("vehicle_count", lane.getVehicleNumber());
     166        46788 :     of.closeTag();
     167        46788 : }
     168              : 
     169              : 
     170              : void
     171         1138 : MSFullExport::writeTLS(OutputDevice& of, SUMOTime /* timestep */) {
     172         1138 :     of.openTag("tls");
     173         1138 :     MSTLLogicControl& vc = MSNet::getInstance()->getTLSControl();
     174         1138 :     std::vector<std::string> ids = vc.getAllTLIds();
     175         5818 :     for (std::vector<std::string>::const_iterator id_it = ids.begin(); id_it != ids.end(); ++id_it) {
     176         4680 :         MSTLLogicControl::TLSLogicVariants& vars = MSNet::getInstance()->getTLSControl().get(*id_it);
     177         4680 :         const MSTrafficLightLogic::LaneVectorVector& lanes = vars.getActive()->getLaneVectors();
     178              : 
     179              :         std::vector<std::string> laneIDs;
     180        52104 :         for (MSTrafficLightLogic::LaneVectorVector::const_iterator i = lanes.begin(); i != lanes.end(); ++i) {
     181              :             const MSTrafficLightLogic::LaneVector& llanes = (*i);
     182        94848 :             for (MSTrafficLightLogic::LaneVector::const_iterator j = llanes.begin(); j != llanes.end(); ++j) {
     183        47424 :                 laneIDs.push_back((*j)->getID());
     184              :             }
     185              :         }
     186              : 
     187         4680 :         std::string lane_output = "";
     188        52104 :         for (int i1 = 0; i1 < (int)laneIDs.size(); ++i1) {
     189        94848 :             lane_output += laneIDs[i1] + " ";
     190              :         }
     191              : 
     192         4680 :         std::string state = vars.getActive()->getCurrentPhaseDef().getState();
     193         9360 :         of.openTag("trafficlight").writeAttr("id", *id_it).writeAttr("state", state).closeTag();
     194         4680 :     }
     195         1138 :     of.closeTag();
     196         1138 : }
     197              : 
     198              : 
     199              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1