Title: An alternative to finite state machines
1An alternative to finite state machines
2Drawbacks 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)
3Cross product example
- Suppose we wanted a handle that moved up and down
4Whats the right FSM controller?
- Assume simple (snap) feedback
- Ignore actions for now
5Whats the right FSM controller?
- Assume simple (snap) feedback
- Ignore actions for now
6Now suppose we wanted a clutched handle
- Clutch is a toggle button
- Handle only moves when clutch is in
- What would clutch machine look like?
7FSM controller for clutch
8FSM controller for clutch
9Putting 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)
10The cross product machine
11The cross product machine
12The cross product machine
- A mess
- state explosion (this is a simple one)
13State 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!
14What 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
15Propositional 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
16PPS
- 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
17PPS 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
18Kinds 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)
19State info field examples
- clutch eng, part_eng, part_diseng, diseng
20State info field examples
- clutch eng, part_eng, part_diseng, diseng
21State info field examples
- clutch eng, part_eng, part_diseng, diseng
- lever up, part_up, part_dn, dn
22State info field examples
- clutch eng, part_eng, part_diseng, diseng
- lever up, part_up, part_dn, dn
23Another 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,
24Another 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
25More 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
26Productions
- 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
27An example the clutched lever
- What are the state info fields?
- What are the input fields?
28An 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
29Productions for the lever
Release_any
Enter_bottom
Press_top
Press_bottom
Enter_top
Release_any
30Productions 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
31Productions for the lever
Release_any
Enter_bottom
Press_top
Press_bottom
Enter_top
Release_any
32Productions 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
33Productions for the lever
Release_any
Enter_bottom
Press_top
Press_bottom
Enter_top
Release_any
34Productions for the lever
- dn, press_bottom ? part_dn
Release_any
Enter_bottom
Press_top
Press_bottom
Enter_top
Release_any
35Productions 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
36Now the clutch part
- clutch eng, part_eng, part_diseng, diseng
37Clutch transitions
- One each of the form
- state, event ? new-state
38Putting this together with the clutch
- Just bunch the productions together!
- Well not quite.
- Whats the problem?
39Putting 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
40Putting 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
41Putting 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
42Note 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
43Note
- 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
44All-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
45What about actions?
- Handled with an additional kind of field Action
Field - names prefixed with !
- can only be on RHS
46Action 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?
47Action 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.
48Other 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
49Other 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?
50Other 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
51Implementing PPS
- Project 4
- due 10/14 at midnight
52Implementing PPS
53Implementing 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.
54PPS 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)