Skip to content

Commit

Permalink
updated examples to use cubesimpleblmo
Browse files Browse the repository at this point in the history
  • Loading branch information
pokutta committed Nov 6, 2023
1 parent 92825dc commit ee5cc6c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 30 deletions.
18 changes: 8 additions & 10 deletions examples/low_dim_in_high_dim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
17 changes: 8 additions & 9 deletions examples/nonlinear.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ using Dates
# using SCIP
# const MOI = MathOptInterface

include("cube_blmo.jl")

n = 40
seed = 10

Expand All @@ -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)
Expand Down
33 changes: 22 additions & 11 deletions examples/worst-case.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ using Boscia
using FrankWolfe
using Test
using Random
using SCIP
# using SCIP
using LinearAlgebra
using Distributions
import MathOptInterface
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ee5cc6c

Please sign in to comment.