Conflict Resolution
When declaring a flow it is defined with a default conflict resolution strategy. A conflict resolution strategy is used to determine which rule to activate when multiple rules are ready to be activated at the same time.
Resolution Strategies
salience
- sort activations on the specifiedsalience
. (NOTE The default salience of a rule is 0).activationRecency
- sort activations on activation recency. This is aLIFO
strategy the latest activation takes precedence.factRecency
- sort activations based onfact
recency. Each time a fact isasserted
ormodified
its recency is incremented.bucketCounter
- sort activations on the internalbucket
counter. The bucket counter is incremented after an activation is fired and the internalworkingMemory
is altered.factRecencyInverse
- sort activations by the oldest fact first. This is aFIFO
strategy, the earliest fact takes precedence.
The default conflict resolution strategy consists of salience
and activationRecency
.
Examples
Example 1
In the above example activation 2 would be fired since it is the most recent activation and the rule salience is the same.
Example 2
In this example activation 1 would fire because it has a greater salience
Overidding The Default Strategy
To override the default strategy you can use the conflictResolution
method on a flow.
The combination of salience
, factRecency
, and activationRecency
would do the following.
- Check if the salience is the same, if not use the activation with the greatest salience.
- If salience is the same check if fact recency is the same. The fact recency is determined by looping through the facts in each activation and until two different recencies are found. The activation with the greatest recency takes precendence.
- If fact recency is the same check the activation recency.
Example 1
In this example activation 1 would fire because it's salience is the greatest.
Example 2
In Example 2 activation 2 would fire because of the third recency entry.
Example 3
In Example 3 activation 2 would fire because salience
and factRecency
are the same but activation 2's activation recency is greater.