From a6ba7e9923fc125fbe94bec4ef874d72ef4cbedb Mon Sep 17 00:00:00 2001
From: Michiel Cottaar <MichielCottaar@protonmail.com>
Date: Tue, 30 Jul 2024 15:39:51 +0100
Subject: [PATCH] Fix previous cost function before optimising again

---
 src/build_sequences.jl | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/build_sequences.jl b/src/build_sequences.jl
index cc8ecab..dc28da4 100644
--- a/src/build_sequences.jl
+++ b/src/build_sequences.jl
@@ -71,7 +71,11 @@ function build_sequence(f::Function, scanner::Union{Nothing, Scanner}, model::Tu
         if optimise
             jump_model = GLOBAL_MODEL[][1]
             if !iszero(num_variables(jump_model))
+                prev_cost_func = nothing
                 for cost_func in iterate_cost()
+                    if !isnothing(prev_cost_func)
+                        @constraint jump_model prev_cost_func == objective_value(jump_model)
+                    end
                     @objective jump_model Min cost_func
                     min_objective = Inf
                     for attempt in 1:n_attempts
@@ -100,7 +104,7 @@ function build_sequence(f::Function, scanner::Union{Nothing, Scanner}, model::Tu
                         println(solution_summary(jump_model))
                         error("Optimisation failed to converge.")
                     end
-                    #@constraint jump_model cost_func == objective_value(jump_model)
+                    prev_cost_func = cost_func
                 end
             end
             return fixed(sequence)
-- 
GitLab