Constraint Satisfaction Problems
Constraints are best used with multi-valued variables, i.e. variables with domains bigger than 2. First you define which variables exist and which are their domains, and then you add constraints that forbid some combinations of values to occur simultaneously.
A trivial example? Suppose you have two series A and B of "nucleotide" variables: A1 A2 A3 A4 ... and B1 B2 B3 B4 ... Each of this Ai and Bi variables have the same domain = {adenine, thymine, guanine, cytosine}.
Then you want to match the two series and add a "base pair" constraint between variable A1 and B1, another similar constraint between A2 and B2... Each constraint allows the variables to take only these value pairs: (Ai=adenine, Bi=thymine) (Ai=thymine, Bi=adenine) (Ai=guanine, Bi=cytosine) or (Ai=cytosine, Bi=guanine). All these constraints are equal except for the variables involved.
So if you later assign Ai with value adenine, you can propagate the constraint and prune from Bi the values adenine, guanine and cytosine which are not supported. In this example this leaves you with only 1 value left in the domain of Bi so you can also assign Bi with the value thymine.
If you ever reach a state with an empty domain, for example if Bi was previously decided not to be thymine, you have to backtrack and erase the decision to assign Ai with adenine.
Note that if later in the program you want to try and match the chain A with B shifted one place, i.e. clean the constraints Ai-Bi and put a new constraint between each Ai with B(i+1), then it is a different "constraint problem" and you have to restart the "constraint solver" procedure - the information gathered through the previous solution search is no longer applicable to this new problem.
|