Skip to content

Commit b28143b

Browse files
authored
Fix non_constant_coefficients for AlgebraElement (#130)
* Fix non_constant_coefficients for AlgebraElement * Fix format
1 parent 475e2a1 commit b28143b

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/constraint.jl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,13 @@ function non_constant(a::AbstractVector{T}) where {T}
194194
# also take care of `collect`ing into a `Vector`
195195
return convert(Vector{non_constant_type(T)}, a)
196196
end
197-
non_constant_coefficients(p) = non_constant(MP.coefficients(p))
197+
function non_constant_coefficients(p::MP.AbstractPolynomialLike)
198+
return non_constant(MP.coefficients(p))
199+
end
200+
function non_constant_coefficients(p::SA.AlgebraElement)
201+
MA.operate!(SA.canonical, SA.coeffs(p))
202+
return non_constant(values(SA.coeffs(p)))
203+
end
198204

199205
## ZeroPoly
200206
function JuMP.build_constraint(
@@ -205,7 +211,7 @@ function JuMP.build_constraint(
205211
kws...,
206212
)
207213
coefs = non_constant_coefficients(p)
208-
monos = MP.monomials(p)
214+
basis = MB.explicit_basis(p)
209215
if domain isa SS.BasicSemialgebraicSet
210216
# p(x) = 0 for all x in a basic semialgebraic set. We replace it by
211217
# p(x) ≤ 0 and p(x) ≥ 0 for all x in the basic semialgebraic set.
@@ -222,7 +228,6 @@ function JuMP.build_constraint(
222228
)
223229
return Constraint(error_fn, p, s, all_kws)
224230
else
225-
basis = MB.SubBasis{MB.Monomial}(monos)
226231
set = JuMP.moi_set(s, basis; domain = domain, kws...)
227232
constraint = JuMP.VectorConstraint(coefs, set, PolynomialShape(basis))
228233
return bridgeable(

test/constraint.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,15 @@ function test_ZeroPolynomialSet(var)
270270
[],
271271
[],
272272
)
273+
_test_constraint(
274+
m,
275+
@constraint(m, MB.algebra_element(p - q) in PolyJuMP.ZeroPoly()),
276+
S,
277+
jump_set,
278+
p - q,
279+
[],
280+
[],
281+
)
273282
_test_constraint(m, @constraint(m, x == y), S, jump_set, x - y, [], [])
274283
_test_constraint(
275284
m,

0 commit comments

Comments
 (0)