Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MathOptInterface says that Interval and GreaterThan constraints aren't supported by CDDLib #75

Closed
nsajko opened this issue Apr 13, 2022 · 4 comments

Comments

@nsajko
Copy link

nsajko commented Apr 13, 2022

import MathOptInterface, CDDLib
const MOI = MathOptInterface

function powers(degree::Int, x::F) where {F <: Real}
        local ret = F[1 for _ in 0:degree]
        for i in 1:degree
                ret[i + 1] = x * ret[i]
        end
        ret
end

sets(pts::Vector{Tuple{F, F}}) where {F <: Real} =
        map(p -> MOI.GreaterThan(p[2]), pts)

saf(cs::Vector{F}, vars::T) where {F <: Real, T <: Any} =
        MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.(cs, vars), zero(F))

safs(degree::Int, pts::Vector{Tuple{F, F}}, vars::T) where {F <: Real, T <: Any} =
        map(p -> saf(powers(degree, p[1]), vars), pts)

constrain(lp::Opt, degree::Int, pts::Vector{Tuple{F, F}}) where
  {Opt <: MOI.AbstractOptimizer, F <: Real} =
        MOI.add_constraints(lp,
                            safs(degree, pts, MOI.add_variables(lp, degree + 1)),
                            sets(pts))

constrain(::Type{F}) where {F <: Real} =
        constrain(CDDLib.Optimizer{F}(), 5, Tuple{F, F}[(0, 1//2), (1, 7//3)])

With this example code constrain(Float64) and constrain(Rational{BigInt}) both lead to MOI errors about the model not supporting the constraint:

MathOptInterface.UnsupportedConstraint{MathOptInterface.ScalarAffineFunction{Float64}, MathOptInterface.GreaterThan{Float64}}: `MathOptInterface.ScalarAffineFunction{Float64}`-in-`MathOptInterface.GreaterThan{Float64}` constraint is not supported by the model.

Using Interval instead of GreaterThan results in a similar error, but LessThan seems to work. Not sure whether this is intended behavior.

@blegat
Copy link
Member

blegat commented Apr 13, 2022

The only supported constraints are EqualTo and LessThan. See
https://github.com/JuliaPolyhedra/Polyhedra.jl/blob/728c80a64ffc2ecadc58138ac0415dbac1df5a6c/src/opt.jl#L84-L88
This is intended behavior as the CDD library only supports these two.
Replace CDDLib.Optimizer{F}() by MOI.instantiate(CDDLib.Optimizer{F}, with_bridge_type=F)
See https://jump.dev/MathOptInterface.jl/stable/reference/models/#MathOptInterface.instantiate

@odow
Copy link
Contributor

odow commented Feb 21, 2024

This can be closed

@odow
Copy link
Contributor

odow commented Feb 22, 2024

Closing as won't fix.

@odow odow closed this as completed Feb 22, 2024
@blegat
Copy link
Member

blegat commented Feb 22, 2024

To complement my above comment, you should add a bridge layer when calling MOI.instantiate and then it will be supported by bridging

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants