An alternative to finite state machines - PowerPoint PPT Presentation

About This Presentation
Title:

An alternative to finite state machines

Description:

natural graphical notation doesn't scale well (& textual version isn't fun) very moded (OK for most small ITs, not good ... Just kidding. 53. Implementing PPS ... – PowerPoint PPT presentation

Number of Views:92
Avg rating:3.0/5.0
Slides: 56
Provided by: ScottH104
Learn more at: http://www.cs.cmu.edu
Category:

less

Transcript and Presenter's Notes

Title: An alternative to finite state machines


1
An alternative to finite state machines
2
Drawbacks of FSMs
  • FSMs offer a lot of advantages, but
  • natural graphical notation doesnt scale well (
    textual version isnt fun)
  • very moded (OK for most small ITs, not good for
    larger things)
  • Hard to deal with independent state information
    (cross product problem)

3
Cross product example
  • Suppose we wanted a handle that moved up and down

4
Whats the right FSM controller?
  • Assume simple (snap) feedback
  • Ignore actions for now

5
Whats the right FSM controller?
  • Assume simple (snap) feedback
  • Ignore actions for now

6
Now suppose we wanted a clutched handle
  • Clutch is a toggle button
  • Handle only moves when clutch is in
  • What would clutch machine look like?

7
FSM controller for clutch
8
FSM controller for clutch
9
Putting these together
  • Need a cross-product machine
  • Merge first and last state of the handle machine,
    with the enabled state of the clutch machine
  • (Analysis to figure out how to do this in general
    is tricky)

10
The cross product machine
11
The cross product machine
12
The cross product machine
  • A mess
  • state explosion (this is a simple one)

13
State explosion
  • It gets worse
  • Suppose we have N things that have to all happen
    once, but we dont care what order
  • good UI gt dont impose unnecessary sequencing
  • Best we can do is 2N states!

14
What do we do about this?
  • Could look at sets of independent FSMs running in
    parallel
  • But interactions arent completely independent
  • E.g. Doesnt hands all-of-N problem

15
Propositional Production Systems
  • AKA PPS
  • Computationally equiv to FSM
  • but looks very different
  • states encoded implicitly
  • does cross-product implicitly at RT
  • exponential of states transitions in linear
    sized spec
  • can do all-of-N in size O(N) spec

16
PPS
  • Primary concept field
  • gets used in several ways
  • basically a category
  • Each field has a set of conditions that it may be
    in
  • values the field may have

17
PPS Fields
  • color black, white, red
  • size small, medium, large
  • Conditions from a field make up a fixed finite
    set
  • an enumeration
  • doesnt allow e.g., integers (simple extension to
    do this)
  • fields have an initial condition value

18
Kinds of PPS fields
  • Several kinds of PPS fields
  • State Info fields
  • normal fields
  • Each independent part of system encoded in one
    field
  • current state of system is indicated by the
    values across all the fields
  • (this is how we solve the cross-product problem)

19
State info field examples
  • clutch eng, part_eng, part_diseng, diseng

20
State info field examples
  • clutch eng, part_eng, part_diseng, diseng

21
State info field examples
  • clutch eng, part_eng, part_diseng, diseng
  • lever up, part_up, part_dn, dn

22
State info field examples
  • clutch eng, part_eng, part_diseng, diseng
  • lever up, part_up, part_dn, dn

23
Another kind of field input fields
  • Serve the role of events
  • One for each type of event
  • use bullet () to distinguish input field
    condition names
  • input mouse_down, mouse_up, mouse_move,
    keypress,

24
Another kind of field input fields
  • Additional fields for other info in event
  • cntrlkey cntrl, nocontrl
  • shiftkey shift, noshift
  • leftbtn leftup, leftdn
  • Small issue here with not having integers
    location time

25
More parts of PPS
  • Can do basic PPS with state info and input fields
  • will see other types in a bit
  • Second major part of PPS
  • productions
  • serves role of transitions
  • how state changes based on current state and input

26
Productions
  • Form
  • ltlist of conditionsgt ? ltlist of conditionsgt
  • Think of as
  • ltpre-conditionsgt ? ltpost-conditionsgt
  • ltantecedentgt ? ltconsequencegt
  • if you find ltthisgt to be true, make the system be
    like ltthatgt
  • LHS may have state info input
  • RHS may only have state info

27
An example the clutched lever
  • What are the state info fields?
  • What are the input fields?

28
An example the clutched lever
  • handle_state up, part_up, part_dn, dn
  • input press_top, press_clutch, press_bottom,
    press_other, release_top, release_clutch,
    release_bottom, release_other, enter_bottom,
    enter_top

29
Productions for the lever
Release_any
Enter_bottom
Press_top
Press_bottom
Enter_top
Release_any
30
Productions for the lever
Release_any
Enter_bottom
Press_top
  • up, press_top ? part_up
  • part_up, enter_bottom ? part_dn
  • part_up, release_top ? up
  • part_up, release_clutch ? up
  • part_up, release_bottom ? up
  • part_up, release_other ? up

Press_bottom
Enter_top
Release_any
31
Productions for the lever
Release_any
Enter_bottom
Press_top
Press_bottom
Enter_top
Release_any
32
Productions for the lever
  • part_dn, release_top ? dn
  • part_dn, release_clutch ? dn
  • part_dn, release_bottom ? dn
  • part_dn, release_none ? dn
  • part_dn, enter_top ? part_up

Release_any
Enter_bottom
Press_top
Press_bottom
Enter_top
Release_any
33
Productions for the lever
Release_any
Enter_bottom
Press_top
Press_bottom
Enter_top
Release_any
34
Productions for the lever
  • dn, press_bottom ? part_dn

Release_any
Enter_bottom
Press_top
Press_bottom
Enter_top
Release_any
35
Productions for the lever
  • up, press_top ? part_up
  • part_up, enter_bottom ? part_dn
  • part_up, release_top ? up
  • part_up, release_clutch ? up
  • part_up, release_bottom ? up
  • part_up, release_other ? up
  • part_dn, release_top ? dn
  • part_dn, release_clutch ? dn
  • part_dn, release_bottom ? dn
  • part_dn, release_none ? dn
  • part_dn, enter_top ? part_up
  • dn, press_bottom ? part_dn

36
Now the clutch part
  • clutch eng, part_eng, part_diseng, diseng

37
Clutch transitions
  • One each of the form
  • state, event ? new-state

38
Putting this together with the clutch
  • Just bunch the productions together!
  • Well not quite.
  • Whats the problem?

39
Putting this together with the clutch
  • Just bunch the productions together!
  • Well not quite.
  • Whats the problem?
  • Not completely independent
  • extra conditions
  • can only move the handle when the clutch is in

40
Putting this together with the clutch
  • Put productions together, then add conditions
    under which the parts affect each other
  • only move handle when clutch eng
  • was up, press_top ? part_up
  • now

41
Putting this together with the clutch
  • Put productions together, then add conditions
    under which the parts affect each other
  • only move handle when clutch eng
  • was up, press_top ? part_up
  • now up, press_top, eng ? part_up
  • etc. for others

42
Note the big advantage of PPS
  • Independent aspects are easier in PPS
  • write them independently
  • add just the connections (typically extra
    conditions)
  • dont have to replicate anything

43
Note
  • We did these examples as translation from FSM
  • After you get familiar it may be better to start
    in PPS
  • Some things are easier to express
  • e.g., all-of-N

44
All-of-N interaction
  • N1 n1_done, n1_not
  • N2 n2_done, n2_not
  • ...
  • state running, done
  • ltsomethinggt ? n1_done // or add n1 to LHS of
    existing
  • ltsomethinggt ? n2_done
  • n1_done, n2_done, ? done

45
What about actions?
  • Handled with an additional kind of field Action
    Field
  • names prefixed with !
  • can only be on RHS

46
Action field examples
  • feedback_actions !show_clutch_in,
    !slow_clutch_out, !show_hand_top, !show_hand_mid,
    !show_hand_bot, !show_grinding,
    !show_not_grinding,
  • Have
  • up, press_top, eng ? part_up
  • Change how?

47
Action field examples
  • feedback_actions !show_clutch_in,
    !slow_clutch_out, !show_hand_top, !show_hand_mid,
    !show_hand_bot, !show_grinding,
    !show_not_grinding,
  • up, press_top, eng ? part_up, !show_hand_mid,
    !show_not_grinding
  • up, press_top, diseng ? up, !show_hand_mid,
    !show_grinding
  • etc.

48
Other field types query fields
  • Predicate over some arbitrary (outside) condition
  • Only on LHS
  • Prefix names with ?
  • This is how we deal with no ints
  • position ?in_clutch, ?in_top, , ?in_none
  • Also semantic tests
  • password_auth ?pw_ok, ?pw_bad

49
Other field types External events
  • Basically just like input events, but from the
    rest of the system
  • prefix with gt
  • reactor_alarm gtnormal, gtwarm, gthot, gtmeltdown
  • Can only appear on which side?

50
Other field types External events
  • Basically just like input events, but from the
    rest of the system
  • prefix with gt
  • reactor_core gtnormal, gtwarm, gthot, gtmeltdown
  • Can only appear on LHS

51
Implementing PPS
  • Project 4
  • due 10/14 at midnight

52
Implementing PPS
  • Just kidding

53
Implementing PPS
  • Wont talk about the details, but straight
    forward implementation
  • only a little more complex that FSM
  • includes things like only execute queries when
    you have to, etc.

54
PPS summary
  • Same power as FSM (what you can do in one, can do
    in other)
  • Deals with cross-product issue
  • independent parts makes it easier to do fewer
    modes
  • generally easier expression
  • But lost FSM graphical notation
  • didnt scale to large things anyway

55
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com