This puzzle can be solved using forward chaining, i.e., by using Drools or any similar RBS, but it isn't possible by implementing the givens as rules, expecting that an increase in the filled-in values will result in a (the) solution. Certainly, it is possible to write a rule such as<br>
<br>rule EnglishRed<br>when<br> $h: House( nationality == null && colour == Colour.RED ||<br> nationality == Nationality.ENGLISHMAN && colour == null )<br>then<br> modify( $h ){<br> setNationality( Nationality.ENGLISHMAN ),<br>
setColour( Colour.RED )<br> }<br>end<br><br>which adds "red" or "Englishman" to a House as soon as the other property is present. But this approach comes to a standstill as soon as more sophisticated mental processes are required in the manual solution technique.<br>
<br>One approach I've tried successfully is to generate all permutations of animals, colours, drinks, nationalities and smokes (120 each), insert them as facts, and to write one big rule according to the givens. A similar approach uses facts consisting of an attribute indication (animal,... smoke), a value and a reference to a House, again starting with all possible associations and using one rule to select the attribute combinations satisfying the givens.<br>
<br>I'm not quite sure how the rules presented by Miles should work, but I don't think that swapping values between House facts is going to work, even when more defensive strategies against looping are employed.<br>
<br>-W<br><br><br><br><br><br><br><br><div class="gmail_quote">On 15 June 2011 14:47, FrankVhh <span dir="ltr"><<a href="mailto:frank.vanhoenshoven@agserv.eu">frank.vanhoenshoven@agserv.eu</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi,<br>
<br>
This is a puzzling one... but then again, I believe that is the idea.<br>
<br>
I should have a very close look at it, but a loop always suggests that there<br>
are rules that re-activate themselves or eachother.<br>
<br>
For example:<br>
<div class="im"><br>
rule "抽kools牌的香烟的人与养马的人是邻居"<br>
when<br>
$h1:House(cigarette == Cigarette.kools)<br>
$h2:House(pet == Pet.horse)<br>
$h3:House(eval(position - $h2.position == 1) || eval(position -<br>
$h2.position == -1))<br>
eval($h1.position - $h2.position != 1 && $h1.position - $h2.position<br>
!= -1)<br>
then<br>
System.out.println("抽kools牌的香烟的人与养马(horse)的人是邻居");<br>
modify($h1){setCigarette($h3.cigarette)};<br>
modify($h3){setCigarette(Cigarette.kools)};<br>
end<br>
<br>
</div>In this rule, $h3 and $h1 might be the same house OR $h1 and $h2 might be<br>
the same house. I think you need to add extra constraints to make sure that<br>
all 3 houses are different.<br>
<br>
But still, I haven't had a thorough look at all the rules neither did I<br>
refresh my knowledge of the zebrapuzzle, so I am not sure whether this is a<br>
complete answer (if any).<br>
<br>
Please let us know.<br>
<br>
Regards,<br>
Frank<br>
<font color="#888888"><br>
<br>
--<br>
View this message in context: <a href="http://drools.46999.n3.nabble.com/rules-users-Can-I-solve-the-Zebra-Puzzle-in-drools-tp3066485p3067138.html" target="_blank">http://drools.46999.n3.nabble.com/rules-users-Can-I-solve-the-Zebra-Puzzle-in-drools-tp3066485p3067138.html</a><br>
Sent from the Drools: User forum mailing list archive at Nabble.com.<br>
<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</font></blockquote></div><br>