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-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
16 // A area where vehicles can park next to the road
17 /****************************************************************************/
18 
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24 
25 #include <cassert>
27 #include <utils/geom/Position.h>
28 #include <utils/geom/GeomHelper.h>
29 #include <microsim/MSNet.h>
30 #include <microsim/MSVehicleType.h>
31 #include "MSLane.h"
32 #include "MSTransportable.h"
33 #include "MSParkingArea.h"
34 
35 
36 // ===========================================================================
37 // method definitions
38 // ===========================================================================
39 MSParkingArea::MSParkingArea(const std::string& id,
40  const std::vector<std::string>& lines,
41  MSLane& lane,
42  double begPos, double endPos,
43  unsigned int capacity,
44  double width, double length, double angle, const std::string& name) :
45  MSStoppingPlace(id, lines, lane, begPos, endPos, name),
46  myCapacity(capacity),
47  myWidth(width),
48  myLength(length),
49  myAngle(angle) {
50  // initialize unspecified defaults
51  if (myWidth == 0) {
53  }
54  if (myLength == 0) {
56  }
57 
58  const double offset = MSNet::getInstance()->lefthand() ? -1 : 1;
59  myShape = lane.getShape().getSubpart(
61  lane.interpolateLanePosToGeometryPos(endPos));
62  myShape.move2side((lane.getWidth() / 2. + myWidth / 2.) * offset);
63  // Initialize space occupancies if there is a road-side capacity
64  // The overall number of lots is fixed and each lot accepts one vehicle regardless of size
65  if (myCapacity > 0) {
66  for (int i = 1; i <= myCapacity; ++i) {
68  mySpaceOccupancies[i].index = i;
69  mySpaceOccupancies[i].vehicle = 0;
70  mySpaceOccupancies[i].myWidth = myWidth;
71  mySpaceOccupancies[i].myLength = myLength;
72  mySpaceOccupancies[i].myEndPos = myBegPos + getSpaceDim() * i;
73 
74  const Position& f = myShape.positionAtOffset(getSpaceDim() * (i - 1));
75  const Position& s = myShape.positionAtOffset(getSpaceDim() * (i));
76  double lot_angle = ((double) atan2((s.x() - f.x()), (f.y() - s.y())) * (double) 180.0 / (double) M_PI) + myAngle;
77  mySpaceOccupancies[i].myRotation = lot_angle;
78  if (myAngle == 0) {
79  // parking parallel to the road
80  mySpaceOccupancies[i].myPosition = s;
81  } else {
82  // angled parking
83  mySpaceOccupancies[i].myPosition = (f + s) * 0.5;
84  }
85 
86  }
87  }
89 }
90 
92 
93 double
94 MSParkingArea::getLastFreePos(const SUMOVehicle& /* forVehicle */) const {
95  return myLastFreePos;
96 }
97 
100  std::map<unsigned int, LotSpaceDefinition >::iterator i;
101  for (i = mySpaceOccupancies.begin(); i != mySpaceOccupancies.end(); i++) {
102  if ((*i).second.vehicle == &forVehicle) {
103  return (*i).second.myPosition;
104  }
105  }
106  return Position::INVALID;
107 }
108 
109 double
111  std::map<unsigned int, LotSpaceDefinition >::iterator i;
112  for (i = mySpaceOccupancies.begin(); i != mySpaceOccupancies.end(); i++) {
113  if ((*i).second.vehicle == &forVehicle) {
114  return (((*i).second.myRotation - 90.) * (double) M_PI / (double) 180.0);
115  }
116  }
117  return 0.;
118 }
119 
120 
121 double
124 }
125 
126 
127 void
128 MSParkingArea::addLotEntry(double x, double y, double z,
129  double width, double length, double angle) {
130 
131  const int i = (int)mySpaceOccupancies.size() + 1;
132 
134  mySpaceOccupancies[i].index = i;
135  mySpaceOccupancies[i].vehicle = 0;
136  mySpaceOccupancies[i].myPosition = Position(x, y, z);
137  mySpaceOccupancies[i].myWidth = width;
138  mySpaceOccupancies[i].myLength = length;
139  mySpaceOccupancies[i].myRotation = angle;
140  mySpaceOccupancies[i].myEndPos = myEndPos;
141  myCapacity = (int)mySpaceOccupancies.size();
143 }
144 
145 
146 void
147 MSParkingArea::enter(SUMOVehicle* what, double beg, double end) {
148  if (myLastFreeLot >= 1 && myLastFreeLot <= (int)mySpaceOccupancies.size()) {
149  mySpaceOccupancies[myLastFreeLot].vehicle = what;
150  myEndPositions[what] = std::pair<double, double>(beg, end);
152  }
153 }
154 
155 
156 void
158  assert(myEndPositions.find(what) != myEndPositions.end());
159  std::map<unsigned int, LotSpaceDefinition >::iterator i;
160  for (i = mySpaceOccupancies.begin(); i != mySpaceOccupancies.end(); i++) {
161  if ((*i).second.vehicle == what) {
162  (*i).second.vehicle = 0;
163  break;
164  }
165  }
166  myEndPositions.erase(myEndPositions.find(what));
168 }
169 
170 
171 void
173  myLastFreeLot = 0;
175  std::map<unsigned int, LotSpaceDefinition >::iterator i;
176  for (i = mySpaceOccupancies.begin(); i != mySpaceOccupancies.end(); i++) {
177  if ((*i).second.vehicle == 0) {
178  myLastFreeLot = (*i).first;
179  myLastFreePos = (*i).second.myEndPos;
180  break;
181  }
182  }
183 }
184 
185 
186 double
188  return myWidth;
189 }
190 
191 
192 double
194  return myLength;
195 }
196 
197 
198 double
200  return myAngle;
201 }
202 
203 
204 int
206  return myCapacity;
207 }
208 
209 
210 int
212  return (int)myEndPositions.size();
213 }
214 
215 
216 /****************************************************************************/
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:43
double y() const
Returns the y-position.
Definition: Position.h:61
double x() const
Returns the x-position.
Definition: Position.h:56
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:160
const PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:449
double getWidth() const
Returns the lane&#39;s width.
Definition: MSLane.h:523
double myAngle
The default angle of each parking space.
const MSLane & myLane
The lane this bus stop is located at.
double getVehicleAngle(const SUMOVehicle &forVehicle)
Returns the angle of parked vehicle.
Representation of a vehicle.
Definition: SUMOVehicle.h:60
double myLastFreePos
The last free position at this stop (variable)
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
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:608
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:465
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, const std::string &name)
Constructor.
Representation of a single lot space.
Position getVehiclePosition(const SUMOVehicle &forVehicle)
Returns the position of parked vehicle.
double getLastFreePos() const
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:71
double getAngle() const
Returns the lot rectangle angle.
static const Position INVALID
used to indicate that a position is valid
Definition: Position.h:274