views:

156

answers:

2

I am designing a rule evaluation system which need to handle a fact database and certain rules over the database. We currently have a modified version of RETE that works partially right with some drawbacks.

The problem is the rules doesn't limit to exact matches but they must also support inequality (as in less than) and other kinds of fuzzy calculations.

Examples, suppose you have this facts

(Salary John 58000) (Salary Sara 78000) (Employee John) (Boss Sara) (Married John Sara) (Works John Stackoverflow)

you might have a rule that says:

(Salary ?w < 60000) /\ (Married ?w) /\ (Works ?w Stackoverflow) ==> Whatever

Obviously the result will be triggering the rule with an ?w value of "John" but the way we're doing that now is by looping trough each element in the fact base that matches the beggining of the first expression (Salary X X) and then making the comparison and storing the results in the fact base it self. For example, after the first pass you'll have the following item added to the fact base:

(Salary John 58000 < 60000)

and once that is made you perform the joins on the usual RETE way. That way it takes up a lot of space in the fact base, specially because rule can refer to any number and so you have those "calculated" facts as long as the rule is active.

On the other hand you can apply several rules with the first expression and you can keep using the standard matching algorithm to trigger the rules.

Does anyone know of any patterns, references or methods that handle this kind of behavior? The usual LEAPS, TREATS, RETE algorithms only handle (as far as I know) "exact" matching.

By the way, this is C# .NET.

A: 

As far as I understand the problem, all the fuzzy rules divide integer or floating point value ranges up into a limited number of subranges. For instance, if a salary is compared to 58000, 60000, 78000 values, you have 4 ranges: <58000, 58000-60000, 60000-78000, >78000.

If that is the case, maybe you can redefine your variables to be integers that are either 0,1,2,3, and thereby convert your inequality rules to equality rules.

Lars D
+1  A: 

CLIPS has supported conditional elements for as long as I've been aware of it - at least 15 years. Check out the basic programming guide for CLIPS and this CLIPS tutorial for examples. You can look at (or modify) the clips source for free.

CLIPS uses prefix notation, so your example conditional might look like:

(defrule fat-boy
    (person-data (name ?name) (weight ?weight))
    (test (> ?weight 100))
=>
    (printout t ?name " weighs " ?weight " kg! " crlf)
)
DaveParillo