Eclipse SUMO - Simulation of Urban MObility
MSDispatch_TraCI.cpp
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 #include <config.h>
21 
22 #include <limits>
23 #include "MSDispatch_TraCI.h"
24 
25 //#define DEBUG_RESERVATION
26 //#define DEBUG_DISPATCH
27 //#define DEBUG_SERVABLE
28 //#define DEBUG_TRAVELTIME
29 //#define DEBUG_DETOUR
30 //#define DEBUG_COND2(obj) (obj->getID() == "p0")
31 #define DEBUG_COND2(obj) (true)
32 
33 // ===========================================================================
34 // MSDispatch_TraCI methods
35 // ===========================================================================
36 
39  SUMOTime reservationTime,
40  SUMOTime pickupTime,
41  const MSEdge* from, double fromPos,
42  const MSEdge* to, double toPos,
43  const std::string& group,
44  int maxCapacity) {
45  Reservation* res = MSDispatch::addReservation(person, reservationTime, pickupTime, from, fromPos, to, toPos, group, maxCapacity);
46  if (!myReservationLookup.has(res)) {
49  }
50  return res;
51 }
52 
53 std::string
55  if (myReservationLookup.has(res)) {
56  return myReservationLookup.getString(res);
57  } else {
58  throw InvalidArgument("Reservation is not known");
59  }
60 }
61 
62 void
63 MSDispatch_TraCI::interpretDispatch(MSDevice_Taxi* taxi, const std::vector<std::string>& reservationsIDs) {
64  std::vector<const Reservation*> reservations;
65  for (std::string resID : reservationsIDs) {
66  if (myReservationLookup.hasString(resID)) {
67  reservations.push_back(myReservationLookup.get(resID));
68  } else {
69  throw InvalidArgument("Reservation id '" + resID + "' is not known");
70  }
71  }
72  if (reservations.size() == 1) {
73  taxi->dispatch(*reservations.front());
74  } else {
75  taxi->dispatchShared(reservations);
76  }
77  // in case of ride sharing the same reservation may occur multiple times
78  std::set<const Reservation*> unique(reservations.begin(), reservations.end());
79  for (const Reservation* res : unique) {
80  servedReservation(res);
81  }
82 }
83 
84 
85 //
86 /****************************************************************************/
long long int SUMOTime
Definition: SUMOTime.h:31
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
A device which collects info on the vehicle trip (mainly on departure and arrival)
Definition: MSDevice_Taxi.h:48
void dispatch(const Reservation &res)
service the given reservation
void dispatchShared(const std::vector< const Reservation * > &reservations)
service the given reservations
StringBijection< Reservation * > myReservationLookup
std::string getReservationID(Reservation *res)
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
void interpretDispatch(MSDevice_Taxi *taxi, const std::vector< std::string > &reservationsIDs)
trigger taxi dispatch.
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
void servedReservation(const Reservation *res)
Definition: MSDispatch.cpp:121
A road/street connecting two junctions.
Definition: MSEdge.h:77
bool has(const T key) const
bool hasString(const std::string &str) const
const std::string & getString(const T key) const
T get(const std::string &str) const
void insert(const std::string str, const T key, bool checkDuplicates=true)