Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2002-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 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 614446 : 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 1166956 : 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 the vehicle's type definition
106 : * @return The vehicle's type definition
107 : */
108 : inline const SUMOVTypeParameter& getVTypeParameter() const {
109 : return *getType();
110 : }
111 :
112 : /// @brief Returns the vehicle's length
113 : inline double getLength() const {
114 1950 : return getType()->length;
115 : }
116 :
117 : inline bool hasJumps() const {
118 461691 : return myJumpTime >= 0;
119 : }
120 :
121 : inline SUMOTime getJumpTime() const {
122 : return myJumpTime;
123 : }
124 :
125 : /// @brief collect mandatory-edge iterators that define jumps in the route
126 : void collectJumps(const ConstROEdgeVector& mandatory, std::set<ConstROEdgeVector::const_iterator>& jumpStarts) const;
127 :
128 : /** @brief Saves the complete vehicle description.
129 : *
130 : * Saves the vehicle itself including the route and stops.
131 : *
132 : * @param[in] os The routes or alternatives output device to store the vehicle's description into
133 : * @param[in] typeos The types - output device to store types into
134 : * @param[in] asAlternatives Whether the route shall be saved as route alternatives
135 : * @param[in] options to find out about defaults and whether exit times for the edges shall be written
136 : * @exception IOError If something fails (not yet implemented)
137 : */
138 : void saveAsXML(OutputDevice& os, OutputDevice* const typeos, bool asAlternatives, OptionsCont& options, int cloneIndex = 0) const;
139 :
140 :
141 : private:
142 : /** @brief Adds a stop to this vehicle
143 : *
144 : * @param[in] stopPar the stop paramters
145 : * @param[in] net pointer to the network, used for edge retrieval
146 : */
147 : void addStop(const SUMOVehicleParameter::Stop& stopPar,
148 : const RONet* net, MsgHandler* errorHandler);
149 :
150 : private:
151 : /// @brief The route the vehicle takes
152 : RORouteDef* const myRoute;
153 :
154 : /// @brief The edges where the vehicle stops
155 : ConstROEdgeVector myStopEdges;
156 :
157 : /// @brief Whether this vehicle has any jumps defined
158 : SUMOTime myJumpTime;
159 :
160 : /// @brief map of all routes that were already saved with a name
161 : static std::map<ConstROEdgeVector, std::string> mySavedRoutes;
162 :
163 : private:
164 : /// @brief Invalidated copy constructor
165 : ROVehicle(const ROVehicle& src);
166 :
167 : /// @brief Invalidated assignment operator
168 : ROVehicle& operator=(const ROVehicle& src);
169 :
170 : };
|