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 <utils/geom/GeomHelper.h>
36 #include <microsim/MSNet.h>
37 #include <microsim/MSVehicleType.h>
39 #include "MSLane.h"
40 #include "MSTransportable.h"
41 #include "MSParkingArea.h"
42 
43 
44 // ===========================================================================
45 // method definitions
46 // ===========================================================================
47 MSParkingArea::MSParkingArea(const std::string& id,
48  const std::vector<std::string>& lines,
49  MSLane& lane,
50  double begPos, double endPos,
51  unsigned int capacity,
52  double width, double length, double angle) :
53  MSStoppingPlace(id, lines, lane, begPos, endPos),
54  myCapacity(capacity),
55  myWidth(width),
56  myLength(length),
57  myAngle(angle) {
58  // initialize unspecified defaults
59  if (myWidth == 0) {
61  }
62  if (myLength == 0) {
64  }
65 
66  const double offset = MSNet::getInstance()->lefthand() ? -1 : 1;
67  myShape = lane.getShape().getSubpart(
69  lane.interpolateLanePosToGeometryPos(endPos));
70  myShape.move2side((lane.getWidth() / 2. + myWidth / 2.) * offset);
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  double lot_angle = ((double) atan2((s.x() - f.x()), (f.y() - s.y())) * (double) 180.0 / (double) M_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 double
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 double
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.) * (double) M_PI / (double) 180.0);
123  }
124  }
125  return 0.;
126 }
127 
128 
129 double
131  return (myEndPos - myBegPos) / myCapacity;
132 }
133 
134 
135 void
136 MSParkingArea::addLotEntry(double x, double y, double z,
137  double width, double length, double 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
155 MSParkingArea::enter(SUMOVehicle* what, double beg, double end) {
156  if (myLastFreeLot >= 1 && myLastFreeLot <= (int)mySpaceOccupancies.size()) {
157  mySpaceOccupancies[myLastFreeLot].vehicle = what;
158  myEndPositions[what] = std::pair<double, double>(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 double
196  return myWidth;
197 }
198 
199 
200 double
202  return myLength;
203 }
204 
205 
206 double
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 /****************************************************************************/
std::map< const SUMOVehicle *, std::pair< double, double > > myEndPositions
A map from objects (vehicles) to the areas they acquire after entering the stop.
int getCapacity() const
Returns the area capacity.
int getOccupancy() const
Returns the area occupancy.
bool lefthand() const
return whether the network was built for lefthand traffic
Definition: MSNet.h:688
int myLastFreeLot
Last free lot number (0 no free lot)
double getLength() const
Returns the lot rectangle length.
double getWidth() const
Returns the lane&#39;s width.
Definition: MSLane.h:500
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.
double x() const
Returns the x-position.
Definition: Position.h:63
const double SUMO_const_laneWidth
Definition: StdDefs.h:50
double interpolateLanePosToGeometryPos(double lanePos) const
Definition: MSLane.h:442
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:169
double getWidth() const
Returns the lot rectangle width.
double getLastFreePos(const SUMOVehicle &forVehicle) const
Returns the last free position on this stop.
double myAngle
The default angle of each parking space.
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:67
double myLastFreePos
The last free position at this stop (variable)
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
PositionVector myShape
The roadside shape of this parkingArea.
double myLength
The default length of each parking space.
double y() const
Returns the y-position.
Definition: Position.h:68
void computeLastFreePos()
Computes the last free position on this stop.
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.
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.
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
#define M_PI
Definition: odrSpiral.cpp:40
virtual ~MSParkingArea()
Destructor.
const PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:426
PositionVector getSubpart(double beginOffset, double endOffset) const
get subpart of a position vector
Representation of a single lot space.
double getSpaceDim() const
Returns the space dimension.
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.
double myWidth
The default width of each parking space.
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
double getAngle() const
Returns the lot rectangle angle.
static const Position INVALID
used to indicate that a position is valid
Definition: Position.h:278