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 MSStopOut.cpp
15 : /// @author Jakob Erdmann
16 : /// @date Wed, 21.12.2016
17 : ///
18 : // Ouput information about planned vehicle stop
19 : /****************************************************************************/
20 : #include <config.h>
21 :
22 : #include <utils/vehicle/SUMOVehicle.h>
23 : #include <utils/options/OptionsCont.h>
24 : #include <utils/common/MsgHandler.h>
25 : #include <microsim/MSNet.h>
26 : #include <microsim/MSEdge.h>
27 : #include <microsim/MSLane.h>
28 : #include <microsim/MSGlobals.h>
29 : #include <microsim/MSParkingArea.h>
30 : #include <microsim/MSStoppingPlace.h>
31 : #include <microsim/MSVehicleType.h>
32 : #include <microsim/trigger/MSChargingStation.h>
33 : #include <microsim/trigger/MSOverheadWire.h>
34 : #include "MSStopOut.h"
35 :
36 :
37 : // ---------------------------------------------------------------------------
38 : // static initialisation methods
39 : // ---------------------------------------------------------------------------
40 : MSStopOut* MSStopOut::myInstance = nullptr;
41 :
42 : void
43 42811 : MSStopOut::init() {
44 85622 : if (OptionsCont::getOptions().isSet("stop-output")) {
45 1234 : myInstance = new MSStopOut(OutputDevice::getDeviceByOption("stop-output"));
46 : }
47 42811 : }
48 :
49 : void
50 40516 : MSStopOut::cleanup() {
51 40516 : delete myInstance;
52 40516 : myInstance = nullptr;
53 40516 : }
54 :
55 : // ===========================================================================
56 : // method definitions
57 : // ===========================================================================
58 1234 : MSStopOut::MSStopOut(OutputDevice& dev) :
59 1234 : myDevice(dev) {
60 1234 : }
61 :
62 2460 : MSStopOut::~MSStopOut() {}
63 :
64 :
65 : void
66 5055 : MSStopOut::stopStarted(const SUMOVehicle* veh, int numPersons, int numContainers, SUMOTime time) {
67 : assert(veh != nullptr);
68 : if (myStopped.count(veh) != 0) {
69 0 : WRITE_WARNINGF(TL("Vehicle '%' stops on edge '%', time=% without ending the previous stop."),
70 : veh->getID(), veh->getEdge()->getID(), time2string(time));
71 : }
72 5055 : myStopped.emplace(veh, StopInfo(numPersons, numContainers));
73 5055 : }
74 :
75 : void
76 2491 : MSStopOut::loadedPersons(const SUMOVehicle* veh, int n) {
77 : // ignore triggered vehicles
78 2491 : if (veh->hasDeparted()) {
79 : if (myStopped.count(veh) == 0) {
80 0 : WRITE_WARNINGF(TL("Vehicle '%' loads persons on edge '%', time=% without starting the stop."),
81 : veh->getID(), veh->getEdge()->getID(), time2string(SIMSTEP));
82 : } else {
83 2430 : myStopped.find(veh)->second.loadedPersons += n;
84 : }
85 : }
86 2491 : }
87 :
88 : void
89 1593 : MSStopOut::unloadedPersons(const SUMOVehicle* veh, int n) {
90 : if (myStopped.count(veh) == 0) {
91 0 : WRITE_WARNINGF(TL("Vehicle '%' unloads persons on edge '%', time=% without starting the stop."),
92 : veh->getID(), veh->getEdge()->getID(), time2string(SIMSTEP));
93 : } else {
94 1593 : myStopped.find(veh)->second.unloadedPersons += n;
95 : }
96 1593 : }
97 :
98 : void
99 187 : MSStopOut::loadedContainers(const SUMOVehicle* veh, int n) {
100 : // ignore triggered vehicles
101 187 : if (veh->hasDeparted()) {
102 : if (myStopped.count(veh) == 0) {
103 0 : WRITE_WARNINGF(TL("Vehicle '%' loads container on edge '%', time=% without starting the stop."),
104 : veh->getID(), veh->getEdge()->getID(), time2string(SIMSTEP));
105 : } else {
106 173 : myStopped.find(veh)->second.loadedContainers += n;
107 : }
108 : }
109 187 : }
110 :
111 : void
112 138 : MSStopOut::unloadedContainers(const SUMOVehicle* veh, int n) {
113 : if (myStopped.count(veh) == 0) {
114 0 : WRITE_WARNINGF(TL("Vehicle '%' unloads container on edge '%', time=% without starting the stop."),
115 : veh->getID(), veh->getEdge()->getID(), time2string(SIMSTEP));
116 : } else {
117 138 : myStopped.find(veh)->second.unloadedContainers += n;
118 : }
119 138 : }
120 :
121 : void
122 4925 : MSStopOut::stopEnded(const SUMOVehicle* veh, const SUMOVehicleParameter::Stop& stop, const std::string& laneOrEdgeID, bool simEnd) {
123 : assert(veh != nullptr);
124 : if (myStopped.count(veh) == 0) {
125 0 : WRITE_WARNINGF(TL("Vehicle '%' ends stop on edge '%', time=% without entering the stop."),
126 : veh->getID(), veh->getEdge()->getID(), time2string(SIMSTEP));
127 0 : return;
128 : }
129 : const StopInfo& si = myStopped.find(veh)->second;
130 4925 : double delay = -1;
131 4925 : double arrivalDelay = -1;
132 4925 : if (stop.until >= 0 && !simEnd) {
133 970 : delay = STEPS2TIME(SIMSTEP - stop.until);
134 : }
135 4925 : if (stop.arrival >= 0) {
136 240 : arrivalDelay = STEPS2TIME(stop.started - stop.arrival);
137 : }
138 4925 : myDevice.openTag("stopinfo");
139 4925 : myDevice.writeAttr(SUMO_ATTR_ID, veh->getID());
140 4925 : myDevice.writeAttr(SUMO_ATTR_TYPE, veh->getVehicleType().getID());
141 4925 : if (MSGlobals::gUseMesoSim) {
142 833 : myDevice.writeAttr(SUMO_ATTR_EDGE, laneOrEdgeID);
143 : } else {
144 4092 : myDevice.writeAttr(SUMO_ATTR_LANE, laneOrEdgeID);
145 : }
146 4925 : myDevice.writeAttr(SUMO_ATTR_POSITION, veh->getPositionOnLane());
147 4925 : myDevice.writeAttr(SUMO_ATTR_PARKING, stop.parking);
148 4925 : myDevice.writeAttr(SUMO_ATTR_STARTED, time2string(stop.started));
149 4925 : myDevice.writeAttr(SUMO_ATTR_ENDED, simEnd ? "-1" : time2string(SIMSTEP));
150 4925 : if (stop.until >= 0) {
151 1940 : myDevice.writeAttr("delay", delay);
152 : }
153 4925 : if (stop.arrival >= 0) {
154 240 : myDevice.writeAttr(SUMO_ATTR_ARRIVALDELAY, arrivalDelay);
155 : }
156 4925 : if (stop.busstop != "") {
157 1829 : myDevice.writeAttr(SUMO_ATTR_BUS_STOP, stop.busstop);
158 : }
159 4925 : if (stop.containerstop != "") {
160 16 : myDevice.writeAttr(SUMO_ATTR_CONTAINER_STOP, stop.containerstop);
161 : }
162 4925 : if (stop.parkingarea != "") {
163 1781 : myDevice.writeAttr(SUMO_ATTR_PARKING_AREA, stop.parkingarea);
164 : }
165 4925 : if (stop.chargingStation != "") {
166 70 : myDevice.writeAttr(SUMO_ATTR_CHARGING_STATION, stop.chargingStation);
167 : }
168 4925 : if (stop.overheadWireSegment != "") {
169 0 : myDevice.writeAttr(SUMO_ATTR_OVERHEAD_WIRE_SEGMENT, stop.overheadWireSegment);
170 : }
171 4925 : if (stop.tripId != "") {
172 31 : myDevice.writeAttr(SUMO_ATTR_TRIP_ID, stop.tripId);
173 : }
174 4925 : if (stop.line != "") {
175 11 : myDevice.writeAttr(SUMO_ATTR_LINE, stop.line);
176 : }
177 4925 : if (stop.split != "") {
178 44 : myDevice.writeAttr(SUMO_ATTR_SPLIT, stop.split);
179 : }
180 4925 : if (MSGlobals::gUseStopEnded) {
181 60 : myDevice.writeAttr(SUMO_ATTR_USED_ENDED, stop.ended >= 0);
182 : }
183 4925 : myDevice.writeAttr("initialPersons", si.initialNumPersons);
184 4925 : myDevice.writeAttr("loadedPersons", si.loadedPersons);
185 4925 : myDevice.writeAttr("unloadedPersons", si.unloadedPersons);
186 4925 : myDevice.writeAttr("initialContainers", si.initialNumContainers);
187 4925 : myDevice.writeAttr("loadedContainers", si.loadedContainers);
188 4925 : myDevice.writeAttr("unloadedContainers", si.unloadedContainers);
189 9850 : myDevice.closeTag();
190 : myStopped.erase(veh);
191 : }
192 :
193 : void
194 112 : MSStopOut::generateOutputForUnfinished() {
195 1340 : while (!myStopped.empty()) {
196 : const auto& item = *myStopped.begin();
197 1228 : const SUMOVehicle* veh = item.first;
198 1228 : const SUMOVehicleParameter::Stop* stop = veh->getNextStopParameter();
199 : assert(stop != nullptr);
200 1228 : const std::string laneOrEdgeID = MSGlobals::gUseMesoSim ? veh->getEdge()->getID() : Named::getIDSecure(veh->getLane());
201 : // erases item from myStopped
202 1228 : stopEnded(veh, *stop, laneOrEdgeID, true);
203 : }
204 112 : }
205 :
206 : /****************************************************************************/
|