IBM ILOG Solver User's Manual > Extending the Library > Writing a Constraint: Allocating Frequencies > Understanding constraints > The constraint propagation algorithm |
The constraint propagation algorithm |
INDEX
![]() |
To see how the propagation algorithm works with constraints, let's look again at the constraint x <= y
, and consider the following fragment of code:
IlcIntVar x(solver,0,3), y(solver,0,2); solver.add( x <= y ); |
When that constraint is posted, the invariant expressed in the previous section becomes active and reduces the domain of x
by removing the value 3. For the moment, that's all that you can deduce about that constraint. Since that constraint has to be taken into account by Solver every time one of the variables in it is modified, the constraint itself is physically attached to these two variables.
Solver was designed specifically to automate and to optimize the reduction of the domains of constrained variables. The Solver algorithm for that purpose is straightforward in principle. When a constrained variable is modified, the constraints posted on that variable are examined to determine whether any values in the domains of other constrained variables are now inconsistent. If this is the case, necessary domain reductions are carried out in turn.
The examination of the constraints on a variable is triggered by any modification of that variable. There are several different kinds of modifications, depending on the class of variable under consideration. Those modifications are referred to as propagation events.
For the class of integer variables, there are, in fact, these propagation events:
When you define a new class of constraint, you must also define the propagation events for that class of constraint. You do so by means of the pure virtual member function, post
.
Sometimes more than one event can be triggered after a variable modification. Specifically, the value event is always accompanied by the range and domain events. Likewise, a range event is always accompanied by a domain event.
To take another example, let's consider a constrained enumerated variable, var
, with a domain containing only two values, value1
and value2
, where value1 < value2
. If you post a constraint like this solver.add(var != value1)
, three events are triggered:
value1
is actually removed from the domain of var
;
var
has been increased.
© Copyright IBM Corp. 1987, 2009. Legal terms. | PREVIOUS NEXT |