Cat & Dog Seating¶
Note
View the source code for this example here.
The cat & dog seating example encoding is an assignment ASP encoding with variables. It models a scenario where there is an event where people are seated on tables depending on their preferences in pets. Dog people are only allowed to sit with other dog people, and cat people are only allowed to sit with other cat people. The goal is to seat all people while adhering to their pet preferences.
Usage¶
Explanation:
asplain examples/cat-dog/encoding.lp examples/cat-dog/instance.lp 1 --open --query='assign("Susana",(1,2))'
Encodings¶
Base Encoding:
%*
Assigns people seats so that dog people dont sit on the same table as cat people
*%
% @label("Person {} likes the pet {}",(P,A,)) :: person(P,A)
% @label("There is a seat with chair {} on table {}",(C,T,)) :: seat((T,C))
% @label("Person {} is a assigned seat {}",(P,S,)) :: assign(P,S)
% @label("Person is assigned a seat")
{assign(P,S):seat(S)}:- person(P,A).
% @label("No two people can be assigned the same seat")
:- assign(P,S), assign(P',S), P'>P.
% @label("If a person is a ssigned a seat, they're sitting")
sitting(P) :- person(P,A), assign(P,S).
% @label("Every person has to be sitting")
:- person(P,A), not sitting(P).
% @label("No cat and dog people in the same seat")
:- assign(P,(T,C)), assign(P',(T,C')), person(P,cat), person(P',dog).
Instance:
person("Susana",cat). person("Alexander",cat). person("Torsten",dog).
seat((1,1..2)). seat((2,1..2)).
% @removable
assign("Torsten", (1,1)).