1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2012-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
10 /// @file MSFullExport.cpp
11 /// @author Daniel Krajzewicz
12 /// @author Mario Krumnow
13 /// @author Michael Behrisch
14 /// @author Jakob Erdmann
15 /// @date 2012-04-26
16 /// @version $Id$
17 ///
18 // Dumping a hugh List of Parameters available in the Simulation
19 /****************************************************************************/
20
21
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26
27 #include <utils/iodevices/OutputDevice.h>
28 #include <utils/emissions/PollutantsInterface.h>
29 #include <utils/emissions/HelpersHarmonoise.h>
30 #include <utils/geom/GeomHelper.h>
31 #include <microsim/MSEdge.h>
32 #include <microsim/MSEdgeControl.h>
33 #include <microsim/MSNet.h>
34 #include <microsim/MSVehicle.h>
35 #include <microsim/MSVehicleControl.h>
36 #include <microsim/traffic_lights/MSTLLogicControl.h>
37 #include <microsim/traffic_lights/MSTrafficLightLogic.h>
38 #include "MSFullExport.h"
39
40
41 // ===========================================================================
42 // method definitions
43 // ===========================================================================
44 void
write(OutputDevice & of,SUMOTime timestep)45 MSFullExport::write(OutputDevice& of, SUMOTime timestep) {
46 of.openTag("data") << " timestep=\"" << time2string(timestep) << "\"";
47 //Vehicles
48 writeVehicles(of);
49 //Edges
50 writeEdge(of);
51 //TrafficLights
52 writeTLS(of, timestep);
53 of.closeTag();
54 }
55
56
57 void
writeVehicles(OutputDevice & of)58 MSFullExport::writeVehicles(OutputDevice& of) {
59 of.openTag("vehicles");
60 MSVehicleControl& vc = MSNet::getInstance()->getVehicleControl();
61 for (MSVehicleControl::constVehIt it = vc.loadedVehBegin(); it != vc.loadedVehEnd(); ++it) {
62 const SUMOVehicle* veh = it->second;
63 const MSVehicle* microVeh = dynamic_cast<const MSVehicle*>(veh);
64 if (veh->isOnRoad()) {
65 std::string fclass = veh->getVehicleType().getID();
66 fclass = fclass.substr(0, fclass.find_first_of("@"));
67 PollutantsInterface::Emissions emiss = PollutantsInterface::computeAll(veh->getVehicleType().getEmissionClass(), veh->getSpeed(), veh->getAcceleration(), veh->getSlope());
68 of.openTag("vehicle").writeAttr("id", veh->getID()).writeAttr("eclass", PollutantsInterface::getName(veh->getVehicleType().getEmissionClass()));
69 of.writeAttr("CO2", emiss.CO2).writeAttr("CO", emiss.CO).writeAttr("HC", emiss.HC).writeAttr("NOx", emiss.NOx);
70 of.writeAttr("PMx", emiss.PMx).writeAttr("fuel", emiss.fuel).writeAttr("electricity", emiss.electricity);
71 of.writeAttr("noise", HelpersHarmonoise::computeNoise(veh->getVehicleType().getEmissionClass(), veh->getSpeed(), veh->getAcceleration()));
72 of.writeAttr("route", veh->getRoute().getID()).writeAttr("type", fclass);
73 if (microVeh != nullptr) {
74 of.writeAttr("waiting", microVeh->getWaitingSeconds());
75 of.writeAttr("lane", microVeh->getLane()->getID());
76 }
77 of.writeAttr("pos", veh->getPositionOnLane()).writeAttr("speed", veh->getSpeed());
78 of.writeAttr("angle", GeomHelper::naviDegree(veh->getAngle())).writeAttr("x", veh->getPosition().x()).writeAttr("y", veh->getPosition().y());
79 of.closeTag();
80 }
81 }
82 of.closeTag();
83 }
84
85 void
writeEdge(OutputDevice & of)86 MSFullExport::writeEdge(OutputDevice& of) {
87 of.openTag("edges");
88 MSEdgeControl& ec = MSNet::getInstance()->getEdgeControl();
89 const MSEdgeVector& edges = ec.getEdges();
90 for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) {
91 MSEdge& edge = **e;
92 of.openTag("edge").writeAttr("id", edge.getID()).writeAttr("traveltime", edge.getCurrentTravelTime());
93 const std::vector<MSLane*>& lanes = edge.getLanes();
94 for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
95 writeLane(of, **lane);
96 }
97 of.closeTag();
98 }
99 of.closeTag();
100 }
101
102
103 void
writeLane(OutputDevice & of,const MSLane & lane)104 MSFullExport::writeLane(OutputDevice& of, const MSLane& lane) {
105
106 of.openTag("lane").writeAttr("id", lane.getID()).writeAttr("CO", lane.getCOEmissions()).writeAttr("CO2", lane.getCO2Emissions());
107 of.writeAttr("NOx", lane.getNOxEmissions()).writeAttr("PMx", lane.getPMxEmissions()).writeAttr("HC", lane.getHCEmissions());
108 of.writeAttr("noise", lane.getHarmonoise_NoiseEmissions()).writeAttr("fuel", lane.getFuelConsumption());
109 of.writeAttr("electricity", lane.getElectricityConsumption()).writeAttr("maxspeed", lane.getSpeedLimit());
110 of.writeAttr("meanspeed", lane.getMeanSpeed() * 3.6).writeAttr("occupancy", lane.getNettoOccupancy()).writeAttr("vehicle_count", lane.getVehicleNumber());
111 of.closeTag();
112 }
113
114
115 void
writeTLS(OutputDevice & of,SUMOTime)116 MSFullExport::writeTLS(OutputDevice& of, SUMOTime /* timestep */) {
117 of.openTag("tls");
118 MSTLLogicControl& vc = MSNet::getInstance()->getTLSControl();
119 std::vector<std::string> ids = vc.getAllTLIds();
120 for (std::vector<std::string>::const_iterator id_it = ids.begin(); id_it != ids.end(); ++id_it) {
121 MSTLLogicControl::TLSLogicVariants& vars = MSNet::getInstance()->getTLSControl().get(*id_it);
122 const MSTrafficLightLogic::LaneVectorVector& lanes = vars.getActive()->getLaneVectors();
123
124 std::vector<std::string> laneIDs;
125 for (MSTrafficLightLogic::LaneVectorVector::const_iterator i = lanes.begin(); i != lanes.end(); ++i) {
126 const MSTrafficLightLogic::LaneVector& llanes = (*i);
127 for (MSTrafficLightLogic::LaneVector::const_iterator j = llanes.begin(); j != llanes.end(); ++j) {
128 laneIDs.push_back((*j)->getID());
129 }
130 }
131
132 std::string lane_output = "";
133 for (int i1 = 0; i1 < (int)laneIDs.size(); ++i1) {
134 lane_output += laneIDs[i1] + " ";
135 }
136
137 std::string state = vars.getActive()->getCurrentPhaseDef().getState();
138 of.openTag("trafficlight").writeAttr("id", *id_it).writeAttr("state", state).closeTag();
139 }
140 of.closeTag();
141 }
142
143