Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/constraint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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.
Expand All @@ -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(
Expand Down
9 changes: 9 additions & 0 deletions test/constraint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down