SUMO - Simulation of Urban MObility
MSBusStop.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-sim.org/
11 // Copyright (C) 2005-2014 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 "MSTrigger.h"
34 #include "MSBusStop.h"
36 #include <microsim/MSVehicleType.h>
37 
38 #ifdef CHECK_MEMORY_LEAKS
39 #include <foreign/nvwa/debug_new.h>
40 #endif // CHECK_MEMORY_LEAKS
41 
42 
43 // ===========================================================================
44 // method definitions
45 // ===========================================================================
46 MSBusStop::MSBusStop(const std::string& id,
47  const std::vector<std::string>& lines,
48  MSLane& lane,
49  SUMOReal begPos, SUMOReal endPos)
50  : Named(id), myLines(lines), myLane(lane),
51  myBegPos(begPos), myEndPos(endPos), myLastFreePos(endPos) {
53 }
54 
55 
57 
58 
59 const MSLane&
61  return myLane;
62 }
63 
64 
67  return myBegPos;
68 }
69 
70 
73  return myEndPos;
74 }
75 
76 
77 void
79  myEndPositions[what] = std::pair<SUMOReal, SUMOReal>(beg, end);
81 }
82 
83 
85 MSBusStop::getLastFreePos(const SUMOVehicle& forVehicle) const {
86  if (myLastFreePos != myEndPos) {
87  return myLastFreePos - forVehicle.getVehicleType().getMinGap();
88  }
89  return myLastFreePos;
90 }
91 
92 
93 void
95  assert(myEndPositions.find(what) != myEndPositions.end());
96  myEndPositions.erase(myEndPositions.find(what));
98 }
99 
100 
101 void
104  std::map<SUMOVehicle*, std::pair<SUMOReal, SUMOReal> >::iterator i;
105  for (i = myEndPositions.begin(); i != myEndPositions.end(); i++) {
106  if (myLastFreePos > (*i).second.second) {
107  myLastFreePos = (*i).second.second;
108  }
109  }
110 }
111 
112 
113 
114 /****************************************************************************/
115 
SUMOReal myEndPos
The end position this bus stop is located at.
Definition: MSBusStop.h:179
SUMOReal getEndLanePosition() const
Returns the end position of this bus stop.
Definition: MSBusStop.cpp:72
SUMOReal getBeginLanePosition() const
Returns the begin position of this bus stop.
Definition: MSBusStop.cpp:66
const MSLane & getLane() const
Returns the lane this bus stop is located at.
Definition: MSBusStop.cpp:60
void computeLastFreePos()
Computes the last free position on this stop.
Definition: MSBusStop.cpp:102
void enter(SUMOVehicle *what, SUMOReal beg, SUMOReal end)
Called if a vehicle enters this stop.
Definition: MSBusStop.cpp:78
Representation of a vehicle.
Definition: SUMOVehicle.h:64
SUMOReal getMinGap() const
Get the free space in front of vehicles of this class.
MSLane & myLane
The lane this bus stop is located at.
Definition: MSBusStop.h:173
void leaveFrom(SUMOVehicle *what)
Called if a vehicle leaves this stop.
Definition: MSBusStop.cpp:94
Base class for objects which have an id.
Definition: Named.h:45
SUMOReal getLastFreePos(const SUMOVehicle &forVehicle) const
Returns the last free position on this stop.
Definition: MSBusStop.cpp:85
MSBusStop(const std::string &id, const std::vector< std::string > &lines, MSLane &lane, SUMOReal begPos, SUMOReal endPos)
Constructor.
Definition: MSBusStop.cpp:46
std::map< SUMOVehicle *, std::pair< SUMOReal, SUMOReal > > myEndPositions
A map from objects (vehicles) to the areas they acquire after entering the stop.
Definition: MSBusStop.h:170
SUMOReal myBegPos
The begin position this bus stop is located at.
Definition: MSBusStop.h:176
virtual ~MSBusStop()
Destructor.
Definition: MSBusStop.cpp:56
#define SUMOReal
Definition: config.h:215
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
SUMOReal myLastFreePos
The last free position at this stop (variable)
Definition: MSBusStop.h:182
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle's type.