LCOV - code coverage report
Current view: top level - src/microsim - MSStoppingPlace.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 64.3 % 14 9
Test Date: 2026-05-24 16:29:35 Functions: 0.0 % 4 0

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2005-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    MSStoppingPlace.h
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Michael Behrisch
      17              : /// @author  Johannes Rummel
      18              : /// @date    Mon, 13.12.2005
      19              : ///
      20              : // A lane area vehicles can halt at
      21              : /****************************************************************************/
      22              : #pragma once
      23              : #include <config.h>
      24              : 
      25              : #include <vector>
      26              : #include <algorithm>
      27              : #include <map>
      28              : #include <string>
      29              : #include <utils/common/Named.h>
      30              : #include <utils/common/Parameterised.h>
      31              : #include <utils/common/RGBColor.h>
      32              : 
      33              : 
      34              : // ===========================================================================
      35              : // class declarations
      36              : // ===========================================================================
      37              : class MSLane;
      38              : class MSEdge;
      39              : class SUMOVehicle;
      40              : class MSTransportable;
      41              : class Position;
      42              : 
      43              : 
      44              : // ===========================================================================
      45              : // class definitions
      46              : // ===========================================================================
      47              : /**
      48              :  * @class MSStoppingPlace
      49              :  * @brief A lane area vehicles can halt at
      50              :  *
      51              :  * The stop tracks the last free space a vehicle may halt at by being
      52              :  *  informed about a vehicle's entering and depart. It keeps the information
      53              :  *  about entered vehicles' begin and end position within an internal
      54              :  *  container ("myEndPositions") and is so able to compute the last free space.
      55              :  *
      56              :  * Please note that using the last free space disallows vehicles to enter a
      57              :  *  free space in between other vehicles.
      58              :  */
      59              : class MSStoppingPlace : public Named, public Parameterised {
      60              : public:
      61              :     enum class AccessExit {
      62              :         PLATFORM,
      63              :         DOORS,
      64              :         CARRIAGE
      65              :     };
      66              : 
      67              :     struct Access {
      68              :         MSLane* const lane;
      69              :         const double startPos;
      70              :         const double endPos;
      71              :         const double length;
      72              :         const AccessExit exit;
      73              :     };
      74              : 
      75              :     /** @brief Constructor
      76              :      *
      77              :      * @param[in] id The id of the stop
      78              :      * @param[in] net The net the stop belongs to
      79              :      * @param[in] lines Names of the lines that halt on this stop
      80              :      * @param[in] lane The lane the stop is placed on
      81              :      * @param[in] begPos Begin position of the stop on the lane
      82              :      * @param[in] endPos End position of the stop on the lane
      83              :      */
      84              :     MSStoppingPlace(const std::string& id,
      85              :                     SumoXMLTag element,
      86              :                     const std::vector<std::string>& lines, MSLane& lane,
      87              :                     double begPos, double endPos,
      88              :                     const std::string name = "",
      89              :                     int capacity = 0,
      90              :                     double parkingLength = 0,
      91              :                     const RGBColor& color = RGBColor::INVISIBLE,
      92              :                     double angle = 90);
      93              : 
      94              : 
      95              : 
      96              :     /// @brief Destructor
      97              :     virtual ~MSStoppingPlace();
      98              : 
      99              : 
     100              :     /** @brief Returns the lane this stop is located at
     101              :      *
     102              :      * @return Reference to the lane the stop is located at
     103              :      */
     104              :     const MSLane& getLane() const;
     105              : 
     106              : 
     107              :     /** @brief Returns the begin position of this stop
     108              :      *
     109              :      * @return The position the stop begins at
     110              :      */
     111              :     double getBeginLanePosition() const;
     112              : 
     113              : 
     114              :     /** @brief Returns the end position of this stop
     115              :      *
     116              :      * @return The position the stop ends at
     117              :      */
     118              :     double getEndLanePosition() const;
     119              : 
     120              :     double getAngle() const {
     121       143977 :         return myAngle;
     122              :     }
     123              : 
     124              :     /// @brief the position in the middle of the stop shape
     125              :     Position getCenterPos() const;
     126              : 
     127              :     /** @brief Called if a vehicle enters this stop
     128              :      *
     129              :      * Stores the position of the entering vehicle in myEndPositions.
     130              :      *
     131              :      * Recomputes the free space using "computeLastFreePos" then.
     132              :      *
     133              :      * @param[in] veh The vehicle that enters the stopping place
     134              :      * @param[in] parking whether this is offroad parking
     135              :      * @see computeLastFreePos
     136              :      */
     137              :     virtual void enter(SUMOVehicle* veh, const bool parking);
     138              : 
     139              : 
     140              :     /** @brief Called if a vehicle leaves this stop
     141              :      *
     142              :      * Removes the position of the vehicle from myEndPositions.
     143              :      *
     144              :      * Recomputes the free space using "computeLastFreePos" then.
     145              :      *
     146              :      * @param[in] what The vehicle that leaves the bus stop
     147              :      * @see computeLastFreePos
     148              :      */
     149              :     virtual void leaveFrom(SUMOVehicle* what);
     150              : 
     151              : 
     152              :     /** @brief Returns the last free position on this stop
     153              :      *
     154              :      * @param[in] forVehicle The vehicle that wants to stop here
     155              :      * @param[in] brakePos the first position on the stop lane that the vehicle can stop at
     156              :      * @return The last free position of this bus stop
     157              :      */
     158              :     virtual double getLastFreePos(const SUMOVehicle& forVehicle, double brakePos = 0) const;
     159              : 
     160            0 :     virtual bool accepts(SUMOVehicle* /*veh*/) const {
     161            0 :         return true;
     162              :     }
     163              : 
     164              :     /// @brief return whether the given vehicle fits at the given position
     165              :     bool fits(double pos, const SUMOVehicle& veh) const;
     166              : 
     167              :     /** @brief Returns the next free waiting place for pedestrians / containers
     168              :      *
     169              :      * @return The next free waiting place for pedestrians / containers
     170              :      */
     171              :     Position getWaitPosition(MSTransportable* person) const;
     172              : 
     173              :     /** @brief Returns the lane position corresponding to getWaitPosition()
     174              :      *
     175              :      * @return The waiting position along the stop lane
     176              :      */
     177              :     double getWaitingPositionOnLane(MSTransportable* t) const;
     178              : 
     179              : 
     180              :     /** @brief For vehicles at the stop this gives the actual stopping
     181              :      *         position of the vehicle. For all others the last free stopping position
     182              :      *
     183              :      */
     184              :     double getStoppingPosition(const SUMOVehicle* veh) const;
     185              : 
     186              :     /** @brief Returns the number of transportables waiting on this stop
     187              :     */
     188            0 :     int getTransportableNumber() const {
     189            6 :         return (int)myWaitingTransportables.size();
     190              :     }
     191              : 
     192              :     /** @brief Returns the transportables waiting on this stop
     193              :      */
     194              :     std::vector<const MSTransportable*> getTransportables() const;
     195              : 
     196              :     /** @brief Returns the number of stopped vehicles waiting on this stop
     197              :     */
     198            0 :     int getStoppedVehicleNumber() const {
     199      6962479 :         return (int)myEndPositions.size();
     200              :     }
     201              : 
     202            0 :     double getLastFreePos() const {
     203         1064 :         return myLastFreePos;
     204              :     }
     205              : 
     206              :     /// @brief whether there is still capacity for more transportables
     207              :     bool hasSpaceForTransportable() const;
     208              : 
     209              :     /// @brief adds a transportable to this stop
     210              :     bool addTransportable(const MSTransportable* p, int spot = -1);
     211              : 
     212              :     /// @brief Removes a transportable from this stop
     213              :     void removeTransportable(const MSTransportable* p);
     214              : 
     215              :     int checkWaitingSpot(const MSTransportable* p) const;
     216              : 
     217              :     /// @brief adds an access point to this stop
     218              :     virtual bool addAccess(MSLane* const lane, const double startPos, const double endPos, double length, const MSStoppingPlace::AccessExit exit);
     219              : 
     220              :     /// @brief lanes and positions connected to this stop
     221              :     const std::vector<Access>& getAllAccessPos() const {
     222              :         return myAccessPos;
     223              :     }
     224              : 
     225              :     /// @brief the position on the given edge which is connected to this stop, -1 on failure
     226              :     double getAccessPos(const MSEdge* edge, SumoRNG* rng = nullptr) const;
     227              : 
     228              :     /// @brief the access on the given edge to the stop, nullptr if there is none
     229              :     const Access* getAccess(const MSEdge* edge) const;
     230              : 
     231              :     const std::string& getMyName() const;
     232              : 
     233              :     /// @brief return the type of this stopping place
     234              :     SumoXMLTag getElement() const {
     235       488862 :         return myElement;
     236              :     }
     237              : 
     238              :     const RGBColor& getColor() const;
     239              : 
     240              :     static int getDefaultTransportablesAbreast(double length, SumoXMLTag element);
     241              : 
     242              :     /// @brief get list of vehicles waiting at this stop
     243              :     std::vector<const SUMOVehicle*> getStoppedVehicles() const;
     244              : 
     245              :     /// @brief get number of persons waiting at this stop
     246              :     inline int getNumWaitingPersons() const {
     247      1590216 :         return (int)myWaitingTransportables.size();
     248              :     }
     249              : 
     250              :     /// @brief get number of persons that can wait at this stop
     251              :     inline int getWaitingCapacity() const {
     252      1590107 :         return myTransportableCapacity;
     253              :     }
     254              : 
     255              :     inline double getParkingLength() const {
     256        47482 :         return (myEndPos - myBegPos) / myParkingFactor;
     257              :     }
     258              : 
     259              :     /// @brief get IDs of persons waiting at this stop
     260              :     void getWaitingPersonIDs(std::vector<std::string>& into) const;
     261              : 
     262              :     bool checkPersonCapacity() const {
     263       119604 :         return myElement == SUMO_TAG_BUS_STOP || myElement == SUMO_TAG_TRAIN_STOP;;
     264              :     }
     265              : 
     266              :     /// @brief perform extra processing after element has been loaded
     267              :     virtual void finishedLoading();
     268              : 
     269              :     /** @brief Remove all vehicles before quick-loading state */
     270              :     void clearState();
     271              : 
     272              : protected:
     273              :     /** @brief Computes the last free position on this stop
     274              :      *
     275              :      * The last free position is the one, the last vehicle ends at.
     276              :      * It is stored in myLastFreePos. If no vehicle halts, the last free
     277              :      *  position gets the value of myEndPos.
     278              :      */
     279              :     void computeLastFreePos();
     280              : 
     281              :     int getTransportablesAbreast() const;
     282              : 
     283              :     static double getDefaultTransportableWidth(SumoXMLTag element);
     284              : 
     285              : protected:
     286              :     /// @brief the type of stopping place
     287              :     const SumoXMLTag myElement;
     288              : 
     289              :     /// @brief The list of lines that are assigned to this stop
     290              :     std::vector<std::string> myLines;
     291              : 
     292              :     /// @brief A map from objects (vehicles) to the areas they acquire after entering the stop
     293              :     std::map<const SUMOVehicle*, std::pair<double, double>, ComparatorNumericalIdLess> myEndPositions;
     294              : 
     295              :     /// @brief The lane this bus stop is located at
     296              :     const MSLane& myLane;
     297              : 
     298              :     /// @brief The begin position this bus stop is located at
     299              :     const double myBegPos;
     300              : 
     301              :     /// @brief The end position this bus stop is located at
     302              :     const double myEndPos;
     303              : 
     304              :     /// @brief The last free position at this stop (variable)
     305              :     double myLastFreePos;
     306              :     /// @brief The length of the last parking vehicle (or 0 if there is none)
     307              :     const SUMOVehicle* myLastParking;
     308              : 
     309              :     /// @brief The name of the stopping place
     310              :     const std::string myName;
     311              : 
     312              :     /// @brief The number of transportables that can wait here
     313              :     const int myTransportableCapacity;
     314              : 
     315              :     /// @brief the scaled space capacity for parking vehicles
     316              :     const double myParkingFactor;
     317              : 
     318              :     /// @brief The color of the stopping place
     319              :     const RGBColor myColor;
     320              : 
     321              :     /// @brief The angle offset for waiting transportables
     322              :     double myAngle;
     323              : 
     324              :     /// @brief row depth of waiting transportables
     325              :     double myTransportableDepth;
     326              :     /// @brief the with of waiting transportables
     327              :     double myTransportableWidth;
     328              : 
     329              :     /// @brief Persons waiting at this stop (mapped to waiting position)
     330              :     std::map<const MSTransportable*, int> myWaitingTransportables;
     331              :     std::set<int> myWaitingSpots;
     332              : 
     333              :     /// @brief lanes and positions connected to this stop
     334              :     std::vector<Access> myAccessPos;
     335              : 
     336              : private:
     337              :     /// @brief Invalidated copy constructor.
     338              :     MSStoppingPlace(const MSStoppingPlace&);
     339              : 
     340              :     /// @brief Invalidated assignment operator.
     341              :     MSStoppingPlace& operator=(const MSStoppingPlace&);
     342              : 
     343              : 
     344              : };
        

Generated by: LCOV version 2.0-1