Skip to content

Commit

Permalink
fix #13512
Browse files Browse the repository at this point in the history
  • Loading branch information
namdre committed Jun 27, 2023
1 parent 8e67afb commit a7e7e36
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/router/ROPerson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,15 +403,31 @@ ROPerson::computeRoute(const RORouterProvider& provider,
if (vehicles.empty()) {
computeIntermodal(time, provider, trip, nullptr, errorHandler);
} else {
double bestCost = std::numeric_limits<double>::infinity();
PersonTrip* best = nullptr;
ROVehicle* bestVeh = nullptr;
for (std::vector<ROVehicle*>::iterator v = vehicles.begin(); v != vehicles.end();) {
if (!computeIntermodal(time, provider, trip, *v, errorHandler)) {
delete (*v)->getRouteDefinition();
delete *v;
v = vehicles.erase(v);
} else {
const double cost = trip->getCost();
if (cost < bestCost) {
bestCost = cost;
if (best != nullptr) {
delete best;
}
best = static_cast<PersonTrip*>(trip->clone());
bestVeh = *v;
}
trip->clearItems();
++v;
}
}
if (best != nullptr) {
trip->copyItems(best, bestVeh);
}
}
}
time += it->getDuration();
Expand Down
32 changes: 32 additions & 0 deletions src/router/ROPerson.h
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,38 @@ class ROPerson : public RORoutable {
virtual bool needsRouting() const {
return myTripItems.empty();
}

double getCost() const {
double result = 0;
for (TripItem* const it : myTripItems) {
result += it->getCost();
}
return result;
}

void clearItems() {
for (TripItem* const it : myTripItems) {
delete it;
}
myTripItems.clear();
}

void copyItems(PersonTrip* trip, ROVehicle* veh) {
for (TripItem* const it : myTripItems) {
delete it;
}
myTripItems = trip->myTripItems;
for (auto it = myVehicles.begin(); it != myVehicles.end();) {
if (*it != veh) {
delete (*it)->getRouteDefinition();
delete (*it);
it = myVehicles.erase(it);
} else {
it++;
}
}
}

void saveVehicles(OutputDevice& os, OutputDevice* const typeos, bool asAlternatives, OptionsCont& options) const;
void saveAsXML(OutputDevice& os, const bool extended, const bool asTrip, OptionsCont& options) const;

Expand Down

0 comments on commit a7e7e36

Please sign in to comment.