Eclipse SUMO - Simulation of Urban MObility
MSDevice_Taxi.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2013-2020 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 
23 #include <utils/common/SUMOTime.h>
25 #include "MSVehicleDevice.h"
26 
27 
28 // ===========================================================================
29 // class declarations
30 // ===========================================================================
31 class SUMOTrafficObject;
32 class MSDispatch;
33 class MSIdling;
34 struct Reservation;
35 
36 
37 // ===========================================================================
38 // class definitions
39 // ===========================================================================
49 public:
50 
51  enum TaxiState {
52  EMPTY = 0, // empty (available for servicing customers)
53  PICKUP = 1, // driving to pick up customer
54  OCCUPIED = 2 // occupied with customer
55  };
56 
60  static void insertOptions(OptionsCont& oc);
61 
62 
73  static void buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into);
74 
76  static void addReservation(MSTransportable* person,
77  const std::set<std::string>& lines,
78  SUMOTime reservationTime,
79  SUMOTime pickupTime,
80  const MSEdge* from, double fromPos,
81  const MSEdge* to, double toPos,
82  const std::string& group);
83 
85  static SUMOTime triggerDispatch(SUMOTime currentTime);
86 
88  static bool hasServableReservations();
89 
91  static void cleanup();
92 
94  return myDispatcher;
95  }
96 
97  static const std::vector<MSDevice_Taxi*>& getFleet() {
98  return myFleet;
99  }
100 
101  static int getMaxCapacity() {
102  return myMaxCapacity;
103  }
104 
105 public:
107  ~MSDevice_Taxi();
108 
111 
121  bool notifyMove(SUMOTrafficObject& veh, double oldPos,
122  double newPos, double newSpeed);
123 
124 
133  bool notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
134 
135 
144  bool notifyLeave(SUMOTrafficObject& veh, double lastPos,
145  MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
147 
148 
150  const std::string deviceName() const {
151  return "taxi";
152  }
153 
155  bool isEmpty();
156 
157  int getState() const {
158  return myState;
159  }
160 
162  static SUMOVehicle* getTaxi();
163 
165  void dispatch(const Reservation& res);
166 
168  void dispatchShared(const std::vector<const Reservation*>& reservations);
169 
171  bool allowsBoarding(MSTransportable* t) const;
172 
174  void customerEntered(const MSTransportable* t);
175 
177  void customerArrived(const MSTransportable* person);
178 
180  std::string getParameter(const std::string& key) const;
181 
183  void setParameter(const std::string& key, const std::string& value);
184 
191  void generateOutput(OutputDevice* tripinfoOut) const;
192 
193 
194 
195 private:
201  MSDevice_Taxi(SUMOVehicle& holder, const std::string& id);
202 
204  void prepareStop(ConstMSEdgeVector& edges,
205  std::vector<SUMOVehicleParameter::Stop>& stops,
206  double& lastPos, const MSEdge* stopEdge, double stopPos,
207  const std::string& action);
208 
210  MSLane* getStopLane(const MSEdge* edge);
211 
213  bool hasFuturePickup();
214 
216  static void initDispatch();
217 
218 private:
219 
220  int myState = EMPTY;
224  double myOccupiedDistance = 0;
230  bool myIsStopped = false;
232  std::set<const MSTransportable*> myCustomers;
233 
236 
243  // @brief the list of available taxis
244  static std::vector<MSDevice_Taxi*> myFleet;
245  // @brief the maximum personCapacity in the fleet
246  static int myMaxCapacity;
247 
248 private:
251 
254 
255 
256 };
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:74
#define SUMOTime_MAX
Definition: SUMOTime.h:32
long long int SUMOTime
Definition: SUMOTime.h:31
Base (microsim) event class.
Definition: Command.h:49
A device which collects info on the vehicle trip (mainly on departure and arrival)
Definition: MSDevice_Taxi.h:48
static void initDispatch()
initialize the dispatch algorithm
static Command * myDispatchCommand
The repeated call to the dispatcher.
void customerArrived(const MSTransportable *person)
called by MSDevice_Transportable upon unloading a person
bool notifyLeave(SUMOTrafficObject &veh, double lastPos, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Saves arrival info.
static SUMOTime triggerDispatch(SUMOTime currentTime)
period command to trigger the dispatch algorithm
MSLane * getStopLane(const MSEdge *edge)
determine stopping lane for taxi
void dispatch(const Reservation &res)
service the given reservation
void dispatchShared(const std::vector< const Reservation * > &reservations)
service the given reservations
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)
void generateOutput(OutputDevice *tripinfoOut) const
Called on writing tripinfo output.
static int myMaxCapacity
MSIdling * myIdleAlgorithm
algorithm for controlling idle behavior
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed)
Checks for waiting steps when the vehicle moves.
MSDevice_Taxi & operator=(const MSDevice_Taxi &)
Invalidated assignment operator.
static const std::vector< MSDevice_Taxi * > & getFleet()
Definition: MSDevice_Taxi.h:97
bool hasFuturePickup()
whether the taxi has another pickup scheduled
bool allowsBoarding(MSTransportable *t) const
whether the given person is allowed to board this taxi
static MSDispatch * myDispatcher
the dispatch algorithm
int myCustomersServed
number of customers that were served
bool isEmpty()
whether the taxi is empty
const std::string deviceName() const
return the name for this type of device
static std::vector< MSDevice_Taxi * > myFleet
int getState() const
static SUMOTime myDispatchPeriod
the time between successive calls to the dispatcher
bool notifyEnter(SUMOTrafficObject &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Saves departure info on insertion.
static void cleanup()
resets counters
double myOccupiedDistance
distance driven with customers
MSDevice_Taxi(SUMOVehicle &holder, const std::string &id)
Constructor.
static void addReservation(MSTransportable *person, const std::set< std::string > &lines, SUMOTime reservationTime, SUMOTime pickupTime, const MSEdge *from, double fromPos, const MSEdge *to, double toPos, const std::string &group)
add new reservation
static bool hasServableReservations()
check whether there are still (servable) reservations in the system
void prepareStop(ConstMSEdgeVector &edges, std::vector< SUMOVehicleParameter::Stop > &stops, double &lastPos, const MSEdge *stopEdge, double stopPos, const std::string &action)
prepare stop for the given action
static SUMOVehicle * getTaxi()
returns a taxi if any exist or nullptr
static int getMaxCapacity()
void customerEntered(const MSTransportable *t)
called by MSDevice_Transportable upon loading a person
MSDevice_Taxi(const MSDevice_Taxi &)
Invalidated copy constructor.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
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
SUMOTime myOccupiedTime
time spent driving with customers
static MSDispatch * getDispatchAlgorithm()
Definition: MSDevice_Taxi.h:93
~MSDevice_Taxi()
Destructor.
std::string getParameter(const std::string &key) const
try to retrieve the given parameter from this device. Throw exception for unsupported key
An algorithm that performs distpach for a taxi fleet.
Definition: MSDispatch.h:85
A road/street connecting two junctions.
Definition: MSEdge.h:77
An algorithm that performs distpach for a taxi fleet.
Definition: MSIdling.h:42
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
Notification
Definition of a vehicle state.
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.
Definition: OutputDevice.h:60
Representation of a vehicle, person, or container.
Representation of a vehicle.
Definition: SUMOVehicle.h:58