I am looking for an algorithm to detect redundant rules.
Rules have a fixed number of input parameters and each parameter has a distinct domain.
Consider three rule parameters Color, Material and Size:
- Color: Red, Green, Blue
- Material: Wood, Glass, Aluminium
- Size: Small, Medium, Large
Each rule can match on multiple values of a parameter or match on any value. The first rule that matches all parameters values is selected. There are no negation rules, but the domain is fixed, so a negation can be achieved by added all others.
+--------------------------------------------------++-----------------
| Rule Parameters || Rule Action
+----------------+------------------+--------------++-----------------
| Color | Material | Size || ==> Price
+----------------+------------------+--------------++-----------------
Rule 1 | Red | Wood, Glass | Large || $100
Rule 2 | Red | Aluminium | Large || $200
Rule 3 | Blue or Green | Wood | Medium || $300
Rule 4 | Red | ** Any ** | Large || $400 <== Redundant
Rule 5 | ** Any ** | ** Any ** | ** Any ** || $500
Rule 4 is redundant due to a combination of Rule 1 and 2. A redundant rule is a rule that will never be matched due to (a combination) of rules defined before that rule. The rule action is not evaluated in the redundancy check.
How to implement this efficiently (in Java)? It should support 1000 rules with 10 parameters with 100 values each. The rules, parameters and parameter values are read from a database (ie. they cannot be hard-coded).
The issue with efficiency is that there are 100^10 combinations of input parameters (each parameter has a domain of 100 values). The algorithm is needed in the rule editor gui, to support the user that is creating the rules. It should find all redundant rules within seconds.
GITHUB
I've created a repository to test proposed solutions: https://github.com/qlp/redundant-rules Currently only a BDD implementation, which is failing with a problem of this size. Maybe my BDD implementation can be improved?