[ library(ic_mdd) | Reference Manual | Alphabetic Index ]

# table(+Tuples, ++Table)

Constrain all tuples to take values from the table rows
Tuples
A collection of tuples of finite domain variables - these will be constrained
Table
A collection of tuples of integers

## Description

This constraint is defined extensionally, i.e. by an explicit table of value tuples that are valid solutions.

Declaratively, all tuples in Tuples are constrained to take only values from Table. Operationally, for each tuple in Tuples, this constraint maintains arc-consistency, i.e. removes all domain values that can no longer be part of a solution. Posting the constraint with multiple tuples in Tuples is equivalent (declaratively and consistency-wise) to posting an individual table-constraint for each tuple in Tuples.

The tuples in both Tuples and Table can be lists, arrays or any collection expression understood by eval_to_list/2.

Compatibility: This constraint is known as in_relation in the global constraint catalog, as table/2 in SICStus Prolog, and extensional() in Gecode.

## Examples

```    :- lib(ic).		% or lib(fd)
:- lib(ic_mdd).	% or lib(fd_mdd)

crossword :-
dim(Grid, [4,4]),
words4(Words),

% constrain rows and columns to be words
( for(I,1,4), fromto(Slots,Slots1,Slots2,[]), param(Grid) do
Slots1 = [Grid[I,*], Grid[*,I] |Slots2]
),
table(Slots, Words),

% find solution(s)
labeling(Grid),

% print result
( foreachelem(Char,Grid,[_,J]) do
( J==1 -> nl ; put(0' ) ), put(Char)
).

% List of allowed words
% Note: `aloe` is the same as the list [0'a, 0'l, 0'o, 0'e], which
% is the same as the list of character codes [97, 108, 111, 101]
words4([`aloe`, `back`, `bash`, `soil`, `help`, `kelp`, `luck`]).

% Sample run:
?- crossword.

b a s h
a l o e
s o i l
h e l p
```