SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MSBusStop.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // A lane area vehicles can halt at
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
10 // Copyright (C) 2001-2014 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
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 "MSTrigger.h"
33 #include "MSBusStop.h"
35 #include <microsim/MSVehicleType.h>
36 
37 #ifdef CHECK_MEMORY_LEAKS
38 #include <foreign/nvwa/debug_new.h>
39 #endif // CHECK_MEMORY_LEAKS
40 
41 
42 // ===========================================================================
43 // method definitions
44 // ===========================================================================
45 MSBusStop::MSBusStop(const std::string& id,
46  const std::vector<std::string>& lines,
47  MSLane& lane,
48  SUMOReal begPos, SUMOReal endPos)
49  : Named(id), myLines(lines), myLane(lane),
50  myBegPos(begPos), myEndPos(endPos), myLastFreePos(endPos) {
52 }
53 
54 
56 
57 
58 const MSLane&
60  return myLane;
61 }
62 
63 
66  return myBegPos;
67 }
68 
69 
72  return myEndPos;
73 }
74 
75 
76 void
78  myEndPositions[what] = std::pair<SUMOReal, SUMOReal>(beg, end);
80 }
81 
82 
84 MSBusStop::getLastFreePos(const SUMOVehicle& forVehicle) const {
85  if (myLastFreePos != myEndPos) {
86  return myLastFreePos - forVehicle.getVehicleType().getMinGap();
87  }
88  return myLastFreePos;
89 }
90 
91 
92 void
94  assert(myEndPositions.find(what) != myEndPositions.end());
95  myEndPositions.erase(myEndPositions.find(what));
97 }
98 
99 
100 void
103  std::map<SUMOVehicle*, std::pair<SUMOReal, SUMOReal> >::iterator i;
104  for (i = myEndPositions.begin(); i != myEndPositions.end(); i++) {
105  if (myLastFreePos > (*i).second.second) {
106  myLastFreePos = (*i).second.second;
107  }
108  }
109 }
110 
111 
112 
113 /****************************************************************************/
114 
SUMOReal myEndPos
The end position this bus stop is located at.
Definition: MSBusStop.h:178
SUMOReal getEndLanePosition() const
Returns the end position of this bus stop.
Definition: MSBusStop.cpp:71
SUMOReal getBeginLanePosition() const
Returns the begin position of this bus stop.
Definition: MSBusStop.cpp:65
const MSLane & getLane() const
Returns the lane this bus stop is located at.
Definition: MSBusStop.cpp:59
void computeLastFreePos()
Computes the last free position on this stop.
Definition: MSBusStop.cpp:101
void enter(SUMOVehicle *what, SUMOReal beg, SUMOReal end)
Called if a vehicle enters this stop.
Definition: MSBusStop.cpp:77
Representation of a vehicle.
Definition: SUMOVehicle.h:63
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:172
void leaveFrom(SUMOVehicle *what)
Called if a vehicle leaves this stop.
Definition: MSBusStop.cpp:93
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:84
MSBusStop(const std::string &id, const std::vector< std::string > &lines, MSLane &lane, SUMOReal begPos, SUMOReal endPos)
Constructor.
Definition: MSBusStop.cpp:45
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:169
SUMOReal myBegPos
The begin position this bus stop is located at.
Definition: MSBusStop.h:175
virtual ~MSBusStop()
Destructor.
Definition: MSBusStop.cpp:55
#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:181
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle's type.