Skip to content

Commit

Permalink
Merge pull request #132 from JuliaConstraints/pool
Browse files Browse the repository at this point in the history
Fix pool and parallel computing issues
  • Loading branch information
Azzaare authored Aug 15, 2024
2 parents 80353c8 + 1d6580d commit 148c3d3
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 16 deletions.
1 change: 0 additions & 1 deletion src/configuration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 2 additions & 4 deletions src/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions src/pool.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/solver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 2 additions & 10 deletions src/solvers/lead.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 23 additions & 0 deletions src/solvers/main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 148c3d3

Please sign in to comment.