From ee5cc6cae0eeced8e856db0c533a0034950eca5e Mon Sep 17 00:00:00 2001 From: Sebastian Pokutta <23001135+pokutta@users.noreply.github.com> Date: Mon, 6 Nov 2023 11:39:24 +0100 Subject: [PATCH] updated examples to use cubesimpleblmo --- examples/low_dim_in_high_dim.jl | 18 ++++++++---------- examples/nonlinear.jl | 17 ++++++++--------- examples/worst-case.jl | 33 ++++++++++++++++++++++----------- 3 files changed, 38 insertions(+), 30 deletions(-) diff --git a/examples/low_dim_in_high_dim.jl b/examples/low_dim_in_high_dim.jl index 1f9dd534f..d8fcb749f 100644 --- a/examples/low_dim_in_high_dim.jl +++ b/examples/low_dim_in_high_dim.jl @@ -9,8 +9,6 @@ using Distributions import MathOptInterface const MOI = MathOptInterface -include("cube_blmo.jl") - # The example from "Optimizing a low-dimensional convex function over a high-dimensional cube" # by Christoph Hunkenschröder, Sebastian Pokutta, Robert Weismantel # https://arxiv.org/abs/2204.05266. @@ -53,17 +51,17 @@ end @test f(x) <= f(result[:raw_solution]) + 1e-6 end -@testset "Low-dimensional function (CubeBLMO)" begin +@testset "Low-dimensional function (CubeSimpleBLMO)" begin int_vars = collect(1:n) - bounds = Boscia.IntegerBounds() - for i in 1:n - push!(bounds, (i, 0.0), :greaterthan) - push!(bounds, (i, 1.0), :lessthan) - end - blmo = CubeBLMO(n, int_vars, bounds) - x, _, result = Boscia.solve(f, grad!, blmo, verbose=true) + lbs = zeros(n) + ubs = ones(n) + + sblmo = Boscia.CubeSimpleBLMO(lbs, ubs, int_vars) + + # modified solve call from managed_blmo.jl automatically wraps sblmo into a managed_blmo + x, _, result = Boscia.solve(f, grad!, sblmo, lbs[int_vars], ubs[int_vars], int_vars, n, verbose=true) if n < 15 # only do for small n valopt, xopt = Boscia.min_via_enum(f, n) diff --git a/examples/nonlinear.jl b/examples/nonlinear.jl index 4aa36a56c..ce906cb84 100644 --- a/examples/nonlinear.jl +++ b/examples/nonlinear.jl @@ -10,8 +10,6 @@ using Dates # using SCIP # const MOI = MathOptInterface -include("cube_blmo.jl") - n = 40 seed = 10 @@ -33,15 +31,16 @@ Random.seed!(seed) ################################################################ -# LMO via CubeBLMO +# LMO via CubeSimpleBLMO ################################################################ int_vars = collect(1:n) -bounds = Boscia.IntegerBounds() -for i in 1:n - push!(bounds, (i, 0.0), :greaterthan) - push!(bounds, (i, 1.0), :lessthan) -end -lmo = CubeBLMO(n, int_vars, bounds) + +lbs = zeros(n) +ubs = ones(n) + +sblmo = Boscia.CubeSimpleBLMO(lbs, ubs, int_vars) +# wrap the sblmo into a bound manager +lmo = Boscia.ManagedBoundedLMO(sblmo, lbs[int_vars], ubs[int_vars], n, int_vars) const A = let A = randn(n, n) diff --git a/examples/worst-case.jl b/examples/worst-case.jl index 4ee5d6178..c27493aeb 100644 --- a/examples/worst-case.jl +++ b/examples/worst-case.jl @@ -2,7 +2,7 @@ using Boscia using FrankWolfe using Test using Random -using SCIP +# using SCIP using LinearAlgebra using Distributions import MathOptInterface @@ -33,16 +33,27 @@ n = 10 @testset "Interface - 2-norm over hypercube -- α = $alpha" for alpha in (0.0, 0.05) diff_point = 0.5 * ones(n) + Random.rand(n) * alpha * 1 / n - 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()) - end - lmo = FrankWolfe.MathOptLMO(o) + + # SCIP variant of the LMO + # 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()) + # end + # lmo = FrankWolfe.MathOptLMO(o) + + int_vars = collect(1:n) + + lbs = zeros(n) + ubs = ones(n) + + sblmo = Boscia.CubeSimpleBLMO(lbs, ubs, int_vars) + # wrap the sblmo into a bound manager + lmo = Boscia.ManagedBoundedLMO(sblmo, lbs[int_vars], ubs[int_vars], n, int_vars) function f(x) return 0.5 * sum((x .- diff_point) .^ 2)