Icarus TNF
Icarus TNF

Reputation: 27

Converting a list of integers into a CLPFD domain

I am trying to convert a list of integers to a CLPFD domain. e.g. [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 documentation. 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. So, if someone could also explain the fd_dom documentation apart from answering my question, I would really appreciate it.

Upvotes: 1

Views: 141

Answers (1)

hakank
hakank

Reputation: 6854

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\/5\/7).
\/(\/(1,5),7)

Note: list_domain_disjunction/2 is not reversible, i.e. it cannot be used to convert an disjuction to a list of integers.

Upvotes: 2

Related Questions