Skip to content

Improve test coverage #91

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

Merged
merged 2 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 17 additions & 0 deletions test/algorithms/Chalmet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,23 @@ function test_vector_of_variables_objective()
return
end

function test_too_many_objectives()
P = Float64[1 0 0 0; 0 1 0 0; 0 0 0 1; 0 0 1 0]
model = MOA.Optimizer(HiGHS.Optimizer)
MOI.set(model, MOA.Algorithm(), MOA.Chalmet())
x = MOI.add_variables(model, 4)
MOI.add_constraint.(model, x, MOI.GreaterThan(0.0))
MOI.add_constraint.(model, x, MOI.LessThan(1.0))
MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE)
f = MOI.Utilities.operate(vcat, Float64, P * x...)
MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f)
@test_throws(
ErrorException("Chalmet requires exactly two objectives"),
MOI.optimize!(model),
)
return
end

end

TestChalmet.run_tests()
17 changes: 17 additions & 0 deletions test/algorithms/EpsilonConstraint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,23 @@ function test_vector_of_variables_objective()
return
end

function test_too_many_objectives()
P = Float64[1 0 0 0; 0 1 0 0; 0 0 0 1; 0 0 1 0]
model = MOA.Optimizer(HiGHS.Optimizer)
MOI.set(model, MOA.Algorithm(), MOA.EpsilonConstraint())
x = MOI.add_variables(model, 4)
MOI.add_constraint.(model, x, MOI.GreaterThan(0.0))
MOI.add_constraint.(model, x, MOI.LessThan(1.0))
MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE)
f = MOI.Utilities.operate(vcat, Float64, P * x...)
MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f)
@test_throws(
ErrorException("EpsilonConstraint requires exactly two objectives"),
MOI.optimize!(model),
)
return
end

end

TestEpsilonConstraint.run_tests()
3 changes: 3 additions & 0 deletions test/algorithms/Hierarchical.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ function test_knapsack()
P = Float64[1 0 0 0; 0 1 1 0; 0 0 1 1; 0 1 0 0]
model = MOA.Optimizer(HiGHS.Optimizer)
MOI.set(model, MOA.Algorithm(), MOA.Hierarchical())
@test MOI.supports(model, MOA.ObjectivePriority(1))
MOI.set.(model, MOA.ObjectivePriority.(1:4), [2, 1, 1, 0])
@test MOI.supports(model, MOA.ObjectiveWeight(1))
MOI.set.(model, MOA.ObjectiveWeight.(1:4), [1, 0.5, 0.5, 1])
@test MOI.supports(model, MOA.ObjectiveRelativeTolerance(1))
MOI.set(model, MOA.ObjectiveRelativeTolerance(1), 0.1)
MOI.set(model, MOI.Silent(), true)
x = MOI.add_variables(model, 4)
Expand Down
22 changes: 22 additions & 0 deletions test/algorithms/Lexicographic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function test_knapsack()
model = MOA.Optimizer(HiGHS.Optimizer)
MOI.set(model, MOA.Algorithm(), MOA.Lexicographic())
@test MOI.supports(model, MOA.LexicographicAllPermutations())
@test MOI.supports(model, MOA.ObjectiveRelativeTolerance(1))
MOI.set(model, MOA.LexicographicAllPermutations(), false)
MOI.set(model, MOA.ObjectiveRelativeTolerance(1), 0.1)
MOI.set(model, MOI.Silent(), true)
Expand Down Expand Up @@ -175,6 +176,27 @@ function test_warn_all_permutations()
return
end

function test_knapsack_time_limit()
P = Float64[1 0 0 0; 0 1 0 0; 0 0 0 1; 0 0 1 0]
model = MOA.Optimizer(HiGHS.Optimizer)
MOI.set(model, MOA.Algorithm(), MOA.Lexicographic())
MOI.set(model, MOA.LexicographicAllPermutations(), false)
MOI.set(model, MOA.ObjectiveRelativeTolerance(1), 0.1)
MOI.set(model, MOI.Silent(), true)
x = MOI.add_variables(model, 4)
MOI.add_constraint.(model, x, MOI.GreaterThan(0.0))
MOI.add_constraint.(model, x, MOI.LessThan(1.0))
MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE)
f = MOI.Utilities.operate(vcat, Float64, P * x...)
f.constants[4] = 1_000.0
MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f)
MOI.add_constraint(model, sum(1.0 * x[i] for i in 1:4), MOI.LessThan(2.0))
MOI.set(model, MOI.TimeLimitSec(), 0.0)
MOI.optimize!(model)
@test MOI.get(model, MOI.TerminationStatus()) == MOI.TIME_LIMIT
return
end

end

TestLexicographic.run_tests()
Loading