Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2001-2026 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 6468 : MSXMLRawOut::write(OutputDevice& of, const MSEdgeControl& ec,
48 : SUMOTime timestep, int precision) {
49 12936 : of.openTag("timestep") << " time=\"" << time2string(timestep) << "\"";
50 6468 : of.setPrecision(precision);
51 : const MSEdgeVector& edges = ec.getEdges();
52 223524 : for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) {
53 217056 : writeEdge(of, **e, timestep);
54 : }
55 6468 : of.setPrecision(gPrecision);
56 6468 : of.closeTag();
57 6468 : }
58 :
59 :
60 : void
61 217056 : MSXMLRawOut::writeEdge(OutputDevice& of, const MSEdge& edge, SUMOTime timestep) {
62 217056 : if (!MSGlobals::gUsingInternalLanes && !edge.isNormal()) {
63 972 : return;
64 : }
65 : //en
66 216084 : bool dump = !MSGlobals::gOmitEmptyEdgesOnDump;
67 216084 : if (!dump) {
68 213444 : if (MSGlobals::gUseMesoSim) {
69 69744 : MESegment* seg = MSGlobals::gMesoNet->getSegmentForEdge(edge);
70 342111 : while (seg != nullptr) {
71 274227 : 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 292833 : for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
80 153175 : if (((**lane).getVehicleNumber() != 0)) {
81 : dump = true;
82 : break;
83 : }
84 : }
85 : }
86 : }
87 : //en
88 216084 : const std::vector<MSTransportable*>& persons = edge.getSortedPersons(timestep);
89 216084 : const std::vector<MSTransportable*>& containers = edge.getSortedContainers(timestep);
90 216084 : if (dump || persons.size() > 0 || containers.size() > 0) {
91 8542 : of.openTag("edge") << " id=\"" << edge.getID() << "\"";
92 8542 : if (dump) {
93 8542 : if (MSGlobals::gUseMesoSim) {
94 2740 : MESegment* seg = MSGlobals::gMesoNet->getSegmentForEdge(edge);
95 14696 : while (seg != nullptr) {
96 11956 : seg->writeVehicles(of);
97 : seg = seg->getNextSegment();
98 : }
99 : } else {
100 : const std::vector<MSLane*>& lanes = edge.getLanes();
101 13354 : for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
102 7552 : writeLane(of, **lane);
103 : }
104 : }
105 : }
106 : // write persons
107 8542 : for (std::vector<MSTransportable*>::const_iterator it_p = persons.begin(); it_p != persons.end(); ++it_p) {
108 0 : writeTransportable(of, *it_p, SUMO_TAG_PERSON);
109 : }
110 : // write containers
111 8542 : for (std::vector<MSTransportable*>::const_iterator it_c = containers.begin(); it_c != containers.end(); ++it_c) {
112 0 : writeTransportable(of, *it_c, SUMO_TAG_CONTAINER);
113 : }
114 17084 : of.closeTag();
115 : }
116 216084 : }
117 :
118 :
119 : void
120 7552 : MSXMLRawOut::writeLane(OutputDevice& of, const MSLane& lane) {
121 7552 : of.openTag("lane").writeAttr(SUMO_ATTR_ID, lane.getID());
122 11946 : for (const MSBaseVehicle* const veh : lane.getVehiclesSecure()) {
123 4394 : writeVehicle(of, *veh);
124 : }
125 7552 : lane.releaseVehicles();
126 7552 : of.closeTag();
127 7552 : }
128 :
129 :
130 : void
131 6426 : MSXMLRawOut::writeVehicle(OutputDevice& of, const MSBaseVehicle& veh) {
132 6426 : if (veh.isOnRoad()) {
133 12852 : of.openTag("vehicle");
134 6426 : of.writeAttr(SUMO_ATTR_ID, veh.getID());
135 6426 : of.writeAttr(SUMO_ATTR_POSITION, veh.getPositionOnLane());
136 6426 : 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 6426 : if (!MSGlobals::gUseMesoSim) {
140 : const MSVehicle& microVeh = static_cast<const MSVehicle&>(veh);
141 : // microsim-specific stuff
142 4394 : if (MSGlobals::gSublane) {
143 755 : const double posLat = microVeh.getLateralPositionOnLane();
144 755 : of.writeAttr(SUMO_ATTR_POSITION_LAT, posLat);
145 755 : of.writeAttr(SUMO_ATTR_SPEED_LAT, microVeh.getLaneChangeModel().getSpeedLat());
146 : }
147 4394 : const int personNumber = microVeh.getPersonNumber();
148 4394 : if (personNumber > 0) {
149 0 : of.writeAttr(SUMO_ATTR_PERSON_NUMBER, personNumber);
150 : }
151 4394 : const int containerNumber = microVeh.getContainerNumber();
152 4394 : if (containerNumber > 0) {
153 0 : of.writeAttr(SUMO_ATTR_CONTAINER_NUMBER, containerNumber);
154 : }
155 4394 : const std::vector<MSTransportable*>& persons = microVeh.getPersons();
156 4394 : for (std::vector<MSTransportable*>::const_iterator it_p = persons.begin(); it_p != persons.end(); ++it_p) {
157 0 : writeTransportable(of, *it_p, SUMO_TAG_PERSON);
158 : }
159 4394 : const std::vector<MSTransportable*>& containers = microVeh.getContainers();
160 4394 : for (std::vector<MSTransportable*>::const_iterator it_c = containers.begin(); it_c != containers.end(); ++it_c) {
161 0 : writeTransportable(of, *it_c, SUMO_TAG_CONTAINER);
162 : }
163 : }
164 12852 : of.closeTag();
165 : }
166 6426 : }
167 :
168 :
169 : void
170 0 : MSXMLRawOut::writeTransportable(OutputDevice& of, const MSTransportable* p, SumoXMLTag tag) {
171 0 : of.openTag(tag);
172 0 : of.writeAttr(SUMO_ATTR_ID, p->getID());
173 0 : of.writeAttr(SUMO_ATTR_POSITION, p->getEdgePos());
174 0 : of.writeAttr(SUMO_ATTR_ANGLE, GeomHelper::naviDegree(p->getAngle()));
175 0 : of.writeAttr(SUMO_ATTR_STAGE, p->getCurrentStageDescription());
176 0 : of.closeTag();
177 0 : }
178 :
179 :
180 : /****************************************************************************/
|