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 "MSLane.h"
25 : #include "MSNet.h"
26 : #include "MSParkingArea.h"
27 : #include "MSStoppingPlace.h"
28 : #include "MSStop.h"
29 :
30 :
31 : // ===========================================================================
32 : // method definitions
33 : // ===========================================================================
34 : double
35 11219001 : MSStop::getEndPos(const SUMOVehicle& veh) const {
36 11219001 : const double brakePos = veh.getEdge() == getEdge() ? veh.getPositionOnLane() + veh.getBrakeGap() : 0;
37 11219001 : if ((pars.parametersSet & STOP_END_SET) != 0) {
38 4437459 : return pars.endPos;
39 6781542 : } else if (busstop != nullptr) {
40 3245160 : return busstop->getLastFreePos(veh, brakePos);
41 3536382 : } else if (containerstop != nullptr) {
42 37242 : return containerstop->getLastFreePos(veh, brakePos);
43 3499140 : } else if (parkingarea != nullptr) {
44 1674884 : return parkingarea->getLastFreePos(veh, brakePos);
45 1824256 : } else if (chargingStation != nullptr) {
46 476802 : return chargingStation->getLastFreePos(veh);
47 1347454 : } else if (overheadWireSegment != nullptr) {
48 0 : return overheadWireSegment->getLastFreePos(veh);
49 : }
50 1347454 : return pars.endPos;
51 : }
52 :
53 : const MSEdge*
54 11304959 : MSStop::getEdge() const {
55 11304959 : if (lane != nullptr) {
56 11304959 : return &lane->getEdge();
57 0 : } else if (segment != nullptr) {
58 0 : return &segment->getEdge();
59 : }
60 : return nullptr;
61 : }
62 :
63 : double
64 3503652 : MSStop::getReachedThreshold() const {
65 3503652 : return isOpposite ? lane->getOppositePos(pars.endPos) - (pars.endPos - pars.startPos) : pars.startPos;
66 : }
67 :
68 : std::string
69 6 : MSStop::getDescription() const {
70 : std::string result;
71 6 : if (parkingarea != nullptr) {
72 8 : result = "parkingArea:" + parkingarea->getID();
73 2 : } else if (containerstop != nullptr) {
74 0 : result = "containerStop:" + containerstop->getID();
75 2 : } else if (busstop != nullptr) {
76 2 : result = "busStop:" + busstop->getID();
77 1 : } else if (chargingStation != nullptr) {
78 0 : result = "chargingStation:" + chargingStation->getID();
79 1 : } else if (overheadWireSegment != nullptr) {
80 0 : result = "overheadWireSegment:" + overheadWireSegment->getID();
81 : } else {
82 3 : result = "lane:" + lane->getID() + " pos:" + toString(pars.endPos);
83 : }
84 6 : if (pars.actType != "") {
85 0 : result += " actType:" + pars.actType;
86 : }
87 6 : return result;
88 : }
89 :
90 :
91 : void
92 830 : MSStop::write(OutputDevice& dev) const {
93 830 : SUMOVehicleParameter::Stop tmp = pars;
94 830 : tmp.duration = duration;
95 830 : if (busstop == nullptr
96 797 : && containerstop == nullptr
97 797 : && parkingarea == nullptr
98 269 : && chargingStation == nullptr) {
99 269 : tmp.parametersSet |= STOP_START_SET | STOP_END_SET;
100 : }
101 830 : tmp.write(dev, false);
102 : // if the stop has already started but hasn't ended yet we are writing it in
103 : // the context of saveState (but we do not want to write the attribute twice
104 830 : if (pars.started >= 0 && (pars.parametersSet & STOP_STARTED_SET) == 0) {
105 976 : dev.writeAttr(SUMO_ATTR_STARTED, time2string(pars.started));
106 : }
107 830 : pars.writeParams(dev);
108 830 : dev.closeTag();
109 830 : }
110 :
111 : void
112 137539 : MSStop::initPars(const SUMOVehicleParameter::Stop& stopPar) {
113 137539 : busstop = MSNet::getInstance()->getStoppingPlace(stopPar.busstop, SUMO_TAG_BUS_STOP);
114 137539 : containerstop = MSNet::getInstance()->getStoppingPlace(stopPar.containerstop, SUMO_TAG_CONTAINER_STOP);
115 137539 : parkingarea = static_cast<MSParkingArea*>(MSNet::getInstance()->getStoppingPlace(stopPar.parkingarea, SUMO_TAG_PARKING_AREA));
116 137539 : chargingStation = MSNet::getInstance()->getStoppingPlace(stopPar.chargingStation, SUMO_TAG_CHARGING_STATION);
117 137539 : overheadWireSegment = MSNet::getInstance()->getStoppingPlace(stopPar.overheadWireSegment, SUMO_TAG_OVERHEAD_WIRE_SEGMENT);
118 137539 : duration = stopPar.duration;
119 137539 : triggered = stopPar.triggered;
120 137539 : containerTriggered = stopPar.containerTriggered;
121 137539 : joinTriggered = stopPar.joinTriggered || stopPar.join != "";
122 137539 : numExpectedPerson = (int)stopPar.awaitedPersons.size();
123 137539 : numExpectedContainer = (int)stopPar.awaitedContainers.size();
124 137539 : }
125 :
126 :
127 : int
128 257 : MSStop::getStateFlagsOld() const {
129 257 : return ((reached ? 1 : 0) + 2 * pars.getFlags());
130 : }
131 :
132 :
133 : SUMOTime
134 122987 : MSStop::getMinDuration(SUMOTime time) const {
135 122987 : if (MSGlobals::gUseStopEnded && pars.ended >= 0) {
136 53 : return pars.ended - time;
137 : }
138 122934 : if (pars.until >= 0) {
139 61895 : if (duration == -1) {
140 51536 : return pars.until - time;
141 : } else {
142 10359 : return MAX2(duration, pars.until - time);
143 : }
144 : } else {
145 61039 : return duration;
146 : }
147 : }
148 :
149 :
150 : SUMOTime
151 636858 : MSStop::getUntil() const {
152 636858 : return MSGlobals::gUseStopEnded && pars.ended >= 0 ? pars.ended : pars.until;
153 : }
154 :
155 :
156 : SUMOTime
157 150269 : MSStop::getArrival() const {
158 150269 : return MSGlobals::gUseStopStarted && pars.started >= 0 ? pars.started : pars.arrival;
159 : }
160 :
161 :
162 : SUMOTime
163 97329 : MSStop::getArrivalFallback() const {
164 97329 : SUMOTime result = getArrival();
165 97329 : if (result < 0) {
166 97248 : result = getUntil();
167 97248 : if (result >= 0 && pars.duration >= 0) {
168 14802 : result -= pars.duration;
169 : }
170 : }
171 97329 : return result;
172 : }
173 :
174 :
175 : double
176 114076291 : MSStop::getSpeed() const {
177 114076291 : return skipOnDemand ? std::numeric_limits<double>::max() : pars.speed;
178 : }
179 :
180 :
181 : bool
182 23380 : MSStop::isInRange(const double pos, const double tolerance) const {
183 23380 : return pars.startPos - tolerance <= pos && pars.endPos + tolerance >= pos;
184 : }
185 :
186 :
187 : std::vector<MSStoppingPlace*>
188 12 : MSStop::getPlaces() const {
189 : std::vector<MSStoppingPlace*> result;
190 12 : if (busstop != nullptr) {
191 12 : result.push_back(busstop);
192 : }
193 12 : if (containerstop != nullptr) {
194 0 : result.push_back(containerstop);
195 : }
196 12 : if (parkingarea != nullptr) {
197 0 : result.push_back(parkingarea);
198 : }
199 12 : if (chargingStation != nullptr) {
200 0 : result.push_back(chargingStation);
201 : }
202 12 : if (overheadWireSegment != nullptr) {
203 0 : result.push_back(overheadWireSegment);
204 : }
205 12 : return result;
206 0 : }
207 :
208 : /****************************************************************************/
|