From 0bda626388906bc9b6e952ba0ef7d3ea1ee91115 Mon Sep 17 00:00:00 2001
From: Romain BERNARD <romain.bernard@uca.fr>
Date: Mon, 24 Jun 2024 13:46:10 +0200
Subject: [PATCH] only increment vehicle id if insertion was a success
 (introduces side effect in while condition)

---
 src/algorithm/DARP/Heuristics/BestInsertionHeuristic.cpp | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/src/algorithm/DARP/Heuristics/BestInsertionHeuristic.cpp b/src/algorithm/DARP/Heuristics/BestInsertionHeuristic.cpp
index b96e273..7bcdf59 100644
--- a/src/algorithm/DARP/Heuristics/BestInsertionHeuristic.cpp
+++ b/src/algorithm/DARP/Heuristics/BestInsertionHeuristic.cpp
@@ -37,10 +37,9 @@ size_t BestInsertionHeuristic::doBestRequestInsertionForRoute(size_t requestId,
     size_t vehicleId = 0;
     bool insertionSuccess{false};
     //Iteratively try inserting in every active vehicle and the first inactive vehicle
-    while(vehicleId <= route.getLastActiveVehicleId() + 1 && !insertionSuccess) {
+    do {
         insertionSuccess = tryVehicleBestInsertion(requestId, vehicleId, route);
-        ++vehicleId;
-    }
+    } while(!insertionSuccess && ++vehicleId <= route.getLastActiveVehicleId() + 1);
 
     //Update last active vehicle ID
     if(vehicleId > route.getLastActiveVehicleId()) {
-- 
GitLab