Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build my own global constraint with the CP-SAT solver of OR-tools?

I am a PhD candidate in data mininig, and I have to create a global constraint with OR-Tools for a data mining purpose.

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

like image 203
djawed bkh Avatar asked Dec 01 '25 11:12

djawed bkh


1 Answers

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

like image 65
Laurent Perron Avatar answered Dec 03 '25 04:12

Laurent Perron



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!