Skip to content
Snippets Groups Projects
Unverified Commit b0595282 authored by Michiel Cottaar's avatar Michiel Cottaar
Browse files

Compute cost function value on the fly rather than passing it around

parent e9025fa7
No related branches found
No related tags found
1 merge request!8Make optimisation more robust
...@@ -76,12 +76,11 @@ function build_sequence(f::Function, scanner::Union{Nothing, Scanner}, model::Tu ...@@ -76,12 +76,11 @@ function build_sequence(f::Function, scanner::Union{Nothing, Scanner}, model::Tu
if !iszero(num_variables(jump_model)) if !iszero(num_variables(jump_model))
optimise_with_cost_func!(jump_model, total_cost_func(), n_attempts) optimise_with_cost_func!(jump_model, total_cost_func(), n_attempts)
prev_cost_func = nothing prev_cost_func = nothing
prev_opt_value = nothing
for cost_func in iterate_cost() for cost_func in iterate_cost()
if !isnothing(prev_cost_func) if !isnothing(prev_cost_func)
@constraint jump_model prev_cost_func <= prev_opt_value @constraint jump_model prev_cost_func <= value(prev_cost_func)
end end
prev_opt_value = optimise_with_cost_func!(jump_model, cost_func, n_attempts) optimise_with_cost_func!(jump_model, cost_func, n_attempts)
prev_cost_func = cost_func prev_cost_func = cost_func
end end
end end
...@@ -152,7 +151,6 @@ function optimise_with_cost_func!(jump_model::Model, cost_func, n_attempts) ...@@ -152,7 +151,6 @@ function optimise_with_cost_func!(jump_model::Model, cost_func, n_attempts)
error("Optimisation failed to converge. The following errors were raised: $err_string. Example errors for each type are printed above.") error("Optimisation failed to converge. The following errors were raised: $err_string. Example errors for each type are printed above.")
end end
backend(jump_model).optimizer.model.inner.x .= min_values backend(jump_model).optimizer.model.inner.x .= min_values
return min_objective
end end
function build_sequence(f::Function, scanner::Union{Nothing, Scanner}=Default_Scanner; optimise=true, n_attempts=20, print_level=0, mu_strategy="adaptive", max_iter=1000, kwargs...) function build_sequence(f::Function, scanner::Union{Nothing, Scanner}=Default_Scanner; optimise=true, n_attempts=20, print_level=0, mu_strategy="adaptive", max_iter=1000, kwargs...)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment