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 MSXMLRawOut.cpp 15 : /// @author Daniel Krajzewicz 16 : /// @author Jakob Erdmann 17 : /// @author Sascha Krieg 18 : /// @author Bjoern Hendriks 19 : /// @author Michael Behrisch 20 : /// @date Mon, 10.05.2004 21 : /// 22 : // Realises dumping the complete network state 23 : /****************************************************************************/ 24 : #include <config.h> 25 : 26 : #include <utils/geom/GeomHelper.h> 27 : #include <microsim/MSEdgeControl.h> 28 : #include <microsim/MSEdge.h> 29 : #include <microsim/MSLane.h> 30 : #include <microsim/MSNet.h> 31 : #include <microsim/MSVehicle.h> 32 : #include <microsim/transportables/MSPModel.h> 33 : #include <microsim/lcmodels/MSAbstractLaneChangeModel.h> 34 : #include <microsim/MSGlobals.h> 35 : #include <microsim/transportables/MSTransportable.h> 36 : #include <utils/iodevices/OutputDevice.h> 37 : #include "MSXMLRawOut.h" 38 : 39 : #include <mesosim/MELoop.h> 40 : #include <mesosim/MESegment.h> 41 : 42 : 43 : // =========================================================================== 44 : // method definitions 45 : // =========================================================================== 46 : void 47 167887 : MSXMLRawOut::write(OutputDevice& of, const MSEdgeControl& ec, 48 : SUMOTime timestep, int precision) { 49 335774 : of.openTag("timestep") << " time=\"" << time2string(timestep) << "\""; 50 167887 : of.setPrecision(precision); 51 : const MSEdgeVector& edges = ec.getEdges(); 52 5023565 : for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) { 53 4855678 : writeEdge(of, **e, timestep); 54 : } 55 167887 : of.setPrecision(gPrecision); 56 167887 : of.closeTag(); 57 167887 : } 58 : 59 : 60 : void 61 4855678 : MSXMLRawOut::writeEdge(OutputDevice& of, const MSEdge& edge, SUMOTime timestep) { 62 4855678 : if (!MSGlobals::gUsingInternalLanes && !edge.isNormal()) { 63 372630 : return; 64 : } 65 : //en 66 4483048 : bool dump = !MSGlobals::gOmitEmptyEdgesOnDump; 67 4483048 : if (!dump) { 68 4480408 : if (MSGlobals::gUseMesoSim) { 69 462840 : MESegment* seg = MSGlobals::gMesoNet->getSegmentForEdge(edge); 70 3279229 : while (seg != nullptr) { 71 2827487 : if (seg->getCarNumber() != 0) { 72 : dump = true; 73 : break; 74 : } 75 : seg = seg->getNextSegment(); 76 : } 77 : } else { 78 : const std::vector<MSLane*>& lanes = edge.getLanes(); 79 8564624 : for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) { 80 4719930 : if (((**lane).getVehicleNumber() != 0)) { 81 : dump = true; 82 : break; 83 : } 84 : } 85 : } 86 : } 87 : //en 88 4483048 : const std::vector<MSTransportable*>& persons = edge.getSortedPersons(timestep); 89 4483048 : const std::vector<MSTransportable*>& containers = edge.getSortedContainers(timestep); 90 4483048 : if (dump || persons.size() > 0 || containers.size() > 0) { 91 202608 : of.openTag("edge") << " id=\"" << edge.getID() << "\""; 92 202608 : if (dump) { 93 186612 : if (MSGlobals::gUseMesoSim) { 94 11978 : MESegment* seg = MSGlobals::gMesoNet->getSegmentForEdge(edge); 95 217972 : while (seg != nullptr) { 96 205994 : seg->writeVehicles(of); 97 : seg = seg->getNextSegment(); 98 : } 99 : } else { 100 : const std::vector<MSLane*>& lanes = edge.getLanes(); 101 465443 : for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) { 102 290809 : writeLane(of, **lane); 103 : } 104 : } 105 : } 106 : // write persons 107 222494 : for (std::vector<MSTransportable*>::const_iterator it_p = persons.begin(); it_p != persons.end(); ++it_p) { 108 19886 : writeTransportable(of, *it_p, SUMO_TAG_PERSON); 109 : } 110 : // write containers 111 202839 : for (std::vector<MSTransportable*>::const_iterator it_c = containers.begin(); it_c != containers.end(); ++it_c) { 112 231 : writeTransportable(of, *it_c, SUMO_TAG_CONTAINER); 113 : } 114 405216 : of.closeTag(); 115 : } 116 : } 117 : 118 : 119 : void 120 290809 : MSXMLRawOut::writeLane(OutputDevice& of, const MSLane& lane) { 121 290809 : of.openTag("lane").writeAttr(SUMO_ATTR_ID, lane.getID()); 122 8535832 : for (const MSBaseVehicle* const veh : lane.getVehiclesSecure()) { 123 8245023 : writeVehicle(of, *veh); 124 : } 125 290809 : lane.releaseVehicles(); 126 290809 : of.closeTag(); 127 290809 : } 128 : 129 : 130 : void 131 8259151 : MSXMLRawOut::writeVehicle(OutputDevice& of, const MSBaseVehicle& veh) { 132 8259151 : if (veh.isOnRoad()) { 133 16518302 : of.openTag("vehicle"); 134 : of.writeAttr(SUMO_ATTR_ID, veh.getID()); 135 8259151 : of.writeAttr(SUMO_ATTR_POSITION, veh.getPositionOnLane()); 136 8259151 : of.writeAttr(SUMO_ATTR_SPEED, veh.getSpeed()); 137 : // TODO: activate action step length output, if required 138 : //of.writeAttr(SUMO_ATTR_ACTIONSTEPLENGTH, veh.getActionStepLength()); 139 8259151 : if (!MSGlobals::gUseMesoSim) { 140 : const MSVehicle& microVeh = static_cast<const MSVehicle&>(veh); 141 : // microsim-specific stuff 142 8245023 : if (MSGlobals::gSublane) { 143 40130 : const double posLat = microVeh.getLateralPositionOnLane(); 144 : of.writeAttr(SUMO_ATTR_POSITION_LAT, posLat); 145 80260 : of.writeAttr(SUMO_ATTR_SPEED_LAT, microVeh.getLaneChangeModel().getSpeedLat()); 146 : } 147 8245023 : const int personNumber = microVeh.getPersonNumber(); 148 8245023 : if (personNumber > 0) { 149 : of.writeAttr(SUMO_ATTR_PERSON_NUMBER, personNumber); 150 : } 151 8245023 : const int containerNumber = microVeh.getContainerNumber(); 152 8245023 : if (containerNumber > 0) { 153 : of.writeAttr(SUMO_ATTR_CONTAINER_NUMBER, containerNumber); 154 : } 155 8245023 : const std::vector<MSTransportable*>& persons = microVeh.getPersons(); 156 8245254 : for (std::vector<MSTransportable*>::const_iterator it_p = persons.begin(); it_p != persons.end(); ++it_p) { 157 231 : writeTransportable(of, *it_p, SUMO_TAG_PERSON); 158 : } 159 8245023 : const std::vector<MSTransportable*>& containers = microVeh.getContainers(); 160 8245685 : for (std::vector<MSTransportable*>::const_iterator it_c = containers.begin(); it_c != containers.end(); ++it_c) { 161 662 : writeTransportable(of, *it_c, SUMO_TAG_CONTAINER); 162 : } 163 : } 164 16518302 : of.closeTag(); 165 : } 166 8259151 : } 167 : 168 : 169 : void 170 21010 : MSXMLRawOut::writeTransportable(OutputDevice& of, const MSTransportable* p, SumoXMLTag tag) { 171 21010 : of.openTag(tag); 172 : of.writeAttr(SUMO_ATTR_ID, p->getID()); 173 21010 : of.writeAttr(SUMO_ATTR_POSITION, p->getEdgePos()); 174 42020 : of.writeAttr(SUMO_ATTR_ANGLE, GeomHelper::naviDegree(p->getAngle())); 175 42020 : of.writeAttr("stage", p->getCurrentStageDescription()); 176 21010 : of.closeTag(); 177 21010 : } 178 : 179 : 180 : /****************************************************************************/