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
rule EnglishRed
when
$h: House( nationality == null && colour == Colour.RED ||
nationality == Nationality.ENGLISHMAN && colour == null )
then
modify( $h ){
setNationality( Nationality.ENGLISHMAN ),
setColour( Colour.RED )
}
end
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.
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.
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.
-W
Hi,
This is a puzzling one... but then again, I believe that is the idea.
I should have a very close look at it, but a loop always suggests that there
are rules that re-activate themselves or eachother.
For example:
In this rule, $h3 and $h1 might be the same house OR $h1 and $h2 might be
rule "抽kools牌的香烟的人与养马的人是邻居"
when
$h1:House(cigarette == Cigarette.kools)
$h2:House(pet == Pet.horse)
$h3:House(eval(position - $h2.position == 1) || eval(position -
$h2.position == -1))
eval($h1.position - $h2.position != 1 && $h1.position - $h2.position
!= -1)
then
System.out.println("抽kools牌的香烟的人与养马(horse)的人是邻居");
modify($h1){setCigarette($h3.cigarette)};
modify($h3){setCigarette(Cigarette.kools)};
end
the same house. I think you need to add extra constraints to make sure that
all 3 houses are different.
But still, I haven't had a thorough look at all the rules neither did I
refresh my knowledge of the zebrapuzzle, so I am not sure whether this is a
complete answer (if any).
Please let us know.
Regards,
Frank
--
View this message in context: http://drools.46999.n3.nabble.com/rules-users-Can-I-solve-the-Zebra-Puzzle-in-drools-tp3066485p3067138.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users