2 Replies Latest reply: Jan 23, 2013 6:00 AM by Ben Rogers RSS

    How rules are executed?

    Rajan.Panchal
      How the rule engine decides which rules to execute in a very complex rulebase? what is the pattern?
        • 1. Re: How rules are executed?
          SnehalS
          OPA does not follow any pattern for executing the rule base. You can't predict what rule may be executed when.

          Cheers,
          Snehal
          • 2. Re: How rules are executed?
            Ben Rogers
            When OPA builds the rulebase, it takes all of the compiled rules and sorts them into an optimised order.

            It does this so that all of the rules can be executed in a highly efficient linear left-to-right sweep. This is all explained in the following Oracle Whitepaper - "Linear Inferencing - High Performance Processing". Page 2 is the most relevant:

            http://www.oracle.com/us/industries/public-sector/029743.pdf

            Have a look at this diagram.

            When the value of an attribute is changed, it triggers an inferencing cycle. OPA knows the structure of the rulebase, so it knows that by changing attribute X then it also affects rule Y and Z.


            So for example:

            A is true if
            ...B is true and
            ...C is true

            D is true if
            ...B is true


            B is used in the rule A and D.
            By setting B, the inferencing cycle will see if A is now known, and D is now known.

            You can do this yourself by doing visual browsers of B.

            Here are some useful help articles about this:

            Inferencing Cycle:

            http://docs.oracle.com/html/E27987_01/Content/Introducing%20Oracle%20Policy%20Modeling/Deter_Engine_and_infer_cycle.htm

            Rule structure and dependencies:

            http://docs.oracle.com/html/E27987_01/Content/Finding%20and%20reporting/Check_rule_structure_and_dependencies.htm

            So... you could predict which attributes will be set next when base attribute(s) have been changed. You can do this by looking at the structure of the rulebase and seeing which inferred attributes (via rules) are set when the base attribute is changed.
            Do a visual browser on a base attribute and "generate influenced rules"... effectively by doing this you are forward-chaining and that is what the Engine will do once a base attribute is changed.

            Try this out in the debugger. Set a base attribute to a different value, and you will see the forward chaining impact ... all of the changed attributes from this cycle will be highlighted in a green background in the debugger...You could check this matches your "prediction" from the visual browser file...

            Hope this helps... let me know if this is not clear.