Skip to content

Commit

Permalink
Update test_algorithm.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Aug 14, 2024
1 parent d2d9d1b commit ee8673f
Showing 1 changed file with 35 additions and 44 deletions.
79 changes: 35 additions & 44 deletions test/test_algorithm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1051,75 +1051,66 @@ 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,
"nlp_solver" => IPOPT,
"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,
"nlp_solver" => IPOPT,
"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,
"nlp_solver" => IPOPT,
"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

0 comments on commit ee8673f

Please sign in to comment.