[英]Converting a list of integers into a CLPFD domain
I am trying to convert a list of integers to a CLPFD domain.我正在尝试将整数列表转换为 CLPFD 域。 eg
[1,5,7]
-> 1\/5\/7
.例如
[1,5,7]
-> 1\/5\/7
。 I tried reading the documentation, but I couldn't find anything.我尝试阅读文档,但找不到任何内容。 The only thing I found is fd_dom/2.
我唯一找到的是 fd_dom/2。 fd_dom documentation.
fd_dom 文档。 Here, they are converting a domain into a list of integers (opposite of what I want).
在这里,他们将域转换为整数列表(与我想要的相反)。 I am new to CLPFD and prolog in general.
一般来说,我是 CLPFD 和 prolog 的新手。 So, if someone could also explain the fd_dom documentation apart from answering my question, I would really appreciate it.
因此,如果有人除了回答我的问题之外还可以解释 fd_dom 文档,我将不胜感激。
Here's what I use for converting a list of integers to be used as a domain (disjunction):这是我用来转换整数列表以用作域(析取)的方法:
list_domain_disjunction([D|Ds],Disj) :-
foldl(disj,Ds,D,Disj).
disj(A,B,C) :- C = \/(B,A).
Example:例子:
?- list_domain_disjunction([1,5,7],X).
X = 1\/5\/7.
One can see how this disjunction is "really" represented using write_canonical/1
:使用
write_canonical/1
可以看到这种分离是如何“真正”表示的:
?- write_canonical(1\/5\/7).
\/(\/(1,5),7)
Note: list_domain_disjunction/2
is not reversible, ie it cannot be used to convert an disjuction to a list of integers.注意:
list_domain_disjunction/2
是不可逆的,即它不能用于将析取转换为整数列表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.