FRAMES NO FRAMES

IlcTableConstraint

public IlcConstraint IlcTableConstraint(IlcIntVarArray vars, IlcIntPredicate predicate)
public IlcConstraint IlcTableConstraint(IlcAnyVarArray vars, IlcAnyPredicate predicate)
public IlcConstraint IlcTableConstraint(IlcAnyVarArray vars, IlcAnyTupleSet set, IlcBool compatible)
public IlcConstraint IlcTableConstraint(IlcAnyVar y, IlcConstAnyArray a, IlcIntVar x)
public IlcConstraint IlcTableConstraint(IlcFloatVar y, IlcConstFloatArray a, IlcIntVar x)
public IlcConstraint IlcTableConstraint(IlcIntVarArray vars, IlcIntTupleSet set, IlcBool compatible)
public IlcConstraint IlcTableConstraint(IlcIntVar y, IlcConstIntArray a, IlcIntVar x)
Definition file: ilsolver/ilcint.h
Include file: <ilsolver/ilosolver.h>

This function can be used to define simple constraints that are not predefined in Solver for use during a Solver search, for example, inside a goal or constraint. (For similar functionality to use in an IBM® ILOG® Concert Technology model, see IloTableConstraint.) This function creates and returns a constraint. That constraint is defined

The semantics of that generic constraint can be indicated in either one of several ways:

The order of the constrained variables in the array vars is important because the same order is respected in the predicate or the set. That is, IlcTableConstraint passes an array of values to the member function isTrue for a predicate or to the member function isIn for a set, where the first such value is a value of vars[0], the second is a value of vars[1], and in general, the ith value is a value of the constrained variable vars[i].

This function will throw an exception (an instance of IloSolver::SolverErrorException) if any of the following conditions occur:

This function reduces domains efficiently, but it may take some time to do so. The time it needs for domain reduction depends on the size of the domains of the constrained variables in vars.

Programming Hint

Solver does not copy the array a when a is an instance of IlcConstAnyArray, IlcConstFloatArray, or IlcConstIntArray. When a is an instance of one of those constant array classes, then Solver will share the array among constraints instead of copying it. In fact, if you want to build a table constraint of the form y=a[x], we strongly recommend that you should use only the function that takes an instance of IlcConstFloatArray or IlcConstIntArray as an argument. In that spirit, you can build an instance of IlcConstIntArray from an instance of IlcIntArray, or an instance of IlcConstFloatArray from an instance of IlcFloatArray.

Examples:

The following code defines a constraint of arity four such that only these combinations of values are allowed: (0, 1, 1, 2), (1, 0, 2, 3), and (0, 0, 2, 1).

 IlcIntTupleSet set(s,4);
 set.add(IlcIntArray(s,4,0,1,1,2));
 set.add(IlcIntArray(s,4,1,0,2,3));
 set.add(IlcIntArray(s,4,0,0,2,1));
 set.close();

 IlcIntVar x(s,0,1),y(s,0,1),z(s,0,3),t(s,0,2);
 IlcIntVarArray vars(s,4,x,y,z,t);
 

Inside a goal or constraint now, you can post that constraint by adding it to an instance of IloSolver, like this:

 s.add(IlcTableConstraint(vars,set,IlcTrue));

The following code defines a constraint of arity three. It uses a predicate that is true if the three variables are pairwise different or the sum of the first two constrained variables is equal to the third variable.

 IlcBool IlcIntPredicateI::isTrue(IlcIntArray val) {
    return((val[0] != val[1] && val[1] != val[2] && val[0] != val[2])
                || (val[0] + val[1] == val[2]));
 }

 IlcIntVar x(s, 0, 3), y(s, 0, 3), z(s, 0, 3);
 IlcIntVarArray vars(s, 3, x, y, z);
 

Inside a goal or constraint now, you can post this constraint by adding it to an instance of IloSolver, like this:

 s.add(IlcTableConstraint(vars, Predicate(s));

See Also: