【问题标题】:How to set up a 12 x 12 matrix using clpfd library如何使用 clpfd 库设置 12 x 12 矩阵
【发布时间】:2016-04-03 19:59:10
【问题描述】:

我是约束逻辑编程的新手,想知道如何使用 clpfd 在 prolog 中设置 12 x 12 矩阵。我正在使用 swi prolog ide。

【问题讨论】:

  • 这是 Prolog 还是 ECLiPSe?
  • @WillemVanOnsem 这是序言我使用的是 swi prolog 而不是 ECLiPSe

标签: matrix prolog clpfd


【解决方案1】:

要分配一个变量矩阵,我们可以在普通的 Prolog 中做:

matrix(N,Rows) :- bagof(R,Y^(between(1,N,Y),length(R,N)),Rows).

然后,使用 library(yall) 约束每个“单元格”从域(比如说 1..3)中获取值:

:- use_module(library(clpfd)).
?- matrix(12, Mat), maplist([R]>>(R ins 1..3), Mat).

或者,使用内置函数:

?- matrix(12, Mat), bagof(t, R^(member(R, Mat), R ins 1..3), _).

【讨论】:

    猜你喜欢
    • 2021-05-08
    • 2023-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-04
    相关资源
    最近更新 更多