From 6d8f3717c505368f62934ef1ac3d2c20d76cdd72 Mon Sep 17 00:00:00 2001 From: reinterpretcat Date: Thu, 17 Aug 2023 22:37:02 +0200 Subject: [PATCH] Fix issue with initial solution and relad (#125) --- CHANGELOG.md | 4 ++++ .../src/construction/features/reloads.rs | 15 +++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 223021482..b5c8589b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +### Fixed + +* reload is removed from the solution passed as initial (#126) + ## [v1.22.0]- 2023-08-08 diff --git a/vrp-pragmatic/src/construction/features/reloads.rs b/vrp-pragmatic/src/construction/features/reloads.rs index 4f96b72cd..2f85395c6 100644 --- a/vrp-pragmatic/src/construction/features/reloads.rs +++ b/vrp-pragmatic/src/construction/features/reloads.rs @@ -259,7 +259,7 @@ impl FixedMultiTrip { } fn promote_multi_trips_when_needed(&self, solution_ctx: &mut SolutionContext) { - let jobs = solution_ctx + let candidate_jobs = solution_ctx .routes .iter() .filter(|route_ctx| self.is_multi_trip_needed(route_ctx)) @@ -269,9 +269,16 @@ impl FixedMultiTrip { }) .collect::>(); - solution_ctx.ignored.retain(|job| !jobs.contains(job)); - solution_ctx.locked.extend(jobs.iter().cloned()); - solution_ctx.required.extend(jobs.into_iter()); + // NOTE: get already assigned jobs to guarantee locking them + let assigned_job = solution_ctx + .routes + .iter() + .flat_map(|route_ctx| route_ctx.route().tour.jobs()) + .filter(|job| self.is_marker_job(job)); + + solution_ctx.ignored.retain(|job| !candidate_jobs.contains(job)); + solution_ctx.locked.extend(candidate_jobs.iter().cloned().chain(assigned_job)); + solution_ctx.required.extend(candidate_jobs.into_iter()); } }