From ee8673f20700f0619e611a6633079a32e837ac63 Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Wed, 14 Aug 2024 16:27:19 +1200 Subject: [PATCH] Update test_algorithm.jl --- test/test_algorithm.jl | 79 +++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 44 deletions(-) diff --git a/test/test_algorithm.jl b/test/test_algorithm.jl index 6400438e..c53fbe09 100644 --- a/test/test_algorithm.jl +++ b/test/test_algorithm.jl @@ -1051,20 +1051,16 @@ end "mip_solver" => HIGHS, "minlp_solver" => JUNIPER, ) - - m = JuMP.Model(test_solver) - - @variable(m, -10 <= objvar <= 20, Int) - - @objective(m, Min, objvar) - - JuMP.optimize!(m) - - @test termination_status(m) == MOI.OPTIMAL - @test isapprox(objective_value(m), -10; atol = 1e-4) - @test isapprox(value(objvar), -10, atol = 1E-6) - @test MOI.get(m, Alpine.NumberOfIterations()) == 0 + model = JuMP.Model(test_solver) + @variable(model, -10 <= x <= 20, Int) + @objective(model, Min, x) + JuMP.optimize!(model) + @test termination_status(model) == MOI.OPTIMAL + @test isapprox(objective_value(model), -10; atol = 1e-4) + @test isapprox(value(x), -10, atol = 1e-6) + @test MOI.get(model, Alpine.NumberOfIterations()) == 0 end + @testset "Test integer variable support 0" begin test_solver = optimizer_with_attributes( Alpine.Optimizer, @@ -1072,19 +1068,17 @@ end "mip_solver" => HIGHS, "minlp_solver" => JUNIPER, ) - - m = JuMP.Model(test_solver) - - @variable(m, objvar, Int) - @constraint(m, -10 <= objvar) - @constraint(m, objvar <= 20) - - @objective(m, Min, objvar) - - @test_throws "Unable to use IntegerToZeroOneBridge because the variable MOI.VariableIndex(1) has a non-finite domain" JuMP.optimize!( - m, + model = JuMP.Model(test_solver) + @variable(model, x, Int) + @objective(model, Min, x) + @test_throws( + ErrorException( + "Unable to use IntegerToZeroOneBridge because the variable MOI.VariableIndex(1) has a non-finite domain", + ), + JuMP.optimize!(model), ) end + @testset "Test integer variable support 1" begin test_solver = optimizer_with_attributes( Alpine.Optimizer, @@ -1092,18 +1086,17 @@ end "mip_solver" => HIGHS, "minlp_solver" => JUNIPER, ) - - m = JuMP.Model(test_solver) - - @variable(m, -10 <= objvar, Int) - @constraint(m, objvar <= 20) - - @objective(m, Min, objvar) - - @test_throws "Unable to use IntegerToZeroOneBridge because the variable MOI.VariableIndex(1) has a non-finite domain" JuMP.optimize!( - m, + model = JuMP.Model(test_solver) + @variable(model, -10 <= x, Int) + @objective(model, Min, x) + @test_throws( + ErrorException( + "Unable to use IntegerToZeroOneBridge because the variable MOI.VariableIndex(1) has a non-finite domain", + ), + JuMP.optimize!(model), ) end + @testset "Test integer variable support 2" begin test_solver = optimizer_with_attributes( Alpine.Optimizer, @@ -1111,15 +1104,13 @@ end "mip_solver" => HIGHS, "minlp_solver" => JUNIPER, ) - - m = JuMP.Model(test_solver) - - @variable(m, objvar <= 20, Int) - @constraint(m, -10 <= objvar) - - @objective(m, Min, objvar) - - @test_throws "Unable to use IntegerToZeroOneBridge because the variable MOI.VariableIndex(1) has a non-finite domain" JuMP.optimize!( - m, + model = JuMP.Model(test_solver) + @variable(model, x <= 20, Int) + @objective(model, Min, x) + @test_throws( + ErrorException( + "Unable to use IntegerToZeroOneBridge because the variable MOI.VariableIndex(1) has a non-finite domain", + ), + JuMP.optimize!(model), ) end