[rules-users] Golfer example finds two identical solutions - the explanation

Dr. Gernot Starke gs at gernotstarke.de
Fri Aug 10 16:23:33 EDT 2007


Hi there,

some people complained that the Golfer-example from the JBoss-Drools  
distribution finds two identical solutions.
I investigated a little and found the "problem":

The rule is underspecified: It binds five Golfer objects, but only  
four of those are completely specified by their respective
condition elements. The fifth, the "Freds right neighbour", lacks  
that completeness...

What happens is the following: The "unknown golfer" can be bound to  
two different facts: I had the "unknown" golfer
printed out - and see what happened:

Fred 1 orange, Joe 2 blue, Bob 4 plaid, Tom 3 red
unknown Tom 2 blue

Fred 1 orange, Joe 2 blue, Bob 4 plaid, Tom 3 red
unknown Joe 2 blue

As the unknown golfer is NOT compared to the actual neighbor, Joe,  
there are two possible instantiations
for our "unknown" golfer...

The solution would be to constraint the unknown-golfer (= Fred's  
right neighbour) to the set of (Bob, Joe, Tom)...
an eval sounds great - too bad the "in" constraint doesn't work...

       // freds right neighbour is either Tom, Bob or Joe!
         eval (($fn == $joe) || ($fn == $bob) || ($fn == $tom))


The simple (but un-elegant) solution is setting an agenda-group rule- 
attribute, prohibing the rule from firing twice.

In his book on JESS, E. Friedemann-Hill shows JESS to deliver only a  
single solution ... I translated the Drools-version
literally to his JESS version (I had to create GolferColor and  
GolferPosition classes, but needed only 32 facts in working memory,
instead of 64 with the combined Golfer-drools version)....

regards,
Gernot


Dr. Gernot Starke
Doing IT Right

---
Willi-Lauf Allee 43, D-50858 Köln
gs at gernotstarke.de,
  +49 (0) 177 - 728 2570
http://www.gernotstarke.de
Blog: http://it-and-more.blogspot.com
****************************************
Das freie Portal für Software-Architekten:
http://www.arc42.de






More information about the rules-users mailing list