Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2005-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 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 7480321 : MSStop::getEndPos(const SUMOVehicle& veh) const {
36 7480321 : const double brakePos = veh.getEdge() == getEdge() ? veh.getPositionOnLane() + veh.getBrakeGap() : 0;
37 7480321 : if ((pars.parametersSet & STOP_END_SET) != 0) {
38 3822963 : return pars.endPos;
39 3657358 : } else if (busstop != nullptr) {
40 841279 : return busstop->getLastFreePos(veh, brakePos);
41 2816079 : } else if (containerstop != nullptr) {
42 23764 : return containerstop->getLastFreePos(veh, brakePos);
43 2792315 : } else if (parkingarea != nullptr) {
44 791750 : return parkingarea->getLastFreePos(veh, brakePos);
45 2000565 : } else if (chargingStation != nullptr) {
46 478237 : return chargingStation->getLastFreePos(veh);
47 1522328 : } else if (overheadWireSegment != nullptr) {
48 0 : return overheadWireSegment->getLastFreePos(veh);
49 : }
50 1522328 : return pars.endPos;
51 : }
52 :
53 : const MSEdge*
54 7556450 : MSStop::getEdge() const {
55 7556450 : if (lane != nullptr) {
56 7556450 : return &lane->getEdge();
57 0 : } else if (segment != nullptr) {
58 0 : return &segment->getEdge();
59 : }
60 : return nullptr;
61 : }
62 :
63 : double
64 3035996 : MSStop::getReachedThreshold() const {
65 3035996 : return isOpposite ? lane->getOppositePos(pars.endPos) - (pars.endPos - pars.startPos) : pars.startPos;
66 : }
67 :
68 : std::string
69 2 : MSStop::getDescription() const {
70 : std::string result;
71 2 : if (parkingarea != nullptr) {
72 0 : 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 2 : if (pars.actType != "") {
85 0 : result += " actType:" + pars.actType;
86 : }
87 2 : return result;
88 : }
89 :
90 :
91 : void
92 569 : MSStop::write(OutputDevice& dev) const {
93 569 : SUMOVehicleParameter::Stop tmp = pars;
94 569 : tmp.duration = duration;
95 569 : if (busstop == nullptr
96 546 : && containerstop == nullptr
97 546 : && parkingarea == nullptr
98 255 : && chargingStation == nullptr) {
99 255 : tmp.parametersSet |= STOP_START_SET | STOP_END_SET;
100 : }
101 569 : 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 569 : if (pars.started >= 0 && (pars.parametersSet & STOP_STARTED_SET) == 0) {
105 426 : dev.writeAttr(SUMO_ATTR_STARTED, time2string(pars.started));
106 : }
107 569 : pars.writeParams(dev);
108 569 : dev.closeTag();
109 569 : }
110 :
111 : void
112 128297 : MSStop::initPars(const SUMOVehicleParameter::Stop& stopPar) {
113 128297 : busstop = MSNet::getInstance()->getStoppingPlace(stopPar.busstop, SUMO_TAG_BUS_STOP);
114 128297 : containerstop = MSNet::getInstance()->getStoppingPlace(stopPar.containerstop, SUMO_TAG_CONTAINER_STOP);
115 128297 : parkingarea = static_cast<MSParkingArea*>(MSNet::getInstance()->getStoppingPlace(stopPar.parkingarea, SUMO_TAG_PARKING_AREA));
116 128297 : chargingStation = MSNet::getInstance()->getStoppingPlace(stopPar.chargingStation, SUMO_TAG_CHARGING_STATION);
117 128297 : overheadWireSegment = MSNet::getInstance()->getStoppingPlace(stopPar.overheadWireSegment, SUMO_TAG_OVERHEAD_WIRE_SEGMENT);
118 128297 : duration = stopPar.duration;
119 128297 : triggered = stopPar.triggered;
120 128297 : containerTriggered = stopPar.containerTriggered;
121 128297 : joinTriggered = stopPar.joinTriggered || stopPar.join != "";
122 128297 : numExpectedPerson = (int)stopPar.awaitedPersons.size();
123 128297 : numExpectedContainer = (int)stopPar.awaitedContainers.size();
124 128297 : }
125 :
126 :
127 : int
128 157 : MSStop::getStateFlagsOld() const {
129 157 : return ((reached ? 1 : 0) + 2 * pars.getFlags());
130 : }
131 :
132 :
133 : SUMOTime
134 53898 : MSStop::getMinDuration(SUMOTime time) const {
135 53898 : if (MSGlobals::gUseStopEnded && pars.ended >= 0) {
136 48 : return pars.ended - time;
137 : }
138 53850 : if (pars.until >= 0) {
139 17728 : if (duration == -1) {
140 12896 : return pars.until - time;
141 : } else {
142 4832 : return MAX2(duration, pars.until - time);
143 : }
144 : } else {
145 36122 : return duration;
146 : }
147 : }
148 :
149 :
150 : SUMOTime
151 488220 : MSStop::getUntil() const {
152 488220 : return MSGlobals::gUseStopEnded && pars.ended >= 0 ? pars.ended : pars.until;
153 : }
154 :
155 :
156 : SUMOTime
157 41035 : MSStop::getArrival() const {
158 41035 : return MSGlobals::gUseStopStarted && pars.started >= 0 ? pars.started : pars.arrival;
159 : }
160 :
161 :
162 : double
163 95359108 : MSStop::getSpeed() const {
164 95359108 : return skipOnDemand ? std::numeric_limits<double>::max() : pars.speed;
165 : }
166 :
167 :
168 : bool
169 19413 : MSStop::isInRange(const double pos, const double tolerance) const {
170 19413 : return pars.startPos - tolerance <= pos && pars.endPos + tolerance >= pos;
171 : }
172 :
173 : /****************************************************************************/
|