33#define DEBUG_COND2(obj) (true)
41 int numDispatched = 0;
44 std::set<MSDevice_Taxi*, MSVehicleDevice::ComparatorNumericalVehicleIdLess> available;
45 for (
auto* taxi : fleet) {
46 if (taxi->isEmpty()) {
47 available.insert(taxi);
53 std::sort(reservations.begin(), reservations.end(),
time_sorter());
55 std::cout <<
SIMTIME <<
" computeDispatch fleet=" << fleet.size() <<
" available=" << available.size() <<
" reservations=" <<
toString(reservations) <<
"\n";
57 for (
auto it = reservations.begin(); it != reservations.end();) {
58 if (available.size() == 0) {
70 bool tooEarly =
false;
71 bool unreachable =
false;
72 bool unreachableDest =
false;
73 for (
auto* taxi : available) {
78 const bool destConnected =
isReachable(now, taxi, *res, router);
79#ifdef DEBUG_TRAVELTIME
81 std::cout <<
SIMTIME <<
" taxi=" << taxi->getHolder().getID() <<
" person=" <<
toString(res->
persons) <<
" traveltime=" <<
time2string(travelTime) <<
" reachable=" << reachable <<
"\n";
84 if (travelTime < closestTime && destConnected) {
85 closestTime = travelTime;
96 }
else if (!destConnected) {
97 unreachableDest =
true;
100 if (tooEarly || closest ==
nullptr) {
104 it = reservations.erase(it);
106 WRITE_WARNINGF(
"Aborting reservation for customers '%' from '%' after waiting time % because no taxi can reach the pickup location, time=%.",
109 WRITE_WARNINGF(
"Aborting reservation for customers '%' to '%' after waiting time % because no taxi can reach the dropoff location, time=%.",
112 std::set<const MSTransportable*> persons = res->
persons;
121 numDispatched +=
dispatch(closest, it, router, reservations);
122 available.erase(closest);
126 myHasServableReservations = reservations.size() > 0 && (available.size() < fleet.size() || numPostponed > 0 || numDispatched > 0);
128 std::cout <<
SIMTIME <<
" reservations=" << reservations.size() <<
" avail=" << available.size()
129 <<
" fleet=" << fleet.size() <<
" postponed=" << numPostponed <<
" dispatched=" << numDispatched <<
"\n";
143 resIt = reservations.erase(resIt);
154 bool havePostponed =
false;
155 int numDispatched = 0;
157 std::set<MSDevice_Taxi*, MSVehicleDevice::ComparatorNumericalVehicleIdLess> available;
158 for (
auto* taxi : fleet) {
159 if (taxi->isEmpty()) {
160 available.insert(taxi);
164 std::cout <<
SIMTIME <<
" computeDispatch fleet=" << fleet.size() <<
" available=" << available.size() <<
"\n";
168 std::vector<Reservation*> activeReservations;
170 if (res->recheck <= now) {
171 activeReservations.push_back(res);
174 while (available.size() > 0 && activeReservations.size() > 0) {
180 for (
auto* taxi : available) {
185 SUMOTime taxiWait = res->pickupTime - (now + travelTime);
186#ifdef DEBUG_TRAVELTIME
187 if (
DEBUG_COND2(person)) std::cout <<
SIMTIME <<
" taxi=" << taxi->getHolder().getID() <<
" person=" <<
toString(res->persons)
192 if (travelTime < closestTime) {
194 closestTime = travelTime;
199 <<
" taxiPos=" << taxi->getHolder().getPositionOnLane() <<
" resFromPos=" << res->fromPos <<
" traveltime=" <<
time2string(travelTime) <<
" taxiWait=" <<
time2string(taxiWait) <<
"\n";
202 recheck =
MIN2(recheck,
214 if (closestTaxi !=
nullptr) {
215 auto closeIt = std::find(activeReservations.begin(), activeReservations.end(), closest);
216 numDispatched +=
dispatch(closestTaxi, closeIt, router, activeReservations);
217 available.erase(closestTaxi);
220 havePostponed =
true;
228 <<
" fleet=" << fleet.size() <<
" postponed=" << havePostponed <<
" dispatched=" << numDispatched <<
"\n";
#define WRITE_WARNINGF(...)
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
@ SVC_TAXI
vehicle is a taxi
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
A device which collects info on the vehicle trip (mainly on departure and arrival)
void dispatch(const Reservation &res)
service the given reservation
sorts reservations by time
void computeDispatch(SUMOTime now, const std::vector< MSDevice_Taxi * > &fleet)
computes dispatch and updates reservations
const SUMOTime myRecheckTime
recheck interval for early reservations
virtual void computeDispatch(SUMOTime now, const std::vector< MSDevice_Taxi * > &fleet)
computes dispatch and updates reservations
const int myRoutingMode
which router/edge weights to use
virtual int dispatch(MSDevice_Taxi *taxi, std::vector< Reservation * >::iterator &resIt, SUMOAbstractRouter< MSEdge, SUMOVehicle > &router, std::vector< Reservation * > &reservations)
trigger taxi dispatch.
const SUMOTime myRecheckSafety
const SUMOTime myMaximumWaitingTime
maximum time to arrive earlier at customer
bool isReachable(SUMOTime t, const MSDevice_Taxi *taxi, const Reservation &res, SUMOAbstractRouter< MSEdge, SUMOVehicle > &router)
compute whether the reservation is servable
int remainingCapacity(const MSDevice_Taxi *taxi, const Reservation *res)
whether the given taxi has sufficient capacity to serve the reservation
static SUMOTime computePickupTime(SUMOTime t, const MSDevice_Taxi *taxi, const Reservation &res, SUMOAbstractRouter< MSEdge, SUMOVehicle > &router)
compute time to pick up the given reservation
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
bool myHasServableReservations
whether the last call to computeDispatch has left servable reservations
std::vector< Reservation * > getReservations()
retrieve all reservations
SUMOTime myKeepUnreachableResTime
the duration before canceling unreachable reservations
void servedReservation(const Reservation *res, MSDevice_Taxi *taxi)
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
MSVehicleRouter & getRouterTT(int rngIndex, const Prohibitions &prohibited={}) const
static MSVehicleRouter & getRouterTT(const int rngIndex, SUMOVehicleClass svc, const Prohibitions &prohibited={})
return the vehicle router instance
SUMOVehicle & getHolder() const
Returns the vehicle that holds this device.
const std::string & getID() const
Returns the id.
std::set< const MSTransportable * > persons