Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2005-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 MSStop.cpp
15 : /// @author Daniel Krajzewicz
16 : /// @author Michael Behrisch
17 : /// @date Mon, 13.12.2005
18 : ///
19 : // A lane area vehicles can halt at
20 : /****************************************************************************/
21 : #include <config.h>
22 :
23 : #include <mesosim/MESegment.h>
24 : #include <mesosim/MELoop.h>
25 : #include "MSLane.h"
26 : #include "MSEdge.h"
27 : #include "MSNet.h"
28 : #include "MSParkingArea.h"
29 : #include "MSStoppingPlace.h"
30 : #include "MSStop.h"
31 :
32 : // ===========================================================================
33 : // method definitions
34 : // ===========================================================================
35 : double
36 11597889 : MSStop::getEndPos(const SUMOVehicle& veh) const {
37 11597889 : const double brakePos = veh.getEdge() == getEdge() ? veh.getPositionOnLane() + veh.getBrakeGap() : 0;
38 11597889 : if ((pars.parametersSet & STOP_END_SET) != 0) {
39 4194911 : return pars.endPos;
40 7402978 : } else if (busstop != nullptr) {
41 3216089 : return busstop->getLastFreePos(veh, brakePos);
42 4186889 : } else if (containerstop != nullptr) {
43 33746 : return containerstop->getLastFreePos(veh, brakePos);
44 4153143 : } else if (parkingarea != nullptr) {
45 1763196 : return parkingarea->getLastFreePos(veh, brakePos);
46 2389947 : } else if (chargingStation != nullptr) {
47 1038061 : return chargingStation->getLastFreePos(veh);
48 1351886 : } else if (overheadWireSegment != nullptr) {
49 0 : return overheadWireSegment->getLastFreePos(veh);
50 : }
51 1351886 : return pars.endPos;
52 : }
53 :
54 : const MSEdge*
55 11690478 : MSStop::getEdge() const {
56 11690478 : if (lane != nullptr) {
57 11690478 : return &lane->getEdge();
58 0 : } else if (segment != nullptr) {
59 0 : return &segment->getEdge();
60 : }
61 : return nullptr;
62 : }
63 :
64 : double
65 3293713 : MSStop::getReachedThreshold() const {
66 3293713 : return isOpposite ? lane->getOppositePos(pars.endPos) - (pars.endPos - pars.startPos) : pars.startPos;
67 : }
68 :
69 : std::string
70 49 : MSStop::getDescription(bool nameOnly) const {
71 : std::string result;
72 49 : if (parkingarea != nullptr) {
73 6 : if (nameOnly) {
74 : return parkingarea->getID();
75 : }
76 12 : result = "parkingArea:" + parkingarea->getID();
77 43 : } else if (containerstop != nullptr) {
78 0 : if (nameOnly) {
79 : return containerstop->getID();
80 : }
81 0 : result = "containerStop:" + containerstop->getID();
82 43 : } else if (busstop != nullptr) {
83 42 : if (nameOnly) {
84 : return busstop->getID();
85 : }
86 2 : result = "busStop:" + busstop->getID();
87 1 : } else if (chargingStation != nullptr) {
88 0 : if (nameOnly) {
89 : return chargingStation->getID();
90 : }
91 0 : result = "chargingStation:" + chargingStation->getID();
92 1 : } else if (overheadWireSegment != nullptr) {
93 0 : if (nameOnly) {
94 : return overheadWireSegment->getID();
95 : }
96 0 : result = "overheadWireSegment:" + overheadWireSegment->getID();
97 : } else {
98 1 : if (nameOnly) {
99 0 : return "";
100 : }
101 3 : result = "lane:" + lane->getID() + " pos:" + toString(pars.endPos);
102 : }
103 8 : if (pars.actType != "") {
104 12 : result += " actType:" + pars.actType;
105 : }
106 8 : return result;
107 : }
108 :
109 :
110 : std::pair<std::string, SumoXMLTag>
111 84605 : MSStop::getStoppingPlaceName() const {
112 84605 : if (busstop != nullptr && !busstop->getMyName().empty()) {
113 1403 : return std::make_pair(busstop->getMyName(), SUMO_TAG_BUS_STOP);
114 83202 : } else if (containerstop != nullptr && !containerstop->getMyName().empty()) {
115 48 : return std::make_pair(containerstop->getMyName(), SUMO_TAG_CONTAINER_STOP);
116 83154 : } else if (parkingarea != nullptr && !parkingarea->getMyName().empty()) {
117 0 : return std::make_pair(parkingarea->getMyName(), SUMO_TAG_PARKING_AREA);
118 83154 : } else if (chargingStation != nullptr && !chargingStation->getMyName().empty()) {
119 0 : return std::make_pair(chargingStation->getMyName(), SUMO_TAG_CHARGING_STATION);
120 83154 : } else if (overheadWireSegment != nullptr && !overheadWireSegment->getMyName().empty()) {
121 0 : return std::make_pair(overheadWireSegment->getMyName(), SUMO_TAG_OVERHEAD_WIRE_SEGMENT);
122 : }
123 : return std::make_pair("", SUMO_TAG_NOTHING);
124 : }
125 :
126 :
127 : void
128 840 : MSStop::write(OutputDevice& dev) const {
129 840 : SUMOVehicleParameter::Stop tmp = pars;
130 840 : tmp.duration = duration;
131 840 : if (busstop == nullptr
132 807 : && containerstop == nullptr
133 807 : && parkingarea == nullptr
134 269 : && chargingStation == nullptr) {
135 269 : tmp.parametersSet |= STOP_START_SET | STOP_END_SET;
136 : }
137 840 : tmp.write(dev, false);
138 : // if the stop has already started but hasn't ended yet we are writing it in
139 : // the context of saveState (but we do not want to write the attribute twice
140 840 : if (pars.started >= 0 && (pars.parametersSet & STOP_STARTED_SET) == 0) {
141 948 : dev.writeAttr(SUMO_ATTR_STARTED, time2string(pars.started));
142 : }
143 840 : pars.writeParams(dev);
144 840 : dev.closeTag();
145 840 : }
146 :
147 : void
148 139421 : MSStop::initPars(const SUMOVehicleParameter::Stop& stopPar) {
149 139421 : busstop = MSNet::getInstance()->getStoppingPlace(stopPar.busstop, SUMO_TAG_BUS_STOP);
150 139421 : containerstop = MSNet::getInstance()->getStoppingPlace(stopPar.containerstop, SUMO_TAG_CONTAINER_STOP);
151 139421 : parkingarea = static_cast<MSParkingArea*>(MSNet::getInstance()->getStoppingPlace(stopPar.parkingarea, SUMO_TAG_PARKING_AREA));
152 139421 : chargingStation = MSNet::getInstance()->getStoppingPlace(stopPar.chargingStation, SUMO_TAG_CHARGING_STATION);
153 139421 : overheadWireSegment = MSNet::getInstance()->getStoppingPlace(stopPar.overheadWireSegment, SUMO_TAG_OVERHEAD_WIRE_SEGMENT);
154 139421 : duration = stopPar.duration;
155 139421 : triggered = stopPar.triggered;
156 139421 : containerTriggered = stopPar.containerTriggered;
157 139421 : joinTriggered = stopPar.joinTriggered || stopPar.join != "";
158 139421 : numExpectedPerson = (int)stopPar.awaitedPersons.size();
159 139421 : numExpectedContainer = (int)stopPar.awaitedContainers.size();
160 139421 : }
161 :
162 :
163 : int
164 258 : MSStop::getStateFlagsOld() const {
165 258 : return ((reached ? 1 : 0) + 2 * pars.getFlags());
166 : }
167 :
168 :
169 : SUMOTime
170 135210 : MSStop::getMinDuration(SUMOTime time) const {
171 135210 : if (MSGlobals::gUseStopEnded && pars.ended >= 0) {
172 53 : return pars.ended - time;
173 : }
174 135157 : if (pars.until >= 0) {
175 70615 : if (duration == -1) {
176 56058 : return pars.until - time;
177 : } else {
178 14557 : return MAX2(duration, pars.until - time);
179 : }
180 : } else {
181 64542 : return duration;
182 : }
183 : }
184 :
185 :
186 : SUMOTime
187 646889 : MSStop::getUntil() const {
188 646889 : return MSGlobals::gUseStopEnded && pars.ended >= 0 ? pars.ended : pars.until;
189 : }
190 :
191 :
192 : SUMOTime
193 152937 : MSStop::getArrival() const {
194 152937 : return MSGlobals::gUseStopStarted && pars.started >= 0 ? pars.started : pars.arrival;
195 : }
196 :
197 :
198 : SUMOTime
199 99918 : MSStop::getArrivalFallback() const {
200 99918 : SUMOTime result = getArrival();
201 99918 : if (result < 0) {
202 99837 : result = getUntil();
203 99837 : if (result >= 0 && pars.duration >= 0) {
204 14832 : result -= pars.duration;
205 : }
206 : }
207 99918 : return result;
208 : }
209 :
210 :
211 : double
212 122554488 : MSStop::getSpeed() const {
213 122554488 : return skipOnDemand ? std::numeric_limits<double>::max() : pars.speed;
214 : }
215 :
216 :
217 : bool
218 26742 : MSStop::isInRange(const double pos, const double tolerance) const {
219 26742 : return pars.startPos - tolerance <= pos && pars.endPos + tolerance >= pos;
220 : }
221 :
222 :
223 : std::vector<MSStoppingPlace*>
224 12 : MSStop::getPlaces() const {
225 : std::vector<MSStoppingPlace*> result;
226 12 : if (busstop != nullptr) {
227 12 : result.push_back(busstop);
228 : }
229 12 : if (containerstop != nullptr) {
230 0 : result.push_back(containerstop);
231 : }
232 12 : if (parkingarea != nullptr) {
233 0 : result.push_back(parkingarea);
234 : }
235 12 : if (chargingStation != nullptr) {
236 0 : result.push_back(chargingStation);
237 : }
238 12 : if (overheadWireSegment != nullptr) {
239 0 : result.push_back(overheadWireSegment);
240 : }
241 12 : return result;
242 0 : }
243 :
244 :
245 : void
246 41 : MSStop::replaceStoppingPlace(MSStoppingPlace* sp) {
247 : // @note: assume iterator edge is handled elsewhere
248 : assert(*edge == &sp->getLane().getEdge());
249 41 : lane = &sp->getLane();
250 : SUMOVehicleParameter::Stop& ncPars = const_cast<SUMOVehicleParameter::Stop&>(pars);
251 41 : ncPars.edge = lane->getEdge().getID();
252 41 : ncPars.lane = lane->getID();
253 41 : ncPars.startPos = sp->getBeginLanePosition();
254 41 : ncPars.endPos = sp->getEndLanePosition();
255 41 : if (MSGlobals::gUseMesoSim) {
256 12 : segment = MSGlobals::gMesoNet->getSegmentForEdge(lane->getEdge(), sp->getEndLanePosition());
257 : }
258 41 : switch (sp->getElement()) {
259 41 : case SUMO_TAG_BUS_STOP:
260 : case SUMO_TAG_TRAIN_STOP:
261 41 : busstop = sp;
262 41 : ncPars.busstop = sp->getID();
263 : break;
264 0 : case SUMO_TAG_CONTAINER_STOP:
265 0 : containerstop = sp;
266 0 : ncPars.containerstop = sp->getID();
267 : break;
268 : case SUMO_TAG_PARKING_AREA:
269 0 : parkingarea = dynamic_cast<MSParkingArea*>(sp);
270 0 : ncPars.parkingarea = sp->getID();
271 : break;
272 0 : case SUMO_TAG_CHARGING_STATION:
273 0 : chargingStation = sp;
274 0 : ncPars.chargingStation = sp->getID();
275 : break;
276 0 : case SUMO_TAG_OVERHEAD_WIRE_SEGMENT:
277 0 : overheadWireSegment = sp;
278 0 : ncPars.overheadWireSegment = sp->getID();
279 : break;
280 41 : default:
281 : // should not happen
282 : assert(false);
283 : }
284 41 : }
285 :
286 : /****************************************************************************/
|