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 MSTransportable.h
15 : /// @author Michael Behrisch
16 : /// @date Tue, 21 Apr 2015
17 : ///
18 : // The common superclass for modelling transportable objects like persons and containers
19 : /****************************************************************************/
20 : #pragma once
21 : #include <config.h>
22 :
23 : #include <set>
24 : #include <cassert>
25 : #include <utils/common/SUMOTime.h>
26 : #include <utils/common/SUMOVehicleClass.h>
27 : #include <utils/common/WrappingCommand.h>
28 : #include <utils/geom/Position.h>
29 : #include <utils/geom/PositionVector.h>
30 : #include <utils/geom/Boundary.h>
31 : #include <utils/router/SUMOAbstractRouter.h>
32 : #include <utils/vehicle/SUMOTrafficObject.h>
33 : #include <microsim/MSRouterDefs.h>
34 : #include <microsim/MSVehicleType.h>
35 : #include "MSStage.h"
36 :
37 :
38 : // ===========================================================================
39 : // class declarations
40 : // ===========================================================================
41 : class MSEdge;
42 : class MSLane;
43 : class MSNet;
44 : class MSStoppingPlace;
45 : class OutputDevice;
46 : class SUMOVehicleParameter;
47 : class SUMOVehicle;
48 : class MSTransportableDevice;
49 :
50 :
51 : // ===========================================================================
52 : // class definitions
53 : // ===========================================================================
54 : /**
55 : * @class MSTransportable
56 : *
57 : * The class holds a simulated moveable object
58 : */
59 : class MSTransportable : public SUMOTrafficObject {
60 : public:
61 : /// @name inherited from SUMOTrafficObject
62 : /// @{
63 5875180 : inline bool isPerson() const {
64 5875180 : return myAmPerson;
65 : }
66 :
67 86 : inline bool isContainer() const {
68 86 : return !myAmPerson;
69 : }
70 :
71 : inline std::string getObjectType() {
72 740 : return myAmPerson ? "Person" : "Container";
73 : }
74 :
75 44363804 : inline NumericalID getNumericalID() const {
76 44363804 : return myNumericalID;
77 : }
78 :
79 4270 : inline bool isStopped() const {
80 4270 : return getCurrentStageType() == MSStageType::WAITING;
81 : }
82 :
83 : double getSlope() const;
84 :
85 : SUMOVehicleClass getVClass() const;
86 :
87 : /// @brief whether the transportable (persons) is jammed as defined by the current pedestrian model
88 0 : virtual bool isJammed() const {
89 0 : return false;
90 : }
91 :
92 : /** @brief Returns the maximum speed (the minimum of desired and physical maximum speed)
93 : * @return The objects's maximum speed
94 : */
95 : double getMaxSpeed() const;
96 :
97 : SUMOTime getWaitingTime(const bool accumulated = false) const;
98 :
99 25562 : double getPreviousSpeed() const {
100 25562 : return getSpeed();
101 : }
102 :
103 9037 : double getAcceleration() const {
104 9037 : return 0.0;
105 : }
106 :
107 1543331 : double getPositionOnLane() const {
108 1543331 : return getEdgePos();
109 : }
110 :
111 : double getBackPositionOnLane(const MSLane* lane) const;
112 :
113 258596 : Position getPosition(const double /*offset*/) const {
114 258596 : return getPosition();
115 : }
116 : /// @}
117 :
118 : /// the structure holding the plan of a transportable
119 : typedef std::vector<MSStage*> MSTransportablePlan;
120 :
121 : /// constructor
122 : MSTransportable(const SUMOVehicleParameter* pars, MSVehicleType* vtype, MSTransportablePlan* plan, const bool isPerson);
123 :
124 : /// destructor
125 : virtual ~MSTransportable();
126 :
127 : /* @brief proceeds to the next step of the route,
128 : * @return Whether the transportables plan continues */
129 : virtual bool proceed(MSNet* net, SUMOTime time, const bool vehicleArrived = false);
130 :
131 710 : virtual bool checkAccess(const MSStage* const prior, const bool waitAtStop = true) {
132 : UNUSED_PARAMETER(prior);
133 : UNUSED_PARAMETER(waitAtStop);
134 710 : return false;
135 : }
136 :
137 : /// @brief set the id (inherited from Named but forbidden for transportables)
138 : void setID(const std::string& newID);
139 :
140 55040055 : inline const SUMOVehicleParameter& getParameter() const {
141 55040055 : return *myParameter;
142 : }
143 :
144 4977851145 : inline const MSVehicleType& getVehicleType() const {
145 4977851145 : return *myVType;
146 : }
147 :
148 : /** @brief Returns the object's "vehicle" type parameter
149 : * @return The object's type parameter
150 : */
151 50159605 : inline const SUMOVTypeParameter& getVTypeParameter() const {
152 50159605 : return myVType->getParameter();
153 : }
154 :
155 : /// @brief returns the associated RNG
156 : SumoRNG* getRNG() const;
157 :
158 : /// @brief returns the index of the associated RNG
159 : int getRNGIndex() const;
160 :
161 : /// Returns the desired departure time.
162 : SUMOTime getDesiredDepart() const;
163 :
164 : /// logs depart time of the current stage
165 : void setDeparted(SUMOTime now);
166 :
167 : /// logs depart time of the current stage
168 : SUMOTime getDeparture() const;
169 :
170 : /// Returns the current destination.
171 : const MSEdge* getDestination() const {
172 80035 : return (*myStep)->getDestination();
173 : }
174 :
175 : /// Returns the destination after the current destination.
176 : const MSEdge* getNextDestination() const {
177 : return (*(myStep + 1))->getDestination();
178 : }
179 :
180 : /// @brief Returns the current edge
181 644333 : const MSEdge* getEdge() const {
182 644333 : return (*myStep)->getEdge();
183 : }
184 :
185 : /// @brief Returns the current lane (may be nullptr)
186 935628 : const MSLane* getLane() const {
187 935628 : return (*myStep)->getLane();
188 : }
189 :
190 0 : const MSLane* getBackLane() const {
191 0 : return getLane();
192 : }
193 :
194 : /// @brief Returns the departure edge
195 : const MSEdge* getFromEdge() const {
196 0 : return (*myStep)->getFromEdge();
197 : }
198 :
199 : /// @brief Return the position on the edge
200 : virtual double getEdgePos() const;
201 :
202 : /// @brief Return the movement directon on the edge
203 : virtual int getDirection() const;
204 :
205 : /// @brief Return the Network coordinate of the transportable
206 : virtual Position getPosition() const;
207 :
208 : /// @brief return the current angle of the transportable
209 : virtual double getAngle() const;
210 :
211 : /// @brief the time this transportable spent waiting in seconds
212 : virtual double getWaitingSeconds() const;
213 :
214 : /// @brief the current speed of the transportable
215 : virtual double getSpeed() const;
216 :
217 : /// @brief the current speed factor of the transportable (where applicable)
218 0 : virtual double getChosenSpeedFactor() const {
219 0 : return 1;
220 : }
221 :
222 : /// @brief the current stage type of the transportable
223 : MSStageType getCurrentStageType() const {
224 4212394 : return (*myStep)->getStageType();
225 : }
226 :
227 : /// @brief the stage type for the nth next stage
228 : MSStageType getStageType(int next) const {
229 : assert(myStep + next < myPlan->end());
230 : assert(myStep + next >= myPlan->begin());
231 31011 : return (*(myStep + next))->getStageType();
232 : }
233 :
234 : /// @brief return textual summary for the given stage
235 : std::string getStageSummary(int stageIndex) const;
236 :
237 : /// Returns the current stage description as a string
238 0 : std::string getCurrentStageDescription() const {
239 21010 : return (*myStep)->getStageDescription(myAmPerson);
240 : }
241 :
242 : /// @brief Return the current stage
243 : MSStage* getCurrentStage() const {
244 6462631 : return *myStep;
245 : }
246 :
247 : /// @brief Return the next (or previous) stage denoted by the offset
248 : inline MSStage* getNextStage(int offset) const {
249 : assert(myStep + offset >= myPlan->begin());
250 : assert(myStep + offset < myPlan->end());
251 182355 : return *(myStep + offset);
252 : }
253 :
254 : /// @brief returns the numerical IDs of edges to be used (possibly of future stages)
255 : const std::set<NumericalID> getUpcomingEdgeIDs() const;
256 :
257 : /// @brief Return the total number stages in this person's plan
258 : inline int getNumStages() const {
259 1808 : return (int)myPlan->size();
260 : }
261 :
262 : /// @brief Return the number of remaining stages (including the current)
263 : inline int getNumRemainingStages() const {
264 54614 : return (int)(myPlan->end() - myStep);
265 : }
266 :
267 : /// @brief Return the index of the current stage
268 : inline int getCurrentStageIndex() const {
269 178519 : return (int)(myStep - myPlan->begin());
270 : }
271 :
272 : /// @brief return the index of the edge within the route
273 452617 : inline int getRoutePosition() const {
274 452617 : return (*myStep)->getRoutePosition();
275 : }
276 :
277 : /// @brief returns the next edge ptr (used by walking persons)
278 0 : virtual const MSEdge* getNextEdgePtr() const {
279 0 : return nullptr;
280 : }
281 :
282 : /** @brief Called on writing tripinfo output
283 : *
284 : * @param[in] os The stream to write the information into
285 : * @exception IOError not yet implemented
286 : */
287 : void tripInfoOutput(OutputDevice& os) const;
288 :
289 : /** @brief Called on writing vehroute output
290 : *
291 : * @param[in] os The stream to write the information into
292 : * @exception IOError not yet implemented
293 : */
294 : void routeOutput(OutputDevice& os, const bool withRouteLength) const;
295 :
296 : /// Whether the transportable waits for the given vehicle in the current step
297 : bool isWaitingFor(const SUMOVehicle* vehicle) const {
298 369619 : return (*myStep)->isWaitingFor(vehicle);
299 : }
300 :
301 : /// @brief Whether the transportable waits for a vehicle
302 : bool isWaiting4Vehicle() const {
303 1838566 : return (*myStep)->isWaiting4Vehicle();
304 : }
305 :
306 : void setAbortWaiting(const SUMOTime timeout);
307 :
308 : /// @brief Abort current stage (used for aborting waiting for a vehicle)
309 : SUMOTime abortStage(SUMOTime step);
310 :
311 : /// @brief The vehicle associated with this transportable
312 : SUMOVehicle* getVehicle() const {
313 362643 : return (*myStep)->getVehicle();
314 : }
315 :
316 : /// @brief Appends the given stage to the current plan
317 : void appendStage(MSStage* stage, int next = -1);
318 :
319 : /// @brief removes the nth next stage
320 : void removeStage(int next, bool stayInSim = true);
321 :
322 : /// @brief set the speed for all present and future (walking) stages and modify the vType so that stages added later are also affected
323 : void setSpeed(double speed);
324 :
325 : /// @brief returns the final arrival pos
326 : double getArrivalPos() const {
327 237 : return myPlan->back()->getArrivalPos();
328 : }
329 :
330 : /// @brief returns the final arrival edge
331 1641 : const MSEdge* getArrivalEdge() const {
332 1641 : return myPlan->back()->getEdges().back();
333 : }
334 :
335 : /** @brief Returns the end point for reroutes (usually the last edge of the route)
336 : *
337 : * @return The rerouting end point
338 : */
339 1615 : const MSEdge* getRerouteDestination() const {
340 1615 : return getArrivalEdge();
341 : }
342 :
343 : bool reroute(SUMOTime t, const std::string& info, MSTransportableRouter& router, const bool onInit = false, const bool withTaz = false, const bool silent = false, const MSEdge* sink = nullptr);
344 :
345 : /// Replaces the current route by the given one
346 : bool replaceRoute(ConstMSRoutePtr route, const std::string& info, bool onInit = false, int offset = 0, bool addStops = true, bool removeStops = true, std::string* msgReturn = nullptr);
347 :
348 : /** @brief Replaces the current vehicle type by the one given
349 : *
350 : * If the currently used vehicle type is marked as being used by this vehicle
351 : * only, it is deleted, first. The new, given type is then assigned to
352 : * "myVType".
353 : * @param[in] type The new vehicle type
354 : * @see MSTransportable::myVType
355 : */
356 : void replaceVehicleType(MSVehicleType* type);
357 :
358 : /** @brief Replaces the current vehicle type with a new one used by this vehicle only
359 : *
360 : * If the currently used vehicle type is already marked as being used by this vehicle
361 : * only, no new type is created.
362 : * @return The new modifiable vehicle type
363 : * @see MSTransportable::myVType
364 : */
365 : MSVehicleType& getSingularType();
366 :
367 : /// @brief return the bounding box of the person
368 : PositionVector getBoundingBox() const;
369 :
370 : /// @brief return whether the person has reached the end of its plan
371 : bool hasArrived() const;
372 :
373 : /// @brief return whether the transportable has started its plan
374 : bool hasDeparted() const;
375 :
376 : /// @brief adapt plan when the vehicle reroutes and now stops at replacement instead of orig
377 : void rerouteParkingArea(MSStoppingPlace* orig, MSStoppingPlace* replacement);
378 :
379 : /// @brief Returns a device of the given type if it exists or nullptr if not
380 : MSDevice* getDevice(const std::type_info& type) const;
381 :
382 : /// @brief set individual junction model paramete (not type related)
383 : void setJunctionModelParameter(const std::string& key, const std::string& value);
384 :
385 : /** @brief Returns this vehicle's devices
386 : * @return This vehicle's devices
387 : */
388 : inline const std::vector<MSTransportableDevice*>& getDevices() const {
389 : return myDevices;
390 : }
391 :
392 0 : virtual bool hasInfluencer() const {
393 0 : return false;
394 : }
395 :
396 : /// @brief whether this transportable is selected in the GUI
397 0 : virtual bool isSelected() const {
398 0 : return false;
399 : }
400 :
401 : /// @brief return routing mode (configures router choice but also handling of transient permission changes)
402 : virtual int getRoutingMode() const;
403 :
404 : /** @brief Saves the current state into the given stream
405 : */
406 : void saveState(OutputDevice& out);
407 :
408 : /** @brief Reconstructs the current state
409 : */
410 : void loadState(const std::string& state);
411 :
412 : protected:
413 : /// the plan of the transportable
414 : const SUMOVehicleParameter* myParameter;
415 :
416 : /// @brief This transportable's type. (mainly used for drawing related information
417 : /// Note sure if it is really necessary
418 : MSVehicleType* myVType;
419 :
420 : /// @brief Whether events shall be written
421 : bool myWriteEvents;
422 :
423 : /// the plan of the transportable
424 : MSTransportablePlan* myPlan;
425 :
426 : /// the iterator over the route
427 : MSTransportablePlan::iterator myStep;
428 :
429 : /// @brief The devices this transportable has
430 : std::vector<MSTransportableDevice*> myDevices;
431 :
432 : private:
433 : const bool myAmPerson;
434 :
435 : const NumericalID myNumericalID;
436 :
437 : WrappingCommand<MSTransportable>* myAbortCommand;
438 :
439 : static NumericalID myCurrentNumericalIndex;
440 :
441 : private:
442 : /// @brief Invalidated copy constructor.
443 : MSTransportable(const MSTransportable&);
444 :
445 : /// @brief Invalidated assignment operator.
446 : MSTransportable& operator=(const MSTransportable&);
447 :
448 : };
|