Line data Source code
1 : /****************************************************************************/ 2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo 3 : // Copyright (C) 2012-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 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/traffic_lights/MSTLLogicControl.h> 36 : #include <microsim/traffic_lights/MSTrafficLightLogic.h> 37 : #include "MSFullExport.h" 38 : 39 : 40 : // =========================================================================== 41 : // method definitions 42 : // =========================================================================== 43 : void 44 960 : MSFullExport::write(OutputDevice& of, SUMOTime timestep) { 45 1920 : of.openTag("data") << " timestep=\"" << time2string(timestep) << "\""; 46 : //Vehicles 47 960 : writeVehicles(of); 48 : //Edges 49 960 : writeEdge(of); 50 : //TrafficLights 51 960 : writeTLS(of, timestep); 52 960 : of.closeTag(); 53 960 : } 54 : 55 : 56 : void 57 960 : MSFullExport::writeVehicles(OutputDevice& of) { 58 960 : of.openTag("vehicles"); 59 960 : MSVehicleControl& vc = MSNet::getInstance()->getVehicleControl(); 60 1920 : for (MSVehicleControl::constVehIt it = vc.loadedVehBegin(); it != vc.loadedVehEnd(); ++it) { 61 960 : const SUMOVehicle* veh = it->second; 62 960 : const MSVehicle* microVeh = dynamic_cast<const MSVehicle*>(veh); 63 960 : if (veh->isOnRoad()) { 64 876 : std::string fclass = veh->getVehicleType().getID(); 65 876 : fclass = fclass.substr(0, fclass.find_first_of("@")); 66 876 : PollutantsInterface::Emissions emiss = PollutantsInterface::computeAll( 67 876 : veh->getVehicleType().getEmissionClass(), veh->getSpeed(), 68 876 : veh->getAcceleration(), veh->getSlope(), 69 876 : veh->getEmissionParameters()); 70 2628 : of.openTag("vehicle").writeAttr("id", veh->getID()).writeAttr("eclass", PollutantsInterface::getName(veh->getVehicleType().getEmissionClass())); 71 4380 : of.writeAttr("CO2", emiss.CO2).writeAttr("CO", emiss.CO).writeAttr("HC", emiss.HC).writeAttr("NOx", emiss.NOx); 72 3504 : of.writeAttr("PMx", emiss.PMx).writeAttr("fuel", emiss.fuel).writeAttr("electricity", emiss.electricity); 73 876 : of.writeAttr("noise", HelpersHarmonoise::computeNoise(veh->getVehicleType().getEmissionClass(), veh->getSpeed(), veh->getAcceleration())); 74 2628 : of.writeAttr("route", veh->getRoute().getID()).writeAttr("type", fclass); 75 876 : if (microVeh != nullptr) { 76 576 : of.writeAttr("waiting", microVeh->getWaitingSeconds()); 77 1152 : of.writeAttr("lane", microVeh->getLane()->getID()); 78 : } 79 2628 : of.writeAttr("pos", veh->getPositionOnLane()).writeAttr("speed", veh->getSpeed()); 80 3504 : of.writeAttr("angle", GeomHelper::naviDegree(veh->getAngle())).writeAttr("x", veh->getPosition().x()).writeAttr("y", veh->getPosition().y()); 81 1752 : of.closeTag(); 82 : } 83 : } 84 960 : of.closeTag(); 85 960 : } 86 : 87 : void 88 960 : MSFullExport::writeEdge(OutputDevice& of) { 89 960 : of.openTag("edges"); 90 960 : MSEdgeControl& ec = MSNet::getInstance()->getEdgeControl(); 91 : const MSEdgeVector& edges = ec.getEdges(); 92 43200 : for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) { 93 42240 : MSEdge& edge = **e; 94 42240 : if (!MSGlobals::gUsingInternalLanes && !edge.isNormal()) { 95 7680 : continue; 96 : } 97 103680 : of.openTag("edge").writeAttr("id", edge.getID()).writeAttr("traveltime", edge.getCurrentTravelTime()); 98 : const std::vector<MSLane*>& lanes = edge.getLanes(); 99 78720 : for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) { 100 44160 : writeLane(of, **lane); 101 : } 102 69120 : of.closeTag(); 103 : } 104 960 : of.closeTag(); 105 960 : } 106 : 107 : 108 : void 109 44160 : MSFullExport::writeLane(OutputDevice& of, const MSLane& lane) { 110 176640 : of.openTag("lane").writeAttr("id", lane.getID()).writeAttr("CO", lane.getEmissions<PollutantsInterface::CO>()).writeAttr("CO2", lane.getEmissions<PollutantsInterface::CO2>()); 111 176640 : of.writeAttr("NOx", lane.getEmissions<PollutantsInterface::NO_X>()).writeAttr("PMx", lane.getEmissions<PollutantsInterface::PM_X>()).writeAttr("HC", lane.getEmissions<PollutantsInterface::HC>()); 112 132480 : of.writeAttr("noise", lane.getHarmonoise_NoiseEmissions()).writeAttr("fuel", lane.getEmissions<PollutantsInterface::FUEL>()); 113 132480 : of.writeAttr("electricity", lane.getEmissions<PollutantsInterface::ELEC>()).writeAttr("maxspeed", lane.getSpeedLimit()); 114 176640 : of.writeAttr("meanspeed", lane.getMeanSpeed()).writeAttr("occupancy", lane.getNettoOccupancy()).writeAttr("vehicle_count", lane.getVehicleNumber()); 115 44160 : of.closeTag(); 116 44160 : } 117 : 118 : 119 : void 120 960 : MSFullExport::writeTLS(OutputDevice& of, SUMOTime /* timestep */) { 121 960 : of.openTag("tls"); 122 960 : MSTLLogicControl& vc = MSNet::getInstance()->getTLSControl(); 123 960 : std::vector<std::string> ids = vc.getAllTLIds(); 124 5280 : for (std::vector<std::string>::const_iterator id_it = ids.begin(); id_it != ids.end(); ++id_it) { 125 4320 : MSTLLogicControl::TLSLogicVariants& vars = MSNet::getInstance()->getTLSControl().get(*id_it); 126 4320 : const MSTrafficLightLogic::LaneVectorVector& lanes = vars.getActive()->getLaneVectors(); 127 : 128 : std::vector<std::string> laneIDs; 129 48480 : for (MSTrafficLightLogic::LaneVectorVector::const_iterator i = lanes.begin(); i != lanes.end(); ++i) { 130 : const MSTrafficLightLogic::LaneVector& llanes = (*i); 131 88320 : for (MSTrafficLightLogic::LaneVector::const_iterator j = llanes.begin(); j != llanes.end(); ++j) { 132 44160 : laneIDs.push_back((*j)->getID()); 133 : } 134 : } 135 : 136 4320 : std::string lane_output = ""; 137 48480 : for (int i1 = 0; i1 < (int)laneIDs.size(); ++i1) { 138 88320 : lane_output += laneIDs[i1] + " "; 139 : } 140 : 141 4320 : std::string state = vars.getActive()->getCurrentPhaseDef().getState(); 142 17280 : of.openTag("trafficlight").writeAttr("id", *id_it).writeAttr("state", state).closeTag(); 143 4320 : } 144 960 : of.closeTag(); 145 960 : } 146 : 147 : 148 : /****************************************************************************/