Decision Analysis (Condition-Action and Event-Condition-Action...

29
Fakultät Informatik, Institut für Software- und Multimediatechnik, Lehrstuhl für Softwaretechnologie Decision Analysis (Condition-Action and Event-Condition-Action Analysis) Analysis) Prof. Dr. U. Aßmann Technische Universität Dresden Institut für Software- und Multimediatechnik Gruppe Softwaretechnologie http://st.inf.tu-dresden.de

Transcript of Decision Analysis (Condition-Action and Event-Condition-Action...

Page 1: Decision Analysis (Condition-Action and Event-Condition-Action …st.inf.tu-dresden.de/files/teaching/ss09/stII09/10e... · 2009. 6. 9. · Decision Trees ¾Decisions can be analyzed

Fakultät Informatik, Institut für Software- und Multimediatechnik, Lehrstuhl für Softwaretechnologie

Decision Analysis (Condition-Action and Event-Condition-Action Analysis)Analysis)

Prof. Dr. U. AßmannTechnische Universität DresdenInstitut für Software- und MultimediatechnikGruppe Softwaretechnologiehttp://st.inf.tu-dresden.de

Page 2: Decision Analysis (Condition-Action and Event-Condition-Action …st.inf.tu-dresden.de/files/teaching/ss09/stII09/10e... · 2009. 6. 9. · Decision Trees ¾Decisions can be analyzed

Contents

► Structured decisions: decision diagrams and decision tables

► Binary decision diagrams (BDD)

► Ordered BDD

TU Dresden, 09.06.2009

Sebastian Richly

Folie

2 von 33

Decision Analysis

Page 3: Decision Analysis (Condition-Action and Event-Condition-Action …st.inf.tu-dresden.de/files/teaching/ss09/stII09/10e... · 2009. 6. 9. · Decision Trees ¾Decisions can be analyzed

Obligatory Reading

► Balzert, Kapitel über Entscheidungstabellen► Ghezzi 6.3 Decision-table based testing► Pfleeger 4 4 5 6► Pfleeger 4.4, 5.6

TU Dresden, 09.06.2009

Sebastian Richly

Folie

3 von 33

Decision Analysis

Page 4: Decision Analysis (Condition-Action and Event-Condition-Action …st.inf.tu-dresden.de/files/teaching/ss09/stII09/10e... · 2009. 6. 9. · Decision Trees ¾Decisions can be analyzed

Goal

Event-condition-action- (ECA-)based design relies on condition analysis

Understand how to describe the control flow of methods and Understand how to describe the control-flow of methods and procedures by decision analysisUnderstand that several views on a decision tree exist (tables, BDD, OBDD)OBDD)

Understand that model checking is a technology with future

C diti A ti A l i l b l d f Condition-Action-Analysis can also be employed for requirements analysis

TU Dresden, 09.06.2009

Sebastian Richly

Folie

4 von 33

Decision Analysis

Page 5: Decision Analysis (Condition-Action and Event-Condition-Action …st.inf.tu-dresden.de/files/teaching/ss09/stII09/10e... · 2009. 6. 9. · Decision Trees ¾Decisions can be analyzed

Decision Analysis (Condition-Action Analysis)

TU Dresden, 09.06.2009

Sebastian Richly

Folie

5 von 33

Decision Analysis

Page 6: Decision Analysis (Condition-Action and Event-Condition-Action …st.inf.tu-dresden.de/files/teaching/ss09/stII09/10e... · 2009. 6. 9. · Decision Trees ¾Decisions can be analyzed

A House-Selling Expert System

Ok, I do not like bungalows, but my wife does not like that the car stands in free space in winter. Hmm... I rather would like to have the half double house... But we need anyway 2 floors, because I need this space for my hobbies. My wife also would like a garden….

H d th t l th t i t d ► How does the system analyze the customers requirements and derive appropriate proposals?

TU Dresden, 09.06.2009

Sebastian Richly

Folie

6 von 33

Decision Analysis

Page 7: Decision Analysis (Condition-Action and Event-Condition-Action …st.inf.tu-dresden.de/files/teaching/ss09/stII09/10e... · 2009. 6. 9. · Decision Trees ¾Decisions can be analyzed

Decision Analysis (Condition-Action Analysis)

Is necessary when complex, intertwined decisions should be made that should result in actions

Decision trees and tables collect actions based on conditionsDecision trees and tables collect actions based on conditionsA simple form of event-condition-action (ECA) rulesHowever, without events, only conditions

Which conditions provoke which actions?

TU Dresden, 09.06.2009

Sebastian Richly

Folie

7 von 33

Decision Analysis

Page 8: Decision Analysis (Condition-Action and Event-Condition-Action …st.inf.tu-dresden.de/files/teaching/ss09/stII09/10e... · 2009. 6. 9. · Decision Trees ¾Decisions can be analyzed

Decision Trees

Decisions can be analyzed with a decision tree

A trie (Präfixbaum) is a tree which has an edge marking Every path in the trie assembles a word from a language of the marking Every path in the trie assembles a word from a language of the marking

A trie on lB = {0,1} is called decision treePaths denote sequences of decisions (a set of vectors over lB). A path corresponds to a vector over lBA set of actions, each for one sequence of decisionsSequences of decisions can be represented in a path in the decision tree

ε

0 1

0 1ε

01 10 1100

11

1

0

0

0

A3 A4 A5000 001

10

A1 A2

A3 A4 A5

A1

TU Dresden, 09.06.2009

Sebastian Richly

Folie

8 von 33

Decision Analysis

Page 9: Decision Analysis (Condition-Action and Event-Condition-Action …st.inf.tu-dresden.de/files/teaching/ss09/stII09/10e... · 2009. 6. 9. · Decision Trees ¾Decisions can be analyzed

Decision Trees with Code Actions

► The action may be code

► The inner nodes of same tree layer correspond to a condition E[i] h i i i hi f h l d► Then, a Trie is isomorphic to an If-then-else cascade

if (E0) then // case E0 === true

if (E1) thenif(E2) then A5else A4 0 1

ε E0

else // case E0 === false

if (E1) thenif(E2) then A3

0 1

110 0

E1

E2( )elseif (E3) then A2else A1

000 001

01 10 110010

A3 A4 A5

E2

E3

A1 A2

TU Dresden, 09.06.2009

Sebastian Richly

Folie

9 von 33

Decision Analysis

Page 10: Decision Analysis (Condition-Action and Event-Condition-Action …st.inf.tu-dresden.de/files/teaching/ss09/stII09/10e... · 2009. 6. 9. · Decision Trees ¾Decisions can be analyzed

Decision Tables

► Conditions and actions can be entered in a table

Condition E0 yes yes no no

Condition E1 yes no yes no

Booleancross product

y y

Action A1 X X

Action A2 X X

Multiple choicequadrant

ε E0

0 1

0 1

110 0

E1

01 10 1100

A1 A2 A1 A2

TU Dresden, 09.06.2009

Sebastian Richly

Folie

10 von 33

Decision Analysis

Page 11: Decision Analysis (Condition-Action and Event-Condition-Action …st.inf.tu-dresden.de/files/teaching/ss09/stII09/10e... · 2009. 6. 9. · Decision Trees ¾Decisions can be analyzed

How to Construct A Decision Table

1) Elaborate decisions

2) Elaborate actions

3) Enter into table

4) Construct a cross boolean product as upper right quadrant (set of boolean vectors)

5) Construct a multiple choice quadrant (lower right) by associating actions to boolean vectors

6) Consolidate■ Coalesce yes/no to “doesn’t matter”■ Introduce Else rule

TU Dresden, 09.06.2009

Sebastian Richly

Folie

11 von 33

Decision Analysis

Page 12: Decision Analysis (Condition-Action and Event-Condition-Action …st.inf.tu-dresden.de/files/teaching/ss09/stII09/10e... · 2009. 6. 9. · Decision Trees ¾Decisions can be analyzed

What Students Should Do to Professors After Exams

Points <= 30 yes yes yes yes No No No no

50 < Points yes yes no no yes yes no no

St. Francophil? yes no yes no yes no yes No

Student pays aB d

X XBordeauxProfessor pays aBordeaux

X

Professor pays a XProfessor pays abeer

X

Student pays abeer

X

Professor drinks abeer

X X X

TU Dresden, 09.06.2009

Sebastian Richly

Folie

12 von 33

Decision Analysis

Page 13: Decision Analysis (Condition-Action and Event-Condition-Action …st.inf.tu-dresden.de/files/teaching/ss09/stII09/10e... · 2009. 6. 9. · Decision Trees ¾Decisions can be analyzed

Common Columns Can Be Folded

Points <= 30 yes - yes no no no

50 P i t50 < Points yes no no yes yes no

St. Francophil? - yes no yes no no

Student pays aBordeaux

X

Professor pays aBordeaux

X

Professor pays ab

XbeerStudent pays abeer

X

Professor drinks a X XProfessor drinks abeer

X X

TU Dresden, 09.06.2009

Sebastian Richly

Folie

13 von 33

Decision Analysis

Page 14: Decision Analysis (Condition-Action and Event-Condition-Action …st.inf.tu-dresden.de/files/teaching/ss09/stII09/10e... · 2009. 6. 9. · Decision Trees ¾Decisions can be analyzed

Or Abbreviated to Else Action (Consolidated Decision Table)

Points <= 30 - yes No No Else

50 < Points no no yes yes

Francophil? yes no yes no

Student pays aBordeaux

X

Professor pays aBordeaux

X

Professor pays abeer

XbeerStudent pays abeer

X

Professor drinks a Xbeer

TU Dresden, 09.06.2009

Sebastian Richly

Folie

14 von 33

Decision Analysis

Page 15: Decision Analysis (Condition-Action and Event-Condition-Action …st.inf.tu-dresden.de/files/teaching/ss09/stII09/10e... · 2009. 6. 9. · Decision Trees ¾Decisions can be analyzed

Applications of Decision Tables and Trees

Deciding (decision management)Complex case distinctions (more than 2 decisions)CASE tools can generate code automaticallyCASE tools can generate code automatically

Requirements analysis

Describing the behavior of methods

ibi b i lDescribing business rulesBefore programming if-cascades, better make first a nice decision tree or table

Configuration managementi i d h fi i iDecisions correspond here to configuration variants

Processor=i486?System=linux?Same application as #ifdefs in C preprocessorSame application as #ifdefs in C preprocessor

Formal design methods

TU Dresden, 09.06.2009

Sebastian Richly

Folie

15 von 33

Decision Analysis

Page 16: Decision Analysis (Condition-Action and Event-Condition-Action …st.inf.tu-dresden.de/files/teaching/ss09/stII09/10e... · 2009. 6. 9. · Decision Trees ¾Decisions can be analyzed

Normalizing Control Flow with Normalized BDD

TU Dresden, 09.06.2009

Sebastian Richly

Folie

16 von 33

Decision Analysis

Page 17: Decision Analysis (Condition-Action and Event-Condition-Action …st.inf.tu-dresden.de/files/teaching/ss09/stII09/10e... · 2009. 6. 9. · Decision Trees ¾Decisions can be analyzed

Truth Tables

► Boolean decision tables are truth tables

Condition E0 Yes Yes No No

Condition E1 Yes No Yes No

Value of F = 0 X XValue of F = 0 X X

Value of F = 1 X X

E0 E1 F

Yes Yes 0

Yes No 1

No Yes 0

No No 1

TU Dresden, 09.06.2009

Sebastian Richly

Folie

17 von 33

Decision Analysis

Page 18: Decision Analysis (Condition-Action and Event-Condition-Action …st.inf.tu-dresden.de/files/teaching/ss09/stII09/10e... · 2009. 6. 9. · Decision Trees ¾Decisions can be analyzed

BDDs (Binary Decision Diagrams)

► Are dags that result by merging the same subtrees into one (common subtree elimination)

1ε E0

0 1

0 1

110 0

E1

000 001

01 10 110010

E2

E3000 001

A1 A2 A3

E3

A1 A2 A3

TU Dresden, 09.06.2009

Sebastian Richly

Folie

18 von 33

Decision Analysis

Page 19: Decision Analysis (Condition-Action and Event-Condition-Action …st.inf.tu-dresden.de/files/teaching/ss09/stII09/10e... · 2009. 6. 9. · Decision Trees ¾Decisions can be analyzed

BDDs (Binary Decision Diagrams)

► If the action is just a boolean value boolean functions f: lBn --> lB can be represented

► The decisions E[i] are regarded as boolean variables► The decisions E[i] are regarded as boolean variables

ε E0

0 1

0 1

110

ε E0

E1

01 10 1100

11

1

0

0

0

E2

000 001 E3

0 1

TU Dresden, 09.06.2009

Sebastian Richly

Folie

19 von 33

Decision Analysis

Page 20: Decision Analysis (Condition-Action and Event-Condition-Action …st.inf.tu-dresden.de/files/teaching/ss09/stII09/10e... · 2009. 6. 9. · Decision Trees ¾Decisions can be analyzed

OBDDs (Ordered Binary Decision Diagrams)

Problem: for one boolean function there are many BDDIdea: introduce a standardized order for the variables

l d d bi d i i diResult: orderd binary decision diagrams

In all OBDD holdsfor all children u of parents v ord(u) > ord(v).

For one order of variables there is one normal form OBDD (canonical OBDD)

Leads to efficient comparison algorithm of booleanLeads to efficient comparison algorithm of booleanfunctions:

compareBooleanFunction() = {

Fix variable order for two BDD

Transform both BDD into OBDDTransform both BDD into OBDD

Compare both OBDD syntactically

}

TU Dresden, 09.06.2009

Sebastian Richly

Folie

20 von 33

Decision Analysis

Page 21: Decision Analysis (Condition-Action and Event-Condition-Action …st.inf.tu-dresden.de/files/teaching/ss09/stII09/10e... · 2009. 6. 9. · Decision Trees ¾Decisions can be analyzed

Complex BDD

TU Dresden, 09.06.2009

Sebastian Richly

Decision Analysis Folie

21 von 33

Page 22: Decision Analysis (Condition-Action and Event-Condition-Action …st.inf.tu-dresden.de/files/teaching/ss09/stII09/10e... · 2009. 6. 9. · Decision Trees ¾Decisions can be analyzed

If-cascades, BDD and OBDD

if A then

if B thenif C h l f l

B B0 1

A AB

if C then true else falseelse

if C then false else true

B

C C C

B

C

11

1

0

0

0C

0011 010elseif B then

if C then false else true0 1

1

elseif C then true else false 0 1

A

A

B

C C

B110 0

B

CC C

0 1

C110 0

Variable order is [A B C] 1Variable order is [A,B,C]TU Dresden, 09.06.2009

Sebastian Richly

Folie

22 von 33

Decision Analysis

Page 23: Decision Analysis (Condition-Action and Event-Condition-Action …st.inf.tu-dresden.de/files/teaching/ss09/stII09/10e... · 2009. 6. 9. · Decision Trees ¾Decisions can be analyzed

TU Dresden, 09.06.2009

Sebastian Richly

Decision Analysis Folie

23 von 33

Page 24: Decision Analysis (Condition-Action and Event-Condition-Action …st.inf.tu-dresden.de/files/teaching/ss09/stII09/10e... · 2009. 6. 9. · Decision Trees ¾Decisions can be analyzed

Normalizing Wild Procedures: Normalized If-Structures with OBDD

There is only one canonical OBDD for one orderDevelop normalized and factorized if-structures with it:1 Elaborate arbitrary decision tree1. Elaborate arbitrary decision tree2. Choose a variable order3. Transform to OBDD4. Transform to If structure5. Factor out common subtrees by subprograms

TU Dresden, 09.06.2009

Sebastian Richly

Folie

24 von 33

Decision Analysis

Page 25: Decision Analysis (Condition-Action and Event-Condition-Action …st.inf.tu-dresden.de/files/teaching/ss09/stII09/10e... · 2009. 6. 9. · Decision Trees ¾Decisions can be analyzed

Applications

ReengineeringStructuring of legacy procedures

C fi ti tConfiguration managementDevelopment of canonical versions of C preprocessor nestings

Enormous help to master large systems

TU Dresden, 09.06.2009

Sebastian Richly

Folie

25 von 33

Decision Analysis

Page 26: Decision Analysis (Condition-Action and Event-Condition-Action …st.inf.tu-dresden.de/files/teaching/ss09/stII09/10e... · 2009. 6. 9. · Decision Trees ¾Decisions can be analyzed

Event-Condition-Action Based Design (ECA)

TU Dresden, 09.06.2009

Sebastian Richly

Folie

26 von 33

Decision Analysis

Page 27: Decision Analysis (Condition-Action and Event-Condition-Action …st.inf.tu-dresden.de/files/teaching/ss09/stII09/10e... · 2009. 6. 9. · Decision Trees ¾Decisions can be analyzed

ECA

► An event-condition-action (ECA) system listens on channel(s) for events, analyses a condition, and executes an action Türaction■ Statecharts, ECA rules

Petri Nets■ Condition analysis can

Tür

öffnen()schließen()verriegeln()Co d t o a a ys s ca

be done by BDD ■ Verification by model

checking verriegel

entriegeln(),schließen()/

beep()

entriegeln()

<<Steuerungsmachine>>

abgesperrt

gn/

amp.rotesLichtAn(

)entriegeln/

amp grün

geschlossen

beep()

amp.grünesLichtA

n()schließe

n/amp.gelbesLichtA

öffnen()/-öffnen(),

verriegeln(),

entriegeln()

öffnen,schließen

,verriegeln

/-

n()entriegeln()/- offen

TU Dresden, 09.06.2009

Sebastian Richly

Folie

27 von 33

Decision Analysis

Page 28: Decision Analysis (Condition-Action and Event-Condition-Action …st.inf.tu-dresden.de/files/teaching/ss09/stII09/10e... · 2009. 6. 9. · Decision Trees ¾Decisions can be analyzed

What Have We Learned

► Decision analysis (Condition-Action analysis) is an important analysis

■ to describe requirements, q ,■ to describe complex behavior of a procedure

► The control-flow of a procedure can be normalized with a BDD and OBDD

► Conditions in large state spaces can be encoded in OBDD and efficiently checked

TU Dresden, 09.06.2009

Sebastian Richly

Folie

32 von 33

Decision Analysis

Page 29: Decision Analysis (Condition-Action and Event-Condition-Action …st.inf.tu-dresden.de/files/teaching/ss09/stII09/10e... · 2009. 6. 9. · Decision Trees ¾Decisions can be analyzed

The End

TU Dresden, 09.06.2009

Sebastian Richly

Folie

33 von 33

Decision Analysis