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