-
Notifications
You must be signed in to change notification settings - Fork 7
Add depth first traverse #274
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
Open
WenjieXiao-2022
wants to merge
12
commits into
main
Choose a base branch
from
depth-first-traverse
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b149614
empty draft
matbesancon a612e36
add depth-first-traverse
WenjieXiao-2022 029b5e4
format
WenjieXiao-2022 d60367c
add traverse strategies tests
WenjieXiao-2022 fb5fb8b
Merge branch 'main' into depth-first-traverse
WenjieXiao-2022 6ef8a5f
update Project.toml
WenjieXiao-2022 ba5e6ca
update Project.toml
WenjieXiao-2022 514df1c
keep the same type for undefined Id
WenjieXiao-2022 d78de83
Remove print and verbose
WenjieXiao-2022 491d046
Update test/traverse_strategy_test.jl
matbesancon bedd07d
Merge branch 'main' into depth-first-traverse
WenjieXiao-2022 ba875be
minor fix
WenjieXiao-2022 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| using Boscia | ||
| using Bonobo | ||
| using FrankWolfe | ||
| using Test | ||
| using Random | ||
| using SCIP | ||
| using LinearAlgebra | ||
|
|
||
| import MathOptInterface | ||
| const MOI = MathOptInterface | ||
|
|
||
| println("\nTraverse Strategy Tests") | ||
WenjieXiao-2022 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| verbose = true | ||
WenjieXiao-2022 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| function build_examples(o, n, seed) | ||
| Random.seed!(seed) | ||
| A = let | ||
| A = randn(n, n) | ||
| A' * A | ||
| end | ||
|
|
||
| @assert isposdef(A) == true | ||
WenjieXiao-2022 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| y = Random.rand(Bool, n) * 0.6 .+ 0.3 | ||
|
|
||
| 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.ZeroOne()) | ||
| MOI.add_constraint(o, xi, MOI.GreaterThan(0.0)) | ||
| MOI.add_constraint(o, xi, MOI.LessThan(1.0)) | ||
| end | ||
| lmo = Boscia.MathOptBLMO(o) | ||
|
|
||
| function f(x) | ||
| d = x - y | ||
| return dot(d, A, d) | ||
| end | ||
|
|
||
| function grad!(storage, x) | ||
| # storage = Ax | ||
| mul!(storage, A, x) | ||
| # storage = 2Ax - 2Ay | ||
| return mul!(storage, A, y, -2, 2) | ||
| end | ||
| return f, grad!, lmo | ||
| end | ||
|
|
||
|
|
||
| @testset "DepthFirstSearch Traverse Strategy" begin | ||
| dimension = 20 | ||
| seed = 1 | ||
| o = SCIP.Optimizer() | ||
| f, grad!, lmo = build_examples(o, dimension, seed) | ||
| time_limit = 60 | ||
|
|
||
| settings = Boscia.create_default_settings() | ||
| settings.branch_and_bound[:verbose] = verbose | ||
| settings.branch_and_bound[:time_limit] = time_limit | ||
| x_mi, _, result_mi = Boscia.solve(f, grad!, lmo, settings=settings) | ||
|
|
||
| @testset "DepthFirstSearch favoring right" begin | ||
| o = SCIP.Optimizer() | ||
| f, grad!, lmo = build_examples(o, dimension, seed) | ||
|
|
||
| settings = Boscia.create_default_settings() | ||
| settings.branch_and_bound[:verbose] = verbose | ||
matbesancon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| settings.branch_and_bound[:time_limit] = time_limit | ||
| settings.branch_and_bound[:traverse_strategy] = Boscia.DepthFirstSearch(true) | ||
| x, _, result = Boscia.solve(f, grad!, lmo, settings=settings) | ||
|
|
||
| @test isapprox(f(x_mi), f(x), atol=1e-6, rtol=1e-3) | ||
| @test isapprox(f(x), f(result[:raw_solution]), atol=1e-6, rtol=1e-3) | ||
| end | ||
|
|
||
| @testset "DepthFirstSearch favoring left" begin | ||
| o = SCIP.Optimizer() | ||
| f, grad!, lmo = build_examples(o, dimension, seed) | ||
|
|
||
| settings = Boscia.create_default_settings() | ||
| settings.branch_and_bound[:verbose] = verbose | ||
| settings.branch_and_bound[:time_limit] = time_limit | ||
| settings.branch_and_bound[:traverse_strategy] = Boscia.DepthFirstSearch(false) | ||
| x, _, result = Boscia.solve(f, grad!, lmo, settings=settings) | ||
|
|
||
| @test isapprox(f(x_mi), f(x), atol=1e-6, rtol=1e-3) | ||
| @test isapprox(f(x), f(result[:raw_solution]), atol=1e-6, rtol=1e-3) | ||
| end | ||
| end | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.