2

I am a phd candidate in data mininig, and i have to create a global constraint with ORtools for a data mining purpose.

The problem is that there is a lack of documentation about creating your own global constraint with CP-Sat in the internet, and i don't know how to start.

djawed bkh
  • 21
  • 5
  • AFAIK it's not possible to create your own new custom constraints with OR-Tools SAT Solver. You can do it with the old Google.OrTools.ConstraintSolver, there is an answer under this question: https://stackoverflow.com/questions/48146639/custom-constraint-or-tools-constraint-programming (which is basically a duplicate of yours...) – Christopher Hamkins Nov 23 '22 at 11:50

1 Answers1

5

It is obviously possible, but very tedious, and very complex.

Writing a new constraint implies:

  • extending the proto to support the constraint
  • writing the input validation
  • writing the solution checker
  • writing the loading (into CP-SAT engine) code
  • writing the presolve rules
  • writing the propagation code. Which is complex as every deduction needs to be fully explained.
  • writing the linearization/cut generation code

The last 3 items are extremely error prone, and very hard to debug, as the effect of cuts and explanations are delayed, and sometimes never used.

For these reason, I recommend expanding the constraint into smaller ones. In fact, most of the CP constraints are expanded (alldiff, element, table, reservoir, inverse, automaton, some products, some modulos).

You can also submit a feature request for a new constraint. It can happen if it is useful/general enough.

Thanks

Laurent Perron
  • 8,594
  • 1
  • 8
  • 22