SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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-2016 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 #ifdef CHECK_MEMORY_LEAKS
42 #include <foreign/nvwa/debug_new.h>
43 #endif // CHECK_MEMORY_LEAKS
44 
45 
46 // ===========================================================================
47 // method definitions
48 // ===========================================================================
49 MSStoppingPlace::MSStoppingPlace(const std::string& id,
50  const std::vector<std::string>& lines,
51  MSLane& lane,
52  SUMOReal begPos, SUMOReal endPos)
53  : Named(id), myLines(lines), myLane(lane),
54  myBegPos(begPos), myEndPos(endPos), myLastFreePos(endPos), myWaitingPos(endPos) {
56 }
57 
58 
60 
61 
62 const MSLane&
64  return myLane;
65 }
66 
67 
70  return myBegPos;
71 }
72 
73 
76  return myEndPos;
77 }
78 
79 
80 void
82  myEndPositions[what] = std::pair<SUMOReal, SUMOReal>(beg, end);
84 }
85 
86 
88 MSStoppingPlace::getLastFreePos(const SUMOVehicle& forVehicle) const {
89  if (myLastFreePos != myEndPos) {
90  return myLastFreePos - forVehicle.getVehicleType().getMinGap();
91  }
92  return myLastFreePos;
93 }
94 
95 
99 }
100 
101 
102 SUMOReal
104  std::map<const SUMOVehicle*, std::pair<SUMOReal, SUMOReal> >::const_iterator i = myEndPositions.find(veh);
105  if (i != myEndPositions.end()) {
106  return i->second.second;
107  } else {
108  return getLastFreePos(*veh);
109  }
110 }
111 
112 void
114  myWaitingTransportables.push_back(p);
116 }
117 
118 
119 void
121  std::vector<MSTransportable*>::iterator i = std::find(myWaitingTransportables.begin(), myWaitingTransportables.end(), p);
122  if (i != myWaitingTransportables.end()) {
123  if (i == myWaitingTransportables.end() - 1) {
125  }
126  if (i == myWaitingTransportables.begin()) {
128  }
129  myWaitingTransportables.erase(i);
130  }
131 }
132 
133 
134 void
136  assert(myEndPositions.find(what) != myEndPositions.end());
137  myEndPositions.erase(myEndPositions.find(what));
139 }
140 
141 
142 void
145  std::map<const SUMOVehicle*, std::pair<SUMOReal, SUMOReal> >::iterator i;
146  for (i = myEndPositions.begin(); i != myEndPositions.end(); i++) {
147  if (myLastFreePos > (*i).second.second) {
148  myLastFreePos = (*i).second.second;
149  }
150  }
151 }
152 
153 
154 bool
155 MSStoppingPlace::hasAccess(const MSEdge* edge) const {
156  if (edge == &myLane.getEdge()) {
157  return true;
158  }
159  for (std::multimap<MSLane*, SUMOReal>::const_iterator i = myAccessPos.begin(); i != myAccessPos.end(); ++i) {
160  if (edge == &i->first->getEdge()) {
161  return true;
162  }
163  }
164  return false;
165 }
166 
167 /****************************************************************************/
168 
MSEdge & getEdge() const
Returns the lane's edge.
Definition: MSLane.h:571
std::vector< MSTransportable * > myWaitingTransportables
Persons waiting at this stop.
SUMOReal myWaitingPos
The next free position for persons / containers.
SUMOReal getLength() const
Get vehicle's length [m].
SUMOReal getEndLanePosition() const
Returns the end position of this stop.
const SUMOReal myEndPos
The end position this bus stop is located at.
SUMOReal 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.
const SUMOReal myBegPos
The begin position this bus stop is located at.
void addTransportable(MSTransportable *p)
adds a transportable to this stop
virtual ~MSStoppingPlace()
Destructor.
std::multimap< MSLane *, SUMOReal > 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.
const MSVehicleType & getVehicleType() const
const MSLane & getLane() const
Returns the lane this stop is located at.
Representation of a vehicle.
Definition: SUMOVehicle.h:66
SUMOReal getMinGap() const
Get the free space in front of vehicles of this class.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
bool hasAccess(const MSEdge *edge) const
checks whether this stop provides access to the given edge
SUMOReal getLastFreePos(const SUMOVehicle &forVehicle) const
Returns the last free position on this stop.
Position positionAtOffset(SUMOReal pos, SUMOReal lateralOffset=0) const
Returns the position at the given length.
MSStoppingPlace(const std::string &id, const std::vector< std::string > &lines, MSLane &lane, SUMOReal begPos, SUMOReal endPos)
Constructor.
void removeTransportable(MSTransportable *p)
Removes a transportable from this stop.
Position getWaitPosition() const
Returns the next free waiting place for pedestrians / containers.
Base class for objects which have an id.
Definition: Named.h:46
void enter(SUMOVehicle *what, SUMOReal beg, SUMOReal end)
Called if a vehicle enters this stop.
void leaveFrom(SUMOVehicle *what)
Called if a vehicle leaves this stop.
SUMOReal myLastFreePos
The last free position at this stop (variable)
SUMOReal interpolateLanePosToGeometryPos(SUMOReal lanePos) const
Definition: MSLane.h:438
SUMOReal getBeginLanePosition() const
Returns the begin position of this stop.
void computeLastFreePos()
Computes the last free position on this stop.
std::map< const SUMOVehicle *, std::pair< SUMOReal, SUMOReal > > myEndPositions
A map from objects (vehicles) to the areas they acquire after entering the stop.
const PositionVector & getShape() const
Returns this lane's shape.
Definition: MSLane.h:427
#define SUMOReal
Definition: config.h:214
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle's type.