From ee6ddb55c4773c16b255d7daffac4d61f0020b28 Mon Sep 17 00:00:00 2001 From: odow Date: Mon, 29 Jan 2024 13:50:54 +1300 Subject: [PATCH] Fix feasibility pump with ScalarNonlinearFunction constraints --- src/filter.jl | 11 ++++++----- test/fpump.jl | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/filter.jl b/src/filter.jl index 6beb507..ad51ed1 100644 --- a/src/filter.jl +++ b/src/filter.jl @@ -42,11 +42,12 @@ function MOI.get(f::LinearFilter, attr::MOI.ListOfModelAttributesSet) end end function MOI.get(f::LinearFilter, attr::MOI.ListOfConstraintTypesPresent) - return filter(MOI.get(f.inner, attr)) do FS - F = FS[1] - return !( - F <: MOI.ScalarQuadraticFunction || - F <: MOI.VectorQuadraticFunction + return filter(MOI.get(f.inner, attr)) do (F, _) + return ( + F <: MOI.VariableIndex || + F <: MOI.ScalarAffineFunction || + F <: MOI.VectorOfVariables || + F <: MOI.VectorAffineFunction ) end end diff --git a/test/fpump.jl b/test/fpump.jl index 3451507..439a3fc 100644 --- a/test/fpump.jl +++ b/test/fpump.jl @@ -292,4 +292,36 @@ include("basic/gamsworld.jl") end @test JuMP.objective_value(m) ≈ 0.0 end + + @testset "FP: Issue 263: FPump with ScalarNonlinearFunction" begin + println("==================================") + println("FP: Issue 263: FPump with ScalarNonlinearFunction") + println("==================================") + ipopt_solver = JuMP.optimizer_with_attributes( + Ipopt.Optimizer, + "print_level" => 0, + "sb" => "yes", + "max_iter" => 50000, + ) + highs_solver = JuMP.optimizer_with_attributes( + HiGHS.Optimizer, + "output_flag" => false, + ) + juniper_solver = JuMP.optimizer_with_attributes( + Juniper.Optimizer, + "nl_solver" => ipopt_solver, + "mip_solver" => highs_solver, + "log_levels" => [], + ) + m = Model(juniper_solver) + @variable(m, x[1:3], Int) + @variable(m, y) + @constraint(m, x[1] * x[2] * x[3] * y >= 5) + optimize!(m) + for i in 1:3 + xval = JuMP.value(x[i]) + @test isapprox(round(xval) - xval, 0; atol = sol_atol) + end + @test JuMP.objective_value(m) ≈ 0.0 + end end