SUMO - Simulation of Urban MObility
MSParkingArea.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 // A area where vehicles can park next to the road
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
11 // Copyright (C) 2015-2017 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 <utils/geom/Position.h>
35 #include <microsim/MSVehicleType.h>
37 #include "MSLane.h"
38 #include "MSTransportable.h"
39 #include "MSParkingArea.h"
40 
41 #ifdef CHECK_MEMORY_LEAKS
42 #include <foreign/nvwa/debug_new.h>
43 #endif // CHECK_MEMORY_LEAKS
44 
45 
46 // ===========================================================================
47 // method definitions
48 // ===========================================================================
49 MSParkingArea::MSParkingArea(const std::string& id,
50  const std::vector<std::string>& lines,
51  MSLane& lane,
52  SUMOReal begPos, SUMOReal endPos,
53  unsigned int capacity,
54  SUMOReal width, SUMOReal length, SUMOReal angle) :
55  MSStoppingPlace(id, lines, lane, begPos, endPos),
56  myCapacity(capacity),
57  myWidth(width),
58  myLength(length),
59  myAngle(angle) {
60  // initialize unspecified defaults
61  if (myWidth == 0) {
63  }
64  if (myLength == 0) {
66  }
67 
68  myShape = lane.getShape();
69  myShape.move2side(lane.getWidth() / 2. + myWidth / 2.);
70  myShape = myShape.getSubpart(begPos, endPos);
71  // Initialize space occupancies if there is a road-side capacity
72  // The overall number of lots is fixed and each lot accepts one vehicle regardless of size
73  if (myCapacity > 0) {
74  for (int i = 1; i <= myCapacity; ++i) {
76  mySpaceOccupancies[i].index = i;
77  mySpaceOccupancies[i].vehicle = 0;
78  mySpaceOccupancies[i].myWidth = myWidth;
79  mySpaceOccupancies[i].myLength = myLength;
80  mySpaceOccupancies[i].myEndPos = myBegPos + getSpaceDim() * i;
81 
82  const Position& f = myShape.positionAtOffset(getSpaceDim() * (i - 1));
83  const Position& s = myShape.positionAtOffset(getSpaceDim() * (i));
84  SUMOReal lot_angle = ((SUMOReal) atan2((s.x() - f.x()), (f.y() - s.y())) * (SUMOReal) 180.0 / (SUMOReal) PI) + myAngle;
85  mySpaceOccupancies[i].myRotation = lot_angle;
86  if (myAngle == 0) {
87  // parking parallel to the road
88  mySpaceOccupancies[i].myPosition = s;
89  } else {
90  // angled parking
91  mySpaceOccupancies[i].myPosition = (f + s) * 0.5;
92  }
93 
94  }
95  }
97 }
98 
100 
101 SUMOReal
102 MSParkingArea::getLastFreePos(const SUMOVehicle& /* forVehicle */) const {
103  return myLastFreePos;
104 }
105 
106 Position
108  std::map<unsigned int, LotSpaceDefinition >::iterator i;
109  for (i = mySpaceOccupancies.begin(); i != mySpaceOccupancies.end(); i++) {
110  if ((*i).second.vehicle == &forVehicle) {
111  return (*i).second.myPosition;
112  }
113  }
114  return Position::INVALID;
115 }
116 
117 SUMOReal
119  std::map<unsigned int, LotSpaceDefinition >::iterator i;
120  for (i = mySpaceOccupancies.begin(); i != mySpaceOccupancies.end(); i++) {
121  if ((*i).second.vehicle == &forVehicle) {
122  return (((*i).second.myRotation - 90.) * (SUMOReal) PI / (SUMOReal) 180.0);
123  }
124  }
125  return 0.;
126 }
127 
128 
129 SUMOReal
131  return (myEndPos - myBegPos) / myCapacity;
132 }
133 
134 
135 void
137  SUMOReal width, SUMOReal length, SUMOReal angle) {
138 
139  const int i = (int)mySpaceOccupancies.size() + 1;
140 
142  mySpaceOccupancies[i].index = i;
143  mySpaceOccupancies[i].vehicle = 0;
144  mySpaceOccupancies[i].myPosition = Position(x, y, z);
145  mySpaceOccupancies[i].myWidth = width;
146  mySpaceOccupancies[i].myLength = length;
147  mySpaceOccupancies[i].myRotation = angle;
148  mySpaceOccupancies[i].myEndPos = myEndPos;
149  myCapacity = (int)mySpaceOccupancies.size();
151 }
152 
153 
154 void
156  if (myLastFreeLot >= 1 && myLastFreeLot <= (int)mySpaceOccupancies.size()) {
157  mySpaceOccupancies[myLastFreeLot].vehicle = what;
158  myEndPositions[what] = std::pair<SUMOReal, SUMOReal>(beg, end);
160  }
161 }
162 
163 
164 void
166  assert(myEndPositions.find(what) != myEndPositions.end());
167  std::map<unsigned int, LotSpaceDefinition >::iterator i;
168  for (i = mySpaceOccupancies.begin(); i != mySpaceOccupancies.end(); i++) {
169  if ((*i).second.vehicle == what) {
170  (*i).second.vehicle = 0;
171  break;
172  }
173  }
174  myEndPositions.erase(myEndPositions.find(what));
176 }
177 
178 
179 void
181  myLastFreeLot = 0;
183  std::map<unsigned int, LotSpaceDefinition >::iterator i;
184  for (i = mySpaceOccupancies.begin(); i != mySpaceOccupancies.end(); i++) {
185  if ((*i).second.vehicle == 0) {
186  myLastFreeLot = (*i).first;
187  myLastFreePos = (*i).second.myEndPos;
188  break;
189  }
190  }
191 }
192 
193 
194 SUMOReal
196  return myWidth;
197 }
198 
199 
200 SUMOReal
202  return myLength;
203 }
204 
205 
206 SUMOReal
208  return myAngle;
209 }
210 
211 
212 int
214  return myCapacity;
215 }
216 
217 
218 int
220  return (int)myEndPositions.size();
221 }
222 
223 
224 /****************************************************************************/
int getCapacity() const
Returns the area capacity.
int getOccupancy() const
Returns the area occupancy.
int myLastFreeLot
Last free lot number (0 no free lot)
const SUMOReal SUMO_const_laneWidth
Definition: StdDefs.h:48
SUMOReal getSpaceDim() const
Returns the space dimension.
A lane area vehicles can halt at.
void enter(SUMOVehicle *what, SUMOReal beg, SUMOReal end)
Called if a vehicle enters this stop.
MSParkingArea(const std::string &id, const std::vector< std::string > &lines, MSLane &lane, SUMOReal begPos, SUMOReal endPos, unsigned int capacity, SUMOReal width, SUMOReal length, SUMOReal angle)
Constructor.
SUMOReal getWidth() const
Returns the lane&#39;s width.
Definition: MSLane.h:496
SUMOReal getVehicleAngle(const SUMOVehicle &forVehicle)
Returns the angle of parked vehicle.
const SUMOReal myEndPos
The end position this bus stop is located at.
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
const SUMOReal myBegPos
The begin position this bus stop is located at.
#define PI
Definition: polyfonts.c:61
Representation of a vehicle.
Definition: SUMOVehicle.h:67
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
PositionVector myShape
The roadside shape of this parkingArea.
Position positionAtOffset(SUMOReal pos, SUMOReal lateralOffset=0) const
Returns the position at the given length.
SUMOReal myLength
The default length of each parking space.
SUMOReal getAngle() const
Returns the lot rectangle angle.
void computeLastFreePos()
Computes the last free position on this stop.
SUMOReal getLastFreePos(const SUMOVehicle &forVehicle) const
Returns the last free position on this stop.
SUMOReal getLength() const
Returns the lot rectangle length.
SUMOReal myAngle
The default angle of each parking space.
int myCapacity
Stop area capacity.
void leaveFrom(SUMOVehicle *what)
Called if a vehicle leaves this stop.
SUMOReal getWidth() const
Returns the lot rectangle width.
SUMOReal myLastFreePos
The last free position at this stop (variable)
virtual ~MSParkingArea()
Destructor.
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
void addLotEntry(SUMOReal x, SUMOReal y, SUMOReal z, SUMOReal width, SUMOReal length, SUMOReal angle)
Add a lot entry to parking area.
SUMOReal myWidth
The default width of each parking space.
std::map< const SUMOVehicle *, std::pair< SUMOReal, SUMOReal > > myEndPositions
A map from objects (vehicles) to the areas they acquire after entering the stop.
const PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:427
void move2side(SUMOReal amount)
move position vector to side using certain ammount
#define SUMOReal
Definition: config.h:208
Representation of a single lot space.
Position getVehiclePosition(const SUMOVehicle &forVehicle)
Returns the position of parked vehicle.
std::map< unsigned int, LotSpaceDefinition > mySpaceOccupancies
A map from objects (vehicles) to the areas they acquire after entering the stop.
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
PositionVector getSubpart(SUMOReal beginOffset, SUMOReal endOffset) const
get subpart of a position vector
static const Position INVALID
used to indicate that a position is valid
Definition: Position.h:278