From b28143bb2f68ff31b3c34d129ff2f403eb1752b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Thu, 4 Jul 2024 10:56:50 +0200 Subject: [PATCH] Fix non_constant_coefficients for AlgebraElement (#130) * Fix non_constant_coefficients for AlgebraElement * Fix format --- src/constraint.jl | 11 ++++++++--- test/constraint.jl | 9 +++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/constraint.jl b/src/constraint.jl index 149a1e1..039e795 100644 --- a/src/constraint.jl +++ b/src/constraint.jl @@ -194,7 +194,13 @@ function non_constant(a::AbstractVector{T}) where {T} # also take care of `collect`ing into a `Vector` return convert(Vector{non_constant_type(T)}, a) end -non_constant_coefficients(p) = non_constant(MP.coefficients(p)) +function non_constant_coefficients(p::MP.AbstractPolynomialLike) + return non_constant(MP.coefficients(p)) +end +function non_constant_coefficients(p::SA.AlgebraElement) + MA.operate!(SA.canonical, SA.coeffs(p)) + return non_constant(values(SA.coeffs(p))) +end ## ZeroPoly function JuMP.build_constraint( @@ -205,7 +211,7 @@ function JuMP.build_constraint( kws..., ) coefs = non_constant_coefficients(p) - monos = MP.monomials(p) + basis = MB.explicit_basis(p) if domain isa SS.BasicSemialgebraicSet # p(x) = 0 for all x in a basic semialgebraic set. We replace it by # p(x) ≤ 0 and p(x) ≥ 0 for all x in the basic semialgebraic set. @@ -222,7 +228,6 @@ function JuMP.build_constraint( ) return Constraint(error_fn, p, s, all_kws) else - basis = MB.SubBasis{MB.Monomial}(monos) set = JuMP.moi_set(s, basis; domain = domain, kws...) constraint = JuMP.VectorConstraint(coefs, set, PolynomialShape(basis)) return bridgeable( diff --git a/test/constraint.jl b/test/constraint.jl index bdf80ee..1f91dd8 100644 --- a/test/constraint.jl +++ b/test/constraint.jl @@ -270,6 +270,15 @@ function test_ZeroPolynomialSet(var) [], [], ) + _test_constraint( + m, + @constraint(m, MB.algebra_element(p - q) in PolyJuMP.ZeroPoly()), + S, + jump_set, + p - q, + [], + [], + ) _test_constraint(m, @constraint(m, x == y), S, jump_set, x - y, [], []) _test_constraint( m,