Skip to content

Commit

Permalink
Fix non_constant_coefficients for AlgebraElement (#130)
Browse files Browse the repository at this point in the history
* Fix non_constant_coefficients for AlgebraElement

* Fix format
  • Loading branch information
blegat authored Jul 4, 2024
1 parent 475e2a1 commit b28143b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
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

0 comments on commit b28143b

Please sign in to comment.