Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add domain variable to global_cardinality?

I'm trying to add a constraint global_cardinality to my program and in the manual of SICStus Prolog is written:

global_cardinality(+Xs,+Vals)

global_cardinality(+Xs,+Vals,+Options)

where Xs = [X1,...,Xd] is a list of integers or domain variables, and Vals = [K1-V1,...,Kn-Vn] is a list of pairs where each key Ki is a unique integer and Vi is a domain variable or an integer. True if every element of Xs is equal to some key and for each pair Ki-Vi, exactly Vi elements of Xs are equal to Ki.

Now I can write:

global_cardinality([A,B,C], [1-2, 2-1]).

to say that the number 1 will be used twice. The number 2 will be used just once.

But I would like to say that the number 1 will be used: once, twice or three times

According to the manual I need a domain variable but what is the proper syntax for that?

like image 215
Martin Vseticka Avatar asked Dec 07 '25 13:12

Martin Vseticka


1 Answers

?- X in 1..3, global_cardinality([A,B,C], [1-X, 2-1]).
like image 163
Mats Carlsson Avatar answered Dec 09 '25 18:12

Mats Carlsson