LCOV - code coverage report
Current view: top level - src/microsim - MSParkingArea.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 50.0 % 2 1
Test Date: 2026-03-02 16:00:03 Functions: - 0 0

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2015-2026 German Aerospace Center (DLR) and others.
       4              : // This program and the accompanying materials are made available under the
       5              : // terms of the Eclipse Public License 2.0 which is available at
       6              : // https://www.eclipse.org/legal/epl-2.0/
       7              : // This Source Code may also be made available under the following Secondary
       8              : // Licenses when the conditions for such availability set forth in the Eclipse
       9              : // Public License 2.0 are satisfied: GNU General Public License, version 2
      10              : // or later which is available at
      11              : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
      12              : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
      13              : /****************************************************************************/
      14              : /// @file    MSParkingArea.h
      15              : /// @author  Mirco Sturari
      16              : /// @author  Mirko Barthauer
      17              : /// @date    Tue, 19.01.2016
      18              : ///
      19              : // A area where vehicles can park next to the road
      20              : /****************************************************************************/
      21              : #pragma once
      22              : #include <config.h>
      23              : 
      24              : #include <vector>
      25              : #include <algorithm>
      26              : #include <map>
      27              : #include <string>
      28              : #include <utils/geom/PositionVector.h>
      29              : #include <utils/common/Named.h>
      30              : #include <utils/vehicle/SUMOVehicleParameter.h>
      31              : #include "MSStoppingPlace.h"
      32              : 
      33              : 
      34              : // ===========================================================================
      35              : // class declarations
      36              : // ===========================================================================
      37              : class MSLane;
      38              : class SUMOVehicle;
      39              : class MSTransportable;
      40              : class MSBaseVehicle;
      41              : class Position;
      42              : class Command;
      43              : 
      44              : 
      45              : // ===========================================================================
      46              : // class definitions
      47              : // ===========================================================================
      48              : /**
      49              :  * @class MSParkingArea
      50              :  * @brief A lane area vehicles can halt at
      51              :  *
      52              :  * The stop tracks the last free space a vehicle may halt at by being
      53              :  *  informed about a vehicle's entering and depart. It keeps the information
      54              :  *  about entered vehicles' begin and end position within an internal
      55              :  *  container ("myEndPositions") and is so able to compute the last free space.
      56              :  *
      57              :  * Please note that using the last free space disallows vehicles to enter a
      58              :  *  free space in between other vehicles.
      59              :  */
      60              : class MSParkingArea : public MSStoppingPlace {
      61              : public:
      62              : 
      63              :     /** @struct LotSpaceDefinition
      64              :       * @brief Representation of a single lot space
      65              :       */
      66              :     struct LotSpaceDefinition {
      67              :         /// @brief default constructor
      68              :         LotSpaceDefinition();
      69              : 
      70              :         /// @brief parameter constructor
      71              :         LotSpaceDefinition(int index, SUMOVehicle* vehicle, double x, double y, double z, double rotation, double slope, double width, double length);
      72              : 
      73              :         /// @brief the running index
      74              :         const int index;
      75              : 
      76              :         /// @brief The last parked vehicle or 0
      77              :         const SUMOVehicle* vehicle;
      78              : 
      79              :         /// @brief The position of the vehicle when parking in this space
      80              :         const Position position;
      81              : 
      82              :         /// @brief The rotation
      83              :         const double rotation;
      84              : 
      85              :         /// @brief The slope
      86              :         const double slope;
      87              : 
      88              :         /// @brief The width
      89              :         const double width;
      90              : 
      91              :         /// @brief The length
      92              :         const double length;
      93              : 
      94              :         /// @brief The position along the lane that the vehicle needs to reach for entering this lot
      95              :         double endPos;
      96              : 
      97              :         ///@brief The angle between lane and lot through which a vehicle must manoeuver to enter the lot
      98              :         double manoeuverAngle;
      99              : 
     100              :         ///@brief Whether the lot is on the LHS of the lane relative to the lane direction
     101              :         bool sideIsLHS;
     102              :     };
     103              : 
     104              :     /** @brief Constructor
     105              :      *
     106              :      * @param[in] id The id of the stop
     107              :      * @param[in] net The net the stop belongs to
     108              :      * @param[in] lines Names of the lines that halt on this stop
     109              :      * @param[in] badges Names which grant access to this parking area
     110              :      * @param[in] lane The lane the stop is placed on
     111              :      * @param[in] begPos Begin position of the stop on the lane
     112              :      * @param[in] endPos End position of the stop on the lane
     113              :      * @param[in] capacity Capacity of the stop
     114              :      * @param[in] width Width of the default lot rectangle
     115              :      * @param[in] length Length of the default lot rectangle
     116              :      * @param[in] angle Angle of the default lot rectangle
     117              :      */
     118              :     MSParkingArea(const std::string& id,
     119              :                   const std::vector<std::string>& lines,
     120              :                   const std::vector<std::string>& badges, MSLane& lane,
     121              :                   double begPos, double endPos, int capacity,
     122              :                   double width, double length, double angle, const std::string& name,
     123              :                   bool onRoad,
     124              :                   const std::string& departPos,
     125              :                   bool lefthand, bool reservable);
     126              : 
     127              :     /// @brief Destructor
     128              :     virtual ~MSParkingArea();
     129              : 
     130              :     /// @brief needed for patching its capacity
     131              :     friend class NLTriggerBuilder;
     132              : 
     133              :     /// @brief Returns the area capacity
     134              :     int getCapacity() const;
     135              : 
     136              :     /// @brief whether vehicles park on the road
     137              :     bool parkOnRoad() const;
     138              : 
     139              :     /// @brief whether parked vehicles must advance in a queue
     140              :     bool mustAdvance(SUMOVehicleClass svc) const;
     141              : 
     142              :     /// @brief whether vehicles may reserve a slot for this parkingArea
     143              :     inline bool isReservable() const {
     144        96156 :         return myReservable;
     145              :     }
     146              : 
     147              :     /// @brief compute lot for this vehicle
     148              :     int getLotIndex(const SUMOVehicle* veh) const;
     149              : 
     150              :     /** @brief Returns the area occupancy
     151              :      *
     152              :      * @return The occupancy computed as number of vehicles in myEndPositions
     153              :      * (reduced by 1 if at least one vehicle has finished parking but is blocked
     154              :      * from entering the road)
     155              :      */
     156              :     int getOccupancy() const;
     157              : 
     158              :     /// @brief Returns the area occupancy
     159              :     int getOccupancyIncludingBlocked() const;
     160              : 
     161              :     int getOccupancyIncludingReservations(const SUMOVehicle* forVehicle) const;
     162              : 
     163              :     int getOccupancyIncludingRemoteReservations(const SUMOVehicle* forVehicle) const;
     164              : 
     165              :     /// @brief Returns the area occupancy at the end of the last simulation step
     166              :     int getLastStepOccupancy() const;
     167              : 
     168              :     int getLastStepOccupancyIncludingRemoteReservations(const SUMOVehicle* forVehicle) const;
     169              : 
     170              :     /// @brief Add a badge to the accepted set
     171              :     void accept(std::string badge);
     172              : 
     173              :     /// @brief Add badges to the accepted set
     174              :     void accept(std::vector<std::string> badges);
     175              : 
     176              :     /// @brief Remove the access right for the given badge
     177              :     void refuse(std::string badge);
     178              : 
     179              :     /// @brief Return the parking accepts the vehicle (due to its given badges)
     180              :     bool accepts(SUMOVehicle* veh) const;
     181              : 
     182              :     /** @brief Called if a vehicle enters this stop
     183              :      *
     184              :      * Stores the position of the entering vehicle in myEndPositions.
     185              :      *
     186              :      * Recomputes the free space using "computeLastFreePos" then.
     187              :      *
     188              :      * @param[in] veh The vehicle that enters the parking area
     189              :      * @param[in] parking whether this is offroad parking
     190              :      * @see computeLastFreePos
     191              :      */
     192              :     void enter(SUMOVehicle* veh, const bool parking);
     193              : 
     194              :     /** @brief Called if a vehicle leaves this stop
     195              :      *
     196              :      * Removes the position of the vehicle from myEndPositions.
     197              :      *
     198              :      * Recomputes the free space using "computeLastFreePos" then.
     199              :      *
     200              :      * @param[in] what The vehicle that leaves the parking area
     201              :      * @see computeLastFreePos
     202              :      */
     203              :     void leaveFrom(SUMOVehicle* what);
     204              : 
     205              :     /// @brief api for reserving spaces at this parkingArea
     206              :     /// @{
     207              :     void addSpaceReservation(const SUMOVehicle* veh);
     208              :     void removeSpaceReservation(const SUMOVehicle* veh);
     209              : 
     210              :     const std::set<const SUMOVehicle*>& getRemoteReservedVehicles() const {
     211            0 :         return myRemoteReservedVehicles;
     212              :     }
     213              :     /// @}
     214              : 
     215              :     /** @brief Called at the end of the time step
     216              :      *
     217              :      * Stores the current occupancy.
     218              :      *
     219              :      * @param[in] currentTime The current simulation time (unused)
     220              :      * @return Always 0 (the event is not rescheduled)
     221              :      */
     222              :     SUMOTime updateOccupancy(SUMOTime currentTime);
     223              : 
     224              :     /// @brief Returns the last free position on this stop
     225              :     double getLastFreePos(const SUMOVehicle& forVehicle, double brakePos = 0) const;
     226              : 
     227              :     /** @brief Returns the last free position on this stop including
     228              :      * reservations from the current lane and time step
     229              :      *
     230              :      * @return The last free position of this bus stop
     231              :      */
     232              :     double getLastFreePosWithReservation(SUMOTime t, const SUMOVehicle& forVehicle, double brakePos);
     233              : 
     234              :     /// @brief Returns the position of parked vehicle
     235              :     Position getVehiclePosition(const SUMOVehicle& forVehicle) const;
     236              : 
     237              :     /// @brief Returns the insertion position of a parked vehicle
     238              :     double getInsertionPosition(const SUMOVehicle& forVehicle) const;
     239              : 
     240              :     /// @brief Returns the angle of parked vehicle
     241              :     double getVehicleAngle(const SUMOVehicle& forVehicle) const;
     242              : 
     243              :     /// @brief Returns the slope of parked vehicle
     244              :     double getVehicleSlope(const SUMOVehicle& forVehicle) const;
     245              : 
     246              :     /** @brief Return the angle of myLastFreeLot - the next parking lot
     247              :      *         only expected to be called after we have established there is space in the parking area
     248              :      *
     249              :      * @return The angle of the lot in degrees
     250              :      */
     251              :     int getLastFreeLotAngle() const;
     252              : 
     253              :     /** @brief Return the GUI angle of myLastFreeLot - the angle the GUI uses to rotate into the next parking lot
     254              :      *         as above, only expected to be called after we have established there is space in the parking area
     255              :      *
     256              :      * @return The GUI angle, relative to the lane, in radians
     257              :      */
     258              :     double getLastFreeLotGUIAngle() const;
     259              : 
     260              :     /// @brief Return the manoeuver angle of the lot where the vehicle is parked
     261              :     int getManoeuverAngle(const SUMOVehicle& forVehicle) const;
     262              : 
     263              :     /// @brief  Return the GUI angle of the lot where the vehicle is parked
     264              :     double getGUIAngle(const SUMOVehicle& forVehicle) const;
     265              : 
     266              :     /** @brief Add a lot entry to parking area
     267              :      *
     268              :      * @param[in] x X position of the lot center
     269              :      * @param[in] y Y position of the lot center
     270              :      * @param[in] z Z position of the lot center
     271              :      * @param[in] width Width of the lot rectangle
     272              :      * @param[in] length Length of the lot rectangle
     273              :      * @param[in] angle Angle of the lot rectangle
     274              :      * @param[in] slope Slope of the lot rectangle
     275              :      * @return Whether the lot entry could be added
     276              :      */
     277              :     virtual void addLotEntry(double x, double y, double z,
     278              :                              double width, double length,
     279              :                              double angle, double slope);
     280              : 
     281              :     /// @brief Returns the lot rectangle width
     282              :     double getWidth() const;
     283              : 
     284              :     /// @brief Returns the lot rectangle length
     285              :     double getLength() const;
     286              : 
     287              :     /// @brief Returns the lot rectangle angle
     288              :     double getAngle() const;
     289              : 
     290              :     /// @brief update state so that vehicles wishing to enter cooperate with exiting vehicles
     291              :     void notifyEgressBlocked();
     292              : 
     293              :     /// @brief get number alternatives
     294              :     int getNumAlternatives() const;
     295              : 
     296              :     /// @brief set number alternatives
     297              :     void setNumAlternatives(int alternatives);
     298              : 
     299              :     /// @brief get the accepted badges
     300              :     std::vector<std::string> getAcceptedBadges() const;
     301              : 
     302              :     /// @brief set the accepted badges
     303              :     void setAcceptedBadges(const std::vector<std::string>& badges);
     304              : 
     305              :     /// @brief get the parking lots (with occupancy)
     306              :     const std::vector<LotSpaceDefinition>& getSpaceOccupancies() const;
     307              : 
     308              :     /// @brief get the parking shape
     309              :     const PositionVector& getShape() const;
     310              : 
     311              : 
     312              : protected:
     313              :     /// @brief overwrite the capacity (caution: will delete ANY previous parking space definitions)
     314              :     void setRoadsideCapacity(int capactity);
     315              : 
     316              :     /// @brief whether overtaking on this lane is impossible for the given vehicle class
     317              :     bool cannotChange(SUMOVehicleClass svc) const; 
     318              : 
     319              : protected:
     320              : 
     321              : 
     322              :     /** @brief Computes the last free position on this stop
     323              :      *
     324              :      * The last free position is the one, the last vehicle ends at.
     325              :      * It is stored in myLastFreePos. If no vehicle halts, the last free
     326              :      *  position gets the value of myEndPos.
     327              :      */
     328              :     void computeLastFreePos();
     329              : 
     330              :     /// @brief Last free lot number (-1 no free lot)
     331              :     int myLastFreeLot;
     332              : 
     333              :     /// @brief Stop area capacity configured via roadsideCapacity
     334              :     int myRoadSideCapacity;
     335              : 
     336              :     /// @brief Stop area total capacity
     337              :     int myCapacity;
     338              : 
     339              :     /// @brief Whether vehicles stay on the road
     340              :     bool myOnRoad;
     341              : 
     342              :     /// @brief Whether this parkingarea may receive reservations by vehicles that are on their way
     343              :     bool myReservable;
     344              : 
     345              :     /// @brief The default width of each parking space
     346              :     double myWidth;
     347              : 
     348              :     /// @brief The default length of each parking space
     349              :     double myLength;
     350              : 
     351              :     /// @brief The default angle of each parking space
     352              :     double myAngle;
     353              : 
     354              :     /// @brief All the spaces in this parking area
     355              :     std::vector<LotSpaceDefinition> mySpaceOccupancies;
     356              : 
     357              :     /// @brief The roadside shape of this parkingArea
     358              :     PositionVector myShape;
     359              : 
     360              :     /// @brief The parking badges to grant access
     361              :     std::set<std::string> myAcceptedBadges;
     362              : 
     363              :     /// @brief whether a vehicle wants to exit but is blocked
     364              :     bool myEgressBlocked;
     365              : 
     366              :     /// @brief track parking reservations from the lane for the current time step
     367              :     SUMOTime myReservationTime;
     368              :     SUMOTime myLastReservationTime;
     369              : 
     370              :     /// @brief number of reservations
     371              :     int myReservations;
     372              :     int myLastReservations;
     373              : 
     374              :     /// @brief reservation max length
     375              :     double myReservationMaxLength;
     376              :     double myLastReservationMaxLength;
     377              : 
     378              :     /// @brief the set of vehicles that performed a local reservation in this step
     379              :     std::set<const SUMOVehicle*> myReservedVehicles;
     380              :     /// @brief the set of vehicles that performed a remote reservation
     381              :     std::set<const SUMOVehicle*> myRemoteReservedVehicles;
     382              :     /// @brief a copy from the last step is needed to achieve thread/lane ordering independence
     383              :     std::set<const SUMOVehicle*> myLastRemoteReservedVehicles;
     384              : 
     385              :     /// @brief maximum length of all parked vehicles
     386              :     double myMaxVehLength;
     387              : 
     388              :     /// @brief the number of alternative parkingAreas that are assigned to parkingAreaRerouter
     389              :     int myNumAlternatives;
     390              : 
     391              :     /// @brief Changes to the occupancy in the current time step
     392              :     int myLastStepOccupancy;
     393              : 
     394              :     /// @brief custom departPos
     395              :     double myDepartPos;
     396              :     DepartPosDefinition myDepartPosDefinition;
     397              : 
     398              :     /// @brief Event for updating the occupancy
     399              :     Command* myUpdateEvent;
     400              : 
     401              : private:
     402              :     /// @brief Invalidated copy constructor.
     403              :     MSParkingArea(const MSParkingArea&) = delete;
     404              : 
     405              :     /// @brief Invalidated assignment operator.
     406              :     MSParkingArea& operator=(const MSParkingArea&) = delete;
     407              : };
        

Generated by: LCOV version 2.0-1