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 151758 : MSXMLRawOut::write(OutputDevice& of, const MSEdgeControl& ec,
48 : SUMOTime timestep, int precision) {
49 303516 : of.openTag("timestep") << " time=\"" << time2string(timestep) << "\"";
50 151758 : of.setPrecision(precision);
51 : const MSEdgeVector& edges = ec.getEdges();
52 4735572 : for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) {
53 4583814 : writeEdge(of, **e, timestep);
54 : }
55 151758 : of.setPrecision(gPrecision);
56 151758 : of.closeTag();
57 151758 : }
58 :
59 :
60 : void
61 4583814 : MSXMLRawOut::writeEdge(OutputDevice& of, const MSEdge& edge, SUMOTime timestep) {
62 4583814 : if (!MSGlobals::gUsingInternalLanes && !edge.isNormal()) {
63 375702 : return;
64 : }
65 : //en
66 4208112 : bool dump = !MSGlobals::gOmitEmptyEdgesOnDump;
67 4208112 : if (!dump) {
68 4205472 : 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 8060874 : for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
80 4441336 : if (((**lane).getVehicleNumber() != 0)) {
81 : dump = true;
82 : break;
83 : }
84 : }
85 : }
86 : }
87 : //en
88 4208112 : const std::vector<MSTransportable*>& persons = edge.getSortedPersons(timestep);
89 4208112 : const std::vector<MSTransportable*>& containers = edge.getSortedContainers(timestep);
90 4208112 : if (dump || persons.size() > 0 || containers.size() > 0) {
91 151926 : of.openTag("edge") << " id=\"" << edge.getID() << "\"";
92 151926 : if (dump) {
93 135930 : 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 323488 : for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
102 199658 : writeLane(of, **lane);
103 : }
104 : }
105 : }
106 : // write persons
107 171812 : 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 152157 : 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 303852 : of.closeTag();
115 : }
116 4208112 : }
117 :
118 :
119 : void
120 199658 : MSXMLRawOut::writeLane(OutputDevice& of, const MSLane& lane) {
121 199658 : of.openTag("lane").writeAttr(SUMO_ATTR_ID, lane.getID());
122 4306121 : for (const MSBaseVehicle* const veh : lane.getVehiclesSecure()) {
123 4106463 : writeVehicle(of, *veh);
124 : }
125 199658 : lane.releaseVehicles();
126 199658 : of.closeTag();
127 199658 : }
128 :
129 :
130 : void
131 4120713 : MSXMLRawOut::writeVehicle(OutputDevice& of, const MSBaseVehicle& veh) {
132 4120713 : if (veh.isOnRoad()) {
133 8241426 : of.openTag("vehicle");
134 : of.writeAttr(SUMO_ATTR_ID, veh.getID());
135 4120713 : of.writeAttr(SUMO_ATTR_POSITION, veh.getPositionOnLane());
136 4120713 : 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 4120713 : if (!MSGlobals::gUseMesoSim) {
140 : const MSVehicle& microVeh = static_cast<const MSVehicle&>(veh);
141 : // microsim-specific stuff
142 4106463 : if (MSGlobals::gSublane) {
143 40200 : const double posLat = microVeh.getLateralPositionOnLane();
144 : of.writeAttr(SUMO_ATTR_POSITION_LAT, posLat);
145 80400 : of.writeAttr(SUMO_ATTR_SPEED_LAT, microVeh.getLaneChangeModel().getSpeedLat());
146 : }
147 4106463 : const int personNumber = microVeh.getPersonNumber();
148 4106463 : if (personNumber > 0) {
149 : of.writeAttr(SUMO_ATTR_PERSON_NUMBER, personNumber);
150 : }
151 4106463 : const int containerNumber = microVeh.getContainerNumber();
152 4106463 : if (containerNumber > 0) {
153 : of.writeAttr(SUMO_ATTR_CONTAINER_NUMBER, containerNumber);
154 : }
155 4106463 : const std::vector<MSTransportable*>& persons = microVeh.getPersons();
156 4106694 : 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 4106463 : const std::vector<MSTransportable*>& containers = microVeh.getContainers();
160 4107125 : 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 8241426 : of.closeTag();
165 : }
166 4120713 : }
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 : /****************************************************************************/
|