25
1 CHAPTER 10 Decision Tables

1 Decision Tables. 2 Introduction construction Types of Decision Tables Limited Entry Extended Entry Combining of Rules General Rule Q

Embed Size (px)

Citation preview

Page 1: 1 Decision Tables. 2  Introduction  construction  Types of Decision Tables  Limited Entry  Extended Entry  Combining of Rules  General Rule  Q

1

CHAPTER 10Decision Tables

Page 2: 1 Decision Tables. 2  Introduction  construction  Types of Decision Tables  Limited Entry  Extended Entry  Combining of Rules  General Rule  Q

2

Content Introduction construction Types of Decision Tables

Limited Entry Extended Entry

Combining of Rules General Rule Q & A

Page 3: 1 Decision Tables. 2  Introduction  construction  Types of Decision Tables  Limited Entry  Extended Entry  Combining of Rules  General Rule  Q

3

Introduction Some programs require solution using

multiple decisions to produce the correct output.

This can be a difficult task as this is not always readily apparent

Decision Tables is a problem-analysis tool used to solved complex decision logic

Decision tables offer a complete, concise and logical way of relating combinations of actions to combinations of conditions

Page 4: 1 Decision Tables. 2  Introduction  construction  Types of Decision Tables  Limited Entry  Extended Entry  Combining of Rules  General Rule  Q

4

Introduction all appropriate conditions must be

satisfied before the conclusion is drawn and the specified action or actions taken

The basic concept of the decision table is therefore the IF…and IF…THEN… relationship.

Decision Table is constructed before

flow chart or structure chart is drawn

Page 5: 1 Decision Tables. 2  Introduction  construction  Types of Decision Tables  Limited Entry  Extended Entry  Combining of Rules  General Rule  Q

5

Construction

The four basic elements of the decision table are known as: The condition stub The condition

entries/rules The action stub The action entries

Condition stub

Condition entries

Action stub

Action entries

Decision Tables Quadrants

Page 6: 1 Decision Tables. 2  Introduction  construction  Types of Decision Tables  Limited Entry  Extended Entry  Combining of Rules  General Rule  Q

6

Construction The condition stub describe the

conditions to be tested Condition entries describes the

possible combination of Boolean values (Yes/No or simply Y/N) for the conditions

The action stub contains possible actions based on the conditions

and action entries describe the actions to be taken which correspond to each Boolean value of each condition.

Page 7: 1 Decision Tables. 2  Introduction  construction  Types of Decision Tables  Limited Entry  Extended Entry  Combining of Rules  General Rule  Q

7

Construction Steps

1. List all possible conditions 2. Determine how many possible

Boolean values combinations/rules. Since each condition has 2

outcomes (T/F), therefore the number of rules is determined by

2n where n is the number of conditionse.g. with 3 conditions, there must be 6

rules - boolean columns

3. List all possible actions4. For each rule, select the

appropriate action/s. Indicate with ‘X’ or tick.

Page 8: 1 Decision Tables. 2  Introduction  construction  Types of Decision Tables  Limited Entry  Extended Entry  Combining of Rules  General Rule  Q

8

Example Consider the following simple logical

situation If it is cold and wet, I will take my

sweater and umbrella. If it is cold, I will take my

sweater. If it is wet, I will take my

umbrella. If it is neither cold nor wet, I will

take neither.

Page 9: 1 Decision Tables. 2  Introduction  construction  Types of Decision Tables  Limited Entry  Extended Entry  Combining of Rules  General Rule  Q

9

Example of construction STEP 1 : List all possible conditions

1. Is it cold?2. Is it wet?

STEP 2 : Determine how many possible Boolean values combinations/rules

Conditions - 2 Thus rules = 22 , which is 4

Page 10: 1 Decision Tables. 2  Introduction  construction  Types of Decision Tables  Limited Entry  Extended Entry  Combining of Rules  General Rule  Q

10

Example of construction

State of weather Rule 1 Rule 2 Rule 3 Rule 4

YesYes

YesNo

NoYes

NoNo

Condition entriesCondition stub

Is it cold?Is it wet?

Page 11: 1 Decision Tables. 2  Introduction  construction  Types of Decision Tables  Limited Entry  Extended Entry  Combining of Rules  General Rule  Q

11

Example of construction STEP 3 : List all possible actions

1. Take sweater2. Take umbrella3. Take neither

Page 12: 1 Decision Tables. 2  Introduction  construction  Types of Decision Tables  Limited Entry  Extended Entry  Combining of Rules  General Rule  Q

12

Example of construction

STEP 4 : For each rule, select the appropriate action/s indicated by ‘X’ or tick. The situation is expressed in a decision table as follows:

State of weather Rule 1 Rule 2 Rule 3 Rule 4

Is it cold?Is it wet?

YesYes

YesNo

NoYes

NoNo

Take sweaterTake umbrellaTake neither

Action stub Action entries

Page 13: 1 Decision Tables. 2  Introduction  construction  Types of Decision Tables  Limited Entry  Extended Entry  Combining of Rules  General Rule  Q

13

Types of Decision Tables 2 Types:-

Limited Entry Table Extended Entry Table

Page 14: 1 Decision Tables. 2  Introduction  construction  Types of Decision Tables  Limited Entry  Extended Entry  Combining of Rules  General Rule  Q

14

Limited Entry Table expresses each condition in the

condition stub as a question which can be answered ‘Yes’ or ‘No’ (2 states) – indicated by Y/N

If condition is inapplicable for any particular rule, entry is indicated by a dash/blank

The number of condition rules required is determine by the formula 2n

Page 15: 1 Decision Tables. 2  Introduction  construction  Types of Decision Tables  Limited Entry  Extended Entry  Combining of Rules  General Rule  Q

15

Example Determine the rate of discount allowed and

whether or not there is free delivery according to the purchaser and/or type of purchase. If the goods are assumed to be televisions with either 23 or 29 inches screens, dealers being approved or non-approved and the sets themselves being either walnut or plastic finish, solve the problem using a decision table if:1. Non-approved dealers are allowed 5% discount.2. Approved dealers are allowed –

a. free delivery on 29 inch setsb. 25% discount on 29 inch walnutc. 20% on other sets

Page 16: 1 Decision Tables. 2  Introduction  construction  Types of Decision Tables  Limited Entry  Extended Entry  Combining of Rules  General Rule  Q

16

Solution

DiscountRule

1Rule

2Rule

3Rule

4Rule

5Rule

6Rule

7Rule

8

Approved dealer? Y Y Y Y N N N N

Walnut finish? Y Y N N Y Y N N

29” screen? Y N Y N Y N Y N

5% discount X X X X

20% discount X X X

25% discount X

Free delivery X X

Page 17: 1 Decision Tables. 2  Introduction  construction  Types of Decision Tables  Limited Entry  Extended Entry  Combining of Rules  General Rule  Q

17

Extended Entry Tables Also known as Mixed Entry Table. Used when the condition entry contains

not a straight forward ‘Yes’ or ‘No’ answer

For example, a condition might be ‘DIRECTION’ and the condition entries ‘North’, ‘South’, ‘East’ and ‘West’.

Page 18: 1 Decision Tables. 2  Introduction  construction  Types of Decision Tables  Limited Entry  Extended Entry  Combining of Rules  General Rule  Q

18

Extended Entry Tables The number of condition rules

required is determine by the multiplying the number of outcome of each conditions.

E.g. condition1 has 2 outcome (Y/N) condition2 has 3 outcome

(100,200,300) condition3 has 2 outcome (Y/N)

Therefore no. of rules required 2x3x2 = 12 rules

Page 19: 1 Decision Tables. 2  Introduction  construction  Types of Decision Tables  Limited Entry  Extended Entry  Combining of Rules  General Rule  Q

19

Example An order will be approved if a

guarantee is available and credit is $100, or if there is no guarantee but credit is $200 in which case special clearance does not apply, or if credit is $100, there is no guarantee and special clearance is given, or if credit is $300, there is no guarantee and no special clearance. If there is no guarantee, credit is $100 and special clearance is not given, the order is not approved and is returned to the client.

Page 20: 1 Decision Tables. 2  Introduction  construction  Types of Decision Tables  Limited Entry  Extended Entry  Combining of Rules  General Rule  Q

20

solution

Order approval

1 2 3 4 5 6 7 8 9 10 11 12

Guarantee? Y Y Y Y Y Y N N N N N N

Credit? 100 200 300 100 200 300 100 200 300 100 200 300

Specialclearance?

Y N Y N Y N Y N Y N Y N

Pass X X X X

Return X

Page 21: 1 Decision Tables. 2  Introduction  construction  Types of Decision Tables  Limited Entry  Extended Entry  Combining of Rules  General Rule  Q

21

General Rules of combining rules If, for any combination of rules, the

condition entries are identical except for one row and the action entries are also identical, the two rules can be combined, a dash being inserted in place of the conditions which are not the same .

Page 22: 1 Decision Tables. 2  Introduction  construction  Types of Decision Tables  Limited Entry  Extended Entry  Combining of Rules  General Rule  Q

22

Combining of Rules

It is possible to combine rules if they are having the same actions.

E.g. If it is cold or wet, I will take my jacket

Weather 1 Rule 1 Rule 2 Rule 3 Rule 4

Is it cold?Is it wet?

YesYes

YesNo

NoYes

NoNo

Take jacketTake nothing

X X XX

Page 23: 1 Decision Tables. 2  Introduction  construction  Types of Decision Tables  Limited Entry  Extended Entry  Combining of Rules  General Rule  Q

23

Combination of rules

It will be noted that for rules 1 and 2 in which the status of the first condition is Yes, the status of the second is immaterial. The action to be taken is the same whether the answer is Yes or No. This is indicated by a dash.

The new table will be:

Weather 2 Rule 1 Rule 2 Rule 3

Is it cold?Is it wet?

Yes-

NoYes

NoNo

Take jacketTake nothing

X XX

Page 24: 1 Decision Tables. 2  Introduction  construction  Types of Decision Tables  Limited Entry  Extended Entry  Combining of Rules  General Rule  Q

24

Combination of rules

The new table for the problem on “Discount” is: Discount Rule 1 Rule 2 Rule 3 Rule 4

Approved dealer? Y Y Y N

Walnut finish? Y - N N

29” screen? Y N Y N

5% discount X

20% discount X X

25% discount X

Free delivery X X

Page 25: 1 Decision Tables. 2  Introduction  construction  Types of Decision Tables  Limited Entry  Extended Entry  Combining of Rules  General Rule  Q

25

Class Exercise – Create a decision table for the following problem:

A carpenter needs a program that computes the price of any desk a customer orders based on the following input fields; order number, desk length in inches and width in inches (3 digits each, no decimals), type of wood (assumed valid type is entered), and a number of drawers (2 digits). The price is computed as follows:

1. The charge for all desk minimum is $2002. If the surface area is over 750 sq. in., add $503. If the wood is “mahogany” add $150; for “oak”

add $125. No charge is added for “pine”4. For every drawer in the desk, there is an

additional $30 charge