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.org/sumo
3 // Copyright (C) 2005-2022 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 "MSParkingArea.h"
26 #include "MSStoppingPlace.h"
27 #include "MSStop.h"
28 
29 
30 // ===========================================================================
31 // method definitions
32 // ===========================================================================
33 double
34 MSStop::getEndPos(const SUMOVehicle& veh) const {
35  const double brakePos = veh.getEdge() == getEdge() ? veh.getPositionOnLane() + veh.getBrakeGap() : 0;
36  if (busstop != nullptr) {
37  return busstop->getLastFreePos(veh, brakePos);
38  } else if (containerstop != nullptr) {
39  return containerstop->getLastFreePos(veh, brakePos);
40  } else if (parkingarea != nullptr) {
41  return parkingarea->getLastFreePos(veh, brakePos);
42  } else if (chargingStation != nullptr) {
43  return chargingStation->getLastFreePos(veh);
44  } else if (overheadWireSegment != nullptr) {
46  }
47  return pars.endPos;
48 }
49 
50 const MSEdge*
51 MSStop::getEdge() const {
52  if (lane != nullptr) {
53  return &lane->getEdge();
54  } else if (segment != nullptr) {
55  return &segment->getEdge();
56  }
57  return nullptr;
58 }
59 
60 double
63 }
64 
65 std::string
67  std::string result;
68  if (parkingarea != nullptr) {
69  result = "parkingArea:" + parkingarea->getID();
70  } else if (containerstop != nullptr) {
71  result = "containerStop:" + containerstop->getID();
72  } else if (busstop != nullptr) {
73  result = "busStop:" + busstop->getID();
74  } else if (chargingStation != nullptr) {
75  result = "chargingStation:" + chargingStation->getID();
76  } else if (overheadWireSegment != nullptr) {
77  result = "overheadWireSegment:" + overheadWireSegment->getID();
78  } else {
79  result = "lane:" + lane->getID() + " pos:" + toString(pars.endPos);
80  }
81  if (pars.actType != "") {
82  result += " actType:" + pars.actType;
83  }
84  return result;
85 }
86 
87 
88 void
91  tmp.duration = duration;
92  if (busstop == nullptr
93  && containerstop == nullptr
94  && parkingarea == nullptr
95  && chargingStation == nullptr) {
97  }
98  tmp.write(dev, false);
99  // if the stop has already started but hasn't ended yet we are writing it in
100  // the context of saveState (but we do not want to write the attribute twice
101  if (pars.started >= 0 && (pars.parametersSet & STOP_STARTED_SET) == 0) {
103  }
104  dev.closeTag();
105 }
106 
107 void
114  duration = stopPar.duration;
115  triggered = stopPar.triggered;
117  joinTriggered = stopPar.joinTriggered || stopPar.join != "";
118  numExpectedPerson = (int)stopPar.awaitedPersons.size();
119  numExpectedContainer = (int)stopPar.awaitedContainers.size();
120 }
121 
122 
123 
124 /****************************************************************************/
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
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
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:352
A road/street connecting two junctions.
Definition: MSEdge.h:77
double getOppositePos(double pos) const
return the corresponding position on the opposite lane
Definition: MSLane.cpp:3817
MSEdge & getEdge() const
Returns the lane's edge.
Definition: MSLane.h:674
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:174
MSStoppingPlace * getStoppingPlace(const std::string &id, const SumoXMLTag category) const
Returns the named stopping place of the given category.
Definition: MSNet.cpp:1250
A lane area vehicles can halt at.
Definition: MSParkingArea.h:58
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:89
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
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:89
void initPars(const SUMOVehicleParameter::Stop &stopPar)
initialize attributes from the given stop parameters
Definition: MSStop.cpp:108
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
const MSEdge * getEdge() const
Definition: MSStop.cpp:51
double getReachedThreshold() const
return startPos taking into account opposite stopping
Definition: MSStop.cpp:61
double getEndPos(const SUMOVehicle &veh) const
return halting position for upcoming stop;
Definition: MSStop.cpp:34
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:66
SUMOTime duration
The stopping duration.
Definition: MSStop.h:67
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:248
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 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)
SUMOTime started
the time at which this stop was reached
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
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.
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.