Simple constraint programming solver

Roman picture Roman · Jun 26, 2013 · Viewed 7.5k times · Source

I'm trying to get familiar with constraint programming.

All documentation/videos I've seen so far just contain description of top-level concepts and code examples based on CP-libraries utilization (like Choko, Gecode, JaCoP etc).

I'd like to implement at least something simple in Java without any libraries.

Are there any resources where I can find working code in Java/C#/C++/Python which implements main CP ideas? (at least "send more money" problem solution).

(or, maybe, if somebody can explain it here, it would be great).

Answer

Med picture Med · Jun 26, 2013

It depends on what are you trying to do.

1- If you want to get started with Constraint Programming (CP) tools, you need first to understand modelling in this approach. For that, you have be able to define a given problem as a set of constraints then you post your model to a solver (that already knows how to deal with these constraints).

I personally find the G12_MiniZinc_Distribution (available via http://www.minizinc.org/) and its latest tutorial a very good way to start (the latest distribution cames with a lot of models). There is also online models if you want to see how a CP model looks like (w.r.t minizinc syntax) : http://www.hakank.org/minizinc.

2- If you have an advanced theoretical understanding of CP, you may directly see the implementation of some techniques (e.g. propagators) from available libraries since developing a CP Solver from scratch is (IMO) a foolish idea. These are some open-source solvers/libraries : G12, Choco, Mistral, Or-Tools.