Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSStop.cpp
Go to the documentation of this file.
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/****************************************************************************/
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// ===========================================================================
35double
36MSStop::getEndPos(const SUMOVehicle& veh) const {
37 const double brakePos = veh.getEdge() == getEdge() ? veh.getPositionOnLane() + veh.getBrakeGap() : 0;
38 if ((pars.parametersSet & STOP_END_SET) != 0) {
39 return pars.endPos;
40 } else if (busstop != nullptr) {
41 return busstop->getLastFreePos(veh, brakePos);
42 } else if (containerstop != nullptr) {
43 return containerstop->getLastFreePos(veh, brakePos);
44 } else if (parkingarea != nullptr) {
45 return parkingarea->getLastFreePos(veh, brakePos);
46 } else if (chargingStation != nullptr) {
47 return chargingStation->getLastFreePos(veh);
48 } else if (overheadWireSegment != nullptr) {
49 return overheadWireSegment->getLastFreePos(veh);
50 }
51 return pars.endPos;
52}
53
54const MSEdge*
56 if (lane != nullptr) {
57 return &lane->getEdge();
58 } else if (segment != nullptr) {
59 return &segment->getEdge();
60 }
61 return nullptr;
62}
63
64double
66 return isOpposite ? lane->getOppositePos(pars.endPos) - (pars.endPos - pars.startPos) : pars.startPos;
67}
68
69std::string
70MSStop::getDescription(bool nameOnly) const {
71 std::string result;
72 if (parkingarea != nullptr) {
73 if (nameOnly) {
74 return parkingarea->getID();
75 }
76 result = "parkingArea:" + parkingarea->getID();
77 } else if (containerstop != nullptr) {
78 if (nameOnly) {
79 return containerstop->getID();
80 }
81 result = "containerStop:" + containerstop->getID();
82 } else if (busstop != nullptr) {
83 if (nameOnly) {
84 return busstop->getID();
85 }
86 result = "busStop:" + busstop->getID();
87 } else if (chargingStation != nullptr) {
88 if (nameOnly) {
89 return chargingStation->getID();
90 }
91 result = "chargingStation:" + chargingStation->getID();
92 } else if (overheadWireSegment != nullptr) {
93 if (nameOnly) {
94 return overheadWireSegment->getID();
95 }
96 result = "overheadWireSegment:" + overheadWireSegment->getID();
97 } else {
98 if (nameOnly) {
99 return "";
100 }
101 result = "lane:" + lane->getID() + " pos:" + toString(pars.endPos);
102 }
103 if (pars.actType != "") {
104 result += " actType:" + pars.actType;
105 }
106 return result;
107}
108
109
110std::pair<std::string, SumoXMLTag>
112 if (busstop != nullptr && !busstop->getMyName().empty()) {
113 return std::make_pair(busstop->getMyName(), SUMO_TAG_BUS_STOP);
114 } else if (containerstop != nullptr && !containerstop->getMyName().empty()) {
115 return std::make_pair(containerstop->getMyName(), SUMO_TAG_CONTAINER_STOP);
116 } else if (parkingarea != nullptr && !parkingarea->getMyName().empty()) {
117 return std::make_pair(parkingarea->getMyName(), SUMO_TAG_PARKING_AREA);
118 } else if (chargingStation != nullptr && !chargingStation->getMyName().empty()) {
119 return std::make_pair(chargingStation->getMyName(), SUMO_TAG_CHARGING_STATION);
120 } else if (overheadWireSegment != nullptr && !overheadWireSegment->getMyName().empty()) {
121 return std::make_pair(overheadWireSegment->getMyName(), SUMO_TAG_OVERHEAD_WIRE_SEGMENT);
122 }
123 return std::make_pair("", SUMO_TAG_NOTHING);
124}
125
126
127void
130 tmp.duration = duration;
131 if (!triggered && !containerTriggered) {
132 // we are writing in the context of saveState. All required
133 // transportables have entered and we must prevent the trigger condition
134 // to be renewed on loading
135 tmp.triggered = false;
136 tmp.containerTriggered = false;
137 }
138 tmp.write(dev, false);
139 // if the stop has already started but hasn't ended yet we are writing it in
140 // the context of saveState (but we do not want to write the attribute twice
141 if (pars.started >= 0 && (pars.parametersSet & STOP_STARTED_SET) == 0) {
143 }
144 pars.writeParams(dev);
145 dev.closeTag();
146}
147
148void
162
163
164int
166 return ((reached ? 1 : 0) + 2 * pars.getFlags());
167}
168
169
172 if (MSGlobals::gUseStopEnded && pars.ended >= 0) {
173 return pars.ended - time;
174 }
175 if (pars.until >= 0) {
176 if (duration == -1) {
177 return pars.until - time;
178 } else {
179 return MAX2(duration, pars.until - time);
180 }
181 } else {
182 return duration;
183 }
184}
185
186
189 return MSGlobals::gUseStopEnded && pars.ended >= 0 ? pars.ended : pars.until;
190}
191
192
195 return MSGlobals::gUseStopStarted && pars.started >= 0 ? pars.started : pars.arrival;
196}
197
198
201 SUMOTime result = getArrival();
202 if (result < 0) {
203 result = getUntil();
204 if (result >= 0 && pars.duration >= 0) {
205 result -= pars.duration;
206 }
207 }
208 return result;
209}
210
211
212double
214 return skipOnDemand ? std::numeric_limits<double>::max() : pars.speed;
215}
216
217
218bool
219MSStop::isInRange(const double pos, const double tolerance) const {
220 return pars.startPos - tolerance <= pos && pars.endPos + tolerance >= pos;
221}
222
223
224std::vector<MSStoppingPlace*>
226 std::vector<MSStoppingPlace*> result;
227 if (busstop != nullptr) {
228 result.push_back(busstop);
229 }
230 if (containerstop != nullptr) {
231 result.push_back(containerstop);
232 }
233 if (parkingarea != nullptr) {
234 result.push_back(parkingarea);
235 }
236 if (chargingStation != nullptr) {
237 result.push_back(chargingStation);
238 }
239 if (overheadWireSegment != nullptr) {
240 result.push_back(overheadWireSegment);
241 }
242 return result;
243}
244
245
246void
248 // @note: assume iterator edge is handled elsewhere
249 assert(*edge == &sp->getLane().getEdge());
250 lane = &sp->getLane();
252 ncPars.edge = lane->getEdge().getID();
253 ncPars.lane = lane->getID();
254 ncPars.startPos = sp->getBeginLanePosition();
255 ncPars.endPos = sp->getEndLanePosition();
257 segment = MSGlobals::gMesoNet->getSegmentForEdge(lane->getEdge(), sp->getEndLanePosition());
258 }
259 switch (sp->getElement()) {
262 busstop = sp;
263 ncPars.busstop = sp->getID();
264 break;
266 containerstop = sp;
267 ncPars.containerstop = sp->getID();
268 break;
270 parkingarea = dynamic_cast<MSParkingArea*>(sp);
271 ncPars.parkingarea = sp->getID();
272 break;
274 chargingStation = sp;
275 ncPars.chargingStation = sp->getID();
276 break;
279 ncPars.overheadWireSegment = sp->getID();
280 break;
281 default:
282 // should not happen
283 assert(false);
284 }
285}
286
287/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:91
const int STOP_END_SET
const int STOP_STARTED_SET
@ SUMO_TAG_CHARGING_STATION
A Charging Station.
@ SUMO_TAG_NOTHING
invalid tag, must be the last one
@ SUMO_TAG_CONTAINER_STOP
A container stop.
@ SUMO_TAG_BUS_STOP
A bus stop.
@ SUMO_TAG_PARKING_AREA
A parking area.
@ SUMO_TAG_TRAIN_STOP
A train stop (alias for bus stop).
@ SUMO_TAG_OVERHEAD_WIRE_SEGMENT
An overhead wire segment.
@ SUMO_ATTR_STARTED
T MAX2(T a, T b)
Definition StdDefs.h:86
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:49
A road/street connecting two junctions.
Definition MSEdge.h:77
static bool gUseMesoSim
Definition MSGlobals.h:106
static bool gUseStopStarted
Definition MSGlobals.h:134
static MELoop * gMesoNet
mesoscopic simulation infrastructure
Definition MSGlobals.h:115
static bool gUseStopEnded
whether the simulation should replay previous stop times
Definition MSGlobals.h:133
MSEdge & getEdge() const
Returns the lane's edge.
Definition MSLane.h:775
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:199
MSStoppingPlace * getStoppingPlace(const std::string &id, const SumoXMLTag category) const
Returns the named stopping place of the given category.
Definition MSNet.cpp:1501
A lane area vehicles can halt at.
void write(OutputDevice &dev) const
Write the current stop configuration (used for state saving).
Definition MSStop.cpp:128
const MSLane * lane
The lane to stop at (microsim only).
Definition MSStop.h:50
bool triggered
whether an arriving person lets the vehicle continue
Definition MSStop.h:69
bool containerTriggered
whether an arriving container lets the vehicle continue
Definition MSStop.h:71
std::vector< MSStoppingPlace * > getPlaces() const
return all stoppingPlaces associated with this stop
Definition MSStop.cpp:225
MSStoppingPlace * containerstop
(Optional) container stop if one is assigned to the stop
Definition MSStop.h:56
double getSpeed() const
return speed for passing waypoint / skipping on-demand stop
Definition MSStop.cpp:213
std::string getDescription(bool nameOnly=false) const
get a short description for showing in the gui
Definition MSStop.cpp:70
bool joinTriggered
whether coupling another vehicle (train) the vehicle continue
Definition MSStop.h:73
bool isOpposite
whether this an opposite-direction stop
Definition MSStop.h:87
SUMOTime getMinDuration(SUMOTime time) const
return minimum stop duration when starting stop at time
Definition MSStop.cpp:171
void initPars(const SUMOVehicleParameter::Stop &stopPar)
initialize attributes from the given stop parameters
Definition MSStop.cpp:149
int getStateFlagsOld() const
return flags as used by Vehicle::getStopState
Definition MSStop.cpp:165
const MESegment * segment
The segment to stop at (mesosim only).
Definition MSStop.h:52
int numExpectedContainer
The number of still expected containers.
Definition MSStop.h:79
bool reached
Information whether the stop has been reached.
Definition MSStop.h:75
MSRouteIterator edge
The edge in the route to stop at.
Definition MSStop.h:48
bool skipOnDemand
whether the decision to skip this stop has been made
Definition MSStop.h:89
SUMOTime getArrivalFallback() const
return arrival / started time or estimated arrival from until/duration
Definition MSStop.cpp:200
bool isInRange(const double pos, const double tolerance) const
whether the stop is in range of the given position
Definition MSStop.cpp:219
const MSEdge * getEdge() const
Definition MSStop.cpp:55
double getReachedThreshold() const
return startPos taking into account opposite stopping
Definition MSStop.cpp:65
double getEndPos(const SUMOVehicle &veh) const
return halting position for upcoming stop;
Definition MSStop.cpp:36
int numExpectedPerson
The number of still expected persons.
Definition MSStop.h:77
std::pair< std::string, SumoXMLTag > getStoppingPlaceName() const
return the name of the stopping place or an empty string
Definition MSStop.cpp:111
MSParkingArea * parkingarea
(Optional) parkingArea if one is assigned to the stop
Definition MSStop.h:58
MSStoppingPlace * chargingStation
(Optional) charging station if one is assigned to the stop
Definition MSStop.h:60
SUMOTime duration
The stopping duration.
Definition MSStop.h:67
SUMOTime getUntil() const
return until / ended time
Definition MSStop.cpp:188
void replaceStoppingPlace(MSStoppingPlace *sp)
modify all properties so the stop happens at sp instead
Definition MSStop.cpp:247
SUMOTime getArrival() const
return arrival / started time
Definition MSStop.cpp:194
const SUMOVehicleParameter::Stop pars
The stop parameter.
Definition MSStop.h:65
MSStoppingPlace * busstop
(Optional) bus stop if one is assigned to the stop
Definition MSStop.h:54
MSStoppingPlace * overheadWireSegment
(Optional) overhead wire segment if one is assigned to the stop
Definition MSStop.h:63
A lane area vehicles can halt at.
double getBeginLanePosition() const
Returns the begin position of this stop.
SumoXMLTag getElement() const
return the type of this stopping place
double getEndLanePosition() const
Returns the end position of this stop.
const MSLane & getLane() const
Returns the lane this stop is located at.
const std::string & getID() const
Returns the id.
Definition Named.h:73
Static storage of an output device and its base (abstract) implementation.
OutputDevice & writeAttr(const ATTR_TYPE &attr, const T &val, const bool isNull=false)
writes a named attribute
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
virtual const MSEdge * getEdge() const =0
Returns the (normal) route edge the object is currently at.
virtual double getPositionOnLane() const =0
Get the object's position along the lane.
Representation of a vehicle.
Definition SUMOVehicle.h:63
virtual double getBrakeGap(bool delayed=false) const =0
get distance for coming to a stop (used for rerouting checks)
Definition of vehicle stop (position and duration).
std::string edge
The edge to stop at.
std::string lane
The lane to stop at.
std::string parkingarea
(Optional) parking area if one is assigned to the stop
double startPos
The stopping position start.
std::string chargingStation
(Optional) charging station if one is assigned to the stop
std::string overheadWireSegment
(Optional) overhead line segment if one is assigned to the stop
std::string join
the id of the vehicle (train portion) to which this vehicle shall be joined
bool triggered
whether an arriving person lets the vehicle continue
void write(OutputDevice &dev, const bool close=true, const bool writeTagAndParents=true) const
Writes the stop as XML.
double endPos
The stopping position end.
std::set< std::string > awaitedPersons
IDs of persons the vehicle has to wait for until departing.
std::set< std::string > awaitedContainers
IDs of containers the vehicle has to wait for until departing.
std::string busstop
(Optional) bus stop if one is assigned to the stop
bool joinTriggered
whether an joined vehicle lets this vehicle continue
std::string containerstop
(Optional) container stop if one is assigned to the stop
bool containerTriggered
whether an arriving container lets the vehicle continue
SUMOTime duration
The stopping duration.