Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2001-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 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 154730 : MSXMLRawOut::write(OutputDevice& of, const MSEdgeControl& ec,
48 : SUMOTime timestep, int precision) {
49 309460 : of.openTag("timestep") << " time=\"" << time2string(timestep) << "\"";
50 154730 : of.setPrecision(precision);
51 : const MSEdgeVector& edges = ec.getEdges();
52 4858544 : for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) {
53 4703814 : writeEdge(of, **e, timestep);
54 : }
55 154730 : of.setPrecision(gPrecision);
56 154730 : of.closeTag();
57 154730 : }
58 :
59 :
60 : void
61 4703814 : MSXMLRawOut::writeEdge(OutputDevice& of, const MSEdge& edge, SUMOTime timestep) {
62 4703814 : if (!MSGlobals::gUsingInternalLanes && !edge.isNormal()) {
63 375726 : return;
64 : }
65 : //en
66 4328088 : bool dump = !MSGlobals::gOmitEmptyEdgesOnDump;
67 4328088 : if (!dump) {
68 4325448 : if (MSGlobals::gUseMesoSim) {
69 463900 : MESegment* seg = MSGlobals::gMesoNet->getSegmentForEdge(edge);
70 3285229 : while (seg != nullptr) {
71 2832561 : 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 8295318 : for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
80 4561123 : if (((**lane).getVehicleNumber() != 0)) {
81 : dump = true;
82 : break;
83 : }
84 : }
85 : }
86 : }
87 : //en
88 4328088 : const std::vector<MSTransportable*>& persons = edge.getSortedPersons(timestep);
89 4328088 : const std::vector<MSTransportable*>& containers = edge.getSortedContainers(timestep);
90 4328088 : if (dump || persons.size() > 0 || containers.size() > 0) {
91 157221 : of.openTag("edge") << " id=\"" << edge.getID() << "\"";
92 157221 : if (dump) {
93 141225 : if (MSGlobals::gUseMesoSim) {
94 12112 : MESegment* seg = MSGlobals::gMesoNet->getSegmentForEdge(edge);
95 218828 : while (seg != nullptr) {
96 206716 : seg->writeVehicles(of);
97 : seg = seg->getNextSegment();
98 : }
99 : } else {
100 : const std::vector<MSLane*>& lanes = edge.getLanes();
101 334018 : for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
102 204905 : writeLane(of, **lane);
103 : }
104 : }
105 : }
106 : // write persons
107 177107 : 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 157452 : 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 314442 : of.closeTag();
115 : }
116 4328088 : }
117 :
118 :
119 : void
120 204905 : MSXMLRawOut::writeLane(OutputDevice& of, const MSLane& lane) {
121 204905 : of.openTag("lane").writeAttr(SUMO_ATTR_ID, lane.getID());
122 4386328 : for (const MSBaseVehicle* const veh : lane.getVehiclesSecure()) {
123 4181423 : writeVehicle(of, *veh);
124 : }
125 204905 : lane.releaseVehicles();
126 204905 : of.closeTag();
127 204905 : }
128 :
129 :
130 : void
131 4195685 : MSXMLRawOut::writeVehicle(OutputDevice& of, const MSBaseVehicle& veh) {
132 4195685 : if (veh.isOnRoad()) {
133 8391370 : of.openTag("vehicle");
134 4195685 : of.writeAttr(SUMO_ATTR_ID, veh.getID());
135 4195685 : of.writeAttr(SUMO_ATTR_POSITION, veh.getPositionOnLane());
136 4195685 : 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 4195685 : if (!MSGlobals::gUseMesoSim) {
140 : const MSVehicle& microVeh = static_cast<const MSVehicle&>(veh);
141 : // microsim-specific stuff
142 4181423 : if (MSGlobals::gSublane) {
143 40206 : const double posLat = microVeh.getLateralPositionOnLane();
144 40206 : of.writeAttr(SUMO_ATTR_POSITION_LAT, posLat);
145 40206 : of.writeAttr(SUMO_ATTR_SPEED_LAT, microVeh.getLaneChangeModel().getSpeedLat());
146 : }
147 4181423 : const int personNumber = microVeh.getPersonNumber();
148 4181423 : if (personNumber > 0) {
149 231 : of.writeAttr(SUMO_ATTR_PERSON_NUMBER, personNumber);
150 : }
151 4181423 : const int containerNumber = microVeh.getContainerNumber();
152 4181423 : if (containerNumber > 0) {
153 662 : of.writeAttr(SUMO_ATTR_CONTAINER_NUMBER, containerNumber);
154 : }
155 4181423 : const std::vector<MSTransportable*>& persons = microVeh.getPersons();
156 4181654 : 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 4181423 : const std::vector<MSTransportable*>& containers = microVeh.getContainers();
160 4182085 : 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 8391370 : of.closeTag();
165 : }
166 4195685 : }
167 :
168 :
169 : void
170 21010 : MSXMLRawOut::writeTransportable(OutputDevice& of, const MSTransportable* p, SumoXMLTag tag) {
171 21010 : of.openTag(tag);
172 21010 : of.writeAttr(SUMO_ATTR_ID, p->getID());
173 21010 : of.writeAttr(SUMO_ATTR_POSITION, p->getEdgePos());
174 21010 : 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 : /****************************************************************************/
|