Vous êtes sur la page 1sur 14

Decision tables

Decision tables are compact and precise ways of modelling complicated logic, such
as that which you might use in a computer program. They do this by mapping the
different states of a program to an action that a program should perform. Decision
tables take on the following format:

The four quadrants


Conditio
ns

Condition
alternatives

Actions

Action entries

The limited-entry decision table is the simplest to describe. The condition


alternatives are simple Boolean values, and the action entries are check-marks,
representing which of the actions in a given column are to be performed.
A technical support company writes a decision table to diagnose printer problems
based upon symptoms described to them over the phone from their clients. They
type the following data into the advice program:
1. Printer does print
2. Red light is flashing
3. Printer is recognised
The program then uses the decision table to find the correct actions to perform,
namely that of Check / Replace ink.

Printer troubleshooter

Rules

Conditio
ns

Printer does not print

Y Y Y Y N N N N

A red light is flashing

Y Y N N Y Y N N

Printer is unrecognised

Y N Y N Y N Y N

Check the power cable

Actions

Check the printer-computer


cable

Ensure printer software is


installed

Check/replace ink

X X

Check for paper jam

X X

Example: Decision Tables


Let's take a look at a computer game example, for a football simulation the following
rules are set up.
Rules
Conditio
ns

90 minutes

Y Y

Team A
Winning

Team B
Winning

Y Y

Draw

Actions

Game Over

Team A Wins

Team B Wins

Extra Time

Keep Playing

X X

What happens when:


1. 90 minutes up
2. the game is a draw
Answer: Keep Playing and give them some extra time
Exercise: Decision Tables
Create a decision table for the following program in an office email system

Send email when Recipient address present, subject present, before 5:30pm

If after 5:30pm then put in pending folder

If Recipient address missing or subject message, give warning message

[Collapse]
Answer :
This question is open to interpretation, but you should have something resembling
this:
Rules
Conditio
ns

Address
Present

Y Y

Actions

Subject
Present

Before 5:30

Y Y Y

Send Mail

Error
Message

Y Y

X X

Make
pending

Describe the use of Decision Tables


[Collapse]
Answer :
Determine logical conditions and consequential actions.

Finite state machines

Example of a simple finite state machine


p = start state
a = transition
q = accept state
A finite state machine consists of states, inputs and outputs. The number of states
is fixed; when an input is executed, the state is changed and an output is possibly
produced. Finite state machines are widely used when designing computer
programs, but also have their uses in engineering, biology, linguistics and other
sciences thanks to their ability to recognise sequences.
A finite state machine expressed visually is a State transition diagram. It is used
to show all the states, inputs and outputs. Each state is represented with a circle,
and each transition with an arrow. Transitions are labelled with an input that causes
a transition and possibly an output that results from it. A double circle signifies the

accept state. Not all FSMs will have an accepting state and it is possible they could
run forever.
A finite state machine can be with or without outputs:
Finite state automaton
Finite State Automaton - an FSM with no outputs

A finite state automata accepting binary input


Looking at the above diagram we can see that it starts in state S1, an input of 1 will
keep it in state one, and an input of 0 will move it to state S2. Once in S2 an input of
1 will keep it there, and an input of 0 will switch it back to S1. This means that the
following inputs are valid:
110011001
001110011
It might appear to accept any binary value, but this isn't true. The only state it can
accept in is state S1. This places the following rule on all accepted inputs: "A
combination of binary digits involving an even number of zeros". This is useful for
parity checks. If I try the following:
110011011
I am stuck in state S2 and the FSM has not accepted. Can you create a FSM to only
accept Binary numbers with odd numbers of 1s?
Exercise: Finite State Automaton

For the FSM above which of these inputs are valid:


1. aaacdb
2. ababacdaaac
3. abcdb
4. acda
5. acdbdb
[Collapse]
Answer :
1. aaacdb (CORRECT)
2. ababacdaaac(CORRECT)
3. abcdb (ERROR no input that accepts b then c)
4. acda (ERROR S1 is not a accepting state)
5. acdbdb (CORRECT)

For the FSM above which of these inputs are valid:


1. 987654321+994-0
2. 5-5+2*4
3. 9+8+7+6+5+4+3+2+1
4. 0+1+2+1+
5. 99+88-77
[Collapse]
Answer :
1. 987654321+994-0 (CORRECT)
2. 5-5+2*4 (ERROR no input *)
3. 9+8+7+6+5+4+3+2+1 (CORRECT)
4. 0+1+2+1+ (ERROR S3 is not a accepting state)
5. 99+88-77 (CORRECT)
Draw a finite state automata that will accept the word Banana whilst using only 3
states
[Collapse]
Answer :

Draw a finite state automata that will accept the words:

Tim

Grit

Grrrrrim

[Collapse]
Answer :

Mealy Machines
Mealy Machine - an FSM with outputs
Some FSMs output values dependant on the state and the input values:

The above Mealy Machine outputs a value for each input. You can tell which is which
by: input / ouput. So for the following input:
000101010
It outputs
000010101

Shifting all the bits right, and dividing the binary number input by two.
Exercise: Mealy Machines

For the Mealy machine above, what do the following inputs output:
1. 50
2. 20,10,20
3. 10,10,10,20
What does this machine do, what do the outputs tell you?
[Collapse]
Answer :
1. 0
2. 30,20,0
3. 40,30,20,0
This machine could be used to track the money going into a vending machine,
letting you know how much you have left to pay on a 50p chocolate bar
What is the difference between a mealy machine and a finite state automaton?
[Collapse]
Answer :

mealy machines output values

finite state automata do not

Extension: non-determinism
In this section we are learning about deterministic finite automaton. This means that
for a state and a valid input there is only one possible transition to take. There are
such things a nondeterministic finite automaton where, for a given input there are
multiple paths (or none) that could be taken:

In state p, for input 1 there are two possible transitions


State transition tables
A state transition table follows every state and input. Inputs are usually placed on
the left, and separated from the outputs, which are on the right. Here's a simple
example of a state machine with two states, and a binary input:

Inp Current
ut State

Next
State

Outp
ut

S1

S2

null

S1

S1

null

S2

S1

null

S2

S3

null

Exercise: State transition tables


Create a state transition table for the following FSM:

[Collapse]
Answer :
Inp Current
ut State

Next
State

Outp
ut

S1

S2

null

S1

S1

null

S2

S1

null

S2

S2

null

Create a state transition table for the following FSM:

[Collapse]
Answer :
Inp Current
ut State

Next
State

Outp
ut

S0

S2

S0

S1

S1

S2

S1

S1

S2

S2

S2

S1

Draw the FSM for the following state transition table:


Next
State

Outp
ut

Timer Green

Green

null

Butto
Green
n

Yellow

null

Timer Yellow

Red

null

Timer Red

Green

null

Input

Current
State

[Collapse]
Answer :

You might have already cottoned on. This represents a traffic light system
Draw the FSM for the following state transition table:
Inp Current
ut State

Next
State

Outp
ut

q0

q0

null

q0

q1

null

q1

q2

null

q1

q1

null

q2

q1

null

q2

q1

null

[Collapse]
Answer :

Vous aimerez peut-être aussi