dev
dev

Reputation: 2594

Resolving constraints in Prolog

I am looking resources for learning resolving of constraints in Prolog. For example,

List=[X, Y, Z], List ins 1..4, X - Y #= Z.

Upvotes: 2

Views: 291

Answers (1)

hakank
hakank

Reputation: 6854

What I understand, your want to get concrete solutions (and not the domains). For this, use label/1 or labeling/2, which will give all the explicit solutions (via backtracking). In SWI-Prolog, these predicates are documented here: labeling/2 .

label(List) is equivalent to labeling([],List).

For this simple example, label(List) would suffice:

?- List=[X, Y, Z], List ins 1..4, X - Y #= Z,label(List).

In general, you would benefit by reading the full documentation of clpfd (here for SWI-Prolog).

Upvotes: 3

Related Questions