SUMO - Simulation of Urban MObility
MSStoppingPlace.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 // A lane area vehicles can halt at
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
11 // Copyright (C) 2005-2017 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <cassert>
33 #include <map>
35 #include <utils/geom/Position.h>
36 #include <microsim/MSVehicleType.h>
37 #include "MSLane.h"
38 #include "MSTransportable.h"
39 #include "MSStoppingPlace.h"
40 
41 
42 // ===========================================================================
43 // method definitions
44 // ===========================================================================
45 MSStoppingPlace::MSStoppingPlace(const std::string& id,
46  const std::vector<std::string>& lines,
47  MSLane& lane,
48  double begPos, double endPos, const std::string name)
49  : Named(id), myLines(lines), myLane(lane),
50  myBegPos(begPos), myEndPos(endPos), myLastFreePos(endPos), myWaitingPos(endPos), myName(name) {
52 }
53 
54 
56 
57 
58 const MSLane&
60  return myLane;
61 }
62 
63 
64 double
66  return myBegPos;
67 }
68 
69 
70 double
72  return myEndPos;
73 }
74 
75 
76 void
77 MSStoppingPlace::enter(SUMOVehicle* what, double beg, double end) {
78  myEndPositions[what] = std::pair<double, double>(beg, end);
80 }
81 
82 
83 double
84 MSStoppingPlace::getLastFreePos(const SUMOVehicle& forVehicle) const {
85  if (myLastFreePos != myEndPos) {
86  return myLastFreePos - forVehicle.getVehicleType().getMinGap();
87  }
88  return myLastFreePos;
89 }
90 
91 
95 }
96 
97 
98 double
100  std::map<const SUMOVehicle*, std::pair<double, double> >::const_iterator i = myEndPositions.find(veh);
101  if (i != myEndPositions.end()) {
102  return i->second.second;
103  } else {
104  return getLastFreePos(*veh);
105  }
106 }
107 
108 void
110  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 bool
151 MSStoppingPlace::hasAccess(const MSEdge* edge) const {
152  if (edge == &myLane.getEdge()) {
153  return true;
154  }
155  for (std::multimap<MSLane*, double>::const_iterator i = myAccessPos.begin(); i != myAccessPos.end(); ++i) {
156  if (edge == &i->first->getEdge()) {
157  return true;
158  }
159  }
160  return false;
161 }
162 
163 
164 const std::string&
166  return myName;
167 }
168 
169 /****************************************************************************/
170 
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.
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:582
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.
const PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:426
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:67
double myLastFreePos
The last free position at this stop (variable)
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
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:46
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:442
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:79
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle&#39;s type.