Constraint Programming (2020)
mareknarozniak.com
mareknarozniak.com
For those not familiar with it yet, this is what's used under the hood by things like systemd: you give a bunch of constraints (ex: service A before service B, service B before service D but after service C, etc) and you get a solution (or none, but that's another story: when there are no solution, you can try to relax some constraints)
If you want to learn more, I suggest playing with Z3 from Microsoft Research: a nice tutorial is https://ericpony.github.io/z3py-tutorial/guide-examples.htm
For a free one, SWIProlog has a very usable and fairly performant constraint library too (CLPFD and CLPQ). It also has the more general "constraint handling rules" (CHR) as an embedded language. If you need to develop your own constraint search strategies, Mozart/Oz 's "space" concept is elegant.
Here's the puzzle page: https://gcanyon.wordpress.com/2009/10/28/a-programming-puzzl...
And the solution in Minizinc: http://www.hakank.org/minizinc/einav_puzzle.mzn
And my solution in J: https://gcanyon.wordpress.com/2009/10/30/a-solution-to-einav...
Like others have already suggested, look into google’s ORtools library
def __mul__(self, other):
return Multiplication(self, other)-
I think constraint programming may get more popular because of LLMs. One of the big issues with them is translating your problem into constraints. It’s tough for people to do that. But an LLM can do that well, even just to make sure its own solution is logical.
A good example is the famous “ All different” constraint. In MIP you would implement that as a fancy summ, in CP one can use a corollary from Berge’s lemma to get a specialised constraint to just enforce that.
Rule of Thump is that CP excels when the problem is thigh lay constraint and one has many global constraints ( those that apply to all variables).
Another point is that contrary to MIP programs that often are modelled directly using sums and inequalities, CP Programms usually are written in a declarative language such as ZINC, which in my opinion makes it easier to get into the subject.
If you are interested: This series of blog posts builds a CP solver in Julia
https://opensourc.es/blog/constraint-solver-1/
ortoools by Google also contains a CP solver and the doc is quite interesting
https://developers.google.com/optimization/cp
Finally there is the dissertation of Guido Tack, who developed a oss Cp solver as his PhD project ( I think that is the internal solver used by SAP software now)