Skip to content

Commit

Permalink
Wrapper for the Mixed Integer Linear Minimization Oracle (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhendryc authored Oct 19, 2023
1 parent f47ce9c commit bd68d30
Show file tree
Hide file tree
Showing 24 changed files with 1,352 additions and 1,099 deletions.
50 changes: 35 additions & 15 deletions examples/approx_planted_point.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,10 @@ using Distributions
import MathOptInterface
const MOI = MathOptInterface


n = 20
diffi = Random.rand(Bool, n) * 0.6 .+ 0.3

@testset "Approximate planted point" begin
o = SCIP.Optimizer()
MOI.set(o, MOI.Silent(), true)
MOI.empty!(o)
x = MOI.add_variables(o, n)
for xi in x
MOI.add_constraint(o, xi, MOI.GreaterThan(0.0))
MOI.add_constraint(o, xi, MOI.LessThan(1.0))
MOI.add_constraint(o, xi, MOI.ZeroOne()) # or MOI.Integer()
end
lmo = FrankWolfe.MathOptLMO(o)
@testset "Approximate planted point - Integer" begin

function f(x)
return 0.5 * sum((x[i] - diffi[i])^2 for i in eachindex(x))
Expand All @@ -32,8 +21,39 @@ diffi = Random.rand(Bool, n) * 0.6 .+ 0.3
@. storage = x - diffi
end

x, _, result = Boscia.solve(f, grad!, lmo, verbose=true)
@testset "Using SCIP" begin
o = SCIP.Optimizer()
MOI.set(o, MOI.Silent(), true)
MOI.empty!(o)
x = MOI.add_variables(o, n)
for xi in x
MOI.add_constraint(o, xi, MOI.GreaterThan(0.0))
MOI.add_constraint(o, xi, MOI.LessThan(1.0))
MOI.add_constraint(o, xi, MOI.ZeroOne()) # or MOI.Integer()
end
lmo = FrankWolfe.MathOptLMO(o)

x, _, result = Boscia.solve(f, grad!, lmo, verbose=true)

@test x == round.(diffi)
@test isapprox(f(x), f(result[:raw_solution]), atol=1e-6, rtol=1e-3)
end

@test x == round.(diffi)
@test isapprox(f(x), f(result[:raw_solution]), atol=1e-6, rtol=1e-3)
@testset "Using Cube LMO" begin
int_vars = []
bin_vars = collect(1:n)

bounds = Boscia.IntegerBounds()
for i in 1:n
push!(bounds, (i, MOI.GreaterThan(0.0)))
push!(bounds, (i, MOI.LessThan(1.0)))
end
blmo = Boscia.CubeBLMO(n, int_vars, bin_vars, bounds)

x, _, result = Boscia.solve(f, grad!, blmo, verbose =true)

@test x == round.(diffi)
@test isapprox(f(x), f(result[:raw_solution]), atol=1e-6, rtol=1e-3)
end
end

5 changes: 3 additions & 2 deletions examples/birkhoff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ x, _, _ = Boscia.solve(f, grad!, lmo, verbose=true)
x, _, result_baseline = Boscia.solve(f, grad!, lmo, verbose=true)
@test f(x) <= f(result_baseline[:raw_solution]) + 1e-6
lmo = build_birkhoff_lmo()
branching_strategy = Boscia.PartialStrongBranching(20, 1e-4, HiGHS.Optimizer())
MOI.set(branching_strategy.optimizer, MOI.Silent(), true)
blmo = Boscia.MathOptBLMO(HiGHS.Optimizer())
branching_strategy = Boscia.PartialStrongBranching(10, 1e-3, blmo)
MOI.set(branching_strategy.bounded_lmo.o, MOI.Silent(), true)
x_strong, _, result_strong =
Boscia.solve(f, grad!, lmo, verbose=true, branching_strategy=branching_strategy)
@test f(x) f(x_strong)
Expand Down
5 changes: 3 additions & 2 deletions examples/strong_branching_portfolio.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ end
@test dot(ai, x) <= bi + 1e-6
@test f(x) <= f(result_baseline[:raw_solution]) + 1e-6

branching_strategy = Boscia.PartialStrongBranching(10, 1e-3, HiGHS.Optimizer())
MOI.set(branching_strategy.optimizer, MOI.Silent(), true)
blmo = Boscia.MathOptBLMO(HiGHS.Optimizer())
branching_strategy = Boscia.PartialStrongBranching(10, 1e-3, blmo)
MOI.set(branching_strategy.bounded_lmo.o, MOI.Silent(), true)

lmo = prepare_portfolio_lmo()
x, _, result_strong_branching =
Expand Down
9 changes: 7 additions & 2 deletions src/Boscia.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module Boscia

using FrankWolfe
import FrankWolfe: compute_extreme_point
export compute_extreme_point
using Random
using SCIP
import MathOptInterface
Expand All @@ -12,17 +14,20 @@ const MOIU = MOI.Utilities

import MathOptSetDistances as MOD

include("integer_bounds.jl")
include("blmo_interface.jl")
include("time_tracking_lmo.jl")
include("bounds.jl")
include("frank_wolfe_variants.jl")
include("build_lmo.jl")
include("node.jl")
include("custom_bonobo.jl")
include("callbacks.jl")
include("problem.jl")
include("infeasible_pairwise.jl")
include("heuristics.jl")
include("strong_branching.jl")
include("utilities.jl")
include("interface.jl")
include("MOI_bounded_oracle.jl")
include("cube_blmo.jl")

end # module
Loading

0 comments on commit bd68d30

Please sign in to comment.