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-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/****************************************************************************/
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) {
48 } else if (overheadWireSegment != nullptr) {
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
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()) {
122 }
123 return std::make_pair("", SUMO_TAG_NOTHING);
124}
125
126
127void
130 tmp.duration = duration;
131 if (busstop == nullptr
132 && containerstop == nullptr
133 && parkingarea == nullptr
134 && chargingStation == nullptr) {
136 }
137 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 if (pars.started >= 0 && (pars.parametersSet & STOP_STARTED_SET) == 0) {
142 }
143 pars.writeParams(dev);
144 dev.closeTag();
145}
146
147void
161
162
163int
165 return ((reached ? 1 : 0) + 2 * pars.getFlags());
166}
167
168
171 if (MSGlobals::gUseStopEnded && pars.ended >= 0) {
172 return pars.ended - time;
173 }
174 if (pars.until >= 0) {
175 if (duration == -1) {
176 return pars.until - time;
177 } else {
178 return MAX2(duration, pars.until - time);
179 }
180 } else {
181 return duration;
182 }
183}
184
185
190
191
196
197
200 SUMOTime result = getArrival();
201 if (result < 0) {
202 result = getUntil();
203 if (result >= 0 && pars.duration >= 0) {
204 result -= pars.duration;
205 }
206 }
207 return result;
208}
209
210
211double
213 return skipOnDemand ? std::numeric_limits<double>::max() : pars.speed;
214}
215
216
217bool
218MSStop::isInRange(const double pos, const double tolerance) const {
219 return pars.startPos - tolerance <= pos && pars.endPos + tolerance >= pos;
220}
221
222
223std::vector<MSStoppingPlace*>
225 std::vector<MSStoppingPlace*> result;
226 if (busstop != nullptr) {
227 result.push_back(busstop);
228 }
229 if (containerstop != nullptr) {
230 result.push_back(containerstop);
231 }
232 if (parkingarea != nullptr) {
233 result.push_back(parkingarea);
234 }
235 if (chargingStation != nullptr) {
236 result.push_back(chargingStation);
237 }
238 if (overheadWireSegment != nullptr) {
239 result.push_back(overheadWireSegment);
240 }
241 return result;
242}
243
244
245void
247 // @note: assume iterator edge is handled elsewhere
248 assert(*edge == &sp->getLane().getEdge());
249 lane = &sp->getLane();
251 ncPars.edge = lane->getEdge().getID();
252 ncPars.lane = lane->getID();
253 ncPars.startPos = sp->getBeginLanePosition();
254 ncPars.endPos = sp->getEndLanePosition();
257 }
258 switch (sp->getElement()) {
261 busstop = sp;
262 ncPars.busstop = sp->getID();
263 break;
265 containerstop = sp;
266 ncPars.containerstop = sp->getID();
267 break;
269 parkingarea = dynamic_cast<MSParkingArea*>(sp);
270 ncPars.parkingarea = sp->getID();
271 break;
273 chargingStation = sp;
274 ncPars.chargingStation = sp->getID();
275 break;
278 ncPars.overheadWireSegment = sp->getID();
279 break;
280 default:
281 // should not happen
282 assert(false);
283 }
284}
285
286/****************************************************************************/
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_START_SET
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:46
MESegment * getSegmentForEdge(const MSEdge &e, double pos=0)
Get the segment for a given edge at a given position.
Definition MELoop.cpp:340
const MSEdge & getEdge() const
Returns the edge this segment belongs to.
Definition MESegment.h:364
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:112
static bool gUseStopEnded
whether the simulation should replay previous stop times
Definition MSGlobals.h:133
double getOppositePos(double pos) const
return the corresponding position on the opposite lane
Definition MSLane.cpp:4395
MSEdge & getEdge() const
Returns the lane's edge.
Definition MSLane.h:769
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:187
MSStoppingPlace * getStoppingPlace(const std::string &id, const SumoXMLTag category) const
Returns the named stopping place of the given category.
Definition MSNet.cpp:1467
A lane area vehicles can halt at.
double getLastFreePos(const SUMOVehicle &forVehicle, double brakePos=0) const
Returns the last free position on this stop.
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:224
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:212
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:170
void initPars(const SUMOVehicleParameter::Stop &stopPar)
initialize attributes from the given stop parameters
Definition MSStop.cpp:148
int getStateFlagsOld() const
return flags as used by Vehicle::getStopState
Definition MSStop.cpp:164
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:199
bool isInRange(const double pos, const double tolerance) const
whether the stop is in range of the given position
Definition MSStop.cpp:218
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:187
void replaceStoppingPlace(MSStoppingPlace *sp)
modify all properties so the stop happens at sp instead
Definition MSStop.cpp:246
SUMOTime getArrival() const
return arrival / started time
Definition MSStop.cpp:193
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 & getMyName() const
virtual double getLastFreePos(const SUMOVehicle &forVehicle, double brakePos=0) const
Returns the last free position on this stop.
const std::string & getID() const
Returns the id.
Definition Named.h:74
Static storage of an output device and its base (abstract) implementation.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
void writeParams(OutputDevice &device) const
write Params in the given outputdevice
virtual const MSEdge * getEdge() const =0
Returns the 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:62
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)
int getFlags() const
return flags as per Vehicle::getStops
SUMOTime started
the time at which this stop was reached
std::string edge
The edge to stop at.
std::string lane
The lane to stop at.
double speed
the speed at which this stop counts as reached (waypoint mode)
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
int parametersSet
Information for the output which parameter were set.
std::string join
the id of the vehicle (train portion) to which this vehicle shall be joined
SUMOTime until
The time at which the vehicle may continue its journey.
std::string actType
act Type (only used by Persons) (used by netedit)
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.
SUMOTime ended
the time at which this stop was ended
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 arrival
The (expected) time at which the vehicle reaches the stop.
SUMOTime duration
The stopping duration.