SUMO - Simulation of Urban MObility
MSContainerStop.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>
33 //#include "MSTrigger.h"
34 #include "MSContainerStop.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 MSContainerStop::MSContainerStop(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 MSContainerStop::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 
const MSLane & getLane() const
Returns the lane this container stop is located at.
MSContainerStop(const std::string &id, const std::vector< std::string > &lines, MSLane &lane, SUMOReal begPos, SUMOReal endPos)
Constructor.
void leaveFrom(SUMOVehicle *what)
Called if a vehicle leaves this stop.
SUMOReal getEndLanePosition() const
Returns the end position of this container stop.
virtual ~MSContainerStop()
Destructor.
SUMOReal myBegPos
The begin position this stop is located at.
SUMOReal getBeginLanePosition() const
Returns the begin position of this container stop.
SUMOReal myEndPos
The end position this stop is located at.
SUMOReal getLastFreePos(const SUMOVehicle &forVehicle) const
Returns the last free position on this stop.
std::map< SUMOVehicle *, std::pair< SUMOReal, SUMOReal > > myEndPositions
A map from objects (vehicles) to the areas they acquire after entering the stop.
void computeLastFreePos()
Computes the last free position on this stop.
MSLane & myLane
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.
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.
SUMOReal myLastFreePos
The last free position at this stop (variable)
#define SUMOReal
Definition: config.h:218
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle's type.