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-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 // 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 {
39  Reservation(const std::vector<MSTransportable*>& _persons,
40  SUMOTime _reservationTime,
41  SUMOTime _pickupTime,
42  const MSEdge* _from, double _fromPos,
43  const MSEdge* _to, double _toPos,
44  const std::string& _group) :
45  persons(_persons.begin(), _persons.end()),
46  reservationTime(_reservationTime),
47  pickupTime(_pickupTime),
48  from(_from),
49  fromPos(_fromPos),
50  to(_to),
51  toPos(_toPos),
52  group(_group),
53  recheck(_reservationTime)
54  {}
55 
56  std::set<MSTransportable*> persons;
59  const MSEdge* from;
60  double fromPos;
61  const MSEdge* to;
62  double toPos;
63  std::string group;
65 
66  bool operator==(const Reservation& other) const {
67  return persons == other.persons
69  && pickupTime == other.pickupTime
70  && from == other.from
71  && fromPos == other.fromPos
72  && to == other.to
73  && toPos == other.toPos
74  && group == other.group;
75  }
76 
78  std::string getID() const;
79 };
80 
85 class MSDispatch : public Parameterised {
86 public:
87 
89  class time_sorter {
90  public:
92  explicit time_sorter() {}
93 
95  int operator()(const Reservation* r1, const Reservation* r2) const {
96  return r1->reservationTime < r2->reservationTime;
97  }
98  };
99 
101  MSDispatch(const std::map<std::string, std::string>& params);
102 
104  virtual ~MSDispatch() { }
105 
107  virtual Reservation* addReservation(MSTransportable* person,
108  SUMOTime reservationTime,
109  SUMOTime pickupTime,
110  const MSEdge* from, double fromPos,
111  const MSEdge* to, double toPos,
112  const std::string& group,
113  int maxCapacity);
114 
116  virtual void computeDispatch(SUMOTime now, const std::vector<MSDevice_Taxi*>& fleet) = 0;
117 
119  std::vector<Reservation*> getReservations();
120 
124  }
125 
128 
130  static double computeDetourTime(SUMOTime t, SUMOTime viaTime, const MSDevice_Taxi* taxi,
131  const MSEdge* from, double fromPos,
132  const MSEdge* via, double viaPos,
133  const MSEdge* to, double toPos,
135  double& timeDirect) ;
136 
137 
140 
141 protected:
142  void servedReservation(const Reservation* res);
143 
146 
147 private:
148  std::map<std::string, std::vector<Reservation*> > myGroupReservations;
149 
150 };
long long int SUMOTime
Definition: SUMOTime.h:31
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:89
time_sorter()
Constructor.
Definition: MSDispatch.h:92
int operator()(const Reservation *r1, const Reservation *r2) const
Comparing operator.
Definition: MSDispatch.h:95
An algorithm that performs distpach for a taxi fleet.
Definition: MSDispatch.h:85
OutputDevice * myOutput
optional file output for dispatch information
Definition: MSDispatch.h:145
virtual ~MSDispatch()
Destructor.
Definition: MSDispatch.h:104
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:139
bool myHasServableReservations
whether the last call to computeDispatch has left servable reservations
Definition: MSDispatch.h:139
std::map< std::string, std::vector< Reservation * > > myGroupReservations
Definition: MSDispatch.h:148
std::vector< Reservation * > getReservations()
retrieve all reservations
Definition: MSDispatch.cpp:111
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:148
virtual Reservation * addReservation(MSTransportable *person, SUMOTime reservationTime, SUMOTime pickupTime, const MSEdge *from, double fromPos, const MSEdge *to, double toPos, const std::string &group, int maxCapacity)
add a new reservation
Definition: MSDispatch.cpp:63
bool hasServableReservations()
check whether there are still (servable) reservations in the system
Definition: MSDispatch.h:122
MSDispatch(const std::map< std::string, std::string > &params)
Constructor;.
Definition: MSDispatch.cpp:51
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:121
A road/street connecting two junctions.
Definition: MSEdge.h:77
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:60
An upper class for objects with additional parameters.
Definition: Parameterised.h:39
bool operator==(const Reservation &other) const
Definition: MSDispatch.h:66
Reservation(const std::vector< MSTransportable * > &_persons, SUMOTime _reservationTime, SUMOTime _pickupTime, const MSEdge *_from, double _fromPos, const MSEdge *_to, double _toPos, const std::string &_group)
Definition: MSDispatch.h:39
SUMOTime pickupTime
Definition: MSDispatch.h:58
const MSEdge * to
Definition: MSDispatch.h:61
SUMOTime recheck
Definition: MSDispatch.h:64
std::string getID() const
debug identification
Definition: MSDispatch.cpp:43
double fromPos
Definition: MSDispatch.h:60
const MSEdge * from
Definition: MSDispatch.h:59
SUMOTime reservationTime
Definition: MSDispatch.h:57
std::string group
Definition: MSDispatch.h:63
std::set< MSTransportable * > persons
Definition: MSDispatch.h:56
double toPos
Definition: MSDispatch.h:62