-
-
Notifications
You must be signed in to change notification settings - Fork 398
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
Feature Request: Reified constraint #2215
Comments
The difference is that indicator constraints are natively supported by quite a few mathematical-optimisation solvers. This kind of things is more common in constraint-programming solvers (and yes, I'm thinking of including this kind of things, but it's not yet ready for prime-time :)!). As I understand it, the goal of the base JuMP right now is more to provide access to existing solver features, not really to provide many things on top of that. |
Oh found that you mentioned it in #2014 |
Hope that JuMP is still the way to go for my ConstraintSolver 😄
which I'm not sure how to work around in JuMP atm. |
It's one of the constraints I'm working on, and indeed it's not that simple to implement… |
New constraints like this are just a matter of defining a set with a formal spec. For example: """
IndexedSet{T}
Defines the set `IndexedSet(data) = {(x, y) | x == data[y]}`.
"""
struct IndexedSet{T} <: MOI.AbstractVectorSet
data::Vector{T}
end
a = [2,3,3,1,4]
@variable(m, 1 <= x <= 5, Int)
@variable(m, 1 <= y <= 5, Int)
@constraint(m, [x, y] in IndexedSet(a)) |
The question for this is more how to make a user friendly version of the underlying |
Depending on how exactly you want the constraint to parse, you may do like https://github.com/dourouc05/JuCP.jl/blob/master/src/sets.jl#L254 or need #2051. |
I'm still not getting how
and:
and it prints:
Where is the |
|
Ah okay thanks for the first part. The:
doesn't get called for me I get a:
Edit: With JuMP v0.21.1. Do I need to change more to use your syntax? |
I need the
Which might be the case because |
The difference is julia> dump(:(a => {y <= 2}))
Expr
head: Symbol call
args: Array{Any}((3,))
1: Symbol =>
2: Symbol a
3: Expr
head: Symbol braces
args: Array{Any}((1,))
1: Expr
head: Symbol call
args: Array{Any}((3,))
1: Symbol <=
2: Symbol y
3: Int64 2
julia> dump(:(a := {y <= 2}))
Expr
head: Symbol :=
args: Array{Any}((2,))
1: Symbol a
2: Expr
head: Symbol braces
args: Array{Any}((1,))
1: Expr
head: Symbol call
args: Array{Any}((3,))
1: Symbol <=
2: Symbol y
3: Int64 2 I'm slightly averse to adding support for constraints that are not part of MOI yet. Would there be any objection to closing this in favor of #2227 so we just have one "Support constraint programming" issue? |
I'm in favour of closing this for #2227. |
I'm happy close this. I have it implemented in my solver now and extending it was relatively straightforward. |
As indicator constraints of the form:
@constraint(m, x => {y == 1})
are allowed it would be valuable to have it in the opposite direction:@constraint(m, {y == 1} => x)
and@constraint(m, x <=> {y == 1})
.A solution can be similar to:
https://github.com/JuliaOpt/JuMP.jl/blob/1119b736b00f84ce210fee7ae9232378fb8d6753/src/indicator.jl
Maybe @dourouc05 has thought about something like this as I found:
https://github.com/dourouc05/ConstraintProgrammingExtensions.jl/blob/master/src/ConstraintProgrammingExtensions.jl#L275-L277
The text was updated successfully, but these errors were encountered: