Skip to content

Commit fe82d6f

Browse files
committed
fix #17644
1 parent c1f8bc9 commit fe82d6f

File tree

5 files changed

+67
-9
lines changed

5 files changed

+67
-9
lines changed

src/microsim/devices/MSDevice_Taxi.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,23 @@ MSDevice_Taxi::cancelCustomer(const MSTransportable* t) {
619619
}
620620

621621

622+
void
623+
MSDevice_Taxi::addCustomer(const MSTransportable* t, const Reservation* res) {
624+
myCustomers.insert(t);
625+
int stopIndex = 0;
626+
MSBaseVehicle& veh = dynamic_cast<MSBaseVehicle&>(myHolder);
627+
for (const Reservation* res2 : myCurrentReservations) {
628+
if (res == res2) {
629+
SUMOVehicleParameter::Stop& stop = const_cast<SUMOVehicleParameter::Stop&>(veh.getStop(stopIndex).pars);
630+
stop.awaitedPersons.insert(t->getID());
631+
stop.permitted.insert(t->getID());
632+
break;
633+
}
634+
stopIndex++;
635+
}
636+
}
637+
638+
622639
void
623640
MSDevice_Taxi::prepareStop(ConstMSEdgeVector& edges,
624641
StopParVector& stops,
@@ -891,6 +908,12 @@ MSDevice_Taxi::checkTaskSwap() {
891908
bestSwap->myCurrentReservations.clear();
892909
bestSwap->myCustomers.clear();
893910
bestSwap->myState = EMPTY;
911+
while (bestSwap->getHolder().hasStops()) {
912+
bestSwap->getHolder().abortNextStop();
913+
}
914+
for (const Reservation* res : myCurrentReservations) {
915+
myDispatcher->swappedRunning(res, this);
916+
}
894917
}
895918
}
896919
}

src/microsim/devices/MSDevice_Taxi.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ class MSDevice_Taxi : public MSVehicleDevice {
178178
/// @brief remove person from reservations
179179
bool cancelCustomer(const MSTransportable* t);
180180

181+
/// @brief add person after extending reservation
182+
void addCustomer(const MSTransportable* t, const Reservation* res);
183+
181184
/// @brief whether the given person is allowed to board this taxi
182185
bool allowsBoarding(const MSTransportable* t) const;
183186

src/microsim/devices/MSDispatch.cpp

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <limits>
2323
#include <microsim/MSNet.h>
2424
#include <microsim/MSEdge.h>
25+
#include <microsim/MSGlobals.h>
2526
#include <microsim/transportables/MSTransportable.h>
2627
#include "MSRoutingEngine.h"
2728
#include "MSDispatch.h"
@@ -36,11 +37,6 @@
3637
// Reservation methods
3738
// ===========================================================================
3839

39-
std::string
40-
Reservation::getID() const {
41-
return toString(persons);
42-
}
43-
4440
// ===========================================================================
4541
// MSDispatch methods
4642
// ===========================================================================
@@ -87,6 +83,28 @@ MSDispatch::addReservation(MSTransportable* person,
8783
// the default empty group implies, no grouping is wanted (and
8884
// transportable ids are unique)
8985
group = person->getID();
86+
} else {
87+
auto it2 = myRunningReservations.find(group);
88+
if (it2 != myRunningReservations.end()) {
89+
for (auto item : it2->second) {
90+
Reservation* res = const_cast<Reservation*>(item.first);
91+
if (res->persons.count(person) == 0
92+
&& res->from == from
93+
&& res->to == to
94+
&& res->fromPos == fromPos
95+
&& res->toPos == toPos) {
96+
MSDevice_Taxi* taxi = item.second;
97+
if (taxi->getState() == taxi->PICKUP
98+
&& remainingCapacity(taxi, res) > 0
99+
&& taxi->compatibleLine(taxi->getHolder().getParameter().line, line)) {
100+
//std::cout << SIMTIME << " addPerson=" << person->getID() << " extendRes=" << toString(res->persons) << " taxi=" << taxi->getHolder().getID() << " state=" << taxi->getState() << "\n";
101+
res->persons.insert(person);
102+
taxi->addCustomer(person, res);
103+
return res;
104+
}
105+
}
106+
}
107+
}
90108
}
91109
Reservation* result = nullptr;
92110
bool added = false;
@@ -294,6 +312,12 @@ MSDispatch::servedReservation(const Reservation* res, MSDevice_Taxi* taxi) {
294312
}
295313

296314

315+
void
316+
MSDispatch::swappedRunning(const Reservation* res, MSDevice_Taxi* taxi) {
317+
myRunningReservations[res->group][res] = taxi;
318+
}
319+
320+
297321
void
298322
MSDispatch::fulfilledReservation(const Reservation* res) {
299323
myRunningReservations[res->group].erase(res);

src/microsim/devices/MSDispatch.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,10 @@ struct Reservation {
101101
&& line == other.line;
102102
}
103103

104-
/// @brief debug identification
105-
std::string getID() const;
104+
/// @brief for sorting by id
105+
std::string getID() const {
106+
return id;
107+
}
106108
};
107109

108110
/**
@@ -195,14 +197,16 @@ class MSDispatch : public Parameterised {
195197
/// @brief whether the last call to computeDispatch has left servable reservations
196198
bool myHasServableReservations = false;
197199

200+
void swappedRunning(const Reservation* res, MSDevice_Taxi* taxi);
201+
198202
protected:
199203
void servedReservation(const Reservation* res, MSDevice_Taxi* taxi);
200204

201205
/// @brief whether the given taxi has sufficient capacity to serve the reservation
202206
int remainingCapacity(const MSDevice_Taxi* taxi, const Reservation* res);
203207

204208
// reservations that are currently being served (could still be used during re-dispatch)
205-
std::map<std::string, std::map<const Reservation*, MSDevice_Taxi*> > myRunningReservations;
209+
std::map<std::string, std::map<const Reservation*, MSDevice_Taxi*, ComparatorIdLess> > myRunningReservations;
206210

207211
/// @brief optional file output for dispatch information
208212
OutputDevice* myOutput;

src/microsim/devices/MSDispatch_RouteExtension.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,16 @@ MSDispatch_RouteExtension::dispatch(MSDevice_Taxi* taxi, std::vector<Reservation
132132
if (sequence.size() > 2) {
133133
taxi->dispatchShared(sequence);
134134
if (myOutput != nullptr) {
135+
std::vector<const MSTransportable*> sharing;
136+
for (const Reservation* s : sequence) {
137+
sharing.insert(sharing.end(), s->persons.begin(), s->persons.end());
138+
}
135139
myOutput->writeXMLHeader("DispatchInfo_RouteExtension", "");
136140
myOutput->openTag("dispatchShared");
137141
myOutput->writeAttr("time", time2string(now));
138142
myOutput->writeAttr("id", taxi->getHolder().getID());
139143
myOutput->writeAttr("persons", toString(res->persons));
140-
myOutput->writeAttr("sharingPersons", toString(sequence));
144+
myOutput->writeAttr("sharingPersons", toString(sharing));
141145
myOutput->writeAttr("type", "routeExtension");
142146
myOutput->closeTag();
143147
}

0 commit comments

Comments
 (0)