Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[optim-api] Fix: respect compatible vehicle list #34

Merged
merged 1 commit into from
Feb 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 14 additions & 21 deletions tsp_simple.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ void MissionsBuilder(const TSPTWDataDT& data, RoutingModel& routing,
int64 disjunction_cost =
!overflow_danger && !CheckOverflow(data_verif, size) ? data_verif : std::pow(2, 52);

std::vector<int64> all_vehicle_indices;
for (int v = 0; v < size_vehicles; ++v)
all_vehicle_indices.push_back(v);

for (int activity = 0; activity <= size_problem; ++activity) {
std::vector<int64>* vect = new std::vector<int64>();

Expand All @@ -118,8 +122,7 @@ void MissionsBuilder(const TSPTWDataDT& data, RoutingModel& routing,

IntVar* cumul_var = routing.GetMutableDimension(kTime)->CumulVar(index);
const int64 late_multiplier = data.LateMultiplier(i);
std::vector<int64> sticky_vehicle = data.VehicleIndices(i);
std::string service_id = data.ServiceId(i);
std::string service_id = data.ServiceId(i);
if (ready.size() > 0 &&
(ready[0] > -CUSTOM_MAX_INT || due.back() < CUSTOM_MAX_INT)) {
if (absl::GetFlag(FLAGS_debug)) {
Expand Down Expand Up @@ -163,25 +166,15 @@ void MissionsBuilder(const TSPTWDataDT& data, RoutingModel& routing,
}
}

if (sticky_vehicle.size() > 0) {
std::vector<int64> vehicle_indices;
std::vector<int64> vehicle_intersection;
std::vector<int64> vehicle_difference;

for (int v = 0; v < size_vehicles; ++v)
vehicle_indices.push_back(v);

std::set_intersection(vehicle_indices.begin(), vehicle_indices.end(),
sticky_vehicle.begin(), sticky_vehicle.end(),
std::back_inserter(vehicle_intersection));
std::set_difference(vehicle_indices.begin(), vehicle_indices.end(),
vehicle_intersection.begin(), vehicle_intersection.end(),
std::back_inserter(vehicle_difference));
if (vehicle_difference.size() > 0) {
for (int64 remove : vehicle_difference)
routing.VehicleVar(index)->RemoveValue(remove);
}
}
std::vector<int64> incompatible_vehicle_indices;
std::vector<int64> compatible_vehicles = data.VehicleIndices(i);

std::set_difference(all_vehicle_indices.begin(), all_vehicle_indices.end(),
compatible_vehicles.begin(), compatible_vehicles.end(),
std::back_inserter(incompatible_vehicle_indices));

for (int64 remove : incompatible_vehicle_indices)
routing.VehicleVar(index)->RemoveValue(remove);

const std::vector<bool>& refill_quantities = data.RefillQuantities(i);
for (std::size_t q = 0; q < data.Quantities(i).size(); ++q) {
Expand Down
4 changes: 0 additions & 4 deletions tsptw_data_dt.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,6 @@ class TSPTWDataDT {
return tsptw_clients_[i.value()].vehicle_indices;
}

void SetVehicleIndices(const int64 i, std::vector<int64>&& vehicle_indices) {
tsptw_clients_[i].vehicle_indices = std::move(vehicle_indices);
}

int32 TimeWindowsSize(const int i) const { return tws_size_[i]; }

int32 Size() const { return size_; }
Expand Down