Skip to content
Snippets Groups Projects

Robust optimisation

1 file
+ 1
1
Compare changes
  • Side-by-side
  • Inline
+ 37
28
@@ -24,6 +24,10 @@ function iterate_cost()
end
end
function total_cost_func()
return sum([10^(-w) * f for (w, f) in GLOBAL_MODEL[][2]]; init=0.)
end
"""
Wrapper to build a sequence.
@@ -71,11 +75,27 @@ function build_sequence(f::Function, scanner::Union{Nothing, Scanner}, model::Tu
if optimise
jump_model = GLOBAL_MODEL[][1]
if !iszero(num_variables(jump_model))
optimise_with_cost_func(jump_model, total_cost_func(), n_attempts)
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
optimise_with_cost_func(jump_model, cost_func, n_attempts)
prev_cost_func = cost_func
end
end
return fixed(sequence)
else
return sequence
end
finally
GLOBAL_MODEL[] = prev_model
GLOBAL_SCANNER[] = prev_scanner
end
end
function optimise_with_cost_func(jump_model::Model, cost_func, n_attempts)
@objective jump_model Min cost_func
min_objective = Inf
for attempt in 1:n_attempts
@@ -104,17 +124,6 @@ function build_sequence(f::Function, scanner::Union{Nothing, Scanner}, model::Tu
println(solution_summary(jump_model))
error("Optimisation failed to converge.")
end
prev_cost_func = cost_func
end
end
return fixed(sequence)
else
return sequence
end
finally
GLOBAL_MODEL[] = prev_model
GLOBAL_SCANNER[] = prev_scanner
end
end
function build_sequence(f::Function, scanner::Union{Nothing, Scanner}, optimiser_constructor; optimise=true, n_attempts=100, kwargs...)
Loading