【问题标题】:Access all posted clpfd constraints SWI vs Sicstus Prolog访问所有发布的 clpfd 约束 SWI 与 Sicstus Prolog
【发布时间】:2020-06-23 15:14:26
【问题描述】:

我正在尝试解决一个问题。 我正在编写一个用于 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)))
]

非常感谢所有帮助!

【问题讨论】:

    标签: prolog clpfd


    【解决方案1】:

    【讨论】:

      猜你喜欢
      • 2016-01-16
      • 1970-01-01
      • 2016-09-03
      • 1970-01-01
      • 1970-01-01
      • 2011-11-11
      • 1970-01-01
      • 2014-01-31
      • 2015-12-30
      相关资源
      最近更新 更多