1 / 21

3.1.1 Fundamentals of Problem Solving

AQA Computing COMP1. 3.1.1 Fundamentals of Problem Solving. Finite State Machines Denise Landau 2013. What is a Finite State Machine?.

kourtney
Download Presentation

3.1.1 Fundamentals of Problem Solving

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. AQA Computing COMP1 3.1.1 Fundamentals of Problem Solving Finite State Machines Denise Landau 2013

  2. What is a Finite State Machine? A state machine is any device that stores the status of something at a given time, and can operate on input to change the status and/or cause to take place for any given change. It consists of: states, input, and outputs • Suitable for controlling processes that react to local conditions only. • The machine is in only one state at a time – the current state. • It can change from one state to another when initiated by a triggering event or condition – the transition. • Have limited memory – which is limited by the number of states.

  3. Mealy Machine Mealy machine is a finite-state machine whose output values are determined both by its current state and the current inputs The Mealy machine is named after George H. Mealy, who presented the concept in a 1955 paper, “A Method for Synthesizing Sequential Circuits”. This is in contrast to a Moore machine, which is an FSM whose output values are determined solely by its current state.

  4. Mealy Machine • A simple Mealy machine has one input and one output. • More complex Mealy machines can have multiple inputs as well as multiple outputs. • Mealy machines provide a rudimentary mathematical model for cipher machines - a Mealy machine can be designed that given a string of letters (a sequence of inputs) can process it into a ciphered string (a sequence of outputs

  5. Examples of FSM • Vending machines (dispense products when the proper combination of coins is deposited) • Lifts (stop at the upper floors before going down) • Traffic lights (change sequence when cars are waiting) • Combination locks (numbers must be input in the right order) • Protocols and communication systems (WLAN, Bluetooth, 3G, 4G) • Satellites critical systems – modelled, implemented or tested using FSM KEYWORD: Automation

  6. Finite State Machines with Outputs • When an FSM produces a response when making a transition, this is an output.

  7. Finite State Machines without Outputs • An FSM without outputs is called a Finite State Automaton (FSA)

  8. Extension – Stretch and Challenge TCP has been modelled using an Extended FSM 1- Always remembers the current state in the variable (CurrState) and the previous state in the variable (PrevState) 2- The TCP endpoint has unlimited buffer space (e.g., buffer space to queue SENDs and RECEIVEs is always available) 3- In any state, whenever a segment is sent, the segment is added to the Retransmission Queue (Rexmt Queue) and the retransmission timer (REXMT) is started. 4- The (REXMT TIMEOUT) event has been modeled in all states except (FIN-WAIT-2, TIME-WAIT, CLOSED), since in these states the endpoint have already received an ACK of its FIN segment (i.e., will not transmit any segments afterwards). 5- The (TIMEWAIT TIMEOUT) event has been modeled in (TIME-WAIT) state only. In all other states, this timer is irrelevant. Follow this link for more information: http://www.lisha.ufsc.br/teaching/dos/ine5357-2009-1/work/g2/final/TR2005-07-22-tcp-EFSM.pdf

  9. State Transition Diagrams 1. Each state is represented with a circle • You must be able to draw and interpret simple state transition diagrams • A finite state machine expressed visually is a State transition diagram • Shows all the states, inputs and outputs. • Not all FSMs will have an accept states and it is possible they could run for ever 3. Double circle signifies the accept state. 2. Each transition is shown with an arrow. Transitions are labelled with an input that causes a transition and possibly an output that results from it.

  10. State Transition Diagrams In this diagram we can see that it starts in state S1 An input of 1 will keep it in state one 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: A finite state automaton (no outputs) accepting binary input 110011001 001110011

  11. State Transition Diagrams 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.

  12. State Transition Diagrams 110011011 Try: You will be stuck in state S2 and the FSM has not accepted. The rules: An input of 1 will keep it in state one 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.

  13. State Transition Diagrams- Exercise Which of these inputs are valid: • aaacdb • ababacdaaac • abcdb • acda • acdbdb

  14. Exercise Answer Answer : • aaacdb (CORRECT) • ababacdaaac(CORRECT) • abcdb (ERROR no input that accepts b then c) • acda (ERROR S1 is not a accepting state) • ac (CORRECT)

  15. State Transition Tables • You must be able to draw and interpret simple state transition tables • A state transition table is a table showing what state (or states ) finite state machine will move to, based on the current state and other inputs. • It is essentially a truth table in which some of the inputs are the current state, and the outputs include the next state, along with other outputs.

  16. Exercise Create a state transition table for the following FSM:

  17. Exercise Answer

  18. Example: Turnstile A turnstile, used to control access to subways and amusement park rides, is a gate with three rotating arms at waist height, one across the entryway. Initially the arms are locked, barring the entry, preventing customers from passing through. Depositing a coin or token in a slot on the turnstile unlocks the arms, allowing a single customer to push through. After the customer passes through, the arms are locked again until another coin is inserted. State diagram for a turnstile Considered as a state machine, the turnstile has two states: Locked and Unlocked.[2]

  19. Example: Turnstile There are two inputs that affect its state: putting a coin in the slot (coin) and pushing the arm (push). In the locked state, pushing on the arm has no effect; no matter how many times the input push is given, it stays in the locked state. Putting a coin in – that is, giving the machine a coin input – shifts the state from Locked to Unlocked. In the unlocked state, putting additional coins in has no effect; that is, giving additional coin inputs does not change the state. However, a customer pushing through the arms, giving a push input, shifts the state back to Locked.

  20. Example: Turnstile The turnstile state machine can be represented by a state transition table, showing for each state the new state and the output (action) resulting from each input

  21. References http://www.swisseduc.ch/compscience/ http://www.swisseduc.ch/compscience/karatojava/docs/programming_general_education.pdf https://en.wikibooks.org/wiki/A-level_Computing/AQA/Problem_Solving,_Programming,_Data_Representation_and_Practical_Exercise/Problem_Solving/Finite_state_machines

More Related