Presentation is loading. Please wait.

Presentation is loading. Please wait.

Automata-Based Programming

Similar presentations


Presentation on theme: "Automata-Based Programming"— Presentation transcript:

1 Automata-Based Programming
General Purpose Finite State Machines Daniela Kolarova

2 Agenda Automata-Based Programming Applications
Finite State Machine Definition Finite State Machine Example FSM Model Simplification FSM Design Approaches What We Achieved …

3 Automata-Based Programming
“A programming technique in which the program or part of it can be thought of as a model of a FSM.” Introduced on a Multiagent systems conference by N. Polikarpova and A. Shalyto (authors of the book “Автоматное программирование”); Warren McCulloch and Walter Pitts, two neurophysiologists, were the first to present a description of finite automata (“A Logical Calculus Immanent in Nervous Activity”); Marvin Minsky – Computation: Finite and Infinite Machines, Prentice-Hall; 2015 Spring StateMachine Framework.

4 Automata-Based Programming Applications
Transformation systems – compilers, archivers; Interactive systems – text editors; Reactive systems – telecommunication systems, hardware controllers;

5 Automata-Based Programming Applications
Finite State Machines in Hardware Programming Language Compilers Workflow Modeling Game Programming State Machines Replication (Implementation of Fault-Tolerant Services)

6 FSM Definition An abstract machine that can be in exactly one of finite number of states at any given time where: The FSM can change from one state to another in response to some external inputs; The change from one state to another is called a transition; A FSM is defined by a list of its states, its initial state, and the conditions for each transition.

7 FSM Model Simplification
Set of States and a defined Start State Set of Inputs Set of Outputs Transition function: Input(I) x State(S) -> State(S') Output function: Input(I) x State(S) -> Output(O) or State(S) -> Output(O)

8 FSM Example: Subway Turnstile SM
State Transition Diagram State Transition Table Locked Unlocked pass/alarm pass/lock coin/unlock coin/thankyou State Event Action Locked pass alarm coin unlock Unlocked lock thankyou

9 FSM Design Approaches Nested Switch/Case Statements
Complex code - hard to understand and change/extend; No separation of FM logic and actions; No way to send data to a specific state; Not thread safe.

10 FSM Design Approaches State Design Pattern: Allows an object to alter its behavior when its internal state changes.

11 FSM Design Approaches State Design Pattern:
Strong separation between actions and the SM Logic; Explicit transitions defined in the states; Distributed logic across states; Tight coupling between state and context.

12 FSM Design Approaches State Transition Table:
Transition logic defined on one place; Adding new transition requires insertion of a row in the table; Efficiency increases if the list is replaced by a Map/HashMap; Readability increases if the construction is implemented via Builder and fluent API; The table defined can easily be validated against the graphically defined one.

13 What We Achieved … Transition logic defined on one place and avoided the traversal of all transitions using a HashMap; Java 8 Features appliade - lambda expressions are optional; Unified Unit testing of all approaches; The Action interface can be used as a wrapper for parallel tasks execution; The example can be easily transformed into a generic state machine and reused.

14 References Polikarpova N. I., Shalyto A. A. Automata-Based programming, Volnei A. Pedroni, Finite State Machines in Hardware Theory and Design (with VHDL and SystemVerilog) Robert C. Martin (2003) Agile Software Development, Principles, Patterns, and Practices 1st Edition, Prentice Halle Erich Gamma, Richard Help, Ralph Johnson, John Vlissides. Design Patterns: Elements of Reusable Object-Oriented Software 1st Edition, Addison-Wesley David Lafreniere, State Machine Design in C++, Dr Dobb's Journal, May 01, 2000, FRED B. SCHNEIDER, Implementing Fault-Tolerant Services Using the State Machine Approach: A Tutorial, Source code with JUnit tests is available at


Download ppt "Automata-Based Programming"

Similar presentations


Ads by Google