From 10ddc90ef026a2a1de43ce6ad7f38585d3184b41 Mon Sep 17 00:00:00 2001 From: Azzaare Date: Thu, 15 Aug 2024 04:19:18 +0000 Subject: [PATCH] Enforce a non-empty pool at initialization of an optimization run --- src/configuration.jl | 1 - src/model.jl | 6 ++---- src/pool.jl | 4 ++++ src/solver.jl | 4 +++- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/configuration.jl b/src/configuration.jl index a457352..8afc24a 100644 --- a/src/configuration.jl +++ b/src/configuration.jl @@ -12,7 +12,6 @@ get_values(c) = c.values get_value(c, x) = get_values(c)[x] set_value!(c, val) = c.value = val -# set_value!(c, x, val) = get_values(c)[x] = val set_values!(c, values) = c.values = values set_sat!(c, b) = c.solution = b diff --git a/src/model.jl b/src/model.jl index 9244ab6..0086a2e 100644 --- a/src/model.jl +++ b/src/model.jl @@ -250,13 +250,11 @@ Add `x` to the constraint `c` list of restricted variables. """ add_var_to_cons!(m::_Model, c, x) = _add!(get_constraint(m, c), x) -""" mts = - get_time_stamp(model) -return TimeStamps(mts, mts, mts, mts, mts, mts, mts) -end - +""" add!(m::M, x) where M <: Union{Model, AbstractSolver} add!(m::M, c) where M <: Union{Model, AbstractSolver} add!(m::M, o) where M <: Union{Model, AbstractSolver} + Add a variable `x`, a constraint `c`, or an objective `o` to `m`. """ function add!(m::_Model, x::Variable) diff --git a/src/pool.jl b/src/pool.jl index f50d99c..3dd7267 100644 --- a/src/pool.jl +++ b/src/pool.jl @@ -21,6 +21,10 @@ function pool(config::Configuration) value = get_value(config) return _Pool(best, configs, status, value) end +function pool!(s) + has_solution(s) || _draw!(s) + s.pool = pool(s.state.configuration) +end is_empty(::EmptyPool) = true is_empty(pool) = isempty(pool.configurations) diff --git a/src/solver.jl b/src/solver.jl index 7aa2ea4..c57414f 100644 --- a/src/solver.jl +++ b/src/solver.jl @@ -238,13 +238,15 @@ function _init!(s, ::Val{:remote}) end end -function _init!(s, ::Val{:local}; pool = pool()) +function _init!(s, ::Val{:local}) get_option(s, "tabu_time") == 0 && set_option!(s, "tabu_time", length_vars(s) ÷ 2) # 10? get_option(s, "tabu_local") == 0 && set_option!(s, "tabu_local", get_option(s, "tabu_time") ÷ 2) get_option(s, "tabu_delta") == 0 && set_option!( s, "tabu_delta", get_option(s, "tabu_time") - get_option(s, "tabu_local")) # 20-30 state!(s) + @warn "Debug" typeof(s) s + pool!(s) return has_solution(s) end