-
-
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
[WIP] Handle !=
constraint via MOI.AllDifferent(2)
#3656
Conversation
4e0d00f
to
37539f3
Compare
parse_constraint_call()
: handle Val{:(!=)}
via MOI.AllDifferent(2)
!=
constraint via MOI.AllDifferent(2)
37539f3
to
bfb59af
Compare
Just add a fallback like function _build_inequality_constraint(error_fn::Function, ::Bool, lhs, rhs)
return error_fn(
"Unsupported form of inequality constraint. The left- and right-hand " *
"sides must both be decision variables.",
)
end Also, just to be explicitly clear before you sink lots of time into this: the wider group of JuMP developers need to have a think about whether we should add a features like |
bfb59af
to
b493e31
Compare
Now with tests. Any tips for docs? |
b493e31
to
8ee39c2
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #3656 +/- ##
=======================================
Coverage 98.28% 98.29%
=======================================
Files 43 44 +1
Lines 5652 5683 +31
=======================================
+ Hits 5555 5586 +31
Misses 97 97 ☔ View full report in Codecov by Sentry. |
``` (@v1.10) pkg> activate /repositories/JuMP.jl Activating project at `/repositories/JuMP.jl` julia> using JuMP Precompiling JuMP 1 dependency successfully precompiled in 10 seconds. 37 already precompiled. julia> model = Model(); julia> @variable(model, x[1:3]) 3-element Vector{VariableRef}: x[1] x[2] x[3] julia> @variable(model, y[1:3]) 3-element Vector{VariableRef}: y[1] y[2] y[3] julia> @constraint(model, x[1] != y[1]) x[1] != y[1] julia> @constraint(model, x .!= y) 3-element Vector{ConstraintRef{Model, MathOptInterface.ConstraintIndex{MathOptInterface.VectorOfVariables, MathOptInterface.AllDifferent}, VectorShape}}: x[1] != y[1] x[2] != y[2] x[3] != y[3] julia> @constraint(model, x != y) ERROR: At REPL[8]:1: `@constraint(model, x != y)`: Ineqality operator with vector operands must be explicitly vectorized, use `.!=` instead of `!=`. Stacktrace: [1] error(::String, ::String) @ Base ./error.jl:44 [2] (::JuMP.Containers.var"#error_fn#98"{String})(str::String) @ JuMP.Containers ~/.julia/compiled/v1.10/JuMP/DmXqY_F8XkK.so:-1 [3] macro expansion @ /repositories/JuMP.jl/src/macros/@constraint.jl:132 [inlined] [4] macro expansion @ /repositories/JuMP.jl/src/macros.jl:393 [inlined] [5] top-level scope @ REPL[8]:1 ``` I'm not yet sure how to support the not-explicitly vectorized case. We'd need to somehow deduce (in `parse_constraint_call()`) that our arguments are vectors, and extend `parse_constraint_call()` to return `vectorized` itself. I'm not convinced this is even possible. Otherwise, we get ``` julia> @constraint(model, x != y) vectorized = false ERROR: MethodError: no method matching _build_inequality_constraint(::Bool, ::JuMP.Containers.var"#error_fn#98"{String}, ::Vector{VariableRef}, ::Vector{VariableRef}) Closest candidates are: _build_inequality_constraint(::Function, ::Bool, ::Vector{VariableRef}, ::Vector{VariableRef}) @ JuMP /repositories/JuMP.jl/src/inequality.jl:14 Stacktrace: [1] macro expansion @ /repositories/JuMP.jl/src/macros/@constraint.jl:132 [inlined] [2] macro expansion @ /repositories/JuMP.jl/src/macros.jl:393 [inlined] [3] top-level scope @ REPL[8]:1 ``` (because we should have called `@constraint.jl:123`) Missing tests, docs. As discussed in jump-dev/MathOptInterface.jl#2405
8ee39c2
to
73f0c9c
Compare
I've added this to the agenda for the next monthly call (Feb 1). I think it needs a discussion. |
Note that i suppose that if there is no decision to support this fully including MOI bits, |
Yes, if we don't add You could still add this to |
Yup. |
@odow while there, could you comment briefly on the status of |
SCIP.jl is maintained by the folks at ZIB: https://github.com/scipopt/SCIP.jl. The core JuMP developers do not maintain it and do not have commit access. |
Hi @LebedevRI, thanks for working on this. We discussed this at length on the monthly developer call. Thoughts:
Conclusions:
I'll post in jump-dev/MathOptInterface.jl#2405 as well with similar/related conclusions. |
I'm not yet sure how to support the not-explicitly vectorized case. We'd need to somehow deduce (in
parse_constraint_call()
) that our arguments are vectors, and extendparse_constraint_call()
to returnvectorized
itself. I'm not convinced this is even possible.Otherwise, we get
(because we should have called
@constraint.jl:123
)Missing tests, docs.
As discussed in jump-dev/MathOptInterface.jl#2405