我想在clingo
,解決那些有一系列事實和約束的斷言經典燈謎的一個實施方案,你必須推斷其他事實。這裏有問題:Clingo:斷言局部約束
五個不同國籍的男子住在五個並排的房子裏,每個房子都是不同的顏色;他們都有不同的工作,不同的喜愛的動物和喜愛的飲料。我們知道:
- 英國人住在紅房子裏。
- 西班牙男人最喜歡的動物是狗。
- 日本人是一位畫家。
- 意大利人喝茶。
- 挪威人住在從左邊的第一個房子。 (number_norw = 1)
- 生活在溫室喝咖啡的人。
- 綠色的房子就在白色的右側。 (number_green = number_white + 1)
- 店員喜歡貓。
- 推銷員住在黃房子裏。
- 牛奶是中心房子裏最受歡迎的飲料。 (number_milk = 3)
- 挪威的房子鄰近於藍色的。 (number_norw = number_blue±1)
- 廚師喜歡汁。
- 生活在房子旁邊的醫生喜歡狐狸。
- 愛馬的人住在推銷員旁邊。
該任務是找出誰喜歡斑馬。 所以我提出斷言:
% Number (the number of the house, 1 being the leftmost of the block, 5 the rightmost)
number(1..5).
% Color
color(red;green;white;yellow;blue).
% Nationality
nationality(english;spanish;japanese;italian;norwegian).
% Animal
animal(dog;cat;fox;horse;zebra).
% Job
job(painter;clerk;salesman;cook;doctor).
% Beverage
beverage(tea;coffee;milk;juice;coke).
% House
house(X, C, N, A, J, B) :-
number(X),
color(C),
nationality(N),
animal(A),
job(J),
beverage(B).
現在我卡在斷言約束;我如何去編碼斷言1.到14.?我只需要理解正確的語法,所以如果有人可以用一兩個例子讓我走上正確的軌道,我可以找出其他的例子。 謝謝。
N.B.注意我可以從5和11推斷出第二座房子是藍色的,因爲11. number_blue = number_norw ± 1
,5. number_norw = 1
和0不在可能的數字範圍內,但我不想將它手動添加到約束因爲我預計clingo
自己弄明白了。
% 1. The English man lives in the red house.
% S: english --> red house <==> red house OR not english
% not S: not (red house OR not english) <==> not red house AND english
% ie. it is not so, that the english man doesn't live in the red house
:- not 1 { house(X, red, english, A, J, B) :
number(X) : animal(A) : job(J) : beverage(B) }.
而作爲另一實例第七assertation:加約束的第一assertation
感謝@imsop添加'clingo'標籤,我自己試圖這樣做,但不能因爲缺乏聲譽。 :) –