MathOptInterface.jl icon indicating copy to clipboard operation
MathOptInterface.jl copied to clipboard

Constraint programming support

Open odow opened this issue 3 years ago • 9 comments

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 image
  • [x] nvalue #1826 image
  • [x] among #1827 image
  • [x] at_least #1828 image
  • [x] count_gt #1829 image
  • [x] bin_packing https://github.com/jump-dev/MathOptInterface.jl/pull/1837 image
  • [x] path https://github.com/jump-dev/MathOptInterface.jl/pull/1837 image
  • [x] cumulative https://github.com/jump-dev/MathOptInterface.jl/pull/1837 image
  • [x] table https://github.com/jump-dev/MathOptInterface.jl/pull/1837 image
  • [x] circuit https://github.com/jump-dev/MathOptInterface.jl/pull/1837 image

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] Cumulative Agreed with Bill to not include
    • [x] Path Agreed 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

odow avatar Apr 20 '22 02:04 odow

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.

odow avatar May 01 '22 22:05 odow

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

odow avatar May 03 '22 01:05 odow

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

odow avatar May 04 '22 03:05 odow

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.

odow avatar May 19 '22 22:05 odow

Initial support for the sets has been merged, and MiniZinc.jl is being registered: https://github.com/JuliaRegistries/General/pull/62010

odow avatar Jun 09 '22 03:06 odow

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.

odow avatar Jun 30 '22 00:06 odow

I've started looking into reified constraints: https://github.com/jump-dev/MiniZinc.jl/pull/13

odow avatar Jul 18 '22 23:07 odow

Blog post is: https://jump.dev/announcements/2022/07/12/constraint-programming/

odow avatar Jul 18 '22 23:07 odow

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.

odow avatar Jul 20 '22 00:07 odow