Difference and Union of Models, 10 years later Ivan Porres Åbo Akademi University ivan.porres@abo.fi MODELS 2013 Conference Miami October 3, 2013 Åbo Akademi University | Domkyrkotorget 3 | 20500 Åbo | Finland Difference and Union of Models Marcus Alanen and Ivan Porres UML 2003 Conference, San Francisco Difference and Union of Models, 10 years later 2 Motivation: Fine-grained version control with optimistic locking Original Model A C B Designer 1 A Designer 2 C A C B D Final Model A C D Difference and Union of Models, 10 years later 3 The Context: 2002-2003 § Martin Fowler: What Is the Point of the UML?, UML 2003 ■ § Jean Bézivin, MDA: From Hype to Hope, and Reality, UML 2003 ■ § “Models as sketches vs formal designs” “Everything is a model” Stuart Kent, "Model Driven Engineering", IFM 2002 ■ Defines MDE, identifies the need for families of languages, transformation, aligns metamodelling with formal language engineering Difference and Union of Models, 10 years later 4 The Problem § Difference of two models: M2 - M1 = Δ § Merge of a model and a model difference M1 + Δ = M2 § Union of Models: Mf = M0 + (M1 - M0) + (M2 - M0 ) § For models in any MOF-based language Difference and Union of Models, 10 years later 5 The Problem designer 2 Original Model A original model A C C A Designer 2 C A C B D A C - B Designer 1 d2 = D B B D Final Model A designer 1 C original model A D C d1 A C - - B original model A d2 d1 A B - + D - Difference and Union of Models, 10 years later B final model C + - = C = B D 6 String-based comparison § Same model, serialized as two different strings <UML:Model xmi.id = '122' name = 'Example Model'/> ... <UML:Model name = 'Example Model' xmi.id = '122'/> ... Difference and Union of Models, 10 years later 7 XML-based comparison § Same model, serialized as two different XML documents <UML:Model xmi.id = '122' name = 'Example Model'> <UML:Namespace.ownedElement> <UML:Class xmi.id = '123' name = 'Customer'> <UML:Class xmi.id = '124' name = 'Product'> ... <UML:Model xmi.id = '122' name = 'Example Model'> <UML:Namespace.ownedElement> <UML:Class xmi.id = '124' name = 'Product'> <UML:Class xmi.id = '123' name = 'Customer'> ... Difference and Union of Models, 10 years later 8 Underlying Model Structure § Typed model elements, attributes store primitive values, features store links to other model elements Person Company 1 +employer * +employee work namespace Example:Model +Name:String +Address:String ownedElement association employer:AssociationEnd work:Association connection ownedElement Compay:Class participant association employee:AssociationEnd ownedElement connection participant Person:Class owner feature ownedElement Address:Attribute feature Name:Attribute String:Class type Difference and Union of Models, 10 years later 9 Underlying Model Structure § Features may be ordered (sequences) or unordered (sets) Person Company 1 +employer * +employee work namespace Example:Model +Name:String +Address:String ownedElement association employer:AssociationEnd work:Association connection ownedElement Compay:Class TheClass participant association employee:AssociationEnd ownedElement connection participant Person:Class +TheMethod(A:Integer,C:Integer) owner feature ownedElement Address:Attribute feature Name:Attribute String:Class type Difference and Union of Models, 10 years later 10 Identification Elements § We assume that each model element has a universally unique, stable identifier § We match elements by identity, not similarity ! Difference and Union of Models, 10 years later 11 Representing Differences as Elementary Operations § The difference of two models is not a model! Operation Dual new(e,t) del(e,t) del(e,t) new(e,t) set(e,a,v0,v1) set(e,a,v1,v0) insert(e0,f,e1) remove(e0,f,e1) remove(e0,f,e1) insert(e0,f,e1) insertAt(e0,f,e1,i) removeAt(e0,f,e1,i) removeAt(e0,f,e1,i) insertAt(e0,f,e1,i) Difference and Union of Models, 10 years later 12 Basic Difference Algorithm § Mold-Mnew=Δ=[N,U,D] § 1. Define a mapping from elements in Mold to Mnew § 2. Define a new operation for each element in Mnew that does not exist in Mold § 3. Define Update Operations § ■ attributes: define a set operation ■ unordered features: insert,remove ■ ordered features: Longest Common Subsequence algorithm 4. Define a delete operation for each element in Mold that does not exist in Mnew Difference and Union of Models, 10 years later 13 Example insert(e, f , et ) remove(e, f , et ) insertAt(e, f , et , i) removeAt(e, f , et , i) remove(e, f , et ) insert(e, f , et ) removeAt(e, f , et , i) insertAt(e, f , et , i) Table1. The Map Between Operations and Dual Operations. AClass Δ = [[ new(Class, u2 ), new(Generalization, u3 )], [ insert(u3 , namespace, u0 ), insert(u3 , parent, u1 ), insert(u3 , child, u2 ), insert(u1 , specialization, u3 ), insert(u0 , ownedElement, u2 ), insert(u0 , ownedElement, u3 ), insert(u2 , namespace, u0 ), insert(u2 , generalization, u3 ), set(u2 , name, “”, “Sub”)], [] ] AClass Sub Figure4. Difference Between Two Simple Models. Difference and Union of Models, 10 years later composition, due to bidirectionality constraints. The new class u 2 is connected to the 14 Basic Merge Algorithm Operation O Dual operation Õ new(e,t) del(e,t) del(e,t) new(e,t) set(e, f , vo , vn ) set(e, f , vn , vo ) insert(e, f , et ) remove(e, f , et ) remove(e, f , et ) insert(e, f , et ) insertAt(e, f , et , i) removeAt(e, f , et , i) removeAt(e, f , eApply t , i) insertAt(e, Δ f , et , i) Table1. The Map Between Operations and Dual Operations. § Δ=[N,U,D], M1 + Δ = M2 ■ 1. Apply all new operations ■ 2. Apply all update operations ■ 3. Apply all delete operations AClass Δ = [[ new(Class, u2 ), new(Generalization, u3 )], [ insert(u3 , namespace, u0 ), insert(u3 , parent, u1 ), insert(u3 , child, u2 ), insert(u1 , specialization, u3 ), insert(u0 , ownedElement, u2 ), insert(u0 , ownedElement, u3 ), insert(u2 , namespace, u0 ), insert(u2 , generalization, u3 ), set(u2 , name, “”, “Sub”)], [] ] AClass Sub Figure4. Difference Between Two Simple Models. Apply dual(Δ) composition, due to bidirectionality constraints. The new class u 2 is connected to the old class u1 via the Generalization element, using its specialization and generalization features. Since all features start with their respective “zero” value, the name feature of the new class is also set by the difference. XMI has facilities for representing arbitrary differences between two models, using an XML element called XMI.difference. The positive operations new, insert and Difference and Union of Models, later in a XMI document using the XMI.add element,15while the insertAt can 10 beyears described negative operations del, remove and removeAt can be specified using the XMI.delete element. The set operation can be represented using the XMI.replace element. XMI Union of Two Models Original Model A C B Designer 1 A Designer 2 C A C B D Final Model A C D § Assume two developers update a model simultaneously ■ § M1-Mbase = Δ1, M2-Mbase = Δ2 We want to merge both changes into the base modelHowever, the order of application of differences matters ■ (Mbase + Δ1 ) + Δ2 ≠ (Mbase + Δ2 ) + Δ1 Difference and Union of Models, 10 years later 16 [A, B,C, D] Example Figure7. Example of a merge of an ordered sequence. Note how the insertion of B at index 1 pushes the insertion of D from index 2 to index 3. [A,C] F1 = [insertAt(B, 1)] . [A, B,C] F2 = [insertAt(D, 2)] # [A, B, D,C] & F2 = [insertAt(D, 2)] [A,C, D] # F1 = [insertAt(B, 1)] [A, B,C, D] Difference and Union of Models, 10 years later 17 Δ is naturally preferred. The modification is necessary to avoid errors. We define the difference minimisation operator ⊗: Union of Two Models Δ"2 = ⊗(Δ2 , Δ1 ), Δ"1 = ⊗(Δ1 , Δ2 ) Now the equation becomes: § Solution: a difference minimization operator ⊗ " " M∪ = Δ1 (Δ2 (Mbase )) = Δ2 (Δ1 (Mbase )) ■ M1-Mbase = Δ2, M2-Mbase = Δ2 This principle■ is illustrated in Figure 5., Without loss of generality, this paper Δ2also ’ = ⊗(Δ Δ ’ = ⊗(Δ Δ ) 2, Δ1), 1 1 2 discusses only the calculation of Δ"2 = ⊗([C2 , F2 , D2 ], [C1 , F1 , D1 ]). ■ Conflict resolution: (Mbase + Δ1 ) + Δ2’ = (Mbase + Δ2 ) + Δ1’ ■ Δ1’ may contain less operations than Δ1 Δ"2 ! " M∪ ! M1 " $ # Δ1 # M2 $ # Δ1 # " ! ! Δ2 Mbase Difference and Union of Models, 10 years later 18 Figure5. The principle of calculating the union of two models, given their base model. Either Conflict Resolution § § Model Elements ■ new,del: not possible since ids are unique ■ del,del: automatic resolution (no actual conflict) ■ del, update: manual or metamodel specific resolution Attributes ■ § set,set: manual or metamodel specific resolution if values are different Features ■ update, update: automatic resolution in some cases based on longest common subsequence, manual or metamodel specific if update breaks multiplicity constraints Difference and Union of Models, 10 years later 19 at the same index. Of importance is also to remember that the resulting sequence F2! (F1 (Forig )) cannot contain the same element twice. The algorithm does not check Ordered Features for such possibilities when interleaving the operations, so the resulting sequence must be inspected for such occurrences, and the user must choose which elements to remove, before modifying the feature e. f . Figure 7 shows an example of the algorithm for interleaving ordered features. [A,C] F1 = [insertAt(B, 1)] ! " F2 = [insertAt(D, 2)] F2! = [insertAt(D, 3)] " ! [A, B,C] [A,C, D] [A, B,C, D] Figure7. Example of a merge of an ordered sequence. Note how the insertion of B at index 1 pushes the insertion of D from index 2 to index 3. 4.2 A Version Control System Difference and Union of Models, 10 years later 20 A Complete Model Union System 1. Model Difference calculation 2. Difference minimization ■ Automatic metamodel-independent conflict resolver ■ ■ Automatic metamodel-dependent conflict resolver ■ ■ Algorithm presented in the article Uses knowledge specific to each modeling language Manual resolution ■ Requires a proper difference visualization and inspection 3. Model union calculation Difference and Union of Models, 10 years later 21 Limitations § Unique, stable, universal model element identifiers across model revisions § Alternative: element matching based on similarity ■ U. Kelte, J. Wehren, J. Niere, A Generic Difference Algorithm for UML Models Difference and Union of Models, 10 years later 22 Limitations § Metamodel is assumed to be static § This is not a realistic assumption, specially for domainspecific modeling languages ■ B. Gruschko, D. Kolovos, R. Paige, Towards synchronizing models with evolving metamodels Difference and Union of Models, 10 years later 23 Limitations § Metamodel independent algorithms are generally applicable but do not exploit useful knowledge of the modeling language in the mapping, conflict resolution and merge steps ■ S. Nejati et al., Matching and Merging of Statecharts Specifications ■ J. Kü̈ster, C Gerth, A. Förster, G. Engels, Detecting and Resolving Process Model Differences in the Absence of a Change Log Difference and Union of Models, 10 years later 24 Limitations § Standardized representation of differences is not discussed ■ § A. Cicchetti, D. Di Ruscio, and A. Pierantonio, A Metamodel Independent Approach to Difference Representation Manual conflict resolution requires inspection of base model and differences ■ H. Störrle, Making sense to modelers: Presenting UML class model differences in prose Difference and Union of Models, 10 years later 25 Limitations § No actual tools are discussed ■ Y. Lin, J.Gray, F. Jouault, DSMDiff: a differentiation tool for domain-specific models ■ C. Brun, A. Pierantonio, Model Differences in the Eclipse Modelling Framework, Eclipse EMF Compare Difference and Union of Models, 10 years later 26 Future work (in 2013)? § Better conflict detection § Better difference reporting § Better tool support for multiple languages § Better conflict resolution § K. Altmanninger, P. Brosch, G. Kappel, P. Langer,M. Seidl, K. Wieland, M. Wimme, Why Model Versioning Research is Needed!? An Experience Report Difference and Union of Models, 10 years later 27 10 year most influential paper? § It describes a problem and solves it ■ § The problem is relevant and general It also describes, sometimes implicitly, many other interesting problems to solve ■ It brings the problem to the attention of a research community Difference and Union of Models, 10 years later 28 10 year most influential paper? § The right time ■ § Anybody could have stumbled into and solved the problem before us The right forum ■ Alanen and Porres, Difference and union of models, Proc. of UML 2003, Springer: 240 citations ■ Alanen and Porres, Version control of software models, Chapter in Advances in UML and XML-Based Software Evolution, 2004, Idea Group Publishing: 9 citations Difference and Union of Models, 10 years later 29 10 year most influential paper? § Would it have been accepted to MODELS 2013? ■ Of course not, it was published 10 years ago ■ No validation, experimental tool, evaluation results Difference and Union of Models, 10 years later 30 The 2003 debate, 10 years later “Models are sketches” Martin Fowler: What is the Point of the UML? ■ “Models are formal artifacts” vs Jean Bézivin, MDA: From Hype to Hope, and Reality We were right (all of us)! ■ UML is the lingua franca for software design sketches ■ Empirical studies show great success in the use of UML and domain-specific languages in the industry. Difference and Union of Models, 10 years later 31 Acknowledgments § Dr. Marcus Alanen § Prof. Ralph Johan Back, Prof. Johan Lilius § The MODELS community Difference and Union of Models, 10 years later 32