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: 2025-12-06 15:35:27 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-2025 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       145596 :         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      3740996 :         return (int)myEndPositions.size();
     200              :     }
     201              : 
     202            0 :     double getLastFreePos() const {
     203         1604 :         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);
     211              : 
     212              :     /// @brief Removes a transportable from this stop
     213              :     void removeTransportable(const MSTransportable* p);
     214              : 
     215              :     /// @brief adds an access point to this stop
     216              :     virtual bool addAccess(MSLane* const lane, const double startPos, const double endPos, double length, const MSStoppingPlace::AccessExit exit);
     217              : 
     218              :     /// @brief lanes and positions connected to this stop
     219              :     const std::vector<Access>& getAllAccessPos() const {
     220              :         return myAccessPos;
     221              :     }
     222              : 
     223              :     /// @brief the position on the given edge which is connected to this stop, -1 on failure
     224              :     double getAccessPos(const MSEdge* edge, SumoRNG* rng = nullptr) const;
     225              : 
     226              :     /// @brief the access on the given edge to the stop, nullptr if there is none
     227              :     const Access* getAccess(const MSEdge* edge) const;
     228              : 
     229              :     const std::string& getMyName() const;
     230              : 
     231              :     /// @brief return the type of this stopping place
     232              :     SumoXMLTag getElement() const {
     233       444724 :         return myElement;
     234              :     }
     235              : 
     236              :     const RGBColor& getColor() const;
     237              : 
     238              :     static int getDefaultTransportablesAbreast(double length, SumoXMLTag element);
     239              : 
     240              :     /// @brief get list of vehicles waiting at this stop
     241              :     std::vector<const SUMOVehicle*> getStoppedVehicles() const;
     242              : 
     243              :     /// @brief get number of persons waiting at this stop
     244              :     inline int getNumWaitingPersons() const {
     245      1547923 :         return (int)myWaitingTransportables.size();
     246              :     }
     247              : 
     248              :     /// @brief get number of persons that can wait at this stop
     249              :     inline int getWaitingCapacity() const {
     250      1547814 :         return myTransportableCapacity;
     251              :     }
     252              : 
     253              :     inline double getParkingLength() const {
     254        46624 :         return (myEndPos - myBegPos) / myParkingFactor;
     255              :     }
     256              : 
     257              :     /// @brief get IDs of persons waiting at this stop
     258              :     void getWaitingPersonIDs(std::vector<std::string>& into) const;
     259              : 
     260              :     bool checkPersonCapacity() const {
     261       118804 :         return myElement == SUMO_TAG_BUS_STOP || myElement == SUMO_TAG_TRAIN_STOP;;
     262              :     }
     263              : 
     264              :     /// @brief perform extra processing after element has been loaded
     265              :     virtual void finishedLoading();
     266              : 
     267              :     /** @brief Remove all vehicles before quick-loading state */
     268              :     void clearState();
     269              : 
     270              : protected:
     271              :     /** @brief Computes the last free position on this stop
     272              :      *
     273              :      * The last free position is the one, the last vehicle ends at.
     274              :      * It is stored in myLastFreePos. If no vehicle halts, the last free
     275              :      *  position gets the value of myEndPos.
     276              :      */
     277              :     void computeLastFreePos();
     278              : 
     279              :     int getTransportablesAbreast() const;
     280              : 
     281              :     static double getDefaultTransportableWidth(SumoXMLTag element);
     282              : 
     283              : protected:
     284              :     /// @brief the type of stopping place
     285              :     const SumoXMLTag myElement;
     286              : 
     287              :     /// @brief The list of lines that are assigned to this stop
     288              :     std::vector<std::string> myLines;
     289              : 
     290              :     /// @brief A map from objects (vehicles) to the areas they acquire after entering the stop
     291              :     std::map<const SUMOVehicle*, std::pair<double, double>, ComparatorNumericalIdLess> myEndPositions;
     292              : 
     293              :     /// @brief The lane this bus stop is located at
     294              :     const MSLane& myLane;
     295              : 
     296              :     /// @brief The begin position this bus stop is located at
     297              :     const double myBegPos;
     298              : 
     299              :     /// @brief The end position this bus stop is located at
     300              :     const double myEndPos;
     301              : 
     302              :     /// @brief The last free position at this stop (variable)
     303              :     double myLastFreePos;
     304              :     /// @brief The length of the last parking vehicle (or 0 if there is none)
     305              :     const SUMOVehicle* myLastParking;
     306              : 
     307              :     /// @brief The name of the stopping place
     308              :     const std::string myName;
     309              : 
     310              :     /// @brief The number of transportables that can wait here
     311              :     const int myTransportableCapacity;
     312              : 
     313              :     /// @brief the scaled space capacity for parking vehicles
     314              :     const double myParkingFactor;
     315              : 
     316              :     /// @brief The color of the stopping place
     317              :     const RGBColor myColor;
     318              : 
     319              :     /// @brief The angle offset for waiting transportables
     320              :     double myAngle;
     321              : 
     322              :     /// @brief row depth of waiting transportables
     323              :     double myTransportableDepth;
     324              :     /// @brief the with of waiting transportables
     325              :     double myTransportableWidth;
     326              : 
     327              :     /// @brief Persons waiting at this stop (mapped to waiting position)
     328              :     std::map<const MSTransportable*, int> myWaitingTransportables;
     329              :     std::set<int> myWaitingSpots;
     330              : 
     331              :     /// @brief lanes and positions connected to this stop
     332              :     std::vector<Access> myAccessPos;
     333              : 
     334              : private:
     335              :     /// @brief Invalidated copy constructor.
     336              :     MSStoppingPlace(const MSStoppingPlace&);
     337              : 
     338              :     /// @brief Invalidated assignment operator.
     339              :     MSStoppingPlace& operator=(const MSStoppingPlace&);
     340              : 
     341              : 
     342              : };
        

Generated by: LCOV version 2.0-1