diff --git a/Project.toml b/Project.toml index 5a2e02b..c82fb76 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "LocalSearchSolvers" uuid = "2b10edaa-728d-4283-ac71-07e312d6ccf3" authors = ["Jean-Francois Baffier"] -version = "0.4.8" +version = "0.4.9" [deps] CompositionalNetworks = "4b67e4b5-442d-4ef5-b760-3f5df3a57537" 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..0dd4925 100644 --- a/src/solver.jl +++ b/src/solver.jl @@ -238,13 +238,14 @@ 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) + pool!(s) return has_solution(s) end diff --git a/src/solvers/lead.jl b/src/solvers/lead.jl index 90e366f..801d702 100644 --- a/src/solvers/lead.jl +++ b/src/solvers/lead.jl @@ -33,14 +33,6 @@ stop_while_loop(s::LeadSolver, ::Atomic{Bool}, ::Int, ::Float64) = isready(s.rc_ function remote_stop!(s::LeadSolver) isready(s.rc_stop) && take!(s.rc_stop) - sat = is_sat(s) - if !sat || !has_solution(s) - while isready(s.rc_report) - wait(s.rc_sol) - t = take!(s.rc_sol) - update_pool!(s, t) - sat && has_solution(t) && break - take!(s.rc_report) - end - end + put!(s.rc_sol, s.pool) + take!(s.rc_report) end diff --git a/src/solvers/main.jl b/src/solvers/main.jl index abe8f30..ff5e08f 100644 --- a/src/solvers/main.jl +++ b/src/solvers/main.jl @@ -116,3 +116,26 @@ function post_process(s::MainSolver) write(path, JSON.json(info)) end end + +function remote_stop!(s::MainSolver) + isready(s.rc_stop) && take!(s.rc_stop) + sat = is_sat(s) + @info "Remote stop: report main pool" best_values(s.pool) has_solution(s) s.rc_report s.rc_sol s.rc_stop length(s.remotes) + if !sat || !has_solution(s) + @warn "debugging remote stop" nworkers() length(s.remotes) + while isready(s.rc_report) || isready(s.rc_sol) + wait(s.rc_sol) + t = take!(s.rc_sol) + @info "Remote stop: report remote pool" best_values(t) length(s.remotes) + update_pool!(s, t) + if sat && has_solution(t) + empty!(s.rc_report) + break + end + @info "mark 1" + isready(s.rc_report) && take!(s.rc_report) + @info "mark 2" + end + end + @info "Remote stop: report best pool" best_values(s.pool) length(s.remotes) +end