IBM ILOG Solver User's Manual > Extending the Library > Writing a Constraint: Allocating Frequencies > Understanding constraints > Elementary modifiers for variables

Besides the accessors such as getMin, getMax, or getValue, defined for integer expressions, there are also predefined elementary modifiers. You can use these modifiers to implement constraints.

Let's look, for example, at how setValue(IlcInt c), one of these predefined modifiers, behaves.

  IlcIntVar x(solver,0,1); 
  x.setValue(1); 

That fragment of code effectively makes the domain of x equal to a singleton (a single element) reduced to the value 1. This behavior literally involves a domain reduction, and this behavior is consistent throughout Solver: if the value 1 were not in the initial domain, Solver would have raised an error.

For example, consider the following contrasting piece of code. It raises an error, fail.

   IlcIntVar x(solver,0,1); 
   x.setValue(2);       // LEADS TO FAILURE 
 

The point here is that elementary modifiers can be used to implement constraints, but they themselves do not behave like constraints.

It's also important to note that modifiers are volatile. By "volatile," it is meant that if a modifier does not have an immediate effect, it will have no later effect. This volatility is another way in which elementary modifiers differ from constraints.

    IlcIntVar x(solver,0,1), y(solver,0,1); 
    (x + y).setValue(1);        // NO EFFECT 

That code has no effect because all the values of the domains can participate in a solution.

Of course, if you use constraints instead, and post them, like this, those hazards can be avoided.

    IlcIntVar x(solver,0,1), y(solver,0,1); 
    solver.add( x + y == 1); 

It's true that this piece of code will not modify a domain, but during the generation of the values of x and y, only the two solutions where the sum is equal to 1 appear. What's happening here is that Solver is saving the constraint so at each modification of the domain of either of the variables, Solver executes the corresponding modifier setValue.

For the class IlcIntExp, here are the modifiers and what they do.

Before leaving the topic of modifiers, it must be emphasized again that they only reduce domains: they don't enlarge domains. For that reason, the following code modifies nothing in the domain of x and, in particular, it does not make the upper boundary of x equal to 2.

  IlcIntVar x(solver,0,1); 
  x.setMax(2);          // DOES NOTHING!