ECLiPSe CLP:在 ic 库中 search/6 找到的子结果之间暂停

ECLiPSe CLP : Pause between subresults found by search/6 in ic library

(此问题涉及 search/6。)

我想知道是否有一种方法——而不是手动跟踪——在每次找到单个变量的新解决方案时暂停 search/6 的执行?

我想完成此操作以进一步调查在受限模型中搜索期间发生的情况。

例如,如果您正在尝试解决经典的数独问题,并且您已经为您的电路板编写了一组约束和打印方法,那么在设置约束之后打印电路板会很有用,但之前搜索,以评估约束的强度。但是,一旦调用搜索来解决数独问题,除非进行跟踪,否则您不会真正了解在其下构建的单个结果。

如果有可能会非常有用,例如:

(这只是一个抽象的例子)

% Let's imagine this is a (very poorly) constrained sudoku board
?- problem(Sudoku),constraint(Sudoku),print(Sudoku).
    [[1,3,_,2,_,_,7,4,_],
     [_,2,5,_,1,_,_,_,_],
     [4,8,_,_,6,_,_,5,_],
     [_,_,_,7,8,_,2,1,_],
     [5,_,_,_,9,_,3,7,_],
     [9,_,_,_,3,_,_,_,5],
     [_,4,_,_,_,6,8,9,_],
     [_,5,3,_,_,1,4,_,_],
     [6,_,_,_,_,_,_,_,_]]

现在搜索:

?- problem(Sudoku),constraint(Sudoku),search_pause(Sudoku,BT),print(Sudoku,BT).
    [[1,3,6,2,_,_,7,4,_],
     [_,2,5,_,1,_,_,_,_],
     [4,8,_,_,6,_,_,5,_],
     [_,_,_,7,8,_,2,1,_],
     [5,_,_,_,9,_,3,7,_],
     [9,_,_,_,3,_,_,_,5],
     [_,4,_,_,_,6,8,9,_],
     [_,5,3,_,_,1,4,_,_],
     [6,_,_,_,_,_,_,_,_]]
     Board[1,3] = 6
     Backtracks = 1

   more ;

使用现有的可视化工具

查看代码的 Visualization Tools Manual. You can get the kind of matrix display you want by adding a viewable_create/2 注释,并从 TkECLiPSe 的 工具菜单启动 Visualisation Client .

使用您自己的检测例程

您可以将 search/6 中的 indomain_xxx 选择方法替换为用户定义的选择方法,您可以在传播后 and/or 之前打印信息。

如果这还不够,您可以将整个内置 search/6 替换为您自己的,这并不难,请参见例如ECLiPSe Tutorial chapter on tree search or my answer to .

使用数据驱动工具进行追踪

使用 ECLiPSe 的数据驱动控制工具,当您的变量发生某些事情时,您可以很容易地显示信息。在最简单的情况下,您对变量实例化做一些事情:

?- suspend(printf("X was instantiated to %w%n",[X]), 1, X->inst),
   writeln(start), X=3, writeln(end).

start
X was instantiated to 3
end

基于这个想法,即使它们发生在黑盒搜索例程中,您也可以编写 code that allows you to follow labeling and propagation steps。有关详细信息,请参阅 link。