LCOV - code coverage report
Current view: top level - src/netbuild - NBPTLine.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 88.2 % 17 15
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) 2001-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    NBPTLine.h
      15              : /// @author  Gregor Laemmel
      16              : /// @author  Nikita Cherednychek
      17              : /// @date    Tue, 20 Mar 2017
      18              : ///
      19              : // The representation of one direction of a single pt line
      20              : /****************************************************************************/
      21              : #pragma once
      22              : #include <config.h>
      23              : 
      24              : #include <memory>
      25              : #include <map>
      26              : #include <string>
      27              : #include <vector>
      28              : 
      29              : 
      30              : // ===========================================================================
      31              : // class declarations
      32              : // ===========================================================================
      33              : class OutputDevice;
      34              : class NBEdge;
      35              : class NBEdgeCont;
      36              : class NBPTStop;
      37              : class NBPTStopCont;
      38              : 
      39              : 
      40              : // ===========================================================================
      41              : // class definitions
      42              : // ===========================================================================
      43              : class NBPTLine {
      44              : public:
      45              :     NBPTLine(const std::string& id, const std::string& name,
      46              :              const std::string& type, const std::string& ref, int interval, const std::string& nightService,
      47              :              SUMOVehicleClass vClass, RGBColor color);
      48              : 
      49              :     void addPTStop(std::shared_ptr<NBPTStop> pStop);
      50              : 
      51              :     const std::string& getLineID() const {
      52         1154 :         return myPTLineId;
      53              :     }
      54              : 
      55              :     const std::string& getName() const {
      56              :         return myName;
      57              :     }
      58              : 
      59              :     const std::string& getType() const {
      60          507 :         return myType;
      61              :     }
      62              : 
      63              :     const std::vector<std::shared_ptr<NBPTStop> >& getStops();
      64              :     void write(OutputDevice& device);
      65              :     void addWayNode(long long int way, long long int node);
      66              : 
      67              :     void setNumOfStops(int numStops, int missingBefore, int missingAfter);
      68              : 
      69              :     /// @brief get line reference (not unique)
      70              :     const std::string& getRef() const {
      71         3552 :         return myRef;
      72              :     }
      73              : 
      74              :     void replaceStops(std::vector<std::shared_ptr<NBPTStop> > stops) {
      75          507 :         myPTStops = stops;
      76          507 :     }
      77              : 
      78              :     void setRevised(std::vector<bool> stopsRevised) {
      79          979 :         myStopsRevised = stopsRevised;
      80          979 :     }
      81              :     /// @brief get stop edges and stop ids and directional validity
      82        12036 :     struct PTStopInfo {
      83         2872 :         PTStopInfo(NBEdge* _edge, const std::string& _stopID, double _pos, bool _revised):
      84         2872 :             edge(_edge), stopID(_stopID), pos(_pos), revised(_revised) {}
      85              :         NBEdge* edge;
      86              :         std::string stopID;
      87              :         double pos;
      88              :         bool revised;
      89              :     };
      90              :     std::vector<PTStopInfo> getStopEdges(const NBEdgeCont& ec) const;
      91              : 
      92              :     /// @brief return first valid edge of myRoute (if it doest not lie after the first stop)
      93              :     NBEdge* getRouteStart(const NBEdgeCont& ec) const;
      94              : 
      95              :     /// @brief return last valid edge of myRoute (if it doest not lie before the last stop)
      96              :     NBEdge* getRouteEnd(const NBEdgeCont& ec) const;
      97              : 
      98              :     /// @brief return whether the mentioned edges appear in that order in the route
      99              :     bool isConsistent(std::vector<NBEdge*> stops) const;
     100              : 
     101              :     SUMOVehicleClass getVClass() const {
     102         9916 :         return myVClass;
     103              :     }
     104              : 
     105              :     /// @brief replace the given stop
     106              :     void replaceStop(std::shared_ptr<NBPTStop> oldStop, std::shared_ptr<NBPTStop> newStop);
     107              : 
     108              :     /// @brief replace the edge with the given edge list
     109              :     void replaceEdge(const std::string& edgeID, const std::vector<NBEdge*>& replacement);
     110              : 
     111              :     /// @brief remove invalid stops from the line
     112              :     void deleteInvalidStops(const NBEdgeCont& ec, const NBPTStopCont& sc);
     113              :     void deleteDuplicateStops();
     114              : 
     115              :     /// @brief remove invalid edges from the line
     116              :     void removeInvalidEdges(const NBEdgeCont& ec);
     117              : 
     118              :     void setName(const std::string& name) {
     119            3 :         myName = name;
     120            3 :     }
     121              : 
     122              :     void setRef(const std::string& line) {
     123            0 :         myRef = line;
     124            0 :     }
     125              : 
     126              :     void setPeriod(int intervalS) {
     127            1 :         myInterval = intervalS / 60;
     128            1 :     }
     129              : 
     130              :     inline const std::vector<std::string>& getWays() const {
     131              :         return myWays;
     132              :     }
     133              : 
     134              :     const std::vector<long long int>* getWayNodes(std::string wayId);
     135              : 
     136              :     const EdgeVector& getEdges() const {
     137              :         return myRoute;
     138              :     }
     139              : 
     140              : private:
     141              :     std::string myName;
     142              :     std::string myType;
     143              :     std::vector<std::shared_ptr<NBPTStop> > myPTStops;
     144              :     // @brief for each stop store a flag that states whether it was successfully matched to the osm-route
     145              :     std::vector<bool> myStopsRevised;
     146              :     std::map<std::string, std::vector<long long int> > myWayNodes;
     147              :     std::vector<std::string> myWays;
     148              :     std::string myCurrentWay;
     149              :     std::string myPTLineId;
     150              :     std::string myRef;
     151              :     // official line color
     152              :     RGBColor myColor;
     153              : 
     154              :     // @brief the service interval in minutes
     155              :     int myInterval;
     156              : 
     157              :     std::string myNightService;
     158              :     SUMOVehicleClass myVClass;
     159              : 
     160              : public:
     161              :     void setEdges(const std::vector<NBEdge*>& edges);
     162              : private:
     163              :     // route of ptline
     164              :     std::vector<NBEdge*> myRoute;
     165              : public:
     166              :     const std::vector<NBEdge*>& getRoute() const;
     167              : private:
     168              : 
     169              :     int myNumOfStops;
     170              :     int myMissingStopsBefore;
     171              :     int myMissingStopsAfter;
     172              : };
        

Generated by: LCOV version 2.0-1