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 
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  myShape = lane.getShape();
65  myShape.move2side(lane.getWidth() / 2. + myWidth / 2.);
66  myShape = myShape.getSubpart(begPos, endPos);
67  // Initialize space occupancies if there is a road-side capacity
68  // The overall number of lots is fixed and each lot accepts one vehicle regardless of size
69  if (myCapacity > 0) {
70  for (int i = 1; i <= myCapacity; ++i) {
72  mySpaceOccupancies[i].index = i;
73  mySpaceOccupancies[i].vehicle = 0;
74  mySpaceOccupancies[i].myWidth = myWidth;
75  mySpaceOccupancies[i].myLength = myLength;
76  mySpaceOccupancies[i].myEndPos = myBegPos + getSpaceDim() * i;
77 
78  const Position& f = myShape.positionAtOffset(getSpaceDim() * (i - 1));
79  const Position& s = myShape.positionAtOffset(getSpaceDim() * (i));
80  double lot_angle = ((double) atan2((s.x() - f.x()), (f.y() - s.y())) * (double) 180.0 / (double) PI) + myAngle;
81  mySpaceOccupancies[i].myRotation = lot_angle;
82  if (myAngle == 0) {
83  // parking parallel to the road
84  mySpaceOccupancies[i].myPosition = s;
85  } else {
86  // angled parking
87  mySpaceOccupancies[i].myPosition = (f + s) * 0.5;
88  }
89 
90  }
91  }
93 }
94 
96 
97 double
98 MSParkingArea::getLastFreePos(const SUMOVehicle& /* forVehicle */) const {
99  return myLastFreePos;
100 }
101 
102 Position
104  std::map<unsigned int, LotSpaceDefinition >::iterator i;
105  for (i = mySpaceOccupancies.begin(); i != mySpaceOccupancies.end(); i++) {
106  if ((*i).second.vehicle == &forVehicle) {
107  return (*i).second.myPosition;
108  }
109  }
110  return Position::INVALID;
111 }
112 
113 double
115  std::map<unsigned int, LotSpaceDefinition >::iterator i;
116  for (i = mySpaceOccupancies.begin(); i != mySpaceOccupancies.end(); i++) {
117  if ((*i).second.vehicle == &forVehicle) {
118  return (((*i).second.myRotation - 90.) * (double) PI / (double) 180.0);
119  }
120  }
121  return 0.;
122 }
123 
124 
125 double
127  return (myEndPos - myBegPos) / myCapacity;
128 }
129 
130 
131 void
132 MSParkingArea::addLotEntry(double x, double y, double z,
133  double width, double length, double angle) {
134 
135  const int i = (int)mySpaceOccupancies.size() + 1;
136 
138  mySpaceOccupancies[i].index = i;
139  mySpaceOccupancies[i].vehicle = 0;
140  mySpaceOccupancies[i].myPosition = Position(x, y, z);
141  mySpaceOccupancies[i].myWidth = width;
142  mySpaceOccupancies[i].myLength = length;
143  mySpaceOccupancies[i].myRotation = angle;
144  mySpaceOccupancies[i].myEndPos = myEndPos;
145  myCapacity = (int)mySpaceOccupancies.size();
147 }
148 
149 
150 void
151 MSParkingArea::enter(SUMOVehicle* what, double beg, double end) {
152  if (myLastFreeLot >= 1 && myLastFreeLot <= (int)mySpaceOccupancies.size()) {
153  mySpaceOccupancies[myLastFreeLot].vehicle = what;
154  myEndPositions[what] = std::pair<double, double>(beg, end);
156  }
157 }
158 
159 
160 void
162  assert(myEndPositions.find(what) != myEndPositions.end());
163  std::map<unsigned int, LotSpaceDefinition >::iterator i;
164  for (i = mySpaceOccupancies.begin(); i != mySpaceOccupancies.end(); i++) {
165  if ((*i).second.vehicle == what) {
166  (*i).second.vehicle = 0;
167  break;
168  }
169  }
170  myEndPositions.erase(myEndPositions.find(what));
172 }
173 
174 
175 void
177  myLastFreeLot = 0;
179  std::map<unsigned int, LotSpaceDefinition >::iterator i;
180  for (i = mySpaceOccupancies.begin(); i != mySpaceOccupancies.end(); i++) {
181  if ((*i).second.vehicle == 0) {
182  myLastFreeLot = (*i).first;
183  myLastFreePos = (*i).second.myEndPos;
184  break;
185  }
186  }
187 }
188 
189 
190 double
192  return myWidth;
193 }
194 
195 
196 double
198  return myLength;
199 }
200 
201 
202 double
204  return myAngle;
205 }
206 
207 
208 int
210  return myCapacity;
211 }
212 
213 
214 int
216  return (int)myEndPositions.size();
217 }
218 
219 
220 /****************************************************************************/
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:48
double y() const
Returns the y-position.
Definition: Position.h:68
double x() const
Returns the x-position.
Definition: Position.h:63
const PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:426
double getWidth() const
Returns the lane&#39;s width.
Definition: MSLane.h:500
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.
#define PI
Definition: polyfonts.c:61
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.
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.
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.
virtual ~MSParkingArea()
Destructor.
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: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