Re: Two questions regarding lib(fd).

From: Joachim Schimpf <j.schimpf_at_icparc.ic.ac.uk>
Date: Wed 11 Sep 2002 03:45:54 PM GMT
Message-ID: <3D7F6532.E1E5FB0B@icparc.ic.ac.uk>
```Ole Tranberg wrote:
>
> So "?Goal" is "(search(Strategy,...),labeling_ff(Vars))".
>
> What does this mean? I got the point of the search strategies (or at least most of it) and I can
> see what is going on in labeling_ff/1. But how do these two work together?
> Is the search strategy some kind of a "help" to the labeling_ff/1?

Look at the following search with 3 variables:

?- [X,Y,Z]::1..3, labeling([X,Y,Z]), writeln([X,Y,Z]), fail.
[1, 1, 1]
[1, 1, 2]
[1, 1, 3]
[1, 2, 1]
[1, 2, 2]
[1, 2, 3]
[1, 3, 1]
[1, 3, 2]
[1, 3, 3]
[2, 1, 1]
[2, 1, 2]
[2, 1, 3]
[2, 2, 1]
[2, 2, 2]
[2, 2, 3]
[2, 3, 1]
[2, 3, 2]
[2, 3, 3]
[3, 1, 1]
[3, 1, 2]
[3, 1, 3]
[3, 2, 1]
[3, 2, 2]
[3, 2, 3]
[3, 3, 1]
[3, 3, 2]
[3, 3, 3]
No (0.05s cpu)

You see that the possible combinations are tried in a particular order.

Now imagine you know somehow that the value 2 is a good choice for Y.
A good search heuristic would then be to first try all the combinations
where Y is 2. You can program this as follows:

?- [X,Y,Z]::1..3, (Y#=2;Y#\=2), labeling([X,Y,Z]), writeln([X,Y,Z]), fail.
[1, 2, 1]
[1, 2, 2]
[1, 2, 3]
[2, 2, 1]
[2, 2, 2]
[2, 2, 3]
[3, 2, 1]
[3, 2, 2]
[3, 2, 3]
[1, 1, 1]
[1, 1, 2]
[1, 1, 3]
[1, 3, 1]
[1, 3, 2]
[1, 3, 3]
[2, 1, 1]
[2, 1, 2]
[2, 1, 3]
[2, 3, 1]
[2, 3, 2]
[2, 3, 3]
[3, 1, 1]
[3, 1, 2]
[3, 1, 3]
[3, 3, 1]
[3, 3, 2]
[3, 3, 3]
No (0.06s cpu)

The roster program uses the same idea. It first makes some
heuristic choices for some of the variables, then it uses
the generic labeling(ff)/1 predicate for the remaining search.
Note that labeling/1 will simply skip variables which are