Skip to content

Commit

Permalink
Dev (#131)
Browse files Browse the repository at this point in the history
* CI and other small fixes (#120)

* Update compat and CI (#115)

* Fixes for a demo

* Cleaning unused files. Added Aqua and other CI

* spelling

* New version

* Fix an issue when restarting (#122)

* Update Project.toml

* Compat, CI, and threads (#126)

* Add an optional sat requirement for stopping the solver (#129)

* Sat stop (#130)

* Add an optional sat requirement for stopping the solver

* Fixes stop with sat condition, opt runs

* Update sub.jl

* Update Project.toml
  • Loading branch information
Azzaare authored Aug 12, 2024
1 parent d558c63 commit c28e310
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "LocalSearchSolvers"
uuid = "2b10edaa-728d-4283-ac71-07e312d6ccf3"
authors = ["Jean-Francois Baffier"]
version = "0.4.7"
version = "0.4.8"

[deps]
CompositionalNetworks = "4b67e4b5-442d-4ef5-b760-3f5df3a57537"
Expand Down
38 changes: 25 additions & 13 deletions src/options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ const print_levels = Dict(
:verbose => 3
)

# # Tabu times
# get!(s, :tabu_time, length_vars(s) ÷ 2) # 10?
# get!(s, :local_tabu, setting(s, :tabu_time) ÷ 2)
# get!(s, :δ_tabu, setting(s, :tabu_time) - setting(s, :local_tabu))# 20-30

"""
Options()
# Arguments:
Expand All @@ -36,28 +31,28 @@ set_time_limit_sec(model, 5.0)
mutable struct Options
dynamic::Bool
info_path::String
iteration::Union{Int, Float64}
iteration::Tuple{Bool, Union{Int, Float64}}
print_level::Symbol
process_threads_map::Dict{Int, Int}
solutions::Int
specialize::Bool
tabu_time::Int
tabu_local::Int
tabu_delta::Float64
time_limit::Float64 # seconds
time_limit::Tuple{Bool, Float64} # seconds

function Options(;
dynamic = false,
info_path = "",
iteration = 10000,
iteration = (false, 100),
print_level = :minimal,
process_threads_map = Dict{Int, Int}(1 => typemax(0)),
solutions = 1,
specialize = !dynamic,
tabu_time = 0,
tabu_local = 0,
tabu_delta = 0.0,
time_limit = 60 # seconds
time_limit = (false, 1.0) # seconds
)
ds_str = "The model types are specialized to the starting domains, constraints," *
" and objectives types. Dynamic elements that add a new type will raise an error!"
Expand All @@ -69,20 +64,33 @@ mutable struct Options

itertime_str = "Both iteration and time limits are disabled. " *
"Optimization runs will run infinitely."
iteration == Inf && time_limit == Inf && @warn itertime_str

new_iteration = if iteration isa Tuple{Bool, Union{Int, Float64}}
iteration
else
iteration = (false, iteration)
end

new_time_limit = if time_limit isa Tuple{Bool, Float64}
time_limit
else
time_limit = (false, time_limit)
end

new_iteration[2] == Inf && new_time_limit[2] == Inf && @warn itertime_str

new(
dynamic,
info_path,
iteration,
new_iteration,
print_level,
process_threads_map,
solutions,
specialize,
tabu_time,
tabu_local,
tabu_delta,
time_limit
new_time_limit
)
end
end
Expand Down Expand Up @@ -137,6 +145,9 @@ _iteration(options) = options.iteration
DOCSTRING
"""
_iteration!(options, iterations) = options.iteration = iterations
function _iteration!(options, iterations::Union{Int, Float64})
options.iteration = (false, iterations)
end

"""
_print_level(options) = begin
Expand Down Expand Up @@ -266,7 +277,8 @@ _time_limit(options) = options.time_limit
DOCSTRING
"""
_time_limit!(options, time) = options.time_limit = time
_time_limit!(options, time::Tuple{Bool, Float64}) = options.time_limit = time
_time_limit!(options, time::Float64) = options.time_limit = (false, time)

function set_option!(options, name, value)
eval(Symbol("_" * name * "!"))(options, value)
Expand Down
2 changes: 1 addition & 1 deletion src/solvers/lead.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ end
function solver(
mlid, model, options, pool, rc_report, rc_sol, rc_stop, strats, ::Val{:lead})
l_options = deepcopy(options)
set_option!(options, "print_level", :silent)
set_option!(l_options, "print_level", :silent)
ss = Vector{_SubSolver}()
return LeadSolver(
mlid, model, l_options, pool, rc_report, rc_sol, rc_stop, state(), strats, ss)
Expand Down
17 changes: 11 additions & 6 deletions src/solvers/main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,26 @@ function _init!(s::MainSolver)
end

function stop_while_loop(s::MainSolver, ::Atomic{Bool}, iter, start_time)
remote_limit = isready(s.rc_stop) # Add ! when MainSolver is passive
iter_limit = iter < get_option(s, "iteration")
time_limit = time() - start_time < get_option(s, "time_limit")
if !remote_limit
@debug "debug stop" iter (time()-start_time)
if !isready(s.rc_stop)
s.status = :solution_limit
return false
end
if !iter_limit

iter_sat = get_option(s, "iteration")[1] && has_solution(s)
iter_limit = iter > get_option(s, "iteration")[2]
if (iter_sat && iter_limit) || iter_limit
s.status = :iteration_limit
return false
end
if !time_limit

time_sat = get_option(s, "time_limit")[1] && has_solution(s)
time_limit = time() - start_time > get_option(s, "time_limit")[2]
if (time_sat && time_limit) || time_limit
s.status = :time_limit
return false
end

return true
end

Expand Down
2 changes: 1 addition & 1 deletion src/solvers/sub.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ end
function solver(mlid, model, options, pool, ::RemoteChannel,
::RemoteChannel, ::RemoteChannel, strats, ::Val{:sub})
sub_options = deepcopy(options)
set_option!(options, "print_level", :silent)
set_option!(sub_options, "print_level", :silent)
return _SubSolver(mlid, model, sub_options, pool, state(), strats)
end

Expand Down

0 comments on commit c28e310

Please sign in to comment.