Eclipse SUMO - Simulation of Urban MObility
MSDispatch.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2007-2022 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 // An algorithm that performs dispatch for the taxi device
19 /****************************************************************************/
20 #pragma once
21 #include <config.h>
22 
23 #include <set>
24 #include <vector>
25 #include <map>
27 #include <utils/common/SUMOTime.h>
28 #include "MSDevice_Taxi.h"
29 
30 // ===========================================================================
31 // class declarations
32 // ===========================================================================
33 class MSTransportable;
34 
35 // ===========================================================================
36 // class definitions
37 // ===========================================================================
38 struct Reservation {
40  NEW = 1, // new reservation (not yet retrieved)
41  RETRIEVED = 2, // retrieved at least once via MSDispatch_TraCI
42  ASSIGNED = 4, // a taxi was dispatched to service this reservation
43  ONBOARD = 8, // a taxi has picked up the persons belonging to this reservation
44  FULFILLED = 16, // the persons belonging to this reservation have been dropped off
45  };
46 
47  Reservation(const std::string& _id,
48  const std::vector<MSTransportable*>& _persons,
49  SUMOTime _reservationTime,
50  SUMOTime _pickupTime,
51  const MSEdge* _from, double _fromPos,
52  const MSEdge* _to, double _toPos,
53  const std::string& _group,
54  const std::string& _line) :
55  id(_id),
56  persons(_persons.begin(), _persons.end()),
57  reservationTime(_reservationTime),
58  pickupTime(_pickupTime),
59  from(_from),
60  fromPos(_fromPos),
61  to(_to),
62  toPos(_toPos),
63  group(_group),
64  line(_line),
65  recheck(_reservationTime),
66  state(NEW)
67  {}
68 
69  std::string id;
70  std::set<MSTransportable*> persons;
73  const MSEdge* from;
74  double fromPos;
75  const MSEdge* to;
76  double toPos;
77  std::string group;
78  std::string line;
81 
82  bool operator==(const Reservation& other) const {
83  return persons == other.persons
85  && pickupTime == other.pickupTime
86  && from == other.from
87  && fromPos == other.fromPos
88  && to == other.to
89  && toPos == other.toPos
90  && group == other.group
91  && line == other.line;
92  }
93 
95  std::string getID() const;
96 };
97 
102 class MSDispatch : public Parameterised {
103 public:
104 
106  class time_sorter {
107  public:
109  explicit time_sorter() {}
110 
112  int operator()(const Reservation* r1, const Reservation* r2) const {
113  return r1->reservationTime < r2->reservationTime;
114  }
115  };
116 
118  MSDispatch(const std::map<std::string, std::string>& params);
119 
121  virtual ~MSDispatch() { }
122 
124  virtual Reservation* addReservation(MSTransportable* person,
125  SUMOTime reservationTime,
126  SUMOTime pickupTime,
127  const MSEdge* from, double fromPos,
128  const MSEdge* to, double toPos,
129  std::string group,
130  const std::string& line,
131  int maxCapacity,
132  int maxContainerCapacity);
133 
135  virtual std::string removeReservation(MSTransportable* person,
136  const MSEdge* from, double fromPos,
137  const MSEdge* to, double toPos,
138  std::string group);
139 
141  virtual void fulfilledReservation(const Reservation* res);
142 
144  virtual void computeDispatch(SUMOTime now, const std::vector<MSDevice_Taxi*>& fleet) = 0;
145 
147  std::vector<Reservation*> getReservations();
148 
150  virtual std::vector<const Reservation*> getRunningReservations();
151 
155  }
156 
159 
161  static double computeDetourTime(SUMOTime t, SUMOTime viaTime, const MSDevice_Taxi* taxi,
162  const MSEdge* from, double fromPos,
163  const MSEdge* via, double viaPos,
164  const MSEdge* to, double toPos,
166  double& timeDirect) ;
167 
168 
171 
172 protected:
173  void servedReservation(const Reservation* res);
174 
176  int remainingCapacity(const MSDevice_Taxi* taxi, const Reservation* res);
177 
178  // reservations that are currently being served (could still be used during re-dispatch)
179  std::set<const Reservation*> myRunningReservations;
180 
183 
185  std::map<std::string, std::vector<Reservation*> > myGroupReservations;
186 
187 };
long long int SUMOTime
Definition: SUMOTime.h:32
A device which collects info on the vehicle trip (mainly on departure and arrival)
Definition: MSDevice_Taxi.h:48
sorts reservations by time
Definition: MSDispatch.h:106
time_sorter()
Constructor.
Definition: MSDispatch.h:109
int operator()(const Reservation *r1, const Reservation *r2) const
Comparing operator.
Definition: MSDispatch.h:112
An algorithm that performs distpach for a taxi fleet.
Definition: MSDispatch.h:102
OutputDevice * myOutput
optional file output for dispatch information
Definition: MSDispatch.h:182
virtual ~MSDispatch()
Destructor.
Definition: MSDispatch.h:121
int remainingCapacity(const MSDevice_Taxi *taxi, const Reservation *res)
whether the given taxi has sufficient capacity to serve the reservation
Definition: MSDispatch.cpp:259
static SUMOTime computePickupTime(SUMOTime t, const MSDevice_Taxi *taxi, const Reservation &res, SUMOAbstractRouter< MSEdge, SUMOVehicle > &router)
compute time to pick up the given reservation
Definition: MSDispatch.cpp:214
virtual std::string removeReservation(MSTransportable *person, const MSEdge *from, double fromPos, const MSEdge *to, double toPos, std::string group)
remove person from reservation. If the whole reservation is removed, return it's id
Definition: MSDispatch.cpp:125
bool myHasServableReservations
whether the last call to computeDispatch has left servable reservations
Definition: MSDispatch.h:170
std::map< std::string, std::vector< Reservation * > > myGroupReservations
Definition: MSDispatch.h:185
std::vector< Reservation * > getReservations()
retrieve all reservations
Definition: MSDispatch.cpp:169
virtual std::vector< const Reservation * > getRunningReservations()
retrieve all reservations that were already dispatched and are still active
Definition: MSDispatch.cpp:179
static double computeDetourTime(SUMOTime t, SUMOTime viaTime, const MSDevice_Taxi *taxi, const MSEdge *from, double fromPos, const MSEdge *via, double viaPos, const MSEdge *to, double toPos, SUMOAbstractRouter< MSEdge, SUMOVehicle > &router, double &timeDirect)
compute directTime and detourTime
Definition: MSDispatch.cpp:223
virtual Reservation * addReservation(MSTransportable *person, SUMOTime reservationTime, SUMOTime pickupTime, const MSEdge *from, double fromPos, const MSEdge *to, double toPos, std::string group, const std::string &line, int maxCapacity, int maxContainerCapacity)
add a new reservation
Definition: MSDispatch.cpp:61
bool hasServableReservations()
check whether there are still (servable) reservations in the system
Definition: MSDispatch.h:153
int myReservationCount
Definition: MSDispatch.h:184
MSDispatch(const std::map< std::string, std::string > &params)
Constructor;.
Definition: MSDispatch.cpp:48
virtual void fulfilledReservation(const Reservation *res)
erase reservation from storage
Definition: MSDispatch.cpp:207
virtual void computeDispatch(SUMOTime now, const std::vector< MSDevice_Taxi * > &fleet)=0
computes dispatch and updates reservations
void servedReservation(const Reservation *res)
Definition: MSDispatch.cpp:185
std::set< const Reservation * > myRunningReservations
Definition: MSDispatch.h:179
A road/street connecting two junctions.
Definition: MSEdge.h:77
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
An upper class for objects with additional parameters.
Definition: Parameterised.h:41
bool operator==(const Reservation &other) const
Definition: MSDispatch.h:82
SUMOTime pickupTime
Definition: MSDispatch.h:72
std::string id
Definition: MSDispatch.h:69
const MSEdge * to
Definition: MSDispatch.h:75
SUMOTime recheck
Definition: MSDispatch.h:79
std::string getID() const
debug identification
Definition: MSDispatch.cpp:40
double fromPos
Definition: MSDispatch.h:74
std::string line
Definition: MSDispatch.h:78
const MSEdge * from
Definition: MSDispatch.h:73
SUMOTime reservationTime
Definition: MSDispatch.h:71
std::string group
Definition: MSDispatch.h:77
ReservationState state
Definition: MSDispatch.h:80
std::set< MSTransportable * > persons
Definition: MSDispatch.h:70
Reservation(const std::string &_id, const std::vector< MSTransportable * > &_persons, SUMOTime _reservationTime, SUMOTime _pickupTime, const MSEdge *_from, double _fromPos, const MSEdge *_to, double _toPos, const std::string &_group, const std::string &_line)
Definition: MSDispatch.h:47
double toPos
Definition: MSDispatch.h:76