【发布时间】:2013-12-13 13:53:09
【问题描述】:
如何告诉 Prolog/CLPFD 只使用特定数量的域作为最后一个资源?
例如: 域从 0...8。我希望 Prolog 只有在没有其他选项的情况下才使用 0 。我使用了“向下”选项进行标记,但分配了太多的 0。
上下文:Hoo-Doo 游戏 -> 生成 8x8 棋盘解决方案,其中任何列、行或对角线的数字都从 1-8 不重复(数独之类)。必须使用两个透明的部分(用 0 表示,可以是任何地方)才能完成解决方案。
代码如下:
...
setDomain(H,BoardSize),
maplist(all_distinct,H),
IndexI is BoardSize - 1,
IndexJ is BoardSize - 2,
checkDiagonalsLR(H,IndexI,IndexJ,BoardSize), %calls the all_distinct
IndexJ2 is BoardSize - 1,
checkDiagonalsRL(H,1,IndexJ2,BoardSize), %calls the all_distinct
transpose(H,Columns), maplist(all_distinct,Columns),
useLabeling(Columns,BoardSize), printBoard(Columns).
useLabeling([],N).
useLabeling([H|T],N) :- labeling([down],H), useLabeling(T,N).
【问题讨论】:
-
请将您的代码添加到问题中。