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

Timeout from callback #173

Merged
merged 5 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions src/MOI_bounded_oracle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
"""
Read bound value for c_idx.
"""
function get_bound(blmo::MathOptBLMO, c_idx, sense::Symbol)

Check warning on line 109 in src/MOI_bounded_oracle.jl

View check run for this annotation

Codecov / codecov/patch

src/MOI_bounded_oracle.jl#L109

Added line #L109 was not covered by tests
return MOI.get(blmo.o, MOI.ConstraintSet(), c_idx)
end

Expand Down Expand Up @@ -271,7 +271,7 @@
Check if the bounds were set correctly in build_LMO.
Safety check only.
"""
function build_LMO_correct(blmo, node_bounds)

Check warning on line 274 in src/MOI_bounded_oracle.jl

View check run for this annotation

Codecov / codecov/patch

src/MOI_bounded_oracle.jl#L274

Added line #L274 was not covered by tests
for list in (node_bounds.lower_bounds, node_bounds.upper_bounds)
for (idx, set) in list
c_idx = MOI.ConstraintIndex{MOI.VariableIndex,typeof(set)}(idx)
Expand Down Expand Up @@ -303,6 +303,7 @@
Check if problem is bounded and feasible, i.e. no contradicting constraints.
"""
function check_feasibility(blmo::MathOptBLMO)
free_model(blmo)
dhendryc marked this conversation as resolved.
Show resolved Hide resolved
MOI.set(
blmo.o,
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}(),
Expand Down Expand Up @@ -391,7 +392,7 @@
"""
Get solving tolerance for the BLMO.
"""
function get_tol(blmo::MathOptBLMO)

Check warning on line 395 in src/MOI_bounded_oracle.jl

View check run for this annotation

Codecov / codecov/patch

src/MOI_bounded_oracle.jl#L395

Added line #L395 was not covered by tests
return get_tol(blmo.o)
end
function get_tol(o::MOI.AbstractOptimizer)
Expand Down Expand Up @@ -444,7 +445,7 @@
"""
Deal with infeasible vertex if necessary, e.g. check what caused it etc.
"""
function check_infeasible_vertex(blmo::MathOptBLMO, tree)

Check warning on line 448 in src/MOI_bounded_oracle.jl

View check run for this annotation

Codecov / codecov/patch

src/MOI_bounded_oracle.jl#L448

Added line #L448 was not covered by tests
node = tree.nodes[tree.root.current_node_id[]]
node_bounds = node.local_bounds
for list in (node_bounds.lower_bounds, node_bounds.upper_bounds)
Expand Down
17 changes: 13 additions & 4 deletions src/callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
check_rounding_value::Bool,
fw_iterations,
min_fw_iterations,
time_ref,
time_limit,
)
vars = get_variables_pointers(tree.root.problem.tlmo.blmo, tree)
# variable to only fetch heuristics when the counter increases
Expand All @@ -13,10 +15,12 @@
@assert isapprox(sum(active_set.weights), 1.0)
@assert sum(active_set.weights .< 0) == 0
# TODO deal with vertices becoming infeasible with conflicts
if !is_linear_feasible(tree.root.problem.tlmo, state.v)
@info "$(state.v)"
check_infeasible_vertex(tree.root.problem.tlmo.blmo, tree)
@assert is_linear_feasible(tree.root.problem.tlmo, state.v)
@debug begin
dhendryc marked this conversation as resolved.
Show resolved Hide resolved
if !is_linear_feasible(tree.root.problem.tlmo, state.v)
@info "$(state.v)"
check_infeasible_vertex(tree.root.problem.tlmo.blmo, tree)
@assert is_linear_feasible(tree.root.problem.tlmo, state.v)

Check warning on line 22 in src/callbacks.jl

View check run for this annotation

Codecov / codecov/patch

src/callbacks.jl#L19-L22

Added lines #L19 - L22 were not covered by tests
end
end
push!(fw_iterations, state.t)

Expand Down Expand Up @@ -108,6 +112,11 @@
end
end

# check for time limit
if isfinite(time_limit) && Dates.now() >= time_ref + Dates.Second(time_limit)
return false
end

return true
end
end
2 changes: 1 addition & 1 deletion src/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
else
@assert FrankWolfe.active_set_validate(active_set)
for a in active_set.atoms
@assert is_linear_feasible(blmo, a)

Check warning on line 137 in src/interface.jl

View check run for this annotation

Codecov / codecov/patch

src/interface.jl#L137

Added line #L137 was not covered by tests
end
v = active_set.atoms[1]
end
Expand Down Expand Up @@ -273,7 +273,7 @@
num_int,
)

fw_callback = build_FW_callback(tree, min_number_lower, true, fw_iterations, min_fw_iterations)
fw_callback = build_FW_callback(tree, min_number_lower, true, fw_iterations, min_fw_iterations, time_ref, tree.root.options[:time_limit])

tree.root.options[:callback] = fw_callback
tree.root.current_node_id[] = Bonobo.get_next_node(tree, tree.options.traverse_strategy).id
Expand Down
1 change: 0 additions & 1 deletion src/node.jl
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ function Bonobo.evaluate_node!(tree::Bonobo.BnBTree, node::FrankWolfeNode)
line_search=tree.root.options[:lineSearch],
lazy=tree.root.options[:lazy],
lazy_tolerance=tree.root.options[:lazy_tolerance],
timeout=tree.root.options[:time_limit],
add_dropped_vertices=tree.root.options[:use_shadow_set],
use_extra_vertex_storage=tree.root.options[:use_shadow_set],
extra_vertex_storage=node.discarded_vertices,
Expand Down
Loading