Skip to content

Commit d7534b4

Browse files
committed
[README.md] added explanation about RETE algorithm added in grule
1 parent ff3aa8d commit d7534b4

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,35 @@ When you make your own function to be called from rule engine, you need to know
374374
2. The function must only return 1 type. Returning multiple variable from function are not acceptable, the rule execution will fail if there are multiple return variable.
375375
3. The way number literal were treated in Grule's DRL is; **decimal** will always taken as `int64` and **real** as `float64`, thus always consider to define your function argument and returns between `int64` and `float64` when your function works with numbers.
376376

377+
## RETE Algorithm
378+
379+
From Wikipedia : The Rete algorithm (/ˈriːtiː/ REE-tee, /ˈreɪtiː/ RAY-tee, rarely /ˈriːt/ REET, /rɛˈteɪ/ reh-TAY) is a pattern matching algorithm for implementing rule-based systems. The algorithm was developed to efficiently apply many rules or patterns to many objects, or facts, in a knowledge base. It is used to determine which of the system's rules should fire based on its data store, its facts.
380+
381+
Some form of RETE algorithm were employed in `grule-rule-engine` starting from version `1.1.0`.
382+
It replaces the __Naive__ approach when evaluating rules to add to `ConflictSet`.
383+
384+
`ExpressionAtom` in the DRL were compiled and will not be duplicated within the working memory of the engine.
385+
This makes the engine performance be increased significantly if you have many rules defined with lots of duplicated expressions
386+
or lots of heavy function/method calls.
387+
388+
Grule's RETE implementation don't have `Class` selector as one expression my involve multiple class. For example an expression such as:
389+
390+
```.go
391+
when
392+
ClassA.attr == ClassB.attr + ClassC.AFunc()
393+
then
394+
...
395+
```
396+
397+
The expression above involve attribute/function result comparison and math operation from 3 different class. This makes
398+
RETE's class separation of expression token difficult.
399+
400+
You can read about RETE algorithm here:
401+
402+
* https://en.wikipedia.org/wiki/Rete_algorithm
403+
* https://www.drdobbs.com/architecture-and-design/the-rete-matching-algorithm/184405218
404+
* https://www.sparklinglogic.com/rete-algorithm-demystified-part-2/
405+
377406
# Tasks and Help Wanted.
378407

379408
* Need to do more and more and more test.

0 commit comments

Comments
 (0)