Eclipse SUMO - Simulation of Urban MObility
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-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 /****************************************************************************/
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 MSStop::getEndPos(const SUMOVehicle& veh) const {
36  const double brakePos = veh.getEdge() == getEdge() ? veh.getPositionOnLane() + veh.getBrakeGap() : 0;
37  if ((pars.parametersSet & STOP_END_SET) != 0) {
38  return pars.endPos;
39  } else if (busstop != nullptr) {
40  return busstop->getLastFreePos(veh, brakePos);
41  } else if (containerstop != nullptr) {
42  return containerstop->getLastFreePos(veh, brakePos);
43  } else if (parkingarea != nullptr) {
44  return parkingarea->getLastFreePos(veh, brakePos);
45  } else if (chargingStation != nullptr) {
46  return chargingStation->getLastFreePos(veh);
47  } else if (overheadWireSegment != nullptr) {
49  }
50  return pars.endPos;
51 }
52 
53 const MSEdge*
54 MSStop::getEdge() const {
55  if (lane != nullptr) {
56  return &lane->getEdge();
57  } else if (segment != nullptr) {
58  return &segment->getEdge();
59  }
60  return nullptr;
61 }
62 
63 double
66 }
67 
68 std::string
70  std::string result;
71  if (parkingarea != nullptr) {
72  result = "parkingArea:" + parkingarea->getID();
73  } else if (containerstop != nullptr) {
74  result = "containerStop:" + containerstop->getID();
75  } else if (busstop != nullptr) {
76  result = "busStop:" + busstop->getID();
77  } else if (chargingStation != nullptr) {
78  result = "chargingStation:" + chargingStation->getID();
79  } else if (overheadWireSegment != nullptr) {
80  result = "overheadWireSegment:" + overheadWireSegment->getID();
81  } else {
82  result = "lane:" + lane->getID() + " pos:" + toString(pars.endPos);
83  }
84  if (pars.actType != "") {
85  result += " actType:" + pars.actType;
86  }
87  return result;
88 }
89 
90 
91 void
94  tmp.duration = duration;
95  if (busstop == nullptr
96  && containerstop == nullptr
97  && parkingarea == nullptr
98  && chargingStation == nullptr) {
100  }
101  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  if (pars.started >= 0 && (pars.parametersSet & STOP_STARTED_SET) == 0) {
106  }
107  pars.writeParams(dev);
108  dev.closeTag();
109 }
110 
111 void
118  duration = stopPar.duration;
119  triggered = stopPar.triggered;
121  joinTriggered = stopPar.joinTriggered || stopPar.join != "";
122  numExpectedPerson = (int)stopPar.awaitedPersons.size();
123  numExpectedContainer = (int)stopPar.awaitedContainers.size();
124 }
125 
126 
127 int
129  return ((reached ? 1 : 0) + 2 * pars.getFlags());
130 }
131 
132 
133 SUMOTime
135  if (MSGlobals::gUseStopEnded && pars.ended >= 0) {
136  return pars.ended - time;
137  }
138  if (pars.until >= 0) {
139  if (duration == -1) {
140  return pars.until - time;
141  } else {
142  return MAX2(duration, pars.until - time);
143  }
144  } else {
145  return duration;
146  }
147 }
148 
149 
150 SUMOTime
153 }
154 
155 
156 double
158  return skipOnDemand ? std::numeric_limits<double>::max() : pars.speed;
159 }
160 
161 
162 bool
163 MSStop::isInRange(const double pos, const double tolerance) const {
164  return pars.startPos - tolerance <= pos && pars.endPos + tolerance >= pos;
165 }
166 
167 /****************************************************************************/
long long int SUMOTime
Definition: GUI.h:35
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition: SUMOTime.cpp:69
const int STOP_START_SET
const int STOP_END_SET
const int STOP_STARTED_SET
@ SUMO_TAG_CHARGING_STATION
A Charging Station.
@ SUMO_TAG_CONTAINER_STOP
A container stop.
@ SUMO_TAG_BUS_STOP
A bus stop.
@ SUMO_TAG_PARKING_AREA
A parking area.
@ SUMO_TAG_OVERHEAD_WIRE_SEGMENT
An overhead wire segment.
@ SUMO_ATTR_STARTED
T MAX2(T a, T b)
Definition: StdDefs.h:82
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
const MSEdge & getEdge() const
Returns the edge this segment belongs to.
Definition: MESegment.h:359
A road/street connecting two junctions.
Definition: MSEdge.h:77
static bool gUseStopEnded
whether the simulation should replay previous stop times
Definition: MSGlobals.h:130
double getOppositePos(double pos) const
return the corresponding position on the opposite lane
Definition: MSLane.cpp:4254
MSEdge & getEdge() const
Returns the lane's edge.
Definition: MSLane.h:756
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:182
MSStoppingPlace * getStoppingPlace(const std::string &id, const SumoXMLTag category) const
Returns the named stopping place of the given category.
Definition: MSNet.cpp:1364
A lane area vehicles can halt at.
Definition: MSParkingArea.h:60
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:92
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
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:157
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:134
void initPars(const SUMOVehicleParameter::Stop &stopPar)
initialize attributes from the given stop parameters
Definition: MSStop.cpp:112
int getStateFlagsOld() const
return flags as used by Vehicle::getStopState
Definition: MSStop.cpp:128
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
bool skipOnDemand
whether the decision to skip this stop has been made
Definition: MSStop.h:89
bool isInRange(const double pos, const double tolerance) const
whether the stop is in range of the given position
Definition: MSStop.cpp:163
const MSEdge * getEdge() const
Definition: MSStop.cpp:54
double getReachedThreshold() const
return startPos taking into account opposite stopping
Definition: MSStop.cpp:64
double getEndPos(const SUMOVehicle &veh) const
return halting position for upcoming stop;
Definition: MSStop.cpp:35
int numExpectedPerson
The number of still expected persons.
Definition: MSStop.h:77
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
std::string getDescription() const
get a short description for showing in the gui
Definition: MSStop.cpp:69
SUMOTime duration
The stopping duration.
Definition: MSStop.h:67
SUMOTime getUntil() const
return until / ended time
Definition: MSStop.cpp:151
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
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.
Definition: OutputDevice.h:61
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:254
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:60
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
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 duration
The stopping duration.