SUMO - Simulation of Urban MObility
MSStoppingPlace.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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
18 // A lane area vehicles can halt at
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
31 #include <cassert>
32 #include <map>
34 #include <utils/geom/Position.h>
35 #include <microsim/MSVehicleType.h>
36 #include "MSLane.h"
37 #include "MSTransportable.h"
38 #include "MSStoppingPlace.h"
39 
40 
41 // ===========================================================================
42 // method definitions
43 // ===========================================================================
44 MSStoppingPlace::MSStoppingPlace(const std::string& id,
45  const std::vector<std::string>& lines,
46  MSLane& lane,
47  double begPos, double endPos, const std::string name)
48  : Named(id), myLines(lines), myLane(lane),
49  myBegPos(begPos), myEndPos(endPos), myLastFreePos(endPos), myWaitingPos(endPos), myName(name) {
51 }
52 
53 
55 
56 
57 const MSLane&
59  return myLane;
60 }
61 
62 
63 double
65  return myBegPos;
66 }
67 
68 
69 double
71  return myEndPos;
72 }
73 
74 
75 void
76 MSStoppingPlace::enter(SUMOVehicle* what, double beg, double end) {
77  myEndPositions[what] = std::pair<double, double>(beg, end);
79 }
80 
81 
82 double
83 MSStoppingPlace::getLastFreePos(const SUMOVehicle& forVehicle) const {
84  if (myLastFreePos != myEndPos) {
85  return myLastFreePos - forVehicle.getVehicleType().getMinGap();
86  }
87  return myLastFreePos;
88 }
89 
90 
94 }
95 
96 
97 double
99  std::map<const SUMOVehicle*, std::pair<double, double> >::const_iterator i = myEndPositions.find(veh);
100  if (i != myEndPositions.end()) {
101  return i->second.second;
102  } else {
103  return getLastFreePos(*veh);
104  }
105 }
106 
107 void
109  myWaitingTransportables.push_back(p);
112 }
113 
114 
115 void
117  std::vector<MSTransportable*>::iterator i = std::find(myWaitingTransportables.begin(), myWaitingTransportables.end(), p);
118  if (i != myWaitingTransportables.end()) {
119  if (i == myWaitingTransportables.end() - 1) {
121  }
122  if (i == myWaitingTransportables.begin()) {
124  }
125  myWaitingTransportables.erase(i);
126  }
127 }
128 
129 
130 void
132  assert(myEndPositions.find(what) != myEndPositions.end());
133  myEndPositions.erase(myEndPositions.find(what));
135 }
136 
137 
138 void
141  std::map<const SUMOVehicle*, std::pair<double, double> >::iterator i;
142  for (i = myEndPositions.begin(); i != myEndPositions.end(); i++) {
143  if (myLastFreePos > (*i).second.second) {
144  myLastFreePos = (*i).second.second;
145  }
146  }
147 }
148 
149 
150 double
152  if (edge == &myLane.getEdge()) {
153  return (myBegPos + myEndPos) / 2.;
154  }
155  for (std::multimap<MSLane*, double>::const_iterator i = myAccessPos.begin(); i != myAccessPos.end(); ++i) {
156  if (edge == &i->first->getEdge()) {
157  return i->second;
158  }
159  }
160  return -1.;
161 }
162 
163 
164 bool
165 MSStoppingPlace::hasAccess(const MSEdge* edge) const {
166  if (edge == &myLane.getEdge()) {
167  return true;
168  }
169  for (std::multimap<MSLane*, double>::const_iterator i = myAccessPos.begin(); i != myAccessPos.end(); ++i) {
170  if (edge == &i->first->getEdge()) {
171  return true;
172  }
173  }
174  return false;
175 }
176 
177 
178 const std::string&
180  return myName;
181 }
182 
183 
184 /****************************************************************************/
Position getWaitPosition() const
Returns the next free waiting place for pedestrians / containers.
std::map< const SUMOVehicle *, std::pair< double, double > > myEndPositions
A map from objects (vehicles) to the areas they acquire after entering the stop.
double getAccessPos(const MSEdge *edge) const
the position on the given edge which is connected to this stop, -1 on failure
MSStoppingPlace(const std::string &id, const std::vector< std::string > &lines, MSLane &lane, double begPos, double endPos, const std::string name="")
Constructor.
MSEdge & getEdge() const
Returns the lane&#39;s edge.
Definition: MSLane.h:607
double getBeginLanePosition() const
Returns the begin position of this stop.
std::vector< MSTransportable * > myWaitingTransportables
Persons waiting at this stop.
bool hasAccess(const MSEdge *edge) const
checks whether this stop provides access to the given edge
const double myEndPos
The end position this bus stop is located at.
void enter(SUMOVehicle *what, double beg, double end)
Called if a vehicle enters this stop.
double getLastFreePos(const SUMOVehicle &forVehicle) const
Returns the last free position on this stop.
T MAX2(T a, T b)
Definition: StdDefs.h:73
const PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:439
const std::string & getMyName() const
void addTransportable(MSTransportable *p)
adds a transportable to this stop
virtual ~MSStoppingPlace()
Destructor.
std::multimap< MSLane *, double > myAccessPos
lanes and positions connected to this stop
A road/street connecting two junctions.
Definition: MSEdge.h:80
const MSLane & myLane
The lane this bus stop is located at.
double getEndLanePosition() const
Returns the end position of this stop.
Representation of a vehicle.
Definition: SUMOVehicle.h:66
double myLastFreePos
The last free position at this stop (variable)
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
double getMinGap() const
Get the free space in front of vehicles of this class.
void removeTransportable(MSTransportable *p)
Removes a transportable from this stop.
Base class for objects which have an id.
Definition: Named.h:54
void leaveFrom(SUMOVehicle *what)
Called if a vehicle leaves this stop.
const std::string myName
The name of the stopping place.
const double myBegPos
The begin position this bus stop is located at.
double interpolateLanePosToGeometryPos(double lanePos) const
Definition: MSLane.h:455
double getLength() const
Get vehicle&#39;s length [m].
void computeLastFreePos()
Computes the last free position on this stop.
const MSVehicleType & getVehicleType() const
double myWaitingPos
The next free position for persons / containers.
const MSLane & getLane() const
Returns the lane this stop is located at.
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
double getStoppingPosition(const SUMOVehicle *veh) const
For vehicles at the stop this gives the the actual stopping position of the vehicle. For all others the last free stopping position.
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle&#39;s type.