Monday, July 27, 2009

Precedence Constraint Posting (PCP) search strategy in Choco solvera

Using a PCP strategy in Choco constraint solver is rather problematic. The solver natively supports search strategies based on assigning a value to a variable. On the other hand PCP strategies are based on posting constraints. This is not natively supported. There are basically two way how to gain this functionality in Choco solver.

The first way is to extend the model with some extra constraints that can be bound to a variable, then AssignVar strategy with a specified variable and value selection can be used. To solve a scheduling problem a preceding constraint is suitable. The constraint has an extra boolean variable that specifies the precedence of given tasks. The search strategy then decides about these boolean variables first. Unfortunately, only several constraints has a variable that can be effectively used to create a PCP strategy.

Another way to use PCP strategy in Choco is much more complicated, the point is to implement an extension of abstract class AbstractLargeIntBranching that does what is required. Likewise, some useful selectors can be defined. The advantage of this approach is the generality, you can implement whichever strategy you like. I implemented some PCP strategies this way. A good pattern for this is CstrBranching class. It is a PCP implementation that can be found in svn sources in version 2.0.0 of the solver. The svn address is https://choco.svn.sourceforge.net/svnroot/choco.