我正在试着做一道题。我正在写一个与Sicstus-Prolog使用的程序,我需要一个功能,我只想出在SWI-Prolog。
具体地说,我正在尝试获取所有clp(fd)约束,这些约束是在运行以下示例代码时发布的。我不想运行标签。
% 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).问题是,虽然SWI实际上返回所有约束,但sicstus不会。
那么,我如何强制进一步求值,以便sicstus也返回更多类似如下的内容:
% 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)))
]而不仅仅是:
% Actual sicstus return value.
[
:(clpfd,in(_A,..(1,4))),
:(clpfd,in(_B,..(1,4))),
:(clpfd,in(_C,..(1,4))),
:(clpfd,in(_D,..(1,4)))
]非常感谢大家的帮助!
发布于 2020-06-24 02:58:14
您需要首先使用assert(clpfd:full_answer).来获取约束。
https://stackoverflow.com/questions/62538102
复制相似问题