Download presentation
Presentation is loading. Please wait.
Published byChristine Parrish Modified over 9 years ago
2
Modeling and Design of Rule-Based Systems Yonglei Tao
3
Key Takeaway Points Business rules are decision-making rules each consists of conditions and actions to perform when the conditions are met. A decision table is used to specify business rules check complete, consistent, and non-redundant generate code support test-case generation and test-driven development enable rules to be updated dynamically 2
4
Business Rules of an Office Worker 10% Pay Raise Promotion Own Office Stay Quit 1234 Y x Y Y x Y - - x NN N 41 1 N N - x 2 Rule Count Decision Table 10% Pay Raise Promotion Own Office Stay Quit Y N Y Y Stay N N Quit Decision Tree 3
5
Decision Table Terminology 10% Pay Raise Promotion Own Office Stay Quit 1234 Y x Y Y x Y - - x NN N 41 1 N N - x 2 Rule Count Decision Table condition stubs condition entry action stubs For checking completeness 4+1+1+2 = 2 3 =8 rule number action entry indifference or don’t care 4
6
Limited and Extended Entry customer rules covered request pay OK order Rule# 1 >2m - 3 X 2 <=2m 3 X reg. 12 due payment X 4 X new 1 no 5 X 2 <=2m new/ NR not new Extended entry decision table: non-binary. conditions extend into condition entries. 10% Pay Raise Promotion Own Office Stay Quit 1234 Y x Y Y x Y - - x NN N 41 1 N N - x 2 Rule Count Limited entry decision table 5
7
Systematic Decision Table Construction 1. Identify conditions that affect actions 2. Identify actions that are affected by conditions 3. Draw a table with appropriate rows and columns 4. Enter the conditions and actions into the condition stubs and action stubs 5. Systematically enter the condition values in the condition entries 6. For each condition combination, check the corresponding action(s). If the actions must be performed in a certain order, use serial numbers to indicate the order 6
8
Systematic Decision Table Construction 10% Pay Raise Promotion Own Office Stay Quit 1234 Y x Y N x N Y Y YY Y 11 1 Y N N 1 Rule Count 5678 N x Y N x N Y Y x NN Y 11 1 N N N x 1 xx 7
9
Progressive Decision Table Construction Enter the conditions one at a time and completes a rule as early as possible promoted work interest 10% raise own office stay quite Y N N N N Y YY 8
10
Progressive Decision Table Construction 1) Draw a table of required rows and columns 2) Enter the actions into the action stubs. Stay Quit Rule Count Rule # 9
11
Progressive Decision Table Construction 3) Enter one of the conditions into condition stub and one of the condition value into the condition entry. Save the remaining values. Promotion 1 Y Remaining Values Stay Quit Rule Count Rule # N 10
12
Progressive Decision Table Construction 4) If the rule can lead to an action then enter “-” in the remaining conditions check the appropriate action entries begin a new rule: copy all the condition entries of the previous rule except the last condition enter one of the remaining values of the last condition Promotion 1 Y Remaining Values Stay Quit Rule Count Rule # N 11
13
Progressive Decision Table Construction else enter another condition and one of its values save the remaining values >=10% Raise Y N Promotion 1 Y Remaining Values Stay Quit Rule Count Rule # N 12
14
Progressive Decision Table Construction 5) Repeat the above step promoted work interest 10% raise own office stay quite Y N N N N Y YY >=10% Raise Y N Promotion 1 Y Remaining Values Stay Quit Rule Count Rule # N X -- 2 Y N X 3 N Y N Work Interest Y N -- X 4 N Y N Own Office Y N X 5 N Y N N X 13
15
Quality Aspect of Decision Table Completeness are there missing rules? check by the rule count are there missing conditions or actions? application dependent Consistency is there more than one rule with the same condition combination but different actions? does a rule have conflicting actions? Non-redundancy can/should some rules be eliminated or merged? 14
16
Rule# Rule Count Stay Quit 10% raise Y X promotedY 1 Y N X 2 N Y - - Y X 3 work interest N Y N X Y 4 --- own office 42141 2 11 N Y N X N 5 N N Y X - 6 N N N X Y 7 N N N X N 8 Are there redundancies in the decision table? What problems can be caused by redundancy? Is there a systematic way to detect and remove redundancies? Decision Table Redundancy 15
17
Decision Table Redundancy Problems can cause inconsistency if one place is modified and the other is not, or modified differently the code is more tedious and more difficult to understand and maintain Benefits to removal shorter and more efficient code code is easier to comprehend will not cause redundancy related inconsistency Removing decision table redundancies is called “decision table consolidation.” 16
18
Decision Table Consolidation Rule# Rule Count Stay Quit 10% raise Y X promotedY 1 Y N X 2 N Y - - Y X 3 work interest N Y N X Y 4 --- own office 42141 2 11 N Y N X N 5 N N Y X - 6 N N N X Y 7 N N N X N 8 rule 4: !promoted & 10% raise & !work interest & own office ==> stay rule 7: !promoted & !10% raise & !work interest & own office ==> stay 17
19
Decision Table Consolidation rules 4+7: (!promoted & !work interest & own office) ==> stay Rule# Rule Count Stay Quit 10% raise Y X promotedY 1 Y N X 2 N Y - - Y X 3 work interest N Y N X Y 4 --- own office 42141 2 11 N Y N X N 5 N N Y X - 6 N N N X Y 7 N N N X N 8 Rule# Rule Count Stay Quit 10% raise Y X promotedY 1 Y N X 2 N Y - - Y X 3 work interest N -- N X Y 4 --- own office 42241 2 1 N Y N X N 5 N N Y X - 6 N N N X N 8 Rule 7 deleted. Rule 4 changed. 18
20
Decision Table Consolidation Rule# Rule Count Stay Quit 10% raise Y X promotedY 1 Y N X 2 N Y - - Y X 3 work interest N -- N X Y 4 --- own office 42241 2 1 N Y N X N 5 N N Y X - 6 N N N X N 8 Rules 5 and 8 differ on only one condition. So they can be merged. Rule# Rule Count Stay Quit 10% raise Y X promotedY 1 Y N X 2 N Y - - Y X 3 work interest N -- N X Y 4 --- own office 42242 2 N -- N X N 5 N N Y X - 6 Rule 8 deleted and rule 5 changed. 19
21
Consolidation Algorithm 2 or more unmarked rules differ on only 1 condition? 1 of the rules has “-” for that condition? delete the other rules Halt Do the rules include all cases for that condition? replace the rules with 1 that has “-” for that condition Y Y Y N N N mark the rules as visited 20
22
Consolidation Algorithm Decision Table >2 or more unmarked rules differ on 1 condition? 1 of the rules has “-” for condition? the rules include all cases for condition? Rule Count delete the other rules replace rules with one with “-” for condition go to this decision table halt Rule # 12 34 Y YY Y Y N N N N -- X X X X X X 21 14 21
23
Code Generation from Decision Table First, arrange the rows and columns so that the condition rows have increasing frequencies of alternating condition values Draw a tree to highlight the alternating columns >1 rule differ on 1 condition? 1 of the rules has “-” for condition? the rules include all cases for condition? Rule Count delete the other rules replace rules with one with “-” for condition go to this decision table halt Rule # 12 3 4 Y YY Y Y N N N N -- X X X X X X 21 1 4 22
24
Code Generation >1 rule differ on 1 condition? 1 of the rules has “-” for condition? the rules include all cases for condition? Rule Count delete the other rules replace rules with one with “-” for condition go to this decision table halt Rule # 12 3 4 Y YY Y Y N N N N -- X X X X X X 21 1 4 while (true) do if (not >1 rule differ on 1 condition) then break else if (1 of the rules has “--” for the condition) then delete the other rules else if (the rules include all cases) then replace rules with one with “--” for that condition end 23
25
Test Case Generation Decision tables are commonly used to generate test cases for cause-effect testing Each rule is a test case identify the component under test initialize the input with appropriate condition values check the output of the actions Support unit testing and system testing 24
26
Decision Tree >1 rule differ on 1 condition? Y N Halt 1 of the rules has “-” for condition? Y N the rules include all cases for condition? Y replace rules with one with “-” for condition; go to this table delete the other rules go to this table N Decision tree is another method to specify process logic. 25
27
Class Exercise Using the consolidation algorithm decision table, consolidate the following decision table. More than $1M business/yr? Good payment history? With us more than 10 years? Priority treatment Normal treatment 1234 Y x Y N x N Y Y YY Y 11 1 Y N N 1 Rule Count 5678 N x Y N x N Y Y x NN Y 11 1 N N N x 1 x x 26
28
Competition of Telephone Companies In the 1990s, U.S. telephone companies (AT&T, MCI, GTE) competed for customers intensively They offered discount plans to attract customers Each new plan required modification of conditional statements of the computer program It required a lot of time to change, compile, test and debug the computer program One company adopted a technology that gave it a competitive advantage The technology is an application of the interpreter patterninterpreter pattern 27
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.