Line data Source code
1 : /****************************************************************************/ 2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo 3 : // Copyright (C) 2001-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 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 1471 : return myPTLineId; 53 : } 54 : 55 : const std::string& getName() const { 56 : return myName; 57 : } 58 : 59 : const std::string& getType() const { 60 788 : 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 4988 : return myRef; 72 : } 73 : 74 : void replaceStops(std::vector<std::shared_ptr<NBPTStop> > stops) { 75 784 : myPTStops = stops; 76 784 : } 77 : /// @brief get stop edges and stop ids 78 : std::vector<std::pair<NBEdge*, std::string> > getStopEdges(const NBEdgeCont& ec) const; 79 : 80 : /// @brief return first valid edge of myRoute (if it doest not lie after the first stop) 81 : NBEdge* getRouteStart(const NBEdgeCont& ec) const; 82 : 83 : /// @brief return last valid edge of myRoute (if it doest not lie before the last stop) 84 : NBEdge* getRouteEnd(const NBEdgeCont& ec) const; 85 : 86 : /// @brief return whether the mentioned edges appear in that order in the route 87 : bool isConsistent(std::vector<NBEdge*> stops) const; 88 : 89 : SUMOVehicleClass getVClass() const { 90 16076 : return myVClass; 91 : } 92 : 93 : /// @brief replace the given stop 94 : void replaceStop(std::shared_ptr<NBPTStop> oldStop, std::shared_ptr<NBPTStop> newStop); 95 : 96 : /// @brief replace the edge with the given edge list 97 : void replaceEdge(const std::string& edgeID, const std::vector<NBEdge*>& replacement); 98 : 99 : /// @brief remove invalid stops from the line 100 : void deleteInvalidStops(const NBEdgeCont& ec, const NBPTStopCont& sc); 101 : void deleteDuplicateStops(); 102 : 103 : /// @brief remove invalid edges from the line 104 : void removeInvalidEdges(const NBEdgeCont& ec); 105 : 106 : void setName(const std::string& name) { 107 3 : myName = name; 108 3 : } 109 : 110 : void setRef(const std::string& line) { 111 0 : myRef = line; 112 0 : } 113 : 114 : void setPeriod(int intervalS) { 115 1 : myInterval = intervalS / 60; 116 1 : } 117 : 118 : inline const std::vector<std::string>& getWays() const { 119 : return myWays; 120 : } 121 : 122 : const std::vector<long long int>* getWayNodes(std::string wayId); 123 : 124 : private: 125 : std::string myName; 126 : std::string myType; 127 : std::vector<std::shared_ptr<NBPTStop> > myPTStops; 128 : std::map<std::string, std::vector<long long int> > myWayNodes; 129 : std::vector<std::string> myWays; 130 : std::string myCurrentWay; 131 : std::string myPTLineId; 132 : std::string myRef; 133 : // official line color 134 : RGBColor myColor; 135 : 136 : // @brief the service interval in minutes 137 : int myInterval; 138 : 139 : std::string myNightService; 140 : SUMOVehicleClass myVClass; 141 : 142 : public: 143 : void setEdges(const std::vector<NBEdge*>& edges); 144 : private: 145 : // route of ptline 146 : std::vector<NBEdge*> myRoute; 147 : public: 148 : const std::vector<NBEdge*>& getRoute() const; 149 : private: 150 : 151 : int myNumOfStops; 152 : int myMissingStopsBefore; 153 : int myMissingStopsAfter; 154 : };