This is a solution to the Drools Puzzle Round 2: The Familiy Puzzle.
Submitted by Dan Berindei (dan.berindei@gmail.com) on Sep 6, 2007.


Dependencies:

* JDK 1.5.0 (using Enums)
* Drools 4.0.1 (Drools 4.0.0 has a problem with the 'in' operator)


Run in Eclipse:

1) Import archive in Eclipse, it should create a proper Drools project
2) You might have to change the reference to the JDT Core jar 
   (since it's not included in the Drools Library, and I have an older version)
3) Execute the main method of the drools.quiz2.FindFamilies class

Run from Command Line:

1) Setup Classpath to include drools
2) Run the main method from the command line in the readme's directory: 
   java -cp bin drools.quiz2.FindFamilies


Final answer is printed to the Console.

Output should look something like this:

Running with rules file /findfamilies-noretract.drl
Found solution: [FamilyTriplet: family1: [Family: husband: Locker wife: Doris son: Henry] family2: [Family: husband: Snyder wife: Edith son: Victor] family3: [Family: husband: Abel wife: Luisa son: Albert]]
Setting up the rule base took: 1452 ms
Finding the solution took 38 ms
Total run time: 1491 ms


Experimenting
I have written two rules files, one with retract() calls and one without.
The retract-less rules file is the one used by default because it seems to perform 
much bettern than the retract-ful one (it takes about half the time).
On the other hand, I like the retract-ful rules file better because there is one rule 
for each requirement in the problem.
You can switch between the rules files by (un-)commenting the right line in the main() method.
I really think it would be nice to be able to use queries inside in the LHS of a rule 
(like functions, but without having to put them inside and eval() call).

I have played a bit with the time measurement. I am using System.nanoTime() instead of 
System.currentTimeMillis() because the resolution of System.currentTimeMillis() is the system 
tick, which on Windows is about 15ms.

I also think I found a couple of bugs while working on the quiz. In the drools.test package you'll 
find a JUnit test that shows that the prefix-or and infix-or operators don't match properly 
when they are used in the LHS of a rule. Also, using either one of the or operators in a query 
generates a ClassCastException.

