Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an optional sat requirement for stopping the solver #129

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
6 changes: 4 additions & 2 deletions src/solvers/main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ 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")
iter_sat = get_option(s, "iteration")[1]
iter_limit = iter_sat || iter < get_option(s, "iteration")[2]
time_limit_sat = get_option(s, "time_limit")[1]
time_limit = time_limit_sat && time() - start_time < get_option(s, "time_limit")[2]
if !remote_limit
s.status = :solution_limit
return false
Expand Down
Loading