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-2015 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>
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 #ifdef CHECK_MEMORY_LEAKS
41 #include <foreign/nvwa/debug_new.h>
42 #endif // CHECK_MEMORY_LEAKS
43 
44 
45 // ===========================================================================
46 // method definitions
47 // ===========================================================================
48 MSStoppingPlace::MSStoppingPlace(const std::string& id,
49  const std::vector<std::string>& lines,
50  MSLane& lane,
51  SUMOReal begPos, SUMOReal endPos)
52  : Named(id), myLines(lines), myLane(lane),
53  myBegPos(begPos), myEndPos(endPos), myLastFreePos(endPos), myWaitingPos(endPos) {
55 }
56 
57 
59 
60 
61 const MSLane&
63  return myLane;
64 }
65 
66 
69  return myBegPos;
70 }
71 
72 
75  return myEndPos;
76 }
77 
78 
79 void
81  myEndPositions[what] = std::pair<SUMOReal, SUMOReal>(beg, end);
83 }
84 
85 
87 MSStoppingPlace::getLastFreePos(const SUMOVehicle& forVehicle) const {
88  if (myLastFreePos != myEndPos) {
89  return myLastFreePos - forVehicle.getVehicleType().getMinGap();
90  }
91  return myLastFreePos;
92 }
93 
94 
98 }
99 
100 
101 void
103  myWaitingTransportables.push_back(p);
105 }
106 
107 
108 void
110  std::vector<MSTransportable*>::iterator i = std::find(myWaitingTransportables.begin(), myWaitingTransportables.end(), p);
111  if (i != myWaitingTransportables.end()) {
112  if (i == myWaitingTransportables.end() - 1) {
114  }
115  if (i == myWaitingTransportables.begin()) {
117  }
118  myWaitingTransportables.erase(i);
119  }
120 }
121 
122 
123 void
125  assert(myEndPositions.find(what) != myEndPositions.end());
126  myEndPositions.erase(myEndPositions.find(what));
128 }
129 
130 
131 void
134  std::map<SUMOVehicle*, std::pair<SUMOReal, SUMOReal> >::iterator i;
135  for (i = myEndPositions.begin(); i != myEndPositions.end(); i++) {
136  if (myLastFreePos > (*i).second.second) {
137  myLastFreePos = (*i).second.second;
138  }
139  }
140 }
141 
142 
143 
144 /****************************************************************************/
145 
std::vector< MSTransportable * > myWaitingTransportables
Persons waiting at this stop.
SUMOReal myWaitingPos
The next free position for persons / containers.
SUMOReal getLength() const
Get vehicle&#39;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.
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.
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:65
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
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:45
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:334
SUMOReal getBeginLanePosition() const
Returns the begin position of this stop.
void computeLastFreePos()
Computes the last free position on this stop.
const PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:323
#define SUMOReal
Definition: config.h:214
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
std::map< SUMOVehicle *, std::pair< SUMOReal, SUMOReal > > myEndPositions
A map from objects (vehicles) to the areas they acquire after entering the stop.
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle&#39;s type.