Hi folks
I am writing a logical inference engine in drools. Logical sentences (class Sentence) which are proven are indicated by the fact Proven( sentence = $sentence )
All Proven(sentence) facts are asserted using the drools logical mechanism (since logical backtracking is required).
For efficiency purposes I want to be able to suppress firing any rules which assert proof of a logical sentence which has already been proven (there may be multiple inferences which prove the same sentence).
If the non existence of a proof of a sentence (not exists Proven(sentence=$sentence) is included in the lhs conditions then that causes problems when the rule logically asserts Proven(sentence) since the insertion invalidates the lhs conditions and hence the rule causes its own retraction (the inserted fact handle return is null).
As a way around this I created a class Piton() to record whether a particular rule has fired. The lhs conditions then become:
(Proven( predicate == $sentence ) or Piton( fireName == $descriptor ) )
Where $descriptor is a string built from the rulename + the set of facts which matched the lhs (ie a descriptor which is unique to the rule fire)
With this approach when a rule asserts Proven(sentence) because it has also asserted Piton( fireName == descriptor ) ) the lhs of the rule still matches the the rule fire is not retracted.
This approach works, but it is rather tedious to implement since the descriptor must be defined in such as way to make it unique (or as far as possible unique) to the particular rule activation. Since the drools variable is not accessible in the lhs of a rule (and hence the activation details are not accessible in the lhs), this means that the descriptor must be handcoded to consist of all matching facts for that lhs.
Is this approach the only way to prevent multiple rule firings for the same proof, or is there a simpler way to achieve this?
Any advice greatly appreciated!
thanks
Tracey