LCOV - code coverage report
Current view: top level - src/router - ROPerson.h (source / functions) Hit Total Coverage
Test: lcov.info Lines: 88 112 78.6 %
Date: 2024-05-08 15:29:52 Functions: 26 38 68.4 %

          Line data    Source code
       1             : /****************************************************************************/
       2             : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3             : // Copyright (C) 2002-2024 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    ROPerson.h
      15             : /// @author  Robert Hilbrich
      16             : /// @author  Michael Behrisch
      17             : /// @date    Sept 2002
      18             : ///
      19             : // A person as used by router
      20             : /****************************************************************************/
      21             : #pragma once
      22             : #include <config.h>
      23             : 
      24             : #include <string>
      25             : #include <iostream>
      26             : #include <utils/common/Parameterised.h>
      27             : #include <utils/common/StdDefs.h>
      28             : #include <utils/common/SUMOTime.h>
      29             : #include <utils/vehicle/SUMOVehicleParameter.h>
      30             : #include <utils/vehicle/SUMOVTypeParameter.h>
      31             : #include "RORoutable.h"
      32             : #include "RORouteDef.h"
      33             : #include "ROVehicle.h"
      34             : 
      35             : 
      36             : // ===========================================================================
      37             : // class declarations
      38             : // ===========================================================================
      39             : class OutputDevice;
      40             : class ROEdge;
      41             : 
      42             : 
      43             : // ===========================================================================
      44             : // class definitions
      45             : // ===========================================================================
      46             : /**
      47             :  * @class ROPerson
      48             :  * @brief A person as used by router
      49             :  */
      50             : class ROPerson : public RORoutable {
      51             : 
      52             : public:
      53             :     class PlanItem;
      54             :     /** @brief Constructor
      55             :      *
      56             :      * @param[in] pars Parameter of this person
      57             :      * @param[in] type The type of the person
      58             :      */
      59             :     ROPerson(const SUMOVehicleParameter& pars, const SUMOVTypeParameter* type);
      60             : 
      61             :     /// @brief Destructor
      62             :     virtual ~ROPerson();
      63             : 
      64             :     static void addTrip(std::vector<PlanItem*>& plan, const std::string& id,
      65             :                         const ROEdge* const from, const ROEdge* const to, const SVCPermissions modeSet, const std::string& vTypes,
      66             :                         const double departPos, const std::string& stopOrigin,
      67             :                         const double arrivalPos, const std::string& busStop,
      68             :                         double walkFactor, const std::string& group);
      69             : 
      70             :     static void addRide(std::vector<PlanItem*>& plan, const ROEdge* const from, const ROEdge* const to, const std::string& lines,
      71             :                         double arrivalPos, const std::string& destStop, const std::string& group);
      72             : 
      73             :     static void addWalk(std::vector<PlanItem*>& plan, const ConstROEdgeVector& edges, const double duration, const double speed,
      74             :                         const double departPos, const double arrivalPos, const std::string& busStop);
      75             : 
      76             :     static void addStop(std::vector<PlanItem*>& plan, const SUMOVehicleParameter::Stop& stopPar, const ROEdge* const stopEdge);
      77             : 
      78             :     class TripItem;
      79             :     /**
      80             :      * @brief Every person has a plan comprising of multiple planItems
      81             :      *
      82             :      */
      83        2094 :     class PlanItem : public Parameterised {
      84             :     public:
      85             :         /// @brief Destructor
      86        1970 :         virtual ~PlanItem() {}
      87             : 
      88             :         virtual PlanItem* clone() const = 0;
      89             : 
      90           0 :         virtual void addTripItem(TripItem* /* tripIt */) {
      91           0 :             throw ProcessError();
      92             :         }
      93             :         virtual const ROEdge* getOrigin() const = 0;
      94             :         virtual const ROEdge* getDestination() const = 0;
      95             :         virtual double getDestinationPos() const = 0;
      96         176 :         virtual void saveVehicles(OutputDevice& /* os */, OutputDevice* const /* typeos */, bool /* asAlternatives */, OptionsCont& /* options */) const {}
      97             :         virtual void saveAsXML(OutputDevice& os, const bool extended, const bool asTrip, OptionsCont& options) const = 0;
      98           4 :         virtual bool isStop() const {
      99           4 :             return false;
     100             :         }
     101         124 :         virtual bool needsRouting() const {
     102         124 :             return false;
     103             :         }
     104           0 :         virtual SUMOVehicleParameter::Stop* getStopParameters() {
     105           0 :             return nullptr;
     106             :         }
     107             : 
     108             :         virtual SUMOTime getDuration() const = 0;
     109           0 :         virtual const std::string& getStopDest() const {
     110           0 :             return UNDEFINED_STOPPING_PLACE;
     111             :         }
     112             : 
     113             :         static const std::string UNDEFINED_STOPPING_PLACE;
     114             :     };
     115             : 
     116             :     /**
     117             :      * @brief A planItem can be a Stop
     118             :      *
     119             :      */
     120             :     class Stop : public PlanItem {
     121             :     public:
     122         124 :         Stop(const SUMOVehicleParameter::Stop& stop, const ROEdge* const stopEdge)
     123         124 :             : stopDesc(stop), edge(stopEdge) {}
     124             : 
     125           0 :         PlanItem* clone() const {
     126           0 :             return new Stop(stopDesc, edge);
     127             :         }
     128             : 
     129           0 :         const ROEdge* getOrigin() const {
     130           0 :             return edge;
     131             :         }
     132          72 :         const ROEdge* getDestination() const {
     133          72 :             return edge;
     134             :         }
     135          76 :         double getDestinationPos() const {
     136          76 :             return (stopDesc.startPos + stopDesc.endPos) / 2;
     137             :         }
     138             :         void saveAsXML(OutputDevice& os, const bool extended, const bool asTrip, OptionsCont& options) const;
     139             : 
     140           4 :         bool isStop() const {
     141           4 :             return true;
     142             :         }
     143         124 :         virtual SUMOVehicleParameter::Stop* getStopParameters() {
     144         124 :             return &stopDesc;
     145             :         }
     146         124 :         SUMOTime getDuration() const {
     147         124 :             return stopDesc.duration;
     148             :         }
     149          76 :         inline const std::string& getStopDest() const {
     150          76 :             return stopDesc.busstop;
     151             :         }
     152             : 
     153             :     private:
     154             :         SUMOVehicleParameter::Stop stopDesc;
     155             :         const ROEdge* const edge;
     156             : 
     157             :     private:
     158             :         /// @brief Invalidated assignment operator
     159             :         Stop& operator=(const Stop& src);
     160             : 
     161             :     };
     162             : 
     163             :     /**
     164             :      * @brief A TripItem is part of a trip, e.g., go from here to here by car
     165             :      *
     166             :      */
     167             :     class TripItem {
     168             :     public:
     169             :         TripItem(const SUMOTime start, const double cost)
     170        3164 :             : myStart(start), myCost(cost) {}
     171             : 
     172             :         /// @brief Destructor
     173             :         virtual ~TripItem() {}
     174             : 
     175             :         virtual TripItem* clone() const = 0;
     176             : 
     177             :         virtual const ROEdge* getOrigin() const = 0;
     178             :         virtual const ROEdge* getDestination() const = 0;
     179             :         virtual double getDestinationPos() const = 0;
     180             :         virtual void saveAsXML(OutputDevice& os, const bool extended, OptionsCont& options) const = 0;
     181             : 
     182             :         inline SUMOTime getStart() const {
     183          20 :             return myStart;
     184             :         }
     185             : 
     186             :         inline SUMOTime getDuration() const {
     187        3316 :             return TIME2STEPS(myCost);
     188             :         }
     189             : 
     190             :         inline double getCost() const {
     191        2100 :             return myCost;
     192             :         }
     193             :     protected:
     194             :         const SUMOTime myStart;
     195             :         const double myCost;
     196             :     };
     197             : 
     198             :     /**
     199             :      * @brief A ride is part of a trip, e.g., go from here to here by car or bus
     200             :      *
     201             :      */
     202             :     class Ride : public TripItem {
     203             :     public:
     204         746 :         Ride(const SUMOTime start, const ROEdge* const _from, const ROEdge* const _to,
     205             :              const std::string& _lines, const std::string& _group, const double cost,
     206             :              const double arrivalPos, const double _length,
     207         746 :              const std::string& _destStop = "", const std::string& _intended = "", const SUMOTime _depart = -1) :
     208             :             TripItem(start, cost),
     209         746 :             from(_from), to(_to),
     210         746 :             lines(_lines),
     211         746 :             group(_group),
     212         746 :             destStop(_destStop),
     213         746 :             intended(_intended),
     214         746 :             depart(_depart),
     215         746 :             arrPos(arrivalPos),
     216         746 :             length(_length) {
     217         746 :         }
     218             : 
     219           0 :         TripItem* clone() const {
     220           0 :             return new Ride(myStart, from, to, lines, group, myCost, arrPos, length, destStop, intended, depart);
     221             :         }
     222             : 
     223           0 :         inline const ROEdge* getOrigin() const {
     224           0 :             return from;
     225             :         }
     226           0 :         inline const ROEdge* getDestination() const {
     227           0 :             return to;
     228             :         }
     229           8 :         inline double getDestinationPos() const {
     230           8 :             return arrPos == std::numeric_limits<double>::infinity() ? -NUMERICAL_EPS : arrPos;
     231             :         }
     232             :         void saveAsXML(OutputDevice& os, const bool extended, OptionsCont& options) const;
     233             : 
     234             :     private:
     235             :         const ROEdge* const from;
     236             :         const ROEdge* const to;
     237             :         const std::string lines;
     238             :         const std::string group;
     239             :         const std::string destStop;
     240             :         const std::string intended;
     241             :         const SUMOTime depart;
     242             :         const double arrPos;
     243             :         const double length;
     244             : 
     245             :     private:
     246             :         /// @brief Invalidated assignment operator
     247             :         Ride& operator=(const Ride& src);
     248             : 
     249             :     };
     250             : 
     251             :     /**
     252             :      * @brief A walk is part of a trip, e.g., go from here to here by foot
     253             :      *
     254             :      */
     255             :     class Walk : public TripItem {
     256             :     public:
     257        2346 :         Walk(const SUMOTime start, const ConstROEdgeVector& _edges, const double cost,
     258             :              const std::vector<double>& _exitTimes,
     259             :              double departPos = std::numeric_limits<double>::infinity(),
     260             :              double arrivalPos = std::numeric_limits<double>::infinity(),
     261             :              const std::string& _destStop = "")
     262        4692 :             : TripItem(start, cost), edges(_edges), exitTimes(_exitTimes), dur(-1), v(-1), dep(departPos), arr(arrivalPos), destStop(_destStop) {}
     263          72 :         Walk(const SUMOTime start, const ConstROEdgeVector& edges, const double cost, const double duration, const double speed,
     264             :              const double departPos, const double arrivalPos, const std::string& _destStop)
     265         144 :             : TripItem(start, cost), edges(edges), dur(duration), v(speed), dep(departPos), arr(arrivalPos), destStop(_destStop) {}
     266             : 
     267          20 :         TripItem* clone() const {
     268          20 :             return new Walk(myStart, edges, myCost, exitTimes, dep, arr, destStop);
     269             :         }
     270             : 
     271           0 :         inline const ROEdge* getOrigin() const {
     272           0 :             return edges.front();
     273             :         }
     274           0 :         inline const ROEdge* getDestination() const {
     275           0 :             return edges.back();
     276             :         }
     277           0 :         inline double getDestinationPos() const {
     278           0 :             return arr == std::numeric_limits<double>::infinity() ? 0 : arr;
     279             :         }
     280             :         void saveAsXML(OutputDevice& os, const bool extended, OptionsCont& options) const;
     281             : 
     282             :     private:
     283             :         const ConstROEdgeVector edges;
     284             :         const std::vector<double> exitTimes;
     285             :         const double dur, v, dep, arr;
     286             :         const std::string destStop;
     287             : 
     288             :     private:
     289             :         /// @brief Invalidated assignment operator
     290             :         Walk& operator=(const Walk& src);
     291             : 
     292             :     };
     293             : 
     294             :     /**
     295             :      * @brief A planItem can be a Trip which contains multiple tripItems
     296             :      *
     297             :      */
     298             :     class PersonTrip : public PlanItem {
     299             :     public:
     300         124 :         PersonTrip(const ROEdge* _to, const std::string _stopDest) :
     301         248 :             from(0), to(_to), modes(SVC_PEDESTRIAN), dep(0), arr(0), stopDest(_stopDest), walkFactor(1.0) {}
     302        1846 :         PersonTrip(const ROEdge* const _from, const ROEdge* const _to, const SVCPermissions modeSet,
     303        1846 :                    const double departPos, const std::string& _stopOrigin, const double arrivalPos, const std::string& _stopDest, double _walkFactor, const std::string& _group) :
     304        7384 :             from(_from), to(_to), modes(modeSet), dep(departPos), arr(arrivalPos), stopOrigin(_stopOrigin), stopDest(_stopDest), walkFactor(_walkFactor), group(_group) { }
     305             :         /// @brief Destructor
     306        3940 :         virtual ~PersonTrip() {
     307        5126 :             for (TripItem* const it : myTripItems) {
     308        3156 :                 delete it;
     309             :             }
     310        2082 :             for (ROVehicle* const v : myVehicles) {
     311         112 :                 delete v->getRouteDefinition();
     312         112 :                 delete v;
     313             :             }
     314        3940 :         }
     315             : 
     316             :         PlanItem* clone() const;
     317             : 
     318         128 :         virtual void addTripItem(TripItem* tripIt) {
     319         128 :             myTripItems.push_back(tripIt);
     320         128 :         }
     321             :         void addVehicle(ROVehicle* veh) {
     322         680 :             myVehicles.push_back(veh);
     323         680 :         }
     324             :         std::vector<ROVehicle*>& getVehicles() {
     325             :             return myVehicles;
     326             :         }
     327        4384 :         const ROEdge* getOrigin() const {
     328        4384 :             return from != 0 ? from : myTripItems.front()->getOrigin();
     329             :         }
     330        4400 :         const ROEdge* getDestination() const {
     331        4400 :             return to;
     332             :         }
     333          20 :         double getDestinationPos() const {
     334          20 :             if (myTripItems.empty()) {
     335             :                 return getArrivalPos(true);
     336             :             } else {
     337           8 :                 return myTripItems.back()->getDestinationPos();
     338             :             }
     339             :         }
     340             :         double getDepartPos(bool replaceDefault = true) const {
     341           4 :             return dep == std::numeric_limits<double>::infinity() && replaceDefault ? 0 : dep;
     342             :         }
     343             :         double getArrivalPos(bool replaceDefault = true) const {
     344        4144 :             return arr == std::numeric_limits<double>::infinity() && replaceDefault ? 0 : arr;
     345             :         }
     346             :         SVCPermissions getModes() const {
     347        1802 :             return modes;
     348             :         }
     349             :         void updateModes(SVCPermissions additionalModes) {
     350          40 :             modes |= additionalModes;
     351          40 :         }
     352             : 
     353             :         const std::string& getGroup() const {
     354         690 :             return group;
     355             :         }
     356             : 
     357             :         const std::string& getStopOrigin() const {
     358        1802 :             return stopOrigin;
     359             :         }
     360             : 
     361        4492 :         const std::string& getStopDest() const {
     362        4492 :             return stopDest;
     363             :         }
     364        1934 :         virtual bool needsRouting() const {
     365        1934 :             return myTripItems.empty();
     366             :         }
     367             : 
     368        1794 :         void setItems(std::vector<TripItem*>& newItems, const ROVehicle* const veh) {
     369             :             assert(myTripItems.empty());
     370             :             myTripItems.swap(newItems);
     371        2474 :             for (auto it = myVehicles.begin(); it != myVehicles.end();) {
     372         680 :                 if (*it != veh) {
     373         568 :                     delete (*it)->getRouteDefinition();
     374         568 :                     delete (*it);
     375         568 :                     it = myVehicles.erase(it);
     376             :                 } else {
     377             :                     it++;
     378             :                 }
     379             :             }
     380        1794 :         }
     381             : 
     382             :         void saveVehicles(OutputDevice& os, OutputDevice* const typeos, bool asAlternatives, OptionsCont& options) const;
     383             :         void saveAsXML(OutputDevice& os, const bool extended, const bool asTrip, OptionsCont& options) const;
     384             : 
     385             :         double getWalkFactor() const {
     386        1802 :             return walkFactor;
     387             :         }
     388             : 
     389             :         /// @brief return duration sum of all trip items
     390             :         SUMOTime getDuration() const;
     391             : 
     392             :     private:
     393             :         const ROEdge* from;
     394             :         const ROEdge* to;
     395             :         SVCPermissions modes;
     396             :         const double dep, arr;
     397             :         const std::string stopOrigin;
     398             :         const std::string stopDest;
     399             :         /// @brief the fully specified trips
     400             :         std::vector<TripItem*> myTripItems;
     401             :         /// @brief the vehicles which may be used for routing
     402             :         std::vector<ROVehicle*> myVehicles;
     403             :         /// @brief walking speed factor
     404             :         double walkFactor;
     405             :         /// @brief group id for travelling in groups
     406             :         const std::string group;
     407             : 
     408             :     private:
     409             :         /// @brief Invalidated assignment operator
     410             :         PersonTrip& operator=(const PersonTrip& src);
     411             : 
     412             :     };
     413             : 
     414             : 
     415             :     /** @brief Returns the first edge the person takes
     416             :      *
     417             :      * @return The person's departure edge
     418             :      */
     419           0 :     const ROEdge* getDepartEdge() const {
     420           0 :         return myPlan.front()->getOrigin();
     421             :     }
     422             : 
     423             : 
     424             :     void computeRoute(const RORouterProvider& provider,
     425             :                       const bool removeLoops, MsgHandler* errorHandler);
     426             : 
     427             : 
     428             :     /** @brief Saves the complete person description.
     429             :      *
     430             :      * Saves the person itself including the trips and stops.
     431             :      *
     432             :      * @param[in] os The routes or alternatives output device to store the routable's description into
     433             :      * @param[in] typeos The types - output device to store additional types into
     434             :      * @param[in] asAlternatives Whether the route shall be saved as route alternatives
     435             :      * @param[in] options to find out about defaults and whether exit times for the edges shall be written
     436             :      * @exception IOError If something fails (not yet implemented)
     437             :      */
     438             :     void saveAsXML(OutputDevice& os, OutputDevice* const typeos, bool asAlternatives, OptionsCont& options) const;
     439             : 
     440             :     std::vector<PlanItem*>& getPlan() {
     441        2066 :         return myPlan;
     442             :     }
     443             : 
     444             : private:
     445             :     bool computeIntermodal(SUMOTime time, const RORouterProvider& provider,
     446             :                            const PersonTrip* const trip, const ROVehicle* const veh,
     447             :                            std::vector<TripItem*>& resultItems, MsgHandler* const errorHandler);
     448             : 
     449             : private:
     450             :     /**
     451             :      * @brief The plan of the person
     452             :      */
     453             :     std::vector<PlanItem*> myPlan;
     454             : 
     455             : 
     456             : private:
     457             :     /// @brief Invalidated copy constructor
     458             :     ROPerson(const ROPerson& src);
     459             : 
     460             :     /// @brief Invalidated assignment operator
     461             :     ROPerson& operator=(const ROPerson& src);
     462             : 
     463             : };

Generated by: LCOV version 1.14