Graph Transformation and Software Technology Chapter 1

Proc (A4) ; if [product available] then Proc(A5) else Proc(A8) … receive order ; ... using two simple rules: delete isolated nodes remove successive.
505KB taille 4 téléchargements 292 vues
Graph Transformation and Software Technology Chapter 1: Motivation Reiko Heckel Software Technology Group

Outline Why it is fun „ Where it comes from „ What it is good for „

„

Concept of the course

Why it is fun: Programming By Example StageCast (www.stagecast.com): a visual programming environment for kids (from 8 years on), based on behavioral rules associated to graphical objects … visual pattern matching … simple internal control structures (priority, sequence, nondeterminism, ...) … external keyboard control …

Î

Rule-based behavior modeling is a natural and intuitive paradigm!

Example: A simple PacMan game; concrete (StageCast) vs. abstract (graph-based) presentation.

States of the PacMan Game: Graph-Based Presentation :Ghost :Field

:Field

:Field

:Field

:Field

:PacMan marbles=3 :Marble

:Field

instance graph (represents a single state; abstracts from spatial layout)

typing

Ghost *

cardinalities (specify additional constraints on well-typed instance graphs)

1

Field 1 * Marble

1 *

PacMan marbles:int

type graph (specifies legal instance graphs Æ state space)

Rules of the PacMan Game: Graph-Based Presentation, PacMan pm:PacMan marbles=m

:Marble

f1:Field

f2:Field

pm:PacMan f1:Field

pm:PacMan marbles=m+1

collect f1:Field

pm:PacMan

movePM f2:Field

f2:Field

f1:Field

f2:Field

PacMan’s rules: collect has priority over movePM

Rules of the PacMan Game: Graph-Based Presentation, Ghost g:Ghost

:PacMan

f1:Field

f2:Field

g:Ghost f1:Field

g:Ghost

kill f1:Field

g:Ghost

moveGhost f2:Field

f2:Field

f1:Field

f2:Field

Ghost’s rules: kill has priority over moveGhost

Graph Transformation :Field

:Ghost

:Field

:Field

:Field

:Field

:PacMan marbles=3 marbles=4 :Marble

:Field

typing

Ghost *

1

Field 1 * Marble

1 *

PacMan marbles:int

collect ; kill

Where it all comes from … Chomsky Grammars

Term Rewriting

Petri Nets

Graph Transformation and Graph Grammars

Chomsky Grammars: Transforming Strings Production A Æ aAb as graph grammar production (represents path expression anbn) 2:

A

3:

1:

a

2:

A

3:

b

4:

Graph grammars: formal language theory for graphical structures … Language

hierarchies (e.g. what are context free graph grammars, and how useful can they be) … Decidability and complexity results … Parsing algorithms

Petri Nets: Transforming (Multi-) Sets A PT net transition as graph transformation rule A

2 C

B

a1:A a2:A

b1:B

b2:B

c:C

Graph transformation: modeling and analysis of concurrent systems … Relation

with Petri nets (use of analysis tools, transfer of concepts) … Independence, causality, and conflicts of rules … Semantics of concurrency

Term Rewriting: Transforming Trees or DAGs Term rewrite rules (directed equations): … …

x*0Æ0 x * s(y) Æ (x * y) + x

Transformation of trees or directed acyclic graphs (DAGs)? or

Graph rewriting: efficient implementation of equational

deduction (in functional programming, code optimization in compiler and DBMS) … …

Relation with term rewriting Termination and confluence

.. and what it is good for Chomsky Grammars

Term Rewriting

Petri Nets

Graph Transformation and Graph Grammars

Diagram Languages

Graph-based Computation

Model and Program Transformation

9

Behaviour Modelling and Visual Programming

Graph-based Language Definition Example: activity diagrams compiled to imperative program, in two phases 1. 2.

Parse diagram (cf. compiler front-end) Generate CSP (cf. compiler back-end)

Analyze Model: Context-Free Graph Grammar Concrete Syntax of Well-Formed Activity Diagrams

Start Graph:

Act

Productions in EBNF-like notation: in

in

in [not c]

[c]

in

Act Act

Act

::=

Act

do something

Act out

out

out

out

Parsing 0 receive order

check availability

4

2

[product available]

[product not available]

calculate prize notify client

1

3

6

8 send receipt

7

5

Generate Semantic Representation: Pair Grammar Source: well-formed

A:Act

activity diagrams

Target: prog. lang. in

in

in [not c]

[c]

Prog(A) in

A1:Act A:Act

A1:Act

::=

A2:Act

do something

A2:Act out

Prog(A)

out ::=

Prog(A1) ; Prog(A2)

out if [c] then Prog(A1) else Prog(A2)

out

do something

Generating Prog(A0)

0 receive order

Prog(A1) ; Prog(A2) … Prog(A3) ; Proc (A4) ;

if [product available] then Proc(A5) else Proc(A8) … receive order ; check availability ; if [product available] then calculate prize; send receipt else notify client

check availability

4

2

[product available]

[product not available]

calculate prize notify client

1

3

6

8 send receipt

7

5

.. and what it is good for Chomsky Grammars

Term Rewriting

Petri Nets

Graph Transformation and Graph Grammars

9 Diagram

Languages

Graph-based Computation

Model and Program Transformation

9 Behaviour

Modelling and Visual Programming

Model (and Program) Transformation „

Explain statechart in terms of equivalent finite automaton

new auction offer something auction running

make bid

make bid no bid

some bid timeout

Flattening Rule: Incoming Transition

s1

a

s2 b s3

s1

a

s2 b s3

Transition from state s1 to the boundary of a complex state represents a transition from s1 to the initial state of the complex state

Flattening Rule: Outgoing Transitions

s1

s2 a

b s3

a

s2 b

s1 a

s3

Transition from boundary of complex state to state s1 represents corresponding transitions from all substates to s1

.. and what it is good for Chomsky Grammars

Term Rewriting

Petri Nets

Graph Transformation and Graph Grammars

9 Diagram Languages

9 Graph-based Computation

Model and Program Transformation

9 Behaviour Modelling and Visual Programming

Bridges of Königsberg (Euler 1736)

„

walk across each of the bridges exactly once, returning to the starting place

Euler Graph „

contains only nodes with even numbers of links

„

can be reduced to a loop

using two simple rules:

remove successive pair of links



delete isolated nodes

Chinese Postman (Kwan 1962)

„

travel across each link to deliver mail, but minimize the amount of additional walking

Eulerization „

add links between pairs of nodes with an odd number of links each x

x+1

if x and y are odd, add link in between y

„

y+1

Graph is Eulerian as soon as rule is no longer applicable

Application in Software Engineering: Model-Based Testing

„

Test a web site by following each link at least once, but minimize additional navigation

.. and what it is good for Chomsky Grammars

Tree Transformations

Petri Nets

Graph Transformation and Graph Grammars

9

9

Graph-based Language Definition

Graph-based Computation

9 Model and Program Transformation

9 Behaviour Modelling and Visual Programming

The Message „

Graphs are everywhere: they provide representations for many real-world and computer science problems … Program

states … Diagrams … City maps …… „

Graph transformation rules are the most natural way to model the manipulation of graphs

Concept of the Course Application-oriented mix …Foundations …Theory …Applications …Tools

For example Ægraph

grammars Æcontext-freeness Ædiagram languages ÆDiaGen

Next lectures: … Graph

Transformation in a Nutshell: Introduction to basic oncepts … Mathematical Background: How to build a formalism