diff --git a/tsp_simple.cc b/tsp_simple.cc index c5816150..7eef91fd 100644 --- a/tsp_simple.cc +++ b/tsp_simple.cc @@ -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 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* vect = new std::vector(); @@ -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 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)) { @@ -163,25 +166,15 @@ void MissionsBuilder(const TSPTWDataDT& data, RoutingModel& routing, } } - if (sticky_vehicle.size() > 0) { - std::vector vehicle_indices; - std::vector vehicle_intersection; - std::vector 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 incompatible_vehicle_indices; + std::vector 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& refill_quantities = data.RefillQuantities(i); for (std::size_t q = 0; q < data.Quantities(i).size(); ++q) { diff --git a/tsptw_data_dt.h b/tsptw_data_dt.h index 213fe21e..47090237 100644 --- a/tsptw_data_dt.h +++ b/tsptw_data_dt.h @@ -249,10 +249,6 @@ class TSPTWDataDT { return tsptw_clients_[i.value()].vehicle_indices; } - void SetVehicleIndices(const int64 i, std::vector&& 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_; }