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 ROVehicle.h 15 : /// @author Daniel Krajzewicz 16 : /// @author Michael Behrisch 17 : /// @author Jakob Erdmann 18 : /// @date Sept 2002 19 : /// 20 : // A vehicle as used by router 21 : /****************************************************************************/ 22 : #pragma once 23 : #include <config.h> 24 : 25 : #include <string> 26 : #include <iostream> 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 : 33 : 34 : // =========================================================================== 35 : // class declarations 36 : // =========================================================================== 37 : class OutputDevice; 38 : class ROEdge; 39 : class RONet; 40 : class RORouteDef; 41 : 42 : 43 : // =========================================================================== 44 : // class definitions 45 : // =========================================================================== 46 : /** 47 : * @class ROVehicle 48 : * @brief A vehicle as used by router 49 : */ 50 : class ROVehicle : public RORoutable { 51 : public: 52 : /** @brief Constructor 53 : * 54 : * @param[in] pars Parameter of this vehicle 55 : * @param[in] route The definition of the route the vehicle shall use 56 : * @param[in] type The type of the vehicle 57 : */ 58 : ROVehicle(const SUMOVehicleParameter& pars, 59 : RORouteDef* route, const SUMOVTypeParameter* type, 60 : const RONet* net, MsgHandler* errorHandler = 0); 61 : 62 : 63 : /// @brief Destructor 64 : virtual ~ROVehicle(); 65 : 66 : 67 : /** @brief Returns the definition of the route the vehicle takes 68 : * 69 : * @return The vehicle's route definition 70 : * 71 : * @todo Why not return a reference? 72 : */ 73 : inline RORouteDef* getRouteDefinition() const { 74 589483 : return myRoute; 75 : } 76 : 77 : 78 : /** @brief Returns the first edge the vehicle takes 79 : * 80 : * @return The vehicle's departure edge 81 : */ 82 : const ROEdge* getDepartEdge() const; 83 : 84 : 85 : void computeRoute(const RORouterProvider& provider, 86 : const bool removeLoops, MsgHandler* errorHandler); 87 : 88 : /** @brief Returns the time the vehicle starts at, 0 for triggered vehicles 89 : * 90 : * @return The vehicle's depart time 91 : */ 92 : inline SUMOTime getDepartureTime() const { 93 1409438 : return MAX2(SUMOTime(0), getParameter().depart); 94 : } 95 : 96 : 97 : inline const ConstROEdgeVector& getStopEdges() const { 98 : return myStopEdges; 99 : } 100 : 101 : 102 : /// @brief compute mandatory edges 103 : ConstROEdgeVector getMandatoryEdges(const ROEdge* requiredStart, const ROEdge* requiredEnd) const; 104 : 105 : /** @brief Returns an upper bound for the speed factor of this vehicle 106 : * 107 : * @return the maximum speed factor 108 : */ 109 : inline double getChosenSpeedFactor() const { 110 8065432 : return getType()->speedFactor.getMax(); 111 : } 112 : 113 : /** @brief Returns the vehicle's type definition 114 : * @return The vehicle's type definition 115 : */ 116 : inline const SUMOVTypeParameter& getVehicleType() const { 117 : return *getType(); 118 : } 119 : 120 : /// @brief Returns the vehicle's length 121 : inline double getLength() const { 122 1340 : return getType()->length; 123 : } 124 : 125 : inline bool hasJumps() const { 126 368956 : return myJumpTime >= 0; 127 : } 128 : 129 : inline SUMOTime getJumpTime() const { 130 : return myJumpTime; 131 : } 132 : 133 : /// @brief collect mandatory-edge iterators that define jumps in the route 134 : void collectJumps(const ConstROEdgeVector& mandatory, std::set<ConstROEdgeVector::const_iterator>& jumpStarts) const; 135 : 136 : /** @brief Saves the complete vehicle description. 137 : * 138 : * Saves the vehicle itself including the route and stops. 139 : * 140 : * @param[in] os The routes or alternatives output device to store the vehicle's description into 141 : * @param[in] typeos The types - output device to store types into 142 : * @param[in] asAlternatives Whether the route shall be saved as route alternatives 143 : * @param[in] options to find out about defaults and whether exit times for the edges shall be written 144 : * @exception IOError If something fails (not yet implemented) 145 : */ 146 : void saveAsXML(OutputDevice& os, OutputDevice* const typeos, bool asAlternatives, OptionsCont& options) const; 147 : 148 : 149 : private: 150 : /** @brief Adds a stop to this vehicle 151 : * 152 : * @param[in] stopPar the stop paramters 153 : * @param[in] net pointer to the network, used for edge retrieval 154 : */ 155 : void addStop(const SUMOVehicleParameter::Stop& stopPar, 156 : const RONet* net, MsgHandler* errorHandler); 157 : 158 : private: 159 : /// @brief The route the vehicle takes 160 : RORouteDef* const myRoute; 161 : 162 : /// @brief The edges where the vehicle stops 163 : ConstROEdgeVector myStopEdges; 164 : 165 : /// @brief Whether this vehicle has any jumps defined 166 : SUMOTime myJumpTime; 167 : 168 : /// @brief map of all routes that were already saved with a name 169 : static std::map<ConstROEdgeVector, std::string> mySavedRoutes; 170 : 171 : private: 172 : /// @brief Invalidated copy constructor 173 : ROVehicle(const ROVehicle& src); 174 : 175 : /// @brief Invalidated assignment operator 176 : ROVehicle& operator=(const ROVehicle& src); 177 : 178 : };