Featured post

GetNextWork functionality in pega

What is GetNextWork in pega? Pega provided a functionality to get the most urgent assignment(task) for user to work on. This is configured o...

Rule resolution process in pega

What is Rule resolution process in pega ?

Rule resolution is a search algorithm for pega process commander to find the most appropriate rule instance of a rule to execute in any situation. This is an internal background process of pega rules process commander.
Rule resolution process

What are the inputs for Rule resolution process?

Process commander needs below inputs to perform the rule resolution algorithm and to return best match for the situation.
  1. Rule key  - Apply to class, Rule name and Rule type. Ex:Section CL:TP-Training-Work ID:PHTemplate
  2. User's Ruleset stack(list)
  3. Class inheritance of the current rule's apply to class.
  4. Circumstance (Property and Date).
  5. Rule availability
  6. User's access roles and privileges

How the rule resolution process works ?

When a particular rule is referenced (or need to be executed at runtime) in the application, rule resolution process will first try to locate the instances of that referenced rule in the Rules cache. So the Rule Resolution process will be executed in below two ways. When the

1. Rule instances are found in the Rules cache.
2. Rule instances are not found in the Rules cache.

Rule instances are found in the Rules cache

If the rule resolution was already run for the rule, the rules cache has a list of all possible rule candidates.When the rule instances are found in the rules cache, pega will follow below steps to finalize the rule and execute.
  1. Find rule in the rules cache
  2. Find the best instance and check for duplicates
  3. Confirm the rule is available for use (Availability is not set to Blocked).
  4. Verify the user is authorized to use the rule
Rule resolution process

Rule instances are not found in the Rules cache

When the rule instances are not found in the rule cache, pega runs a sub process (from above flow) to populate rules cache and once cache is populated then it will find the best match by eliminating duplicates and checks the rule availability and verifies if the user is authorized to access the rule.

Populating rules cache

Populate rules cache
  1. Choose all instances with the correct purpose.
  2. Discard rules where Availability = Not Available
  3. Discard inapplicable rulesets and versions.
  4. Discard all candidates not defined in a class in the ancestor tree.
  5. Rank remaining rule candidates.
Ranking rules

  a. Sort the remaining rule candidates.
  b. Remove rule candidates with an Availability set to Withdrawn
  c. Determine default rule candidate.

       6. Set the rules cache.
       7. Find the best instance and check for duplicates.
       8. Confirm the rule is available for use (if the rule Availability is set to Blocked).
       9. Verify the user is authorized to use the rule.
 
We will see two scenarios in detailed and how pega use rule resolution algorithm to find the best instance of a rule. 

1. Rule instances are found in the Rules cache

Let's take a section AllocateBudget in a Service Request case. Section will be displayed after Inspection review has done in Review stage and AllocateBudget section is circumstanced with property "IssueSeverity=High".

rule resolution with example

A Service Request is raised and IssueSeverity is Medium

Find the rule in the rules cache - example

Users ruleset stack:

user ruleset stack

Rule resolution algorithm will follow below steps to find the best match as the instances are found in the rules cache.
Rule resolution steps in pega
  1. Find rule in the rules cache
  2. Find the best instance and check for duplicates
  3. Confirm the rule is available for use (Availability is not set to Blocked).
  4. Verify the user is authorized to use the rule

1.Find the rule in the rules cache.

Pega searches the Rules Cache for a list of all possible rule candidates for the rule "AllocateBudget" section and it founds below three instances.
Find the rule in the rules cache

2. Find the best instance and check for duplicates.

From above three instances pega has to pick one suitable rule accordingly. The best instance will be picked up by pega where the instance matches with a Property or Date circumstance or a Default rule instance if no exact circumstances are found.

When a rule that matches any of these conditions is found, the rule resolution algorithm checks whether the next rule in the list is equally correct. If a subsequent match is found, Pega sends a message that there are duplicate rules and stops processing. If no other matches are found, Pega prepares to use the rule that matched the listed conditions.

In this case the section "AllocateBudget" is circumstanced with Property IssueSeverity="High" but in the case creation user has selected Issue severity as "Medium".
First instance from the list will be skipped as the circumstance is High but pega is looking for Medium (Medium is selected in the Service Request case creation).
Second instance has a date range specified as Before 01 Jul, 2020. The current system date is 17 July 2020 (Case creation date).The date range circumstance is not met, so the rule candidate is skipped and Pega moves to the next rule in the list. 
Third instance does not have a qualifier, so the system selects this rule.

Find the best instance and check for duplicates

3. Confirm the rule is available for use.

In this step Rule resolution algorithm checks for the rule availability, if the rule availability is "Blocked", execution is halted.
From the above list third instance is qualified and the availability is "Available" so the rule is considered available to run.
Confirm the rule is available for use

4.Verify the user is authorized to use the rule.

This is the final step in rule resolution algorithm, in this last step pega checks if the user has authorization to access the rule. It checks if the user has the privileges required by the rule.

In this case rule (section - AllocateBudget) have no privileges so this instance will be selected and executed. 

2. Rule instances are not found in the Rules cache.

Pega uses a caching mechanism called the Rules Cache to help ensure rule resolution operates efficiently. When the rule instances are not found in Rules cache pega uses multiple steps to populate rules cache and determine the best instance to select and execute.
Populate rules cache
In the Populate rules cache process we have below steps:
  1. Choose all instances with the correct purpose.
  2. Discard rules where Availability = Not Available
  3. Discard inapplicable rulesets and versions.
  4. Discard all candidates not defined in a class in the ancestor tree.
  5. Rank remaining rule candidates.
  a. Sort the remaining rule candidates.
  b. Remove rule candidates with an Availability set to Withdrawn
  c. Determine default rule candidate.

1. Choose all instances with the correct purpose.

This is the first step in populate cache process where the rule resolution algorithm generates a list of all rules that match the purpose of the referenced rule (Section - AllocateBudget). 
Purpose of the rule is the combination of Apply to class, rule type and rule name  (TP-Training-Work-ServiceRequest Rule-HTML-Section AllocateBudget) but in this step rule resolution algorithm excludes Apply to class and creates a list with rule type (Rule-HTML-Section) and rule name (AllocateBudget). In this example it creates a list with 23 rules where section name as AllocateBudget. At the end of this cache population process pega will identify the list of rules and put them in rules cache.

S.No

Apply to class

Rule type

Rule name

Availability

Ruleset

Version

Qualifier

1

TP-Training-Work-ServiceRequest

Rule-HTML-Section

AllocateBudget

Not Available

ServiceRequest

02-02-01

 

2

TP-Training-Work-ServiceRequest

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-02-01

 

3

TP-Training-Work-ServiceRequest

Rule-HTML-Section

AllocateBudget

Withdrawn

ServiceRequest

02-01-10

 

4

TP-Training-Work-ServiceRequest

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

 

5

TP-Training-Work-ServiceRequest

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-01

 

6

TP-Training-Work-ServiceRequest

Rule-HTML-Section

AllocateBudget

Blocked

ServiceRequest

01-01-01

 

7

TP-Training-Work-Complaints

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-01

 

8

TP-Training-Work-Complaints

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

01-01-01

 

9

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Not Available

ServiceRequest

02-01-01

 

10

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

 

11

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

Yes (Circumstance)

12

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

Yes (Date)

13

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-01

 

14

TP

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

01-01-01

 

15

TP

Rule-HTML-Section

AllocateBudget

Available

TP

03-01-01

 

16

TP

Rule-HTML-Section

AllocateBudget

Available

TP

02-10-01

 

17

TP

Rule-HTML-Section

AllocateBudget

Available

TP

02-10-01

 

18

TP

Rule-HTML-Section

AllocateBudget

Available

TP

02-01-01

 

19

TP

Rule-HTML-Section

AllocateBudget

Available

TP

01-01-01

 

20

PH-Online-Work-OneHelp

Rule-HTML-Section

AllocateBudget

Available

OneHelp

01-01-06

 

21

PH-Online-Work- OneHelp

Rule-HTML-Section

AllocateBudget

Not Available

OneHelp

02-01-05

 

22

PH-Online-Work

Rule-HTML-Section

AllocateBudget

Available

OneHelp

01-01-01

 

23

PH

Rule-HTML-Section

AllocateBudget

Available

PH

01-01-01

 





















































































2. Discard rules where Availability = Not Available

In this step algorithm will discard and remove the rules where availability is "Not Available". 

From the above list we have 3 rules where availability is set as "Not Available". After removing three rule we have a list with 20 rules.

S.No

Apply to class

Rule type

Rule name

Availability

Ruleset

Version

Qualifier

1

TP-Training-Work-ServiceRequest

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-02-01

 

2

TP-Training-Work-ServiceRequest

Rule-HTML-Section

AllocateBudget

Withdrawn

ServiceRequest

02-01-10

 

3

TP-Training-Work-ServiceRequest

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

 

4

TP-Training-Work-ServiceRequest

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-01

 

5

TP-Training-Work-ServiceRequest

Rule-HTML-Section

AllocateBudget

Blocked

ServiceRequest

01-01-01

 

6

TP-Training-Work-Complaints

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-01

 

7

TP-Training-Work-Complaints

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

01-01-01

 

8

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

 

9

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

Yes (Circumstance)

10

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

Yes (Date)

11

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-01

 

12

TP

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

01-01-01

 

13

TP

Rule-HTML-Section

AllocateBudget

Available

TP

03-01-01

 

14

TP

Rule-HTML-Section

AllocateBudget

Available

TP

02-10-01

 

15

TP

Rule-HTML-Section

AllocateBudget

Available

TP

02-10-01

 

16

TP

Rule-HTML-Section

AllocateBudget

Available

TP

02-01-01

 

17

TP

Rule-HTML-Section

AllocateBudget

Available

TP

01-01-01

 

18

PH-Online-Work-OneHelp

Rule-HTML-Section

AllocateBudget

Available

OneHelp

01-01-06

 

19

PH-Online-Work

Rule-HTML-Section

AllocateBudget

Available

OneHelp

01-01-01

 

20

PH

Rule-HTML-Section

AllocateBudget

Available

PH

01-01-01

 











































































3. Discard inapplicable rulesets and versions.

In this step, rule resolution algorithm uses operator's ruleset list(stack) to determine which rules the operator can access. Below is the Ruleset stack for the operator and operator has ServiceRequest:02-01 and TP:03-01 rulesets in the stack.
ruleset list

  • Each rule in the lit must belong to a ruleset in the operators ruleset list.
  • Each rule's ruleset Major version must have the same as the operator's ruleset Major version.
  • Each rule's Minor version less than or equal to the specified Minor version number listed in the operator's ruleset list.
  • Rulestes which are not there in the Operators ruleset stack will be eliminated. In this example OneHelp and PH rulesets are not listed in the operator's ruleset list.
After considering operator's ruleset list and above points, rule resolution have identified below 11 rules which are not satisfying the conditions and will be eliminated from the list.

1

TP-Training-Work-ServiceRequest

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-02-01

 

5

TP-Training-Work-ServiceRequest

Rule-HTML-Section

AllocateBudget

Blocked

ServiceRequest

01-01-01

 


7

TP-Training-Work-Complaints

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

01-01-01

 



12

TP

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

01-01-01

 





14

TP

Rule-HTML-Section

AllocateBudget

Available

TP

02-10-01

 

15

TP

Rule-HTML-Section

AllocateBudget

Available

TP

02-10-01

 

16

TP

Rule-HTML-Section

AllocateBudget

Available

TP

02-01-01

 

17

TP

Rule-HTML-Section

AllocateBudget

Available

TP

01-01-01

 

18

PH-Online-Work-OneHelp

Rule-HTML-Section

AllocateBudget

Available

OneHelp

01-01-06

 

19

PH-Online-Work

Rule-HTML-Section

AllocateBudget

Available

OneHelp

01-01-01

 

20

PH

Rule-HTML-Section

AllocateBudget

Available

PH

01-01-01

 


















After eliminating above 11 rules which are not satisfied with the conditions we have 9 rules in the list.

S.No

Apply to class

Rule type

Rule name

Availability

Ruleset

Version

Qualifier

1

TP-Training-Work-ServiceRequest

Rule-HTML-Section

AllocateBudget

Withdrawn

ServiceRequest

02-01-10

 

2

TP-Training-Work-ServiceRequest

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

 

3

TP-Training-Work-ServiceRequest

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-01

 

4

TP-Training-Work-Complaints

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-01

 

5

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

 

6

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

Yes (Circumstance)

7

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

Yes (Date)

8

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-01

 

9

TP

Rule-HTML-Section

AllocateBudget

Available

TP

03-01-01

 






























4. Discard all candidates not defined in a class in the ancestor tree.

In this step, algorithm uses Ancestor tree which is nothing but Rule's inheritance. Algorithm examines rule's (Here rule is Section -AllocateBudget) Apply To class (TP-Training-Work-ServiceRequest) to determine if the rules from above list are there in the inheritance hierarchy of the referenced rule (section in this case). 

From the above list of 9 rules, algorithm identified 1 rule which is not there in the inheritance path.

Below rule's Apply to class is not there in the ancestor tree of the referenced rule.

4

TP-Training-Work-Complaints

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-01

 




after removing disqualified rule we have 8 rules in the list as shown below.

S.No

Apply to class

Rule type

Rule name

Availability

Ruleset

Version

Qualifier

1

TP-Training-Work-ServiceRequest

Rule-HTML-Section

AllocateBudget

Withdrawn

ServiceRequest

02-01-10

 

2

TP-Training-Work-ServiceRequest

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

 

3

TP-Training-Work-ServiceRequest

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-01

 

4

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

 

5

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

Yes (Circumstance)

6

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

Yes (Date)

7

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-01

 

8

TP

Rule-HTML-Section

AllocateBudget

Available

TP

03-01-01

 























5. Rank remaining rule candidates.

In this step, algorithm uses a sub-process to rank the remaining candidates by using below three steps.
Ranking rules
          A. Sort the remaining rule candidates.
  B. Remove rule candidates with an Availability set to Withdrawn
  C. Determine default rule candidate.

A.Sort the remaining rule candidates.

In this step, algorithm sorts the remaining rules in this specific order.
  • Class
  • Ruleset
  • Circumstance
  • Circumstance Date
  • Data/time Range
  • Version

Class - If the Apply to class of the rule from the remaining list is closer to the referenced rule's apply to class then it will be ranked higher.

Ruleset - Within each class, rules are sorted according to the operators ruleset stack.

Circumstance, Circumstance Date and Date/time range - are used as qualifiers to further refine the rules.

Version - Lastly rules are sorted with the ruleset versions to ensure circumstanced rules are not overridden if the base rule is updated recently.

After considering the above criteria, algorithm sorts the remaining rules as shown below. Row number 4 from above list will comes after row number 5.

S.No

Apply to class

Rule type

Rule name

Availability

Ruleset

Version

Qualifier

1

TP-Training-Work-ServiceRequest

Rule-HTML-Section

AllocateBudget

Withdrawn

ServiceRequest

02-01-10

 

2

TP-Training-Work-ServiceRequest

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

 

3

TP-Training-Work-ServiceRequest

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-01

 

4

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

Yes (Circumstance)

5

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

Yes (Date)

6

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

 

7

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-01

 

8

TP

Rule-HTML-Section

AllocateBudget

Available

TP

03-01-01

 
























B. Remove rule candidates with an Availability set to Withdrawn

One we have the sorting order, algorithm removes the rules where availability is withdrawn.

If the rule availability is "Withdrawn" indicates that Withdrawn version and below (lower) versions of the same rule (same rule type, name and class) will not be selected during rule resolution process.

From above list, rule (row number 1) in 02-01-10 is Withdrawn, so current version and lower versions of same type, name and class will be removed. In this example row numbers 1,2 and 3 are removed from the list.

S.No

Apply to class

Rule type

Rule name

Availability

Ruleset

Version

Qualifier

1

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

Yes (Circumstance)

2

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

Yes (Date)

3

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

 

4

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-01

 

5

TP

Rule-HTML-Section

AllocateBudget

Available

TP

03-01-01

 
















C. Determine default rule candidate.

In this last step of ranking process, algorithm determines default rule.

Default rule is the first rule from the list without any qualifiers (any circumstances). After identifying the default rule, algorithm removes the rules below the Default rule from the list.

In this example, Row number 3 which is there in ServiceRequest:02-01-05 is the default rule and row numbers 4 and 5 will be removed from the list.

S.No

Apply to class

Rule type

Rule name

Availability

Ruleset

Version

Qualifier

1

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

Yes (Circumstance)

2

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

Yes (Date)

3

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

 











6. Set the rules cache

After Ranking process has done, algorithm sets the remaining rules into the rules cache. In this scenario, finally we have 3 rules in the rules cache.

Algorithm successfully Populated rules cache, now algorithm uses below steps to finalize the rule, select and execute from the rules cache (already explained above as part of Rule instances are found in the Rules cache).

  1. Find rule in the rules cache
  2. Find the best instance and check for duplicates
  3. Confirm the rule is available for use (Availability is not set to Blocked).
  4. Verify the user is authorized to use the rule

Happy Learning 😃 Share with others. Sharing is Learning 😄



5 comments:

  1. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. Glad..it helped you. Hope you will like other posts as well. Share with others.

      Delete
  2. Thanks for the detailed explanation. Kudos to your team for the great effort.

    ReplyDelete
  3. Thanks a lot for such a clear explanations

    ReplyDelete