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 "MSRouteHandler.h"
31#include "MSStop.h"
32
33// ===========================================================================
34// method definitions
35// ===========================================================================
36
37double
38MSStop::getEndPos(const SUMOVehicle& veh) const {
39 const double brakePos = veh.getEdge() == getEdge() ? veh.getPositionOnLane() + veh.getBrakeGap() : 0;
40 if ((pars.parametersSet & STOP_END_SET) != 0) {
41 return pars.endPos;
42 } else if (busstop != nullptr) {
43 return busstop->getLastFreePos(veh, brakePos);
44 } else if (containerstop != nullptr) {
45 return containerstop->getLastFreePos(veh, brakePos);
46 } else if (parkingarea != nullptr) {
47 return parkingarea->getLastFreePos(veh, brakePos);
48 } else if (chargingStation != nullptr) {
50 } else if (overheadWireSegment != nullptr) {
52 }
53 return pars.endPos;
54}
55
56const MSEdge*
58 if (lane != nullptr) {
59 return &lane->getEdge();
60 } else if (segment != nullptr) {
61 return &segment->getEdge();
62 }
63 return nullptr;
64}
65
66double
70
71std::string
72MSStop::getDescription(bool nameOnly) const {
73 std::string result;
74 if (parkingarea != nullptr) {
75 if (nameOnly) {
76 return parkingarea->getID();
77 }
78 result = "parkingArea:" + parkingarea->getID();
79 } else if (containerstop != nullptr) {
80 if (nameOnly) {
81 return containerstop->getID();
82 }
83 result = "containerStop:" + containerstop->getID();
84 } else if (busstop != nullptr) {
85 if (nameOnly) {
86 return busstop->getID();
87 }
88 result = "busStop:" + busstop->getID();
89 } else if (chargingStation != nullptr) {
90 if (nameOnly) {
91 return chargingStation->getID();
92 }
93 result = "chargingStation:" + chargingStation->getID();
94 } else if (overheadWireSegment != nullptr) {
95 if (nameOnly) {
96 return overheadWireSegment->getID();
97 }
98 result = "overheadWireSegment:" + overheadWireSegment->getID();
99 } else {
100 if (nameOnly) {
101 return "";
102 }
103 result = "lane:" + lane->getID() + " pos:" + toString(pars.endPos);
104 }
105 if (pars.actType != "") {
106 result += " actType:" + pars.actType;
107 }
108 return result;
109}
110
111
112std::pair<std::string, SumoXMLTag>
114 if (busstop != nullptr && !busstop->getMyName().empty()) {
115 return std::make_pair(busstop->getMyName(), SUMO_TAG_BUS_STOP);
116 } else if (containerstop != nullptr && !containerstop->getMyName().empty()) {
117 return std::make_pair(containerstop->getMyName(), SUMO_TAG_CONTAINER_STOP);
118 } else if (parkingarea != nullptr && !parkingarea->getMyName().empty()) {
119 return std::make_pair(parkingarea->getMyName(), SUMO_TAG_PARKING_AREA);
120 } else if (chargingStation != nullptr && !chargingStation->getMyName().empty()) {
121 return std::make_pair(chargingStation->getMyName(), SUMO_TAG_CHARGING_STATION);
122 } else if (overheadWireSegment != nullptr && !overheadWireSegment->getMyName().empty()) {
124 }
125 return std::make_pair("", SUMO_TAG_NOTHING);
126}
127
128
129void
132 tmp.duration = duration;
133 if (!triggered && !containerTriggered) {
134 // we are writing in the context of saveState. All required
135 // transportables have entered and we must prevent the trigger condition
136 // to be renewed on loading
137 tmp.triggered = false;
138 tmp.containerTriggered = false;
139 }
140 tmp.write(dev, false);
141 // if the stop has already started but hasn't ended yet we are writing it in
142 // the context of saveState (but we do not want to write the attribute twice
143 if (pars.started >= 0 && (pars.parametersSet & STOP_STARTED_SET) == 0) {
145 }
146 pars.writeParams(dev);
147 dev.closeTag();
148}
149
150void
164
165
166int
168 return ((reached ? 1 : 0) + 2 * pars.getFlags());
169}
170
171
174 if (MSGlobals::gUseStopEnded && pars.ended >= 0) {
175 return pars.ended - time;
176 }
177 if (pars.until >= 0) {
178 if (duration == -1) {
179 return pars.until - time;
180 } else {
181 return MAX2(duration, pars.until - time);
182 }
183 } else {
184 return duration;
185 }
186}
187
188
193
194
199
200
203 SUMOTime result = getArrival();
204 if (result < 0) {
205 result = getUntil();
206 if (result >= 0 && pars.duration >= 0) {
207 result -= pars.duration;
208 }
209 }
210 return result;
211}
212
213
214double
216 return skipOnDemand ? std::numeric_limits<double>::max() : pars.speed;
217}
218
219
220bool
221MSStop::isInRange(const double pos, const double tolerance) const {
222 return pars.startPos - tolerance <= pos && pars.endPos + tolerance >= pos;
223}
224
225
226std::vector<MSStoppingPlace*>
228 std::vector<MSStoppingPlace*> result;
229 if (busstop != nullptr) {
230 result.push_back(busstop);
231 }
232 if (containerstop != nullptr) {
233 result.push_back(containerstop);
234 }
235 if (parkingarea != nullptr) {
236 result.push_back(parkingarea);
237 }
238 if (chargingStation != nullptr) {
239 result.push_back(chargingStation);
240 }
241 if (overheadWireSegment != nullptr) {
242 result.push_back(overheadWireSegment);
243 }
244 return result;
245}
246
247
248void
250 // @note: assume iterator edge is handled elsewhere
251 assert(*edge == &sp->getLane().getEdge());
252 lane = &sp->getLane();
254 ncPars.edge = lane->getEdge().getID();
255 ncPars.lane = lane->getID();
256 ncPars.startPos = sp->getBeginLanePosition();
257 ncPars.endPos = sp->getEndLanePosition();
260 }
261 switch (sp->getElement()) {
264 busstop = sp;
265 ncPars.busstop = sp->getID();
266 break;
268 containerstop = sp;
269 ncPars.containerstop = sp->getID();
270 break;
272 parkingarea = dynamic_cast<MSParkingArea*>(sp);
273 ncPars.parkingarea = sp->getID();
274 break;
276 chargingStation = sp;
277 ncPars.chargingStation = sp->getID();
278 break;
281 ncPars.overheadWireSegment = sp->getID();
282 break;
283 default:
284 // should not happen
285 assert(false);
286 }
287}
288
289/****************************************************************************/
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
constexpr SUMOTime TIME2STEPS(double x)
Definition SUMOTime.h:60
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
double sample(SumoRNG *which=nullptr) const
Draw a sample of the distribution using the given RNG.
MESegment * getSegmentForEdge(const MSEdge &e, double pos=0)
Get the segment for a given edge at a given position.
Definition MELoop.cpp:384
const MSEdge & getEdge() const
Returns the edge this segment belongs to.
Definition MESegment.h:374
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
double getOppositePos(double pos) const
return the corresponding position on the opposite lane
Definition MSLane.cpp:4468
MSEdge & getEdge() const
Returns the lane's edge.
Definition MSLane.h:790
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:201
MSStoppingPlace * getStoppingPlace(const std::string &id, const SumoXMLTag category) const
Returns the named stopping place of the given category.
Definition MSNet.cpp:1521
A lane area vehicles can halt at.
double getLastFreePos(const SUMOVehicle &forVehicle, double brakePos=0) const override
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:130
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:227
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:215
std::string getDescription(bool nameOnly=false) const
get a short description for showing in the gui
Definition MSStop.cpp:72
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:173
void initPars(const SUMOVehicleParameter::Stop &stopPar)
initialize attributes from the given stop parameters
Definition MSStop.cpp:151
int getStateFlagsOld() const
return flags as used by Vehicle::getStopState
Definition MSStop.cpp:167
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:202
bool isInRange(const double pos, const double tolerance) const
whether the stop is in range of the given position
Definition MSStop.cpp:221
const MSEdge * getEdge() const
Definition MSStop.cpp:57
double getReachedThreshold() const
return startPos taking into account opposite stopping
Definition MSStop.cpp:67
double getEndPos(const SUMOVehicle &veh) const
return halting position for upcoming stop;
Definition MSStop.cpp:38
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:113
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:190
void replaceStoppingPlace(MSStoppingPlace *sp)
modify all properties so the stop happens at sp instead
Definition MSStop.cpp:249
SUMOTime getArrival() const
return arrival / started time
Definition MSStop.cpp:196
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: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, const bool escape=false)
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
static SumoRNG * getParsingRNG()
get parsing RNG
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)
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.
Distribution_Parameterized durationDist
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.