On Model Transformation and Graph Transformation Tom Mens Service de Génie Logiciel Institut d Informatique Université de Mons-Hainaut
Contexte Ingénierie Dirigée par les Modèles An approach to software development where the principal artefacts are models scope of (as opposed to programs) this talk level of abstraction code only code driven Round-trip Engineering model driven model only Model Model Model Model visualise synchronise generate Program Program Program Program level of automation 18 janvier 2008, LIP6, Paris, France GPL - Journée sur les transformations de modèles 2
Questions Les formalismes et outils actuels sont-ils adaptés à la transformation de modèles? Transformation de graphes? Transformation de termes? Programmation logique? Expression graphique des transformations? Expression déclarative des transformations? Comment contrôler les transformations? Formalismes pour le flux de contrôle? Comment valider les transformations? Comment réutiliser les transformations? 18 janvier 2008, LIP6, Paris, France GPL - Journée sur les transformations de modèles 3
Réponses selon le point de vue de la Transformation de Graphes (TG) Le formalisme de TG est-il adapté à la transformation de modèles? Oui, mais besoin de meilleur support outillé Besoin d une expression graphique des transformations? Oui, pour la syntaxe concrète ET abstraite Expression déclarative des transformations? Oui, par définition de la transformation de graphes Comment contrôler les TG? Programmed/controlled graph rewriting, story-driven modelling Comment valider les TG? Termination analysis, critical pair analysis, Comment réutiliser les TG? Peu supporté par les outils actuels (travaux en cours) 18 janvier 2008, LIP6, Paris, France GPL - Journée sur les transformations de modèles 4
Tool Support Combining technical spaces La technologie des transformations de graphes (basée principalement sur les grammaires de graphes) AGG + Tiger Eclipse plug-ins Fujaba, Moflon ATOM3, VIATRA2, GrGen.Net, MoTMoT, GReAT, GROOVE La technologie de l ingénierie dirigée par les modèles (IDM) (basée principalement sur les techniques de métamodélisation) OMG: MOF, UML, BPMN, Eclipse: Ecore, EMF, GEF, W3C: XML, XMI, XSLT, Défi: combiner les forces de ces technologies P.e. Support EMF et XML pour la transformation de graphes 18 janvier 2008, LIP6, Paris, France GPL - Journée sur les transformations de modèles 5
Grammaires ou métamodèles? GrammarWare versus ModelWare GrammarWare relies on grammar technology (including tree rewriting, graph rewriting, parser and compiler technology) ModelWare relies on metamodelling technology e.g. UML, MOF, EMF, Both approaches are complementary and can be combined E.g. Generating test models: Use GT to generate instance models from metamodels [Ehrig&al, SoSyM 2008] E.g. Use GT to generate visual editors for domain-specific languages Expressiveness versus usability Interesting experience (Mark Minas): A graph transformation tool for specifying domain-specific graph-like languages (and editors) DiaPlan: based on graph grammars DiaMeta: based on metamodeling DiaMeta is less expressive, but easier to use by non-experts 18 janvier 2008, LIP6, Paris, France GPL - Journée sur les transformations de modèles 6
Support de la transformation de modèles par transformation de graphes Études de cas
Etudes de cas Tiger project Concrete visual syntax for modeling and model transformation Tiger EMF Transformation Eclipse-based support for graph transformation Fujaba UML-based round-trip engineering based on graph transformation Story diagrams: Sophisticated control mechanism AGG critical pair analysis Formal analysis and support for incremental model inconsistency resolution 18 janvier 2008, LIP6, Paris, France GPL - Journée sur les transformations de modèles 8
Etude de cas 1 Tiger project http://tfs.cs.tu-berlin.de/tigerprj/ K. Ehrig, C. Ermel, S. Hansgen, G. Taentzer. Generation of Visual Editors as Eclipse Plug-Ins. Proc. Int l Conf. Automated Software Engineering (ASE).
Défi: Représentation concrète et abstraite des modèles représentation concrète représentation abstraite contraintes de lay-out Le méta-modèle niveau M2 niveau M1 respecte Le diagramme visualise est conforme à Le modèle 18 janvier 2008, LIP6, Paris, France GPL - Journée sur les transformations de modèles 10
Défi: Représentation concrète et abstraite des modèles représentation concrète représentation abstraite Le numéro se trouve à l intérieur de la place Le nom de la place se trouve en dessous Le nom de la transition se trouve à l intérieur niveau M2 niveau M1 respecte est conforme à Le diagramme visualise :Place token=1 name="p1" :Place token=2 name="p3" beginarcpt endarcpt :ArcPT inscr="a1" :Transition token=0 name="t" endarcpt :ArcPT inscr="a3" beginarctp :Place token=0 name="p2" endarctp :ArcTP inscr="a2" 18 janvier 2008, LIP6, Paris, France GPL - Journée sur les transformations beginarcpt de modèles 11
Etude de cas 1 : Tiger Project Tool setup Tiger Eclipse plug-in Metamodel specification Visual syntax specification Specification of manipulation rules Generated Eclipse plug-in A domain-specific modeling environment uses AGG graph transformation engine 18 janvier 2008, LIP6, Paris, France GPL - Journée sur les transformations de modèles 12
Etude de cas 1 : Tiger Project Exemple : Petri Nets What the end-user sees : A tool for creating, manipulating, transforming Petri Nets Using concrete visual syntax 18 janvier 2008, LIP6, Paris, France GPL - Journée sur les transformations de modèles 13
Etude de cas 1 : Tiger Project Exemple : Petri Nets What the developer sees : A tool for specifying the metamodel / type graph A tool for specifying the visual notation 18 janvier 2008, LIP6, Paris, France GPL - Journée sur les transformations de modèles 14
Etude de cas 1 : Tiger Project Exemple : Petri Nets What the developer sees : A tool for specifying instance models / graphs Using the visual syntax notation 18 janvier 2008, LIP6, Paris, France GPL - Journée sur les transformations de modèles 15
Etude de cas 1 : Tiger Project Exemple : Petri Nets What the developer sees A tool for specifying model transformation through graph transformation Using visual notation 18 janvier 2008, LIP6, Paris, France GPL - Journée sur les transformations de modèles 16
Etude de cas 1 : Tiger Project Autre exemple: diagrammes d activités 18 janvier 2008, LIP6, Paris, France GPL - Journée sur les transformations de modèles 17
Etude de cas 2 Tiger EMF transformation project http://tfs.cs.tu-berlin.de/emftrans/ E. Biermann, K. Ehrig, C. Kohler, G. Kuhns, G.Taentzer, E. Weiss. Graphical Definition of In-Place Transformations in the Eclipse Modeling Framework. Proc. Int l Conf. MODELS 2006.
Case study 2 Tiger EMF transformation project Tiger EMF transformation project http://tfs.cs.tu-berlin.de/emftrans/ Combines the virtues of Eclipse EMF with model transformation based on underlying graph transformation engine (AGG) Allows formal reasoning over the transformation rules 18 janvier 2008, LIP6, Paris, France GPL - Journée sur les transformations de modèles 19
Case study 2 Tiger EMF transformation project Refactoring Example : Pull Up Attribute Step 1: Check if all subclasses contain the attribute to be pulled up 18 janvier 2008, LIP6, Paris, France GPL - Journée sur les transformations de modèles 20
Case study 2 Tiger EMF transformation project Refactoring Example : Pull Up Attribute Step 2: If all subclasses have the attribute, then pull it up 18 janvier 2008, LIP6, Paris, France GPL - Journée sur les transformations de modèles 21
Case study 2 Tiger EMF transformation project Refactoring Example : Pull Up Attribute Step 3: After pulling up, delete the attribute in all subclasses. 18 janvier 2008, LIP6, Paris, France GPL - Journée sur les transformations de modèles 22
Case study 2 Tiger EMF transformation project Refactoring Example : Pull Up Attribute Step 4: If there are still annotations, delete them. 18 janvier 2008, LIP6, Paris, France GPL - Journée sur les transformations de modèles 23
Etude de cas 3 Fujaba http://www.fujaba.de/ S. Burmester, H. Giese, M. Hirsch, D. Schilling, M. Tichy. The Fujaba Real-Time Tool Suite: Model-Driven Development of Safety-Critical, Real-Time Systems. Proc. Int l Conf. Software Engineering (ICSE) 2005.
Etude de cas 3 : Fujaba Fujaba is a round-trip engineering tool for UML and Java Behaviour can be specified as «story diagrams» Combination of UML activity diagrams and object diagrams Java code generation Experiment in Fujaba Specify refactorings as graph transformations using story diagrams Generate refactoring code from these transformations Advantages easier to specify and understand refactorings (visual notation) easier to implement refactorings (automatic code generation) 18 janvier 2008, LIP6, Paris, France GPL - Journée sur les transformations de modèles 25
Etude de cas 3 : Fujaba Generating refactoring code from GT specifications refactoring execution Java programs round-trip engineering UML models Fujaba tool graph transformations specified as story diagrams refactoring specification 18 janvier 2008, LIP6, Paris, France GPL - Journée sur les transformations de modèles 26
Etude de cas 3 : Fujaba Generating refactoring code Métamodèle de Fujaba 18 janvier 2008, LIP6, Paris, France GPL - Journée sur les transformations de modèles 27
Etude de cas 3 : Fujaba Generating refactoring code Refactoring framework in Fujaba 18 janvier 2008, LIP6, Paris, France GPL - Journée sur les transformations de modèles 28
Etude de cas 3 : Fujaba Generating refactoring code Pull Up Method model refactoring as Graph Transformation 1. Match method > (Hidden) Cast target 2. Match container > Link Navigation 3. Match stub > Link Navigation 4. Match superclass > Link Navigation 5. Remove method from container 6. Add method to superclass 18 janvier 2008, LIP6, Paris, France GPL - Journée sur les transformations de modèles 29
Etude de cas 3 : Fujaba Generating refactoring code [p1.getindex()] [ failure] 18 janvier 2008, LIP6, Paris, France GPL - Journée sur les transformations de modèles 30
Etude de cas 3 : Fujaba Generating refactoring code 18 janvier 2008, LIP6, Paris, France GPL - Journée sur les transformations de modèles 31
Case Study 3 : Fujaba Generating refactoring code Fujaba Plugin 18 janvier 2008, LIP6, Paris, France GPL - Journée sur les transformations de modèles 32
Etude de cas 3 : Fujaba Generating refactoring code Running Prototype 3 Execute Refactoring Import Java Sources (by directory) 2 Rearrange diagrams 1 parse Old Sources 4 regenerate New Sources 18 janvier 2008, LIP6, Paris, France GPL - Journée sur les transformations de modèles 33
Etude de cas 4 AGG Critical Pair Analysis http://tfs.cs.tu-berlin.de/agg/ T. Mens, R. Van Der Straeten, M. D hondt. Detecting and resolving model inconsistencies using transformation dependency analysis. Proc. Int l Conf. MODELS 2006.
Goal : Formal Support for Incremental Model Improvement Goal Formally specify model defects and their resolution strategies as graph transformation rules Formally analyse to support the model improvement process Automate the detection of problems Interactively support the resolution of these problems Detect cycles in the resolution process Feasibility study Implementation in the AGG general-purpose graph transformation tool 18 janvier 2008, LIP6, Paris, France GPL - Journée sur les transformations de modèles 35
Goal: Formal Support for Incremental Model Improvement Iterative process defect detection rules? defect resolution rules? model detect model defects select defects to be resolved choose resolution strategy apply resolution rules annotate model with detected problems modify model by selected resolution rules (may give rise to new defects) 18 janvier 2008, LIP6, Paris, France GPL - Journée sur les transformations de modèles 36
Example of a model inconsistency Dangling Operation Reference selectreverse is used in the statemachine but is not defined in class AutomaticGear or any of its ancestors statemachine diagram behaviour AutomaticGear boolean driveselected selectdrive() reach2ndspeed() reach3rdspeed() dropbelow2ndspeed() dropbelow3rdspeed() Gear int noofgears = 3 selectneutral selectfirst selectsecond 18 janvier 2008, LIP6, Paris, France GPL - Journée sur les transformations de modèles 37
Tool support SIRP tool Simple Iterative Resolution Process An interactive tool for detecting and resolving model problems 18 janvier 2008, LIP6, Paris, France GPL - Journée sur les transformations de modèles 38
Step 1: Specify the metamodel AGG type graph 18 janvier 2008, LIP6, Paris, France GPL - Journée sur les transformations de modèles 39
Step 2: Represent the model as a graph Automatic generation of the graph representation for the model This graph conforms to the type graph specified before 18 janvier 2008, LIP6, Paris, France GPL - Journée sur les transformations de modèles 40
Example of a model defect Dangling operation reference Graph representation contains Operation name= selectdrive Class name= AutomaticGear isabstract=false gen Class name= Gear isabstract=false Operation behaviour name= selectneutral contains Operation name= selectreverse StateMachine Region contains referredoperation contains Conflict State name= Neutral Transition State source target name= Reverse description= dangling operation reference 18 janvier 2008, LIP6, Paris, France GPL - Journée sur les transformations de modèles 41
Step 3: Specify defect detection rules Dangling operation reference Graph transformation rule for detection negative application condition (NAC) left-hand side (LHS) right-hand side (RHS) 18 janvier 2008, LIP6, Paris, France GPL - Journée sur les transformations de modèles 42
Step 4: Specify resolution rules Dangling operation reference Graph transformation rule for resolution 18 janvier 2008, LIP6, Paris, France GPL - Journée sur les transformations de modèles 44
Tool support revisited open graph and apply all detection rules list all found defects (Conflict nodes in the graph) list all resolution rules for selected defect apply selected resolution rule to the graph display resolution history 18 janvier 2008, LIP6, Paris, France GPL - Journée sur les transformations de modèles 45
Step 5: Detect mutually conflicting resolutions Some resolution rules cannot be jointly applied (parallel conflict!) Conflict graph can be generated by means of critical pair analysis 18 janvier 2008, LIP6, Paris, France GPL - Journée sur les transformations de modèles 46
Step 5: Detect mutually conflicting resolutions Example of a critical pair detecting a parallel conflict between resolution rules the resolution rules are not jointly applicable 18 janvier 2008, LIP6, Paris, France GPL - Journée sur les transformations de modèles 48
Step 6: Detect sequential dependencies Some resolution rules may induce new defects (part of the) generated graph of sequential dependencies 18 janvier 2008, LIP6, Paris, France GPL - Journée sur les transformations de modèles 49
Step 6: Detect sequential dependencies Example of a sequential dependency representing an induced defect 18 janvier 2008, LIP6, Paris, France GPL - Journée sur les transformations de modèles 51
Step 6: Detect sequential dependencies We can use the dependency graph to detect potential cycles in the resolution process Cycles should be avoided, since this implies that the resolution process may continue forever 18 janvier 2008, LIP6, Paris, France GPL - Journée sur les transformations de modèles 52
Conclusions
Lessons Learned Graph transformation tool support for model transformation is starting to become available Still in a research prototype phase Formal analysis of transformations Available in AGG and some other tools, with some limitations Expressiveness of transformations Very good in Fujaba, less in AGG Performance Heavily depends on the tool Reusability of transformations Better tool support (and formal support) needed 18 janvier 2008, LIP6, Paris, France GPL - Journée sur les transformations de modèles 54
GT performance comparison 18 janvier 2008, LIP6, Paris, France GPL - Journée sur les transformations de modèles 55