Constraint programming support
This issue is to track support for a limited subset of constraint programming in MOI. At present, we don't envisage MOI having the same scope as MiniZinc, but we want users to be able to write down common constraint programs and solve them using a specialized constraint programming solver, or a MIP solver via bridges.
Background
- https://github.com/jump-dev/JuMP.jl/issues/2227
- https://github.com/JuliaConstraints/ConstraintProgrammingExtensions.jl
MathOptInterface
Add new sets to MOI. Definitions taken from: https://www.minizinc.org/doc-2.5.5/en/lib-globals.html
- [x]
all_different: #1825
- [x]
nvalue#1826
- [x]
among#1827
- [x]
at_least#1828
- [x]
count_gt#1829
- [x]
bin_packinghttps://github.com/jump-dev/MathOptInterface.jl/pull/1837
- [x]
pathhttps://github.com/jump-dev/MathOptInterface.jl/pull/1837
- [x]
cumulativehttps://github.com/jump-dev/MathOptInterface.jl/pull/1837
- [x]
tablehttps://github.com/jump-dev/MathOptInterface.jl/pull/1837
- [x]
circuithttps://github.com/jump-dev/MathOptInterface.jl/pull/1837
MOI.Bridges
- Add bridges from new sets to MILP reformulations as appropriate
- [x] AllDifferent https://github.com/jump-dev/MathOptInterface.jl/pull/1923
- [x] BinPacking #1925
- [x] Circuit #1929
- [x] CountAtLeast #1920
- [x] CountBelongs #1919
- [x] CountDistinct https://github.com/jump-dev/MathOptInterface.jl/pull/1901
- [x] CountGreaterThan #1927
- [x]
CumulativeAgreed with Bill to not include - [x]
PathAgreed with Bill to not include - [x] Table
MOI.FileFormats
- [x]
Add FlatZinc writer. Initial work here: https://github.com/JuliaConstraints/ConstraintProgrammingExtensions.jl/tree/master/src/FlatZinc - [x] Add MiniZinc writer https://github.com/jump-dev/MiniZinc.jl
- [x] Add new sets to MathOptFormat #1954
MOI.Test
- [x] Add new tests for constraint solvers
Solvers
Update solvers to new sets in MOI
- [x] https://github.com/JuliaConstraints/Chuffed.jl
- [x] https://github.com/JuliaConstraints/CPLEXCP.jl Replaced by the MiniZinc interface: https://github.com/jump-dev/MiniZinc.jl
I've opened PRs to add the first 5 sets, since they are the simplest. There's still some bike shedding to be done. For the next step, I'll add the FlatZinc file format to get things in place. One we have that, we can start some end-to-end tests with a CP solver, and that should flush out any issues before we work on the other 5 sets.
I've been taking a look at FlatZinc support. it's actually slightly more complicated than it looks, because its effectively MOI without bridges, and each solver supports a different set of constraints. What would be easier to target is MiniZinc, and then have MiniZinc compile down to FlatZinc when passed a particular solver. For example, Chuffed_jll contains a directory of re-definitions, which are equivalent to our bridges.
First step is to get libminizinc building: https://github.com/JuliaPackaging/Yggdrasil/pull/4861
I now have https://github.com/jump-dev/MiniZinc.jl.
This writes the JuMP model into a flattened form of MiniZinc, and we then call out to different solvers. The benefit of this is that it automatically supports all of the solvers that MiniZinc supports, so it works for Chuffed and Gurobi, for example.
I have it working locally, but MiniZinc_jll is segfaulting: https://github.com/JuliaPackaging/Yggdrasil/pull/4866
Bill says
i assume that MOI++ including constraints you're working on will support reified constraints so that in principle we might support something like alldiff(x1,x3,x5) or alldiff(x2,x4,x6) which translates to: alldif_reif(x1,x3,x5,b1) and alldiff_reif(x2,x4,x6,b2) and (b1 or b2)
we don't necessarily need models for all reified constraints now and those could be filled in over time.
We could probably add Reified{S} similar to how we have indicator constraints.
Initial support for the sets has been merged, and MiniZinc.jl is being registered: https://github.com/JuliaRegistries/General/pull/62010
MILP bridges are largely done. I haven't done Path and Cumulative because they're quite complicated, but Cbc, HiGHS, and Gurobi are all passing tests with the new constraint programming sets!
Once #1931 is merged, I'll prep for v1.6.0, and then write a blog post showing off the new goods.
I've started looking into reified constraints: https://github.com/jump-dev/MiniZinc.jl/pull/13
Blog post is: https://jump.dev/announcements/2022/07/12/constraint-programming/
This issue is pretty close to completion. One blocker is deciding whether to add the Reified set. I've added Reified to MiniZinc.jl, but adding to MOI would add a lot more sets, and the reified to MILP bridges are much more complicated.