The screenshot shows the forward chainer in action when solving the 8-queens puzzle. This is an application of the eq, in and nq constraints modelled by forward chaining and documented in a previous post. To be able to solve the 8-queens we needed to add additional constraints, namely X # \= Y + Z constraints. The constraints have been named naddr/3 and are solved via additional forward chaining rules.

The predicate queens/2 will setup the constraints and not yet do a labeling. The predicate expects a list of a variables and a finite domain. The predicate then performs the following steps:

% queens(+List)
queens(L,D) :-

The first step is domain_list/2 which will asign the domain D to all the variables in L, thus assuring that the queens are on the checker board. The second step is different_list/1 which will create constraints that basically assure that the queens don't attack each other horizontally. Finally the step noattack_list/1 will generate constraints that avoid a diagonal attack. The later will use naddr/3 constraints.

The left side of the screenshot shows the result of setting up the constraints for a checker board of size 3. The right side of the screenshot shows the labeling of the constraints for a checkboard of size 8. Redo would deliver additional results. When we count we see that the labeling will generate 92 solutions, as expected.

The Queens and naddr Constraint Source Code:

Previous Post about eq, in and nq Constraints:
Shared publicly