Detecting Conflicts in Conditions that use Expressions - Gnorion/BizVR GitHub Wiki

A simple Example

In these two rules

DT1: R1: if age < 30 then eligible is 'yes'    
DT1: R2: if age > 20 then eligible is 'no' 

we can immediately see there is a conflict for any age in the range (20..30). And validator will detect this.

However...... Take a look at these two rules:

DT1: R1: if age < minimum then eligible is 'yes'    
DT1: R2: if age > maximum then eligible is 'no'   

at first glance you would think these two rules do not overlap, right?

However note that the rules are comparing two variables (whose values won't get assigned until the rules are actually executing) What if during execution age=25, maximum=20 and minimum=30? then we'd have a conflict.

But Validation takes place long before the rules actually get executed so we won't have actual values to compare. The best we can do is probably to have validator report this:

POTENTIAL RULE CONFLICT IN: DT1 and DT1
Currently Attribute eligible is set to 'yes' by rule R1 and 'no' by rule R2. 
This occurs when age in (maximum..minimum) but only when maximum < minimum. 

Its still going to be up to the user to ensure that the value of maximum is greater than the value of minimum. Perhaps that's another business rule they need to write.

This is just one example of the difficulties associated with detecting conflicts when the rule conditions contains variables and not literals.

A More Complex Example

Consider these rules (where min, max and threshold are set somewhere else

R1: IF age in [min..max] THEN exemption='yes'
R2: IF age < threshold THEN exemption='no'

Should we be concerned about these rules?

Could they cause a problem?

Again (at first glance) they seem perfectly reasonable.

But VV will determine there is a potential conflict that could result in the rules producing the wrong result.

VV observes:

Attribute exemption can be set to 'yes' by rule R1 and 'no' by rule R2. 
This can occur when age<threshold and age in [min..max].

There is no conflict when threshold<min or age>=max

Check to make sure any values you set do not cause a conflict.

This conflict detection should work no matter how complex the expressions.

For example in these rules

R1: IF total <= sum(every amt in collection satisfies age in [0..100]) THEN discount=5
R2: IF total >= sum(every amt in collection satisfies age in [0..100]) THEN discount=10

VV will detect:

Currently Attribute discount is set to 5 by rule R1 and 10 by rule R2. 
This occurs when total =sum(every amt in collection satisfies age in [0..100]). 

Potential Conflicts between two ranges specified with expressions

These two rules use ranges. Do we have a potential conflict here? Yes, of course. If either range overlaps the other during execution then we have the potential for a conflict.

R1: IF age in [min..max] THEN group='A'
R2: IF age in [lower..upper] THEN group='B'

VV can detect this and warn you:

Currently Attribute group is set to 'A' by rule R1 and 'B' by rule R2. 
This occurs when age is in the region where the two ranges overlap. 
This may or may not occur during execution - if necessary add a rule to check. 
Review these conditions and either 
1. eliminate the overlap or 
2. ensure the actions have the same value
⚠️ **GitHub.com Fallback** ⚠️