SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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-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 <microsim/MSVehicleType.h>
35 #include "MSStoppingPlace.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 MSStoppingPlace::MSStoppingPlace(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 MSStoppingPlace::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 getEndLanePosition() const
Returns the end position of this stop.
virtual ~MSStoppingPlace()
Destructor.
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.
SUMOReal myEndPos
The end position this bus stop is located at.
SUMOReal getLastFreePos(const SUMOVehicle &forVehicle) const
Returns the last free position on this stop.
SUMOReal myBegPos
The begin position this bus stop is located at.
MSLane & myLane
The lane this bus stop is located at.
MSStoppingPlace(const std::string &id, const std::vector< std::string > &lines, MSLane &lane, SUMOReal begPos, SUMOReal endPos)
Constructor.
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 getBeginLanePosition() const
Returns the begin position of this stop.
void computeLastFreePos()
Computes the last free position on this stop.
#define SUMOReal
Definition: config.h:215
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.