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.dev/sumo
3 // Copyright (C) 2007-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 /****************************************************************************/
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 class MSStoppingPlace;
35 
36 // ===========================================================================
37 // class definitions
38 // ===========================================================================
39 struct Reservation {
41  NEW = 1, // new reservation (not yet retrieved)
42  RETRIEVED = 2, // retrieved at least once via MSDispatch_TraCI
43  ASSIGNED = 4, // a taxi was dispatched to service this reservation
44  ONBOARD = 8, // a taxi has picked up the persons belonging to this reservation
45  FULFILLED = 16, // the persons belonging to this reservation have been dropped off
46  };
47 
48  Reservation(const std::string& _id,
49  const std::vector<const MSTransportable*>& _persons,
50  SUMOTime _reservationTime,
51  SUMOTime _pickupTime,
52  SUMOTime _earliestPickupTime,
53  const MSEdge* _from, double _fromPos,
54  const MSStoppingPlace* _fromStop,
55  const MSEdge* _to, double _toPos,
56  const MSStoppingPlace* _toStop,
57  const std::string& _group,
58  const std::string& _line) :
59  id(_id),
60  persons(_persons.begin(), _persons.end()),
61  reservationTime(_reservationTime),
62  pickupTime(_pickupTime),
63  earliestPickupTime(_earliestPickupTime),
64  from(_from),
65  fromPos(_fromPos),
66  fromStop(_fromStop),
67  to(_to),
68  toPos(_toPos),
69  toStop(_toStop),
70  group(_group),
71  line(_line),
72  recheck(_reservationTime),
73  state(NEW)
74  {}
75 
76  std::string id;
77  std::set<const MSTransportable*> persons;
81  const MSEdge* from;
82  double fromPos;
84  const MSEdge* to;
85  double toPos;
87  std::string group;
88  std::string line;
91 
92  bool operator==(const Reservation& other) const {
93  return persons == other.persons
95  && pickupTime == other.pickupTime
96  && from == other.from
97  && fromPos == other.fromPos
98  && to == other.to
99  && toPos == other.toPos
100  && group == other.group
101  && line == other.line;
102  }
103 
105  std::string getID() const;
106 };
107 
112 class MSDispatch : public Parameterised {
113 public:
114 
116  class time_sorter {
117  public:
119  explicit time_sorter() {}
120 
122  int operator()(const Reservation* r1, const Reservation* r2) const {
124  }
125  };
126 
128  MSDispatch(const Parameterised::Map& params);
129 
131  virtual ~MSDispatch();
132 
134  virtual Reservation* addReservation(MSTransportable* person,
135  SUMOTime reservationTime,
136  SUMOTime pickupTime,
137  SUMOTime earliestPickupTime,
138  const MSEdge* from, double fromPos,
139  const MSStoppingPlace* fromStop,
140  const MSEdge* to, double toPos,
141  const MSStoppingPlace* tostop,
142  std::string group,
143  const std::string& line,
144  int maxCapacity,
145  int maxContainerCapacity);
146 
148  virtual std::string removeReservation(MSTransportable* person,
149  const MSEdge* from, double fromPos,
150  const MSEdge* to, double toPos,
151  std::string group);
152 
157  const MSEdge* from, double fromPos,
158  const MSEdge* to, double toPos,
159  std::string group, double newFromPos);
160 
162  virtual void fulfilledReservation(const Reservation* res);
163 
165  virtual void computeDispatch(SUMOTime now, const std::vector<MSDevice_Taxi*>& fleet) = 0;
166 
168  std::vector<Reservation*> getReservations();
169 
171  virtual std::vector<const Reservation*> getRunningReservations();
172 
176  }
177 
180 
182  static double computeDetourTime(SUMOTime t, SUMOTime viaTime, const MSDevice_Taxi* taxi,
183  const MSEdge* from, double fromPos,
184  const MSEdge* via, double viaPos,
185  const MSEdge* to, double toPos,
187  double& timeDirect) ;
188 
189 
192 
193 protected:
194  void servedReservation(const Reservation* res);
195 
197  int remainingCapacity(const MSDevice_Taxi* taxi, const Reservation* res);
198 
199  // reservations that are currently being served (could still be used during re-dispatch)
200  std::set<const Reservation*> myRunningReservations;
201 
204 
206  std::map<std::string, std::vector<Reservation*> > myGroupReservations;
207 
208 };
long long int SUMOTime
Definition: GUI.h:35
T MAX2(T a, T b)
Definition: StdDefs.h:82
A device which collects info on the vehicle trip (mainly on departure and arrival)
Definition: MSDevice_Taxi.h:49
sorts reservations by time
Definition: MSDispatch.h:116
time_sorter()
Constructor.
Definition: MSDispatch.h:119
int operator()(const Reservation *r1, const Reservation *r2) const
Comparing operator.
Definition: MSDispatch.h:122
An algorithm that performs distpach for a taxi fleet.
Definition: MSDispatch.h:112
OutputDevice * myOutput
optional file output for dispatch information
Definition: MSDispatch.h:203
int remainingCapacity(const MSDevice_Taxi *taxi, const Reservation *res)
whether the given taxi has sufficient capacity to serve the reservation
Definition: MSDispatch.cpp:316
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:271
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 its id
Definition: MSDispatch.cpp:137
bool myHasServableReservations
whether the last call to computeDispatch has left servable reservations
Definition: MSDispatch.h:191
virtual Reservation * updateReservationFromPos(MSTransportable *person, const MSEdge *from, double fromPos, const MSEdge *to, double toPos, std::string group, double newFromPos)
update fromPos of the person's reservation. TODO: if there is already a reservation with the newFromP...
Definition: MSDispatch.cpp:181
std::map< std::string, std::vector< Reservation * > > myGroupReservations
Definition: MSDispatch.h:206
std::vector< Reservation * > getReservations()
retrieve all reservations
Definition: MSDispatch.cpp:226
virtual std::vector< const Reservation * > getRunningReservations()
retrieve all reservations that were already dispatched and are still active
Definition: MSDispatch.cpp:236
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:280
virtual Reservation * addReservation(MSTransportable *person, SUMOTime reservationTime, SUMOTime pickupTime, SUMOTime earliestPickupTime, const MSEdge *from, double fromPos, const MSStoppingPlace *fromStop, const MSEdge *to, double toPos, const MSStoppingPlace *tostop, std::string group, const std::string &line, int maxCapacity, int maxContainerCapacity)
add a new reservation
Definition: MSDispatch.cpp:70
bool hasServableReservations()
check whether there are still (servable) reservations in the system
Definition: MSDispatch.h:174
int myReservationCount
Definition: MSDispatch.h:205
virtual void fulfilledReservation(const Reservation *res)
erase reservation from storage
Definition: MSDispatch.cpp:264
MSDispatch(const Parameterised::Map &params)
Constructor;.
Definition: MSDispatch.cpp:48
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:242
std::set< const Reservation * > myRunningReservations
Definition: MSDispatch.h:200
virtual ~MSDispatch()
Destructor.
Definition: MSDispatch.cpp:59
A road/street connecting two junctions.
Definition: MSEdge.h:77
A lane area vehicles can halt at.
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
std::map< std::string, std::string > Map
parameters map
Definition: Parameterised.h:45
bool operator==(const Reservation &other) const
Definition: MSDispatch.h:92
const MSStoppingPlace * toStop
Definition: MSDispatch.h:86
SUMOTime pickupTime
Definition: MSDispatch.h:79
const MSStoppingPlace * fromStop
Definition: MSDispatch.h:83
std::string id
Definition: MSDispatch.h:76
const MSEdge * to
Definition: MSDispatch.h:84
SUMOTime recheck
Definition: MSDispatch.h:89
std::string getID() const
debug identification
Definition: MSDispatch.cpp:40
double fromPos
Definition: MSDispatch.h:82
std::string line
Definition: MSDispatch.h:88
const MSEdge * from
Definition: MSDispatch.h:81
SUMOTime reservationTime
Definition: MSDispatch.h:78
std::string group
Definition: MSDispatch.h:87
ReservationState state
Definition: MSDispatch.h:90
Reservation(const std::string &_id, const std::vector< const MSTransportable * > &_persons, 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, const std::string &_line)
Definition: MSDispatch.h:48
SUMOTime earliestPickupTime
Definition: MSDispatch.h:80
std::set< const MSTransportable * > persons
Definition: MSDispatch.h:77
double toPos
Definition: MSDispatch.h:85