Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSDevice_Taxi.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2013-2026 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/****************************************************************************/
18// A device which controls a taxi
19/****************************************************************************/
20#pragma once
21#include <config.h>
22
25#include "MSVehicleDevice.h"
26
27
28// ===========================================================================
29// class declarations
30// ===========================================================================
32class MSDispatch;
33class MSIdling;
35struct Reservation;
36
37
38// ===========================================================================
39// class definitions
40// ===========================================================================
50public:
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
61 static void insertOptions(OptionsCont& oc);
62
63
74 static void buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into);
75
77 static bool isReservation(const std::set<std::string>& lines);
78
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
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
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
106 static SUMOTime triggerDispatch(SUMOTime currentTime);
107
109 static bool hasServableReservations();
110
112 static void cleanup();
113
115 return myDispatcher;
116 }
117
118 static const std::vector<MSDevice_Taxi*>& getFleet() {
119 return myFleet;
120 }
121
122public:
125
128
138 bool notifyMove(SUMOTrafficObject& veh, double oldPos,
139 double newPos, double newSpeed);
140
141
150 bool notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
152
153
155 const std::string deviceName() const {
156 return "taxi";
157 }
158
160 bool isEmpty();
161
162 int getState() const {
163 return myState;
164 }
165
167 static bool hasFleet();
168
170 void dispatch(const Reservation& res);
171
173 void dispatchShared(std::vector<const Reservation*> reservations);
174
177
179 bool cancelCustomer(const MSTransportable* t);
180
182 void addCustomer(const MSTransportable* t, const Reservation* res);
183
185 bool allowsBoarding(const MSTransportable* t) const;
186
188 void customerEntered(const MSTransportable* t);
189
191 void customerArrived(const MSTransportable* person);
192
195 void saveState(OutputDevice& out) const;
196
200 void loadState(const SUMOSAXAttributes& attrs);
201
203 static void finalizeLoadState();
204
206 std::string getParameter(const std::string& key) const;
207
209 void setParameter(const std::string& key, const std::string& value);
210
217 void generateOutput(OutputDevice* tripinfoOut) const;
218
220 bool compatibleLine(const Reservation* res);
221
222 static bool compatibleLine(const std::string& taxiLine, const std::string& rideLine);
223
225 static void allCustomersErased();
226
228 static const std::map<SUMOVehicleClass, std::string>& getTaxiTypes();
229
231
233 static void initDispatch(SUMOTime next = -1);
234
235protected:
240 const double frontOnLane,
241 const double timeOnLane,
242 const double meanSpeedFrontOnLane,
243 const double meanSpeedVehicleOnLane,
244 const double travelledDistanceFrontOnLane,
245 const double travelledDistanceVehicleOnLane,
246 const double meanLengthOnLane);
247
248private:
254 MSDevice_Taxi(SUMOVehicle& holder, const std::string& id);
255
256 void updateMove(const SUMOTime traveltime, const double travelledDist);
257
259 void prepareStop(ConstMSEdgeVector& edges,
260 StopParVector& stops,
261 double& lastPos, const MSEdge* stopEdge, double stopPos,
262 const MSStoppingPlace* stopPlace,
263 const std::string& action, const Reservation* res, const bool isPickup);
264
266 MSLane* getStopLane(const MSEdge* edge, const std::string& action);
267
269 bool hasFuturePickup();
270
272 void checkTaskSwap();
273
274private:
275
286 bool myIsStopped = false;
288 std::set<const MSTransportable*> myCustomers;
289
292
295
297 std::set<const Reservation*> myCurrentReservations;
298
301
309 std::vector<const Reservation*> myLastDispatch;
310 // @brief the list of available taxis
311 static std::vector<MSDevice_Taxi*> myFleet;
312 // @brief the maximum personCapacity in the fleet
313 static int myMaxCapacity;
314 // @brief the maximum container capacity in the fleet
316
318 static std::map<SUMOVehicleClass, std::string> myTaxiTypes;
319
321
323 static std::map<std::string, MSDevice_Taxi*> myStateLoadedCustomers;
325 static std::map<std::string, MSDevice_Taxi*> myStateLoadedReservations;
326private:
329
332
333
334};
long long int SUMOTime
Definition GUI.h:36
std::vector< const MSEdge * > ConstMSEdgeVector
Definition MSEdge.h:74
#define SUMOTime_MAX
Definition SUMOTime.h:34
std::vector< SUMOVehicleParameter::Stop > StopParVector
Base (microsim) event class.
Definition Command.h:50
A device that performs vehicle rerouting based on current edge speeds.
A device which collects info on the vehicle trip (mainly on departure and arrival)
void prepareStop(ConstMSEdgeVector &edges, StopParVector &stops, double &lastPos, const MSEdge *stopEdge, double stopPos, const MSStoppingPlace *stopPlace, const std::string &action, const Reservation *res, const bool isPickup)
prepare stop for the given action
void addCustomer(const MSTransportable *t, const Reservation *res)
add person after extending reservation
static Command * myDispatchCommand
The repeated call to the dispatcher.
void customerArrived(const MSTransportable *person)
called by MSDevice_Transportable upon unloading a person
static SUMOTime triggerDispatch(SUMOTime currentTime)
period command to trigger the dispatch algorithm
void dispatch(const Reservation &res)
service the given reservation
std::set< const MSTransportable * > myCustomers
the customer of the current reservation
SUMOTime myServiceEnd
the time at which the taxi service ends (end the vehicle may leave the simulation)
static void updateReservationFromPos(MSTransportable *person, const std::set< std::string > &lines, const MSEdge *from, double fromPos, const MSEdge *to, double toPos, const std::string &group, double newFromPos)
update reservation's fromPos due to pre-booking
bool cancelCustomer(const MSTransportable *t)
remove person from reservations
void generateOutput(OutputDevice *tripinfoOut) const
Called on writing tripinfo output.
static int myMaxCapacity
void dispatchShared(std::vector< const Reservation * > reservations)
service the given reservations
static void addReservation(MSTransportable *person, const std::set< std::string > &lines, SUMOTime reservationTime, SUMOTime pickupTime, SUMOTime earliestPickupTime, const MSEdge *from, double fromPos, const MSStoppingPlace *fromStop, const MSEdge *to, double toPos, const MSStoppingPlace *toStop, const std::string &group)
add new reservation
MSIdling * myIdleAlgorithm
algorithm for controlling idle behavior
std::set< const Reservation * > myCurrentReservations
reservations currently being served
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed)
Checks for waiting steps when the vehicle moves.
bool hasFuturePickup()
whether the taxi has another pickup scheduled
void cancelCurrentCustomers()
remove the persons the taxi is currently waiting for from reservations
std::vector< const Reservation * > myLastDispatch
the last dispatch order
static MSDispatch * myDispatcher
the dispatch algorithm
int myCustomersServed
number of customers that were served
void updateMove(const SUMOTime traveltime, const double travelledDist)
void notifyMoveInternal(const SUMOTrafficObject &veh, const double frontOnLane, const double timeOnLane, const double meanSpeedFrontOnLane, const double meanSpeedVehicleOnLane, const double travelledDistanceFrontOnLane, const double travelledDistanceVehicleOnLane, const double meanLengthOnLane)
Internal notification about the vehicle moves, see MSMoveReminder::notifyMoveInternal()
static int myMaxContainerCapacity
MSDevice_Routing * myRoutingDevice
routing device (if the vehicle has one)
bool isEmpty()
whether the taxi is empty
static std::map< std::string, MSDevice_Taxi * > myStateLoadedCustomers
ids of customers loaded from state
const std::string deviceName() const
return the name for this type of device
static std::vector< MSDevice_Taxi * > myFleet
static void removeReservation(MSTransportable *person, const std::set< std::string > &lines, const MSEdge *from, double fromPos, const MSEdge *to, double toPos, const std::string &group)
retract reservation
int getState() const
static SUMOTime myDispatchPeriod
the time between successive calls to the dispatcher
static SUMOTime myNextDispatchTime
bool notifyEnter(SUMOTrafficObject &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Saves departure info on insertion.
static void cleanup()
resets counters
static bool isReservation(const std::set< std::string > &lines)
whether the given lines description is a taxi call
double myOccupiedDistance
distance driven with customers
static bool hasFleet()
returns whether taxis have been loaded
static void allCustomersErased()
signal the end of the simulation and the removal of all customers
bool allowsBoarding(const MSTransportable *t) const
whether the given person is allowed to board this taxi
static bool hasServableReservations()
check whether there are still (servable) reservations in the system
static const std::map< SUMOVehicleClass, std::string > & getTaxiTypes()
return all types that are known to carry a taxi device (or the default type if no devices are initial...
static SUMOTime getNextDispatchTime()
MSDevice_Taxi & operator=(const MSDevice_Taxi &)
Invalidated assignment operator.
void saveState(OutputDevice &out) const
Saves the state of the device.
void customerEntered(const MSTransportable *t)
called by MSDevice_Transportable upon loading a person
MSDevice_Taxi(const MSDevice_Taxi &)
Invalidated copy constructor.
bool compatibleLine(const Reservation *res)
whether the given reservation is compatible with the taxi line
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
static void finalizeLoadState()
call during state loading after all transportables are loaded
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_Taxi-options.
bool myIsStopped
whether the vehicle is currently stopped
void setParameter(const std::string &key, const std::string &value)
try to set the given parameter for this device. Throw exception for unsupported key
void loadState(const SUMOSAXAttributes &attrs)
Loads the state of the device from the given description.
SUMOTime myOccupiedTime
time spent driving with customers
bool myReachedServiceEnd
whether the taxi has reached its schedule service end
~MSDevice_Taxi()
Destructor.
static std::map< std::string, MSDevice_Taxi * > myStateLoadedReservations
ids of reservations loaded from state
static const std::vector< MSDevice_Taxi * > & getFleet()
static std::map< SUMOVehicleClass, std::string > myTaxiTypes
storing only one type per vClass
MSLane * getStopLane(const MSEdge *edge, const std::string &action)
determine stopping lane for taxi
void checkTaskSwap()
optionally swap tasks when a taxi becomes idle
static void initDispatch(SUMOTime next=-1)
initialize the dispatch algorithm
std::string getParameter(const std::string &key) const
try to retrieve the given parameter from this device. Throw exception for unsupported key
static MSDispatch * getDispatchAlgorithm()
An algorithm that performs distpach for a taxi fleet.
Definition MSDispatch.h:114
A road/street connecting two junctions.
Definition MSEdge.h:77
An algorithm that performs distpach for a taxi fleet.
Definition MSIdling.h:43
Representation of a lane in the micro simulation.
Definition MSLane.h:84
Notification
Definition of a vehicle state.
A lane area vehicles can halt at.
Abstract in-vehicle device.
A storage for options typed value containers)
Definition OptionsCont.h:89
Static storage of an output device and its base (abstract) implementation.
Encapsulated SAX-Attributes.
Representation of a vehicle, person, or container.
Representation of a vehicle.
Definition SUMOVehicle.h:63