SUMO - Simulation of Urban MObility
MSParkingArea.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2015-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
18 // A area where vehicles can park next to the road
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>
33 #include <utils/geom/Position.h>
34 #include <utils/geom/GeomHelper.h>
35 #include <microsim/MSNet.h>
36 #include <microsim/MSVehicleType.h>
37 #include "MSLane.h"
38 #include "MSTransportable.h"
39 #include "MSParkingArea.h"
40 
41 
42 // ===========================================================================
43 // method definitions
44 // ===========================================================================
45 MSParkingArea::MSParkingArea(const std::string& id,
46  const std::vector<std::string>& lines,
47  MSLane& lane,
48  double begPos, double endPos,
49  unsigned int capacity,
50  double width, double length, double angle) :
51  MSStoppingPlace(id, lines, lane, begPos, endPos),
52  myCapacity(capacity),
53  myWidth(width),
54  myLength(length),
55  myAngle(angle) {
56  // initialize unspecified defaults
57  if (myWidth == 0) {
59  }
60  if (myLength == 0) {
62  }
63 
64  const double offset = MSNet::getInstance()->lefthand() ? -1 : 1;
65  myShape = lane.getShape().getSubpart(
67  lane.interpolateLanePosToGeometryPos(endPos));
68  myShape.move2side((lane.getWidth() / 2. + myWidth / 2.) * offset);
69  // Initialize space occupancies if there is a road-side capacity
70  // The overall number of lots is fixed and each lot accepts one vehicle regardless of size
71  if (myCapacity > 0) {
72  for (int i = 1; i <= myCapacity; ++i) {
74  mySpaceOccupancies[i].index = i;
75  mySpaceOccupancies[i].vehicle = 0;
76  mySpaceOccupancies[i].myWidth = myWidth;
77  mySpaceOccupancies[i].myLength = myLength;
78  mySpaceOccupancies[i].myEndPos = myBegPos + getSpaceDim() * i;
79 
80  const Position& f = myShape.positionAtOffset(getSpaceDim() * (i - 1));
81  const Position& s = myShape.positionAtOffset(getSpaceDim() * (i));
82  double lot_angle = ((double) atan2((s.x() - f.x()), (f.y() - s.y())) * (double) 180.0 / (double) M_PI) + myAngle;
83  mySpaceOccupancies[i].myRotation = lot_angle;
84  if (myAngle == 0) {
85  // parking parallel to the road
86  mySpaceOccupancies[i].myPosition = s;
87  } else {
88  // angled parking
89  mySpaceOccupancies[i].myPosition = (f + s) * 0.5;
90  }
91 
92  }
93  }
95 }
96 
98 
99 double
100 MSParkingArea::getLastFreePos(const SUMOVehicle& /* forVehicle */) const {
101  return myLastFreePos;
102 }
103 
104 Position
106  std::map<unsigned int, LotSpaceDefinition >::iterator i;
107  for (i = mySpaceOccupancies.begin(); i != mySpaceOccupancies.end(); i++) {
108  if ((*i).second.vehicle == &forVehicle) {
109  return (*i).second.myPosition;
110  }
111  }
112  return Position::INVALID;
113 }
114 
115 double
117  std::map<unsigned int, LotSpaceDefinition >::iterator i;
118  for (i = mySpaceOccupancies.begin(); i != mySpaceOccupancies.end(); i++) {
119  if ((*i).second.vehicle == &forVehicle) {
120  return (((*i).second.myRotation - 90.) * (double) M_PI / (double) 180.0);
121  }
122  }
123  return 0.;
124 }
125 
126 
127 double
130 }
131 
132 
133 void
134 MSParkingArea::addLotEntry(double x, double y, double z,
135  double width, double length, double angle) {
136 
137  const int i = (int)mySpaceOccupancies.size() + 1;
138 
140  mySpaceOccupancies[i].index = i;
141  mySpaceOccupancies[i].vehicle = 0;
142  mySpaceOccupancies[i].myPosition = Position(x, y, z);
143  mySpaceOccupancies[i].myWidth = width;
144  mySpaceOccupancies[i].myLength = length;
145  mySpaceOccupancies[i].myRotation = angle;
146  mySpaceOccupancies[i].myEndPos = myEndPos;
147  myCapacity = (int)mySpaceOccupancies.size();
149 }
150 
151 
152 void
153 MSParkingArea::enter(SUMOVehicle* what, double beg, double end) {
154  if (myLastFreeLot >= 1 && myLastFreeLot <= (int)mySpaceOccupancies.size()) {
155  mySpaceOccupancies[myLastFreeLot].vehicle = what;
156  myEndPositions[what] = std::pair<double, double>(beg, end);
158  }
159 }
160 
161 
162 void
164  assert(myEndPositions.find(what) != myEndPositions.end());
165  std::map<unsigned int, LotSpaceDefinition >::iterator i;
166  for (i = mySpaceOccupancies.begin(); i != mySpaceOccupancies.end(); i++) {
167  if ((*i).second.vehicle == what) {
168  (*i).second.vehicle = 0;
169  break;
170  }
171  }
172  myEndPositions.erase(myEndPositions.find(what));
174 }
175 
176 
177 void
179  myLastFreeLot = 0;
181  std::map<unsigned int, LotSpaceDefinition >::iterator i;
182  for (i = mySpaceOccupancies.begin(); i != mySpaceOccupancies.end(); i++) {
183  if ((*i).second.vehicle == 0) {
184  myLastFreeLot = (*i).first;
185  myLastFreePos = (*i).second.myEndPos;
186  break;
187  }
188  }
189 }
190 
191 
192 double
194  return myWidth;
195 }
196 
197 
198 double
200  return myLength;
201 }
202 
203 
204 double
206  return myAngle;
207 }
208 
209 
210 int
212  return myCapacity;
213 }
214 
215 
216 int
218  return (int)myEndPositions.size();
219 }
220 
221 
222 /****************************************************************************/
std::map< const SUMOVehicle *, std::pair< double, double > > myEndPositions
A map from objects (vehicles) to the areas they acquire after entering the stop.
double getSpaceDim() const
Returns the space dimension.
int myLastFreeLot
Last free lot number (0 no free lot)
A lane area vehicles can halt at.
void enter(SUMOVehicle *what, double beg, double end)
Called if a vehicle enters this stop.
const double myEndPos
The end position this bus stop is located at.
const double SUMO_const_laneWidth
Definition: StdDefs.h:49
double y() const
Returns the y-position.
Definition: Position.h:67
double x() const
Returns the x-position.
Definition: Position.h:62
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:167
const PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:439
double getWidth() const
Returns the lane&#39;s width.
Definition: MSLane.h:513
double myAngle
The default angle of each parking space.
const MSLane & myLane
The lane this bus stop is located at.
MSParkingArea(const std::string &id, const std::vector< std::string > &lines, MSLane &lane, double begPos, double endPos, unsigned int capacity, double width, double length, double angle)
Constructor.
double getVehicleAngle(const SUMOVehicle &forVehicle)
Returns the angle of parked vehicle.
Representation of a vehicle.
Definition: SUMOVehicle.h:66
double myLastFreePos
The last free position at this stop (variable)
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
PositionVector myShape
The roadside shape of this parkingArea.
double myLength
The default length of each parking space.
int getCapacity() const
Returns the area capacity.
PositionVector getSubpart(double beginOffset, double endOffset) const
get subpart of a position vector
void computeLastFreePos()
Computes the last free position on this stop.
bool lefthand() const
return whether the network was built for lefthand traffic
Definition: MSNet.h:597
int getOccupancy() const
Returns the area occupancy.
void move2side(double amount)
move position vector to side using certain ammount
void addLotEntry(double x, double y, double z, double width, double length, double angle)
Add a lot entry to parking area.
double getLength() const
Returns the lot rectangle length.
const double myBegPos
The begin position this bus stop is located at.
int myCapacity
Stop area capacity.
void leaveFrom(SUMOVehicle *what)
Called if a vehicle leaves this stop.
double getWidth() const
Returns the lot rectangle width.
#define M_PI
Definition: odrSpiral.cpp:40
virtual ~MSParkingArea()
Destructor.
double interpolateLanePosToGeometryPos(double lanePos) const
Definition: MSLane.h:455
Representation of a single lot space.
Position getVehiclePosition(const SUMOVehicle &forVehicle)
Returns the position of parked vehicle.
double getLastFreePos(const SUMOVehicle &forVehicle) const
Returns the last free position on this stop.
std::map< unsigned int, LotSpaceDefinition > mySpaceOccupancies
A map from objects (vehicles) to the areas they acquire after entering the stop.
double myWidth
The default width of each parking space.
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
double getAngle() const
Returns the lot rectangle angle.
static const Position INVALID
used to indicate that a position is valid
Definition: Position.h:277