Previous Up Next

11.3  Repair Constraints

Once a constraint has been declared to be a repair constraint it is monitored for violation. Whether a repair constraint is considered to be violated depends on the states of its variables. A temporary assignment of the variables is used for checking constraints. This assignment is called the tentative assignment and is described above. A constraint which is violated in this way is called a conflict constraint.

Normal constraints are turned into repair constraints by giving them one of the following annotations:

Constraint r_conflict ConflictSet

This is the simplest form of annotation. r_conflict/2 makes a constraint known to the repair library, i.e. it will initiate monitoring of Constraint for conflicts. When the constraint goes into conflict, it will show up in the conflict set denoted by ConflictSet, from where it can be retrieved using conflict_constraints/2. Constraint can be any goal that works logically, it should be useable as a ground check, and work on any instantiation pattern. Typically, it will be a constraint from some solver library. ConflictSet can be a user-defined name (an atom) or it can be a variable in which case the system returns a conflict set handle that can later be passed to conflict_constraints/2. Example constraint with annotation:

fd:(Capacity >= sum(Weights))  r_conflict  cap_cstr

Note that using different conflict sets for different groups of constraints will often make the search algorithm easier and more efficient. A second allowed form of the r_conflict/2 annotation is Constraint r_conflict ConflictSet-ConflictData. If this is used, ConflictData will appear in the conflict set instead of the Constraint itself. This feature can be used to pass additional information to the search algorithm.

Constraint r_conflict_prop ConflictSet

In addition to what r_conflict/2 does, the r_conflict_prop/2 annotation causes the Constraint to be activated as a goal as soon as it goes into conflict for the first time. If Constraint is a finite-domain constraint for example, this means that domain-based propagation on Constraint will start at that point in time.

Note that if you want constraint propagation from the very beginning, you should simply write the constraint twice, once without and once with annotation.


Previous Up Next