Search code examples
prologclpfd

Access all posted clpfd constraints SWI vs Sicstus Prolog


I am trying to work out a problem. I am writing a program for use with Sicstus-Prolog and I need a functionality I have only figured out in SWI-Prolog.

Specifically I am trying to get all clp(fd) constraints, that are posted when running the following sample code. I do not want to run labeling.

% Sicstus Prolog
% ?- N=4, length(List,N), domain(List, 1, N), all_different(List), bar(List), copy_term(List,List,M).

% SWI-Prolog
% ?- N=4, length(List,N), List ins 1..N, all_different(List), bar(List), copy_term(List,List,M).

:- use_module(library(clpfd)).

bar([]).
bar([Var|T]) :-
    bar_aux(Var,T,1),
    bar(T).

bar_aux(_,[],_).
bar_aux(Var,[Var2|T],N) :-
    Var #\= Var2 + N,
    N1 is N + 1,
    bar_aux(Var,T,N1).

The problem is, that while SWI actually returns all constraints, sicstus does not.

So how can I force further evaluation, so that sicstus also returns something more like this:

% Actual SWI return value.
[
  :(clpfd,in(_25130,..(1,4))),
  :(clpfd,#\=(_25130,+(_25346,3))),
  :(clpfd,#\=(_25130,+(_25274,2))),
  :(clpfd,#\=(_25130,+(_25202,1))),
  :(clpfd,all_different([_25130,_25202,_25274,_25346])),
  :(clpfd,in(_25346,..(1,4))),
  :(clpfd,#\=(_25274,+(_25346,1))),
  :(clpfd,#\=(_25202,+(_25346,2))),
  :(clpfd,in(_25274,..(1,4))),
  :(clpfd,#\=(_25202,+(_25274,1))),
  :(clpfd,in(_25202,..(1,4)))
]

as opposed to just:

% Actual sicstus return value.
[
  :(clpfd,in(_A,..(1,4))),
  :(clpfd,in(_B,..(1,4))),
  :(clpfd,in(_C,..(1,4))),
  :(clpfd,in(_D,..(1,4)))
]

All help is greatly appreciated!


Solution

  • You need to assert(clpfd:full_answer). first to get the constraints.

    See https://sicstus.sics.se/sicstus/docs/latest4/html/sicstus.html/Answer-Constraints.html#Answer-Constraints