diff --git a/test/algorithms/Chalmet.jl b/test/algorithms/Chalmet.jl index 16e85a8..5221b24 100644 --- a/test/algorithms/Chalmet.jl +++ b/test/algorithms/Chalmet.jl @@ -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() diff --git a/test/algorithms/EpsilonConstraint.jl b/test/algorithms/EpsilonConstraint.jl index 1607760..e24aa58 100644 --- a/test/algorithms/EpsilonConstraint.jl +++ b/test/algorithms/EpsilonConstraint.jl @@ -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() diff --git a/test/algorithms/Hierarchical.jl b/test/algorithms/Hierarchical.jl index 0f10785..c6d1279 100644 --- a/test/algorithms/Hierarchical.jl +++ b/test/algorithms/Hierarchical.jl @@ -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) diff --git a/test/algorithms/Lexicographic.jl b/test/algorithms/Lexicographic.jl index a255b85..a9f8ed3 100644 --- a/test/algorithms/Lexicographic.jl +++ b/test/algorithms/Lexicographic.jl @@ -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) @@ -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()