Skip to content

Commit

Permalink
fixing canceling of bookings, ref. #11429
Browse files Browse the repository at this point in the history
  • Loading branch information
rummel123 committed Mar 12, 2024
1 parent 1c0d464 commit 3616da0
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 50 deletions.
2 changes: 1 addition & 1 deletion src/libsumo/Person.cpp
Expand Up @@ -183,7 +183,7 @@ Person::filterReservation(int onlyNew, const Reservation* res, std::vector<libsu
return false;
}
std::vector<std::string> personIDs;
for (MSTransportable* p : res->persons) {
for (const MSTransportable* p : res->persons) {
personIDs.push_back(p->getID());
}
std::sort(personIDs.begin(), personIDs.end());
Expand Down
78 changes: 34 additions & 44 deletions src/microsim/devices/MSDevice_Taxi.cpp
Expand Up @@ -313,6 +313,7 @@ MSDevice_Taxi::dispatchShared(std::vector<const Reservation*> reservations) {
}
}
#endif
myLastDispatch = reservations;
ConstMSEdgeVector tmpEdges;
std::vector<SUMOVehicleParameter::Stop> stops;
double lastPos = myHolder.getPositionOnLane();
Expand All @@ -333,7 +334,7 @@ MSDevice_Taxi::dispatchShared(std::vector<const Reservation*> reservations) {
// check how often existing customers appear in the new reservations
std::map<const MSTransportable*, int> nOccur;
for (const Reservation* res : reservations) {
for (MSTransportable* person : res->persons) {
for (const MSTransportable* person : res->persons) {
if (myCustomers.count(person) != 0) {
nOccur[person] += 1;
if (myCurrentReservations.count(res) == 0) {
Expand Down Expand Up @@ -433,7 +434,7 @@ MSDevice_Taxi::dispatchShared(std::vector<const Reservation*> reservations) {
for (const Reservation* res : reservations) {
myCurrentReservations.insert(res);
bool isPickup = false;
for (MSTransportable* person : res->persons) {
for (const MSTransportable* person : res->persons) {
if (myCustomers.count(person) == 0) {
myCustomers.insert(person);
isPickup = true;
Expand All @@ -451,7 +452,7 @@ MSDevice_Taxi::dispatchShared(std::vector<const Reservation*> reservations) {
stops.back().permitted.insert(transportable->getID());
}
// proof this lines: Is needed for pre-booking?
std::set<MSTransportable*> persons = res->persons;
std::set<const MSTransportable*> persons = res->persons;
for (auto itr = persons.begin(); itr != persons.end(); itr++) {
stops.back().awaitedPersons.insert((*itr)->getID());
}
Expand Down Expand Up @@ -532,55 +533,44 @@ MSDevice_Taxi::cancelCurrentCustomers() {

bool
MSDevice_Taxi::cancelCustomer(const MSTransportable* t) {
// ist es ein aktueller Customer des Taxis?
// entferne den Customer
// passe an:
// DONE: - myCustomers
// offen: - state (empty, pickup, occupied)
// neuer Memeber: Liste der Reservation Pointers --> myReservations, ist das nicht "myCurrentReservations"?
// transportable aus entsprechender Reservierung entfernen,
// Reservierung beibehalten, wenn noch andere Person transportiert wird,
// sonst entfernen
// am Ende dipatchShared aufrufen, um "stops" zu aktualisieren

// is the given transportable a customer of the reservations?
if (myCustomers.find(t) == myCustomers.end()) {
if (myCustomers.count(t) == 0) {
return false;
}
myCustomers.erase(t);
// if there are no other reservations (not occupied by or is going to pickup other customers)
if (isEmpty()) {
// cleanup
for (const Reservation* res : myCurrentReservations) {
myDispatcher->fulfilledReservation(res);
// check whether a single reservation has been fulfilled or another customer is part of the reservation
for (auto resIt = myCurrentReservations.begin(); resIt != myCurrentReservations.end();) {
bool fulfilled = false;
if ((*resIt)->persons.size() == 1 && (*resIt)->persons.count(t) != 0) {
// the reservation contains only the customer
fulfilled = true;
}
if (fulfilled) {
// delete the reservation
myDispatcher->fulfilledReservation(*resIt);
// remove reservation from the current dispatch
for (auto it = myLastDispatch.begin(); it != myLastDispatch.end();) {
if (*it == *resIt)
it = myLastDispatch.erase(it);
else
++it;
}
// remove reservation from the served reservations
resIt = myCurrentReservations.erase(resIt);
}
myCurrentReservations.clear();
if (MSGlobals::gUseMesoSim && MSNet::getInstance()->getCurrentTimeStep() < myServiceEnd) {
myIdleAlgorithm->idle(this);
else {
++resIt;
}
}
else {
// check whether a single reservation has been fulfilled or another customer is part of the reservation
for (auto resIt = myCurrentReservations.begin(); resIt != myCurrentReservations.end();) {
bool fulfilled = true;
for (MSTransportable* t : (*resIt)->persons) {
if (myCustomers.count(t) != 0) {
fulfilled = false;
break;
}
}
if (fulfilled) {
myDispatcher->fulfilledReservation(*resIt);
resIt = myCurrentReservations.erase(resIt);
}
else {
++resIt;
}
myState &= ~PICKUP; // remove state PICKUP
for (const Reservation* res : myCurrentReservations) {
// if there is another pickup in the dispatch left, add the state PICKUP
if (std::count(myLastDispatch.begin(), myLastDispatch.end(), res) == 2) {
myState |= PICKUP; // add state PICKUP
}
}
myState &= ~PICKUP; // remove state PICKUP
// use myDispatcher->getReservations() or myDispatcher->getRunningReservations() ???
dispatchShared(myDispatcher->getRunningReservations()); // also sets PICKUP if needed
// if there are reservations left, go on with the dispatch
dispatchShared(myLastDispatch);
return true;
}

Expand Down Expand Up @@ -791,7 +781,7 @@ MSDevice_Taxi::customerArrived(const MSTransportable* person) {
// check whether a single reservation has been fulfilled
for (auto resIt = myCurrentReservations.begin(); resIt != myCurrentReservations.end();) {
bool fulfilled = true;
for (MSTransportable* t : (*resIt)->persons) {
for (const MSTransportable* t : (*resIt)->persons) {
if (myCustomers.count(t) != 0) {
fulfilled = false;
break;
Expand Down
2 changes: 2 additions & 0 deletions src/microsim/devices/MSDevice_Taxi.h
Expand Up @@ -276,6 +276,8 @@ class MSDevice_Taxi : public MSVehicleDevice {
static MSDispatch* myDispatcher;
/// @brief The repeated call to the dispatcher
static Command* myDispatchCommand;
/// @brief the last dispatch order
std::vector<const Reservation*> myLastDispatch;
// @brief the list of available taxis
static std::vector<MSDevice_Taxi*> myFleet;
// @brief the maximum personCapacity in the fleet
Expand Down
4 changes: 2 additions & 2 deletions src/microsim/devices/MSDispatch.h
Expand Up @@ -45,7 +45,7 @@ struct Reservation {
};

Reservation(const std::string& _id,
const std::vector<MSTransportable*>& _persons,
const std::vector<const MSTransportable*>& _persons,
SUMOTime _reservationTime,
SUMOTime _pickupTime,
SUMOTime _earliestPickupTime,
Expand All @@ -69,7 +69,7 @@ struct Reservation {
{}

std::string id;
std::set<MSTransportable*> persons;
std::set<const MSTransportable*> persons;
SUMOTime reservationTime;
SUMOTime pickupTime;
SUMOTime earliestPickupTime;
Expand Down
6 changes: 3 additions & 3 deletions src/microsim/devices/MSDispatch_TraCI.cpp
Expand Up @@ -109,7 +109,7 @@ MSDispatch_TraCI::splitReservation(std::string resID, std::vector<std::string> p
throw InvalidArgument("Cannot split reservation '" + resID + "' after dispatch");
}
std::set<std::string> allPersons;
for (MSTransportable* t : res->persons) {
for (const MSTransportable* t : res->persons) {
allPersons.insert(t->getID());
}
for (std::string p : personIDs) {
Expand All @@ -120,9 +120,9 @@ MSDispatch_TraCI::splitReservation(std::string resID, std::vector<std::string> p
if (personIDs.size() == allPersons.size()) {
throw InvalidArgument("Cannot remove all person from reservation '" + resID + "'");
}
std::vector<MSTransportable*> split;
std::vector<const MSTransportable*> split;
for (const std::string& p : personIDs) {
for (MSTransportable* const t : res->persons) {
for (const MSTransportable* const t : res->persons) {
if (t->getID() == p) {
res->persons.erase(t);
split.push_back(t);
Expand Down

0 comments on commit 3616da0

Please sign in to comment.