2007-01-26

Checked in the RuleCompiler

I just updated the Subversion repository at SourceForge with the latest code for pyRete. The RuleCompiler now passes "all" tests. I can't say I've done any extensive testing yet but the tests I've written gives it quite a good work-out.

The most complicated rule (as for as the RuleCompiler is concerned) tested is:

>>> import pyRete
>>> from pyRete.flags import *

>>> @pyRete.Rule
... def test1_11(a = int, b = int, c = int):
... abc = a + b + c
... a2 = a * a
... if abc == a2:
... pass

>>> ruleengine = pyRete.RuleEngine()
>>> ruleengine.watch(ACTIVATIONS, COMPILATIONS)
>>> ruleengine.add(test1_11)
>>> ruleengine.assert_fact(range(1,11)) # 1..10
>>> ruleengine.run()

# test1_11: +O+O+O+T+T+B+P
# Activation 2/100, test1_11: {'a': 2, 'c': 1, 'b': 1, 'abc': 4, 'a2': 4}
# Activation 3/100, test1_11: {'a': 3, 'c': 3, 'b': 3, 'abc': 9, 'a2': 9}
# Activation 4/100, test1_11: {'a': 3, 'c': 4, 'a2': 9, 'abc': 9, 'b': 2}
# Activation 4/100, test1_11: {'a': 3, 'c': 2, 'a2': 9, 'abc': 9, 'b': 4}
# Activation 5/100, test1_11: {'a': 3, 'c': 5, 'a2': 9, 'abc': 9, 'b': 1}
# Activation 5/100, test1_11: {'a': 3, 'c': 1, 'a2': 9, 'abc': 9, 'b': 5}
# Activation 6/100, test1_11: {'a': 4, 'c': 6, 'a2': 16, 'abc': 16, 'b': 6}
# Activation 7/100, test1_11: {'a': 4, 'c': 7, 'a2': 16, 'abc': 16, 'b': 5}
# Activation 7/100, test1_11: {'a': 4, 'c': 5, 'a2': 16, 'abc': 16, 'b': 7}
# Activation 8/100, test1_11: {'a': 4, 'c': 8, 'a2': 16, 'abc': 16, 'b': 4}
# Activation 8/100, test1_11: {'a': 4, 'c': 4, 'a2': 16, 'abc': 16, 'b': 8}
# Activation 9/100, test1_11: {'a': 4, 'c': 9, 'a2': 16, 'abc': 16, 'b': 3}
# Activation 9/100, test1_11: {'a': 4, 'c': 3, 'a2': 16, 'abc': 16, 'b': 9}
# Activation 10/100, test1_11: {'a': 4, 'c': 10, 'a2': 16, 'abc': 16, 'b': 2}
# Activation 10/100, test1_11: {'a': 4, 'c': 2, 'a2': 16, 'abc': 16, 'b': 10}
# Activation 10/100, test1_11: {'a': 5, 'c': 10, 'a2': 25, 'abc': 25, 'b': 10}
Getting the TestNodes working was quite a challenge. There were several times that the run-time behaviour of a compiled Rete Network didn't give the expected results and it was quite difficult to figure out what was actually going on. I'm quite glad I wrote the Rete Network viewer because I would never have pulled it off without it. The complete re-write of the RuleCompiler has also turned out much better than I expected. The code is clear and almost readable. I still need to write some more comments though, but then again, who doesn't?

Next up. NotNodes.

Inga kommentarer: