Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2013-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 MSDevice_Taxi.h
15 : /// @author Jakob Erdmann
16 : /// @date 16.12.2019
17 : ///
18 : // A device which controls a taxi
19 : /****************************************************************************/
20 : #pragma once
21 : #include <config.h>
22 :
23 : #include <utils/common/SUMOTime.h>
24 : #include <utils/common/WrappingCommand.h>
25 : #include "MSVehicleDevice.h"
26 :
27 :
28 : // ===========================================================================
29 : // class declarations
30 : // ===========================================================================
31 : class SUMOTrafficObject;
32 : class MSDispatch;
33 : class MSIdling;
34 : class MSDevice_Routing;
35 : struct Reservation;
36 :
37 :
38 : // ===========================================================================
39 : // class definitions
40 : // ===========================================================================
41 : /**
42 : * @class MSDevice_Taxi
43 : * @brief A device which collects info on the vehicle trip (mainly on departure and arrival)
44 : *
45 : * Each device collects departure time, lane and speed and the same for arrival.
46 : *
47 : * @see MSDevice
48 : */
49 : class MSDevice_Taxi : public MSVehicleDevice {
50 : public:
51 :
52 : enum TaxiState {
53 : EMPTY = 0, // empty (available for servicing customers)
54 : PICKUP = 1, // driving to pick up customer
55 : OCCUPIED = 2 // occupied with customer
56 : };
57 :
58 : /** @brief Inserts MSDevice_Taxi-options
59 : * @param[filled] oc The options container to add the options to
60 : */
61 : static void insertOptions(OptionsCont& oc);
62 :
63 :
64 : /** @brief Build devices for the given vehicle, if needed
65 : *
66 : * The options are read and evaluated whether a Taxi-device shall be built
67 : * for the given vehicle.
68 : *
69 : * The built device is stored in the given vector.
70 : *
71 : * @param[in] v The vehicle for which a device may be built
72 : * @param[filled] into The vector to store the built device in
73 : */
74 : static void buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into);
75 :
76 : /// @brief whether the given lines description is a taxi call
77 : static bool isReservation(const std::set<std::string>& lines);
78 :
79 : /// add new reservation
80 : static void addReservation(MSTransportable* person,
81 : const std::set<std::string>& lines,
82 : SUMOTime reservationTime,
83 : SUMOTime pickupTime,
84 : SUMOTime earliestPickupTime,
85 : const MSEdge* from, double fromPos,
86 : const MSStoppingPlace* fromStop,
87 : const MSEdge* to, double toPos,
88 : const MSStoppingPlace* toStop,
89 : const std::string& group);
90 :
91 : /// @brief retract reservation
92 : static void removeReservation(MSTransportable* person,
93 : const std::set<std::string>& lines,
94 : const MSEdge* from, double fromPos,
95 : const MSEdge* to, double toPos,
96 : const std::string& group);
97 :
98 : /// @brief update reservation's fromPos due to pre-booking
99 : static void updateReservationFromPos(MSTransportable* person,
100 : const std::set<std::string>& lines,
101 : const MSEdge* from, double fromPos,
102 : const MSEdge* to, double toPos,
103 : const std::string& group, double newFromPos);
104 :
105 : /// @brief period command to trigger the dispatch algorithm
106 : static SUMOTime triggerDispatch(SUMOTime currentTime);
107 :
108 : /// @brief check whether there are still (servable) reservations in the system
109 : static bool hasServableReservations();
110 :
111 : /// @brief resets counters
112 : static void cleanup();
113 :
114 : static MSDispatch* getDispatchAlgorithm() {
115 3169 : return myDispatcher;
116 : }
117 :
118 : static const std::vector<MSDevice_Taxi*>& getFleet() {
119 : return myFleet;
120 : }
121 :
122 : public:
123 : /// @brief Destructor.
124 : ~MSDevice_Taxi();
125 :
126 : /// @name Methods called on vehicle movement / state change, overwriting MSDevice
127 : /// @{
128 :
129 : /** @brief Checks for waiting steps when the vehicle moves
130 : *
131 : * @param[in] veh Vehicle that asks this reminder.
132 : * @param[in] oldPos Position before move.
133 : * @param[in] newPos Position after move with newSpeed.
134 : * @param[in] newSpeed Moving speed.
135 : *
136 : * @return True (always).
137 : */
138 : bool notifyMove(SUMOTrafficObject& veh, double oldPos,
139 : double newPos, double newSpeed);
140 :
141 :
142 : /** @brief Saves departure info on insertion
143 : *
144 : * @param[in] veh The entering vehicle.
145 : * @param[in] reason how the vehicle enters the lane
146 : * @return Always true
147 : * @see MSMoveReminder::notifyEnter
148 : * @see MSMoveReminder::Notification
149 : */
150 : bool notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
151 : /// @}
152 :
153 :
154 : /// @brief return the name for this type of device
155 1358 : const std::string deviceName() const {
156 1358 : return "taxi";
157 : }
158 :
159 : /// @brief whether the taxi is empty
160 : bool isEmpty();
161 :
162 : int getState() const {
163 9435 : return myState;
164 : }
165 :
166 : /// @brief returns a taxi if any exist or nullptr
167 : static SUMOVehicle* getTaxi();
168 :
169 : /// @brief service the given reservation
170 : void dispatch(const Reservation& res);
171 :
172 : /// @brief service the given reservations
173 : void dispatchShared(std::vector<const Reservation*> reservations);
174 :
175 : /// @brief remove the persons the taxi is currently waiting for from reservations
176 : void cancelCurrentCustomers();
177 :
178 : /// @brief remove person from reservations
179 : bool cancelCustomer(const MSTransportable* t);
180 :
181 : /// @brief whether the given person is allowed to board this taxi
182 : bool allowsBoarding(const MSTransportable* t) const;
183 :
184 : /// @brief called by MSDevice_Transportable upon loading a person
185 : void customerEntered(const MSTransportable* t);
186 :
187 : /// @brief called by MSDevice_Transportable upon unloading a person
188 : void customerArrived(const MSTransportable* person);
189 :
190 : /// @brief try to retrieve the given parameter from this device. Throw exception for unsupported key
191 : std::string getParameter(const std::string& key) const;
192 :
193 : /// @brief try to set the given parameter for this device. Throw exception for unsupported key
194 : void setParameter(const std::string& key, const std::string& value);
195 :
196 : /** @brief Called on writing tripinfo output
197 : *
198 : * @param[in] os The stream to write the information into
199 : * @exception IOError not yet implemented
200 : * @see MSDevice::generateOutput
201 : */
202 : void generateOutput(OutputDevice* tripinfoOut) const;
203 :
204 : /// @brief whether the given reservation is compatible with the taxi line
205 : bool compatibleLine(const Reservation* res);
206 :
207 : static bool compatibleLine(const std::string& taxiLine, const std::string& rideLine);
208 :
209 : protected:
210 : /** @brief Internal notification about the vehicle moves, see MSMoveReminder::notifyMoveInternal()
211 : *
212 : */
213 : void notifyMoveInternal(const SUMOTrafficObject& veh,
214 : const double frontOnLane,
215 : const double timeOnLane,
216 : const double meanSpeedFrontOnLane,
217 : const double meanSpeedVehicleOnLane,
218 : const double travelledDistanceFrontOnLane,
219 : const double travelledDistanceVehicleOnLane,
220 : const double meanLengthOnLane);
221 :
222 : private:
223 : /** @brief Constructor
224 : *
225 : * @param[in] holder The vehicle that holds this device
226 : * @param[in] id The ID of the device
227 : */
228 : MSDevice_Taxi(SUMOVehicle& holder, const std::string& id);
229 :
230 : void updateMove(const SUMOTime traveltime, const double travelledDist);
231 :
232 : /// @brief prepare stop for the given action
233 : void prepareStop(ConstMSEdgeVector& edges,
234 : std::vector<SUMOVehicleParameter::Stop>& stops,
235 : double& lastPos, const MSEdge* stopEdge, double stopPos,
236 : const MSStoppingPlace* stopPlace,
237 : const std::string& action, const Reservation* res, const bool isPickup);
238 :
239 : /// @brief determine stopping lane for taxi
240 : MSLane* getStopLane(const MSEdge* edge, const std::string& action);
241 :
242 : /// @brief whether the taxi has another pickup scheduled
243 : bool hasFuturePickup();
244 :
245 : /// @brief initialize the dispatch algorithm
246 : static void initDispatch();
247 :
248 : private:
249 :
250 : int myState = EMPTY;
251 : /// @brief number of customers that were served
252 : int myCustomersServed = 0;
253 : /// @brief distance driven with customers
254 : double myOccupiedDistance = 0;
255 : /// @brief time spent driving with customers
256 : SUMOTime myOccupiedTime = 0;
257 : /// @brief the time at which the taxi service ends (end the vehicle may leave the simulation)
258 : SUMOTime myServiceEnd = SUMOTime_MAX;
259 : /// @brief whether the vehicle is currently stopped
260 : bool myIsStopped = false;
261 : /// @brief the customer of the current reservation
262 : std::set<const MSTransportable*> myCustomers;
263 :
264 : /// @brief algorithm for controlling idle behavior
265 : MSIdling* myIdleAlgorithm;
266 :
267 : /// @brief whether the taxi has reached its schedule service end
268 : bool myReachedServiceEnd = false;
269 :
270 : /// @brief reservations currently being served
271 : std::set<const Reservation*> myCurrentReservations;
272 :
273 : /// @brief routing device (if the vehicle has one)
274 : MSDevice_Routing* myRoutingDevice = nullptr;
275 :
276 : /// @brief the time between successive calls to the dispatcher
277 : static SUMOTime myDispatchPeriod;
278 : /// @brief the dispatch algorithm
279 : static MSDispatch* myDispatcher;
280 : /// @brief The repeated call to the dispatcher
281 : static Command* myDispatchCommand;
282 : /// @brief the last dispatch order
283 : std::vector<const Reservation*> myLastDispatch;
284 : // @brief the list of available taxis
285 : static std::vector<MSDevice_Taxi*> myFleet;
286 : // @brief the maximum personCapacity in the fleet
287 : static int myMaxCapacity;
288 : // @brief the maximum container capacity in the fleet
289 : static int myMaxContainerCapacity;
290 :
291 : static std::set<std::string> myVClassWarningVTypes;
292 :
293 : private:
294 : /// @brief Invalidated copy constructor.
295 : MSDevice_Taxi(const MSDevice_Taxi&);
296 :
297 : /// @brief Invalidated assignment operator.
298 : MSDevice_Taxi& operator=(const MSDevice_Taxi&);
299 :
300 :
301 : };
|