Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2005-2025 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 11517509 : MSStop::getEndPos(const SUMOVehicle& veh) const {
37 11517509 : const double brakePos = veh.getEdge() == getEdge() ? veh.getPositionOnLane() + veh.getBrakeGap() : 0;
38 11517509 : if ((pars.parametersSet & STOP_END_SET) != 0) {
39 4755591 : return pars.endPos;
40 6761918 : } else if (busstop != nullptr) {
41 3225887 : return busstop->getLastFreePos(veh, brakePos);
42 3536031 : } else if (containerstop != nullptr) {
43 37242 : return containerstop->getLastFreePos(veh, brakePos);
44 3498789 : } else if (parkingarea != nullptr) {
45 1674537 : return parkingarea->getLastFreePos(veh, brakePos);
46 1824252 : } else if (chargingStation != nullptr) {
47 477297 : return chargingStation->getLastFreePos(veh);
48 1346955 : } else if (overheadWireSegment != nullptr) {
49 0 : return overheadWireSegment->getLastFreePos(veh);
50 : }
51 1346955 : return pars.endPos;
52 : }
53 :
54 : const MSEdge*
55 11603412 : MSStop::getEdge() const {
56 11603412 : if (lane != nullptr) {
57 11603412 : return &lane->getEdge();
58 0 : } else if (segment != nullptr) {
59 0 : return &segment->getEdge();
60 : }
61 : return nullptr;
62 : }
63 :
64 : double
65 3815019 : MSStop::getReachedThreshold() const {
66 3815019 : return isOpposite ? lane->getOppositePos(pars.endPos) - (pars.endPos - pars.startPos) : pars.startPos;
67 : }
68 :
69 : std::string
70 40 : MSStop::getDescription(bool nameOnly) const {
71 : std::string result;
72 40 : if (parkingarea != nullptr) {
73 4 : if (nameOnly) {
74 : return parkingarea->getID();
75 : }
76 8 : result = "parkingArea:" + parkingarea->getID();
77 36 : } else if (containerstop != nullptr) {
78 0 : if (nameOnly) {
79 : return containerstop->getID();
80 : }
81 0 : result = "containerStop:" + containerstop->getID();
82 36 : } else if (busstop != nullptr) {
83 35 : 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 6 : if (pars.actType != "") {
104 0 : result += " actType:" + pars.actType;
105 : }
106 6 : return result;
107 : }
108 :
109 :
110 : std::pair<std::string, SumoXMLTag>
111 84490 : MSStop::getStoppingPlaceName() const {
112 84490 : if (busstop != nullptr && !busstop->getMyName().empty()) {
113 1265 : return std::make_pair(busstop->getMyName(), SUMO_TAG_BUS_STOP);
114 83225 : } else if (containerstop != nullptr && !containerstop->getMyName().empty()) {
115 48 : return std::make_pair(containerstop->getMyName(), SUMO_TAG_CONTAINER_STOP);
116 83177 : } else if (parkingarea != nullptr && !parkingarea->getMyName().empty()) {
117 0 : return std::make_pair(parkingarea->getMyName(), SUMO_TAG_PARKING_AREA);
118 83177 : } else if (chargingStation != nullptr && !chargingStation->getMyName().empty()) {
119 0 : return std::make_pair(chargingStation->getMyName(), SUMO_TAG_CHARGING_STATION);
120 83177 : } 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 830 : MSStop::write(OutputDevice& dev) const {
129 830 : SUMOVehicleParameter::Stop tmp = pars;
130 830 : tmp.duration = duration;
131 830 : if (busstop == nullptr
132 797 : && containerstop == nullptr
133 797 : && parkingarea == nullptr
134 269 : && chargingStation == nullptr) {
135 269 : tmp.parametersSet |= STOP_START_SET | STOP_END_SET;
136 : }
137 830 : 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 830 : if (pars.started >= 0 && (pars.parametersSet & STOP_STARTED_SET) == 0) {
141 976 : dev.writeAttr(SUMO_ATTR_STARTED, time2string(pars.started));
142 : }
143 830 : pars.writeParams(dev);
144 830 : dev.closeTag();
145 830 : }
146 :
147 : void
148 138342 : MSStop::initPars(const SUMOVehicleParameter::Stop& stopPar) {
149 138342 : busstop = MSNet::getInstance()->getStoppingPlace(stopPar.busstop, SUMO_TAG_BUS_STOP);
150 138342 : containerstop = MSNet::getInstance()->getStoppingPlace(stopPar.containerstop, SUMO_TAG_CONTAINER_STOP);
151 138342 : parkingarea = static_cast<MSParkingArea*>(MSNet::getInstance()->getStoppingPlace(stopPar.parkingarea, SUMO_TAG_PARKING_AREA));
152 138342 : chargingStation = MSNet::getInstance()->getStoppingPlace(stopPar.chargingStation, SUMO_TAG_CHARGING_STATION);
153 138342 : overheadWireSegment = MSNet::getInstance()->getStoppingPlace(stopPar.overheadWireSegment, SUMO_TAG_OVERHEAD_WIRE_SEGMENT);
154 138342 : duration = stopPar.duration;
155 138342 : triggered = stopPar.triggered;
156 138342 : containerTriggered = stopPar.containerTriggered;
157 138342 : joinTriggered = stopPar.joinTriggered || stopPar.join != "";
158 138342 : numExpectedPerson = (int)stopPar.awaitedPersons.size();
159 138342 : numExpectedContainer = (int)stopPar.awaitedContainers.size();
160 138342 : }
161 :
162 :
163 : int
164 258 : MSStop::getStateFlagsOld() const {
165 258 : return ((reached ? 1 : 0) + 2 * pars.getFlags());
166 : }
167 :
168 :
169 : SUMOTime
170 132441 : MSStop::getMinDuration(SUMOTime time) const {
171 132441 : if (MSGlobals::gUseStopEnded && pars.ended >= 0) {
172 53 : return pars.ended - time;
173 : }
174 132388 : if (pars.until >= 0) {
175 68979 : if (duration == -1) {
176 54592 : return pars.until - time;
177 : } else {
178 14387 : return MAX2(duration, pars.until - time);
179 : }
180 : } else {
181 63409 : return duration;
182 : }
183 : }
184 :
185 :
186 : SUMOTime
187 639995 : MSStop::getUntil() const {
188 639995 : return MSGlobals::gUseStopEnded && pars.ended >= 0 ? pars.ended : pars.until;
189 : }
190 :
191 :
192 : SUMOTime
193 151502 : MSStop::getArrival() const {
194 151502 : return MSGlobals::gUseStopStarted && pars.started >= 0 ? pars.started : pars.arrival;
195 : }
196 :
197 :
198 : SUMOTime
199 98535 : MSStop::getArrivalFallback() const {
200 98535 : SUMOTime result = getArrival();
201 98535 : if (result < 0) {
202 98454 : result = getUntil();
203 98454 : if (result >= 0 && pars.duration >= 0) {
204 14826 : result -= pars.duration;
205 : }
206 : }
207 98535 : return result;
208 : }
209 :
210 :
211 : double
212 120177848 : MSStop::getSpeed() const {
213 120177848 : return skipOnDemand ? std::numeric_limits<double>::max() : pars.speed;
214 : }
215 :
216 :
217 : bool
218 23384 : MSStop::isInRange(const double pos, const double tolerance) const {
219 23384 : 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 34 : MSStop::replaceStoppingPlace(MSStoppingPlace* sp) {
247 : // @note: assume iterator edge is handled elsewhere
248 : assert(*edge == &sp->getLane().getEdge());
249 34 : lane = &sp->getLane();
250 : SUMOVehicleParameter::Stop& ncPars = const_cast<SUMOVehicleParameter::Stop&>(pars);
251 34 : ncPars.edge = lane->getEdge().getID();
252 34 : ncPars.lane = lane->getID();
253 34 : ncPars.startPos = sp->getBeginLanePosition();
254 34 : ncPars.endPos = sp->getEndLanePosition();
255 34 : if (MSGlobals::gUseMesoSim) {
256 10 : segment = MSGlobals::gMesoNet->getSegmentForEdge(lane->getEdge(), sp->getEndLanePosition());
257 : }
258 34 : switch (sp->getElement()) {
259 34 : case SUMO_TAG_BUS_STOP:
260 : case SUMO_TAG_TRAIN_STOP:
261 34 : busstop = sp;
262 34 : 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 34 : default:
281 : // should not happen
282 : assert(false);
283 : }
284 34 : }
285 :
286 : /****************************************************************************/
|