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=" << destConnected <<
"\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*, ComparatorNumericalIdLess> 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 if (!available.empty() && !activeReservations.empty()) {
175 struct DispatchCandidate {
180 bool operator<(
const DispatchCandidate& other)
const {
181 if (travelTime != other.travelTime) {
182 return travelTime < other.travelTime;
184 if (resIdx != other.resIdx) {
185 return resIdx < other.resIdx;
187 return taxiIdx < other.taxiIdx;
190 const std::vector<MSDevice_Taxi*> availableVec(available.begin(), available.end());
191 std::vector<DispatchCandidate> candidates;
192 candidates.reserve(activeReservations.size() * availableVec.size());
193 router.
init(-1, now);
195 for (
int tIdx = 0; tIdx < (int)availableVec.size(); ++tIdx) {
197 for (
int rIdx = 0; rIdx < (int)activeReservations.size(); ++rIdx) {
204#ifdef DEBUG_TRAVELTIME
211 candidates.push_back({travelTime, rIdx, tIdx, res});
216 std::sort(candidates.begin(), candidates.end());
217 for (
const DispatchCandidate& cand : candidates) {
218 if (available.empty() || activeReservations.empty()) {
221 MSDevice_Taxi*
const closestTaxi = availableVec[cand.taxiIdx];
222 if (available.count(closestTaxi) == 0) {
225 auto closeIt = std::find(activeReservations.begin(), activeReservations.end(), cand.res);
226 if (closeIt == activeReservations.end()) {
233 <<
" taxiWait=" <<
time2string(cand.res->pickupTime - (now + cand.travelTime)) <<
"\n";
235 numDispatched +=
dispatch(closestTaxi, closeIt, router, activeReservations);
236 available.erase(closestTaxi);
238 if (!available.empty() && !activeReservations.empty()) {
240 havePostponed =
true;
247 <<
" 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
bool compatibleLine(const Reservation *res)
whether the given reservation is compatible with the taxi line
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
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
const int myRoutingMode
which router/edge weights to use
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
virtual SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouter() const
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.
void init(const int edgeID, const SUMOTime msTime)
void setAutoBulkMode(const bool mode)
virtual double getPositionOnLane() const =0
Get the object's position along the lane.
bool operator<(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
std::set< const MSTransportable *, ComparatorNumericalIdLess > persons