Retract is an action type used to withdraw an earlier asserted object from the Engine (either passed as a part of the invokeRuleset method or as a result of firing the Assert action), which has been used in the condition of any of the rule in a ruleset.
The retract action does not affect the list returned by the invokeRuleset method
Note
The outcome of a retract action is that the Engine discards any inferences caused by the object. A rule that was satisfied earlier by that object is removed from the Firing Queue. But, if a rule was satisfied and the actions fired, those actions cannot be undone.
Retract :: object to be retracted
If |
|
Solution is not OK |
|
Then |
|
Retract :: solution |
Optimization, best match/first match and solutions are asserted initially or created and introduced as a part of assert separation. In this case, you might want to retract the unfit ones and clear the clutter and speed up processing.
Example
If |
|
Solution is not ok |
|
Then |
|
Retract :: solution |
In this example, the second action would usually be to assert the next proposed Solution object.
Sometimes, an object satisfies many rules. Of these rules, there may be an exception rule, which if true, should prevent other rules from being fired. In this case, you might want to retract that object. Retracting an object results in rules which might have been satisfied to be discarded. This can be handled in other ways too, defining a mutual exclusion rule may be an option. However, in some cases, using the Retract action may be easier.