0

I'm learning Answer Set Programming by solving the zebra puzzle.
I found some solution examples online.
But someone told me that I can solve the puzzle without using cardinality constraint macro to generate solution Candidates. Like without using this

 { color(House, Color) : colors(Color) }= 1 :- houses(House).
 { color(House, Color) : houses(House) }= 1 :- colors(Color).

the goal is to generate different models with a unique combination of color(House, Color).

Is this possible without {atom: atom}=1:-atoms.?

DuDa
  • 3,718
  • 4
  • 16
  • 36
AmuMa
  • 1
  • 1
  • The simple answer is yes, you can always exchange cardinality constraints with other structures, the real question would be: does it make sense to do so? – DuDa Dec 12 '21 at 19:47

1 Answers1

0

You can do this with inequality constraints, and a weak constraint to generate the maximal number of combinations.

% Generate assignments of colors to houses.
{ color(House, Color) } :- houses(House), colors(Color).

% A house can only have one color.
:- color(House, Color_1), color(House, Color_2), houses(House),
   colors(Color_1), colors(Color_2), Color_1 != Color_2.

% Each color can only be assigned to one house.
:- color(House_1, Color), color(House_2, Color), colors(Color),
   houses(House_1), houses(House_2), House_1 != House_2.

% Generate a maximal number of combinations (i.e. all of them).
:~ color(House, Color), houses(House), colors(Color). [-1@0, House, Color]

Although, this needlessly more verbose than your current encoding.

Ollie Kampo
  • 38
  • 1
  • 3