An Introduction to Statecharts Modelling and Simulation Simon







































- Slides: 39
An Introduction to Statecharts Modelling and Simulation Simon Van Mierlo simon. vanmierlo@uantwerpen. be Hans Vangheluwe hans. vangheluwe@uantwerpen. be
Complex Systems • Complexity: timed, autonomous, reactive (to events) behaviour. • In contrast to transformational systems, which take input and, eventually, produce output.
Modelling Reactive Systems • Interaction with the environment: reactive to events. l ve e l w • Autonomous behaviour: timeouts. ” o l w o o o h t “ s. i s ) v S ” O • Describe system with modes (hierarchical) and concurrent units. t a d h n w (a “ : e g m a s i u l • Use programming language + threads and timeouts (OS)? g a n m a l r o g f n i e t m a i r m a“Nontrivial psoftware written with threads, semaphores, and r o g r o p p Pr a t s 1 o mutexes are incomprehensible to humans” m -> 1 E. A. Lee, "The problem with threads, " in Computer, vol. 39, no. 5, pp. 33 -42, May 2006.
Discrete-Event Abstraction
Statecharts • Visual (topological, not geometric) formalism. • Precisely defined syntax and semantics. • Many uses: • • • Documentation (for human communication) Analysis (of behavioural properties) Simulation Code synthesis … and derived, such as testing, optimization, …
Statecharts History • Introduced by David Harel in 19871 • Notation based on higraphs = graphs combined with Venn diagrams • Semantics extend deterministic finite state automata with: • • • Depth (Hierarchy) Orthogonality Broadcast Communication Time History Syntactic sugar, such as enter/exit actions 2 David Harel, Statecharts: a visual formalism for complex systems, Science of Computer Programming, Volume 8, Issue 3, 1987, Pages 231 -274
Running Example Controller input (Physical) Plant <<observe>> output <<act>> Environment
Deployment (Simulated) Plant (Physical) Plant Controller system input system output 1 Environment <<observe>> <<act>> 2
Workflow 3 Hans Vangheluwe and Ghislain C. Vansteenkiste. A multi-paradigm modeling and simulation methodology: Formalisms and languages. In European Simulation Symposium (ESS), pages 168 -172. Society for Computer Simulation International (SCS), October 1996. Genoa, Italy. 4 FTG+PM: An Integrated Framework for Investigating Model Transformation Chains, Levi Lu cio, Sadaf Mustafiz, Joachim Denil, Hans Vangheluwe, Maris Jukss. System Design Languages Forum (SDL) 2013, Montreal, Quebec. LNCS Volume 7916, pp 182 -202, 2013.
Requirements • R 1: Three differently colored lights: red, green, yellow. • R 2: At most one light is on at any point in time. • R 3: Initially, the red light is on. • R 4: Cycles through red on, green on, and yellow on. 5 s 3 s 2 s • R 5: Duration: Red -> 60 s, Green -> 50 s, Yellow -> 10 s • R 6: Police can interrupt autonomous operation. • Result = blinking yellow light (on -> 1 s, off -> 1 s). • R 7: Police can resume an interrupted traffic light. • Result = light which was on at time of interrupt is turned on again.
Workflow
States • R 1: Three differently colored lights: red, green, yellow. • R 2: At most one light is on at any point in time. ff, Y: o ff, f} : of : o f, G of , Y: on {R: {R on } } : off G , n Y: o ff, {R: o G : (Simulated) Plant <<observe>> Environment
Default State • R 1: Three differently colored lights: red, green, yellow. • R 2: At most one light is on at any point in time. • R 3: Initially, the red light is on. ff, Y: o ff, f} : of : o f, G of , Y: on {R: {R on } ff} o : G n, Y: o ff, {R: o G : (Simulated) Plant <<observe>> Environment
Transitions • • • R 1: Three differently colored lights: red, green, yellow. R 2: At most one light is on at any point in time. R 3: Initially, the red light is on. R 4: Cycles through red on, green on, and yellow on. R 5: Duration: Red -> 5 s, Green -> 3 s, Yellow -> 2 s ff, Y: o ff, f} : of : o f, G of , Y: on {R: {R on } ff} o : G n, Y: o ff, {R: o G : event(params) [guard] / output_action(params) (Simulated) Plant <<observe>> Environment
Yakindu 1: Modelling 5 https: //www. itemis. com/en/yakindu/state-machine/
Workflow
Yakindu: Simulation
Workflow
Hierarchy • R 6: Police can interrupt autonomous operation. • Result = blinking yellow light (on -> 1 s, off -> 1 s). • R 7: Police can resume an interrupted traffic light. Semantics/Meaning? FLATTEN
Statemate, Yakindu, … Hierarchy: Modified Example Semantics/Meaning? (unwanted) non-determinism! FLATTEN determinism! Rhapsody, …
Yakindu: Hierarchy
History • R 7: Police can resume an interrupted traffic light. • Result = light which was on at time of interrupt is turned on again. H shallow history H* deep history
Yakindu: History
Concurrency Semantics/Meaning? FLATTEN
Workflow
Yakindu: Simulation
Workflow
Statecharts Testing Generator System Under Study 6 Zeigler BP. Theory of modelling and simulation. New York: Wiley-Interscience, 1976. Acceptor 7 Mamadou K. Traoré, Alexandre Muzy, Capturing the dual relationship between simulation models and their context, Simulation Modelling Practice and Theory, Volume 14, Issue 2, February 2006, Pages 126 -142
Orthogonal Components (White-Box)
Workflow
Yakindu: Testing
Yakindu: Testing Interface Callback Synchronization
Yakindu: Testing
Workflow
Code Generation interrupts events Interface: • set. Red(boolean) • set. Green(boolean) • set. Yellow(boolean) Interface: • in event police
Sample Generated Code Files Ø 8 files Ø 1311 lines of code Ø 302 manual (UI) code
Interface Setup Code Generator Runner
Deployed Application
Recap • Model the behaviour of complex, timed, reactive, autonomous systems. • “What” instead of “How” (= implemented by Statecharts compiler) • Abstractions: • • States (composite, orthogonal) Transitions Timeouts Events • Tool support: • Yakindu • SCCD 8 8 Simon Van Mierlo, Yentl Van Tendeloo, Bart Meyers, Joeri Exelmans, and Hans Vangheluwe. SCCD: SCXML extended with class diagrams. In 3 rd Workshop on Engineering Interactive Systems with SCXML, part of EICS 2016, 2016.