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 151751 : MSXMLRawOut::write(OutputDevice& of, const MSEdgeControl& ec,
48 : SUMOTime timestep, int precision) {
49 303502 : of.openTag("timestep") << " time=\"" << time2string(timestep) << "\"";
50 151751 : of.setPrecision(precision);
51 : const MSEdgeVector& edges = ec.getEdges();
52 4735257 : for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) {
53 4583506 : writeEdge(of, **e, timestep);
54 : }
55 151751 : of.setPrecision(gPrecision);
56 151751 : of.closeTag();
57 151751 : }
58 :
59 :
60 : void
61 4583506 : MSXMLRawOut::writeEdge(OutputDevice& of, const MSEdge& edge, SUMOTime timestep) {
62 4583506 : if (!MSGlobals::gUsingInternalLanes && !edge.isNormal()) {
63 375702 : return;
64 : }
65 : //en
66 4207804 : bool dump = !MSGlobals::gOmitEmptyEdgesOnDump;
67 4207804 : if (!dump) {
68 4205164 : if (MSGlobals::gUseMesoSim) {
69 463864 : MESegment* seg = MSGlobals::gMesoNet->getSegmentForEdge(edge);
70 3284999 : while (seg != nullptr) {
71 2832355 : 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 8060128 : for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
80 4440891 : if (((**lane).getVehicleNumber() != 0)) {
81 : dump = true;
82 : break;
83 : }
84 : }
85 : }
86 : }
87 : //en
88 4207804 : const std::vector<MSTransportable*>& persons = edge.getSortedPersons(timestep);
89 4207804 : const std::vector<MSTransportable*>& containers = edge.getSortedContainers(timestep);
90 4207804 : if (dump || persons.size() > 0 || containers.size() > 0) {
91 151919 : of.openTag("edge") << " id=\"" << edge.getID() << "\"";
92 151919 : if (dump) {
93 135923 : if (MSGlobals::gUseMesoSim) {
94 12100 : MESegment* seg = MSGlobals::gMesoNet->getSegmentForEdge(edge);
95 218704 : while (seg != nullptr) {
96 206604 : seg->writeVehicles(of);
97 : seg = seg->getNextSegment();
98 : }
99 : } else {
100 : const std::vector<MSLane*>& lanes = edge.getLanes();
101 323468 : for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
102 199645 : writeLane(of, **lane);
103 : }
104 : }
105 : }
106 : // write persons
107 171805 : 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 152150 : 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 303838 : of.closeTag();
115 : }
116 4207804 : }
117 :
118 :
119 : void
120 199645 : MSXMLRawOut::writeLane(OutputDevice& of, const MSLane& lane) {
121 199645 : of.openTag("lane").writeAttr(SUMO_ATTR_ID, lane.getID());
122 4306101 : for (const MSBaseVehicle* const veh : lane.getVehiclesSecure()) {
123 4106456 : writeVehicle(of, *veh);
124 : }
125 199645 : lane.releaseVehicles();
126 199645 : of.closeTag();
127 199645 : }
128 :
129 :
130 : void
131 4120706 : MSXMLRawOut::writeVehicle(OutputDevice& of, const MSBaseVehicle& veh) {
132 4120706 : if (veh.isOnRoad()) {
133 8241412 : of.openTag("vehicle");
134 : of.writeAttr(SUMO_ATTR_ID, veh.getID());
135 4120706 : of.writeAttr(SUMO_ATTR_POSITION, veh.getPositionOnLane());
136 4120706 : 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 4120706 : if (!MSGlobals::gUseMesoSim) {
140 : const MSVehicle& microVeh = static_cast<const MSVehicle&>(veh);
141 : // microsim-specific stuff
142 4106456 : if (MSGlobals::gSublane) {
143 40193 : const double posLat = microVeh.getLateralPositionOnLane();
144 : of.writeAttr(SUMO_ATTR_POSITION_LAT, posLat);
145 80386 : of.writeAttr(SUMO_ATTR_SPEED_LAT, microVeh.getLaneChangeModel().getSpeedLat());
146 : }
147 4106456 : const int personNumber = microVeh.getPersonNumber();
148 4106456 : if (personNumber > 0) {
149 : of.writeAttr(SUMO_ATTR_PERSON_NUMBER, personNumber);
150 : }
151 4106456 : const int containerNumber = microVeh.getContainerNumber();
152 4106456 : if (containerNumber > 0) {
153 : of.writeAttr(SUMO_ATTR_CONTAINER_NUMBER, containerNumber);
154 : }
155 4106456 : const std::vector<MSTransportable*>& persons = microVeh.getPersons();
156 4106687 : 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 4106456 : const std::vector<MSTransportable*>& containers = microVeh.getContainers();
160 4107118 : 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 8241412 : of.closeTag();
165 : }
166 4120706 : }
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 : /****************************************************************************/
|