conformance.tex 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. \chapter{Conformance}
  2. Model management operations (\textit{e.g.}, conformance checking, or versioning) frequently act upon both the model and the metamodel, or should be applicable on all models, independently of their metamodel.
  3. As such, they are often in conflict with the principle of strict metamodelling.
  4. We try to find a balance between strict metamodelling (\axiomHumanInteraction), and the principle of modelling everything explicitly (\axiomModelEverything).
  5. By introducing multiple definitions of conformance, we can keep strict metamodelling while still implementing such model management functions.
  6. The basic idea is to allow a single model to conform to multiple metamodels.
  7. The conceptual graph, representing the model, is interpreted depending on the metamodel being used.
  8. Examples of metamodels might be a domain-specific metamodel (\textit{e.g.}, a Petri Net metamodel), or a more physically-oriented metamodel (\textit{e.g.}, a Graph metamodel).
  9. Depending on the interpretation given to the levels, different level hierarchies are constructed.
  10. It is these level hierarchies that impose the restrictions on strict metamodelling.
  11. \begin{figure}
  12. \center
  13. \includegraphics[width=0.4\columnwidth]{images/RelationLingPhys.pdf}
  14. \caption{Different conformance relations}
  15. \label{fig:conformance}
  16. \end{figure}
  17. Fig.~\ref{fig:conformance} presents some different notions of conformance that can be devised on the Modelverse.
  18. While the amount of conformance relations can vary, each model will have a mapping to the PTM, which is required to physically represent the model.
  19. And it will have a mapping to the Linguistic Type Model (LTM), using conformance$_\perp$.
  20. This relates to \axiomMultiView, as a single model can be seen from different views, and relates to \axiomInteroperability, as it allows for the uniform representation of all data.
  21. \section{Graph conformance}
  22. As all our data is (conceptually) represented using a graph, the graph instance can also be interpreted as a linguistic instance of a graph metamodel.
  23. Because all defined CRUD operations constrain the result to a well-formed graph, all models in the Modelverse conform to this metamodel by construction.
  24. Every model represented in the Modelverse is conceptually representable as a graph.
  25. Knowing this, the complete Modelverse can be flattened to a single level, which conforms to the graph formalism.
  26. Within this single level, all operations and links between elements are non-level crossing, and are therefore correctly typed (by the graph metamodel).
  27. Note however, that these methods are unable to guarantee conformance to any linguistic metamodel, apart from the graph metamodel.
  28. As such, all multi-formalism models can also be represented using this single metamodel, thus partially addressing \axiomMultiFormalism and \axiomMultiAbstraction.
  29. Multiple users (\axiomMultiUser) can also use this view to collaborate on a single model, while having different interpretations of it.
  30. \section{Linguistic conformance}
  31. Finally there is the linguistic conformance between the model and the metamodel, which is necessary to complete the support for our axioms (\axiomHumanInteraction).
  32. It is the highest level, and offers the most features to the user, but is also the most fragile.
  33. Linguistic conformance cannot be guaranteed at all, and requires continuous checking to make sure it is enforced for the desired model and metamodel.
  34. In contrast, conformance$_\perp$ was guaranteed by design.
  35. Because a conformance$_L$ view is only a specific view on a model, a single model can conform to multiple metamodels.
  36. The function $conforms : \mathcal{G} \times \mathcal{G} \times 2^{IDS \rightarrow IDS} \rightarrow \mathbb{B}$ is defined to determine linguistic conformance, and can be implemented by the user.
  37. It takes three parameters: two graphs --- a model and a metamodel, both subgraphs of the MvS graph --- and a mapping between them.
  38. This mapping encapsulates all typing information, thus typing is completely separated from the model and metamodels.
  39. Since multiple mappings can be stored, multiple typing relations are supported.
  40. During syntax-directed editing, a mapping will be constructed (and used) with the information provided by the user.
  41. Retyping can be done by modifying the mapping, and checking conformance afterwards.
  42. We define a possible conformance$_L$ relation, to be seen as an example of our approach.
  43. This relation bases itself on the top level model: the Model at the MetaCircular Level (MMCL).
  44. In this model, we have three basic elements: a \textit{Class} (mapped to nodes), an \textit{Association} (connecting classes; mapped to edges), and \textit{Inheritance} between classes (mapping to the union type).
  45. Using \textit{Inheritance}, the \textit{Association} becomes a special kind of \textit{Class} in our MMCL.
  46. We call our example conformance relation \textit{conformance$_\alpha$} to indicate that it is one of many possible implementations.
  47. First, we define a subfunction which defines transitive closure of inheritance links, where $A \leq B$ means that $A$ is a (possibly indirect) subclass of $B$.
  48. $A \xrightarrow{{} \inheritancearrow {}} B$ means that there is an association, typed by the \textit{Inheritance} link, from $A$ to $B$.
  49. \begin{align*}
  50. A \xrightarrow{{} \inheritancearrow {}} B &\Rightarrow A \leq B \\
  51. A \leq C \land C \leq B &\Rightarrow A \leq B \\
  52. A == B &\Rightarrow A \leq B \\
  53. \end{align*}
  54. A conformance relation for the primitive elements is defined, constraining the provided map.
  55. \begin{gather*}
  56. conforms: (N \cup E) \times (N \cup E) \times 2^{IDS \times IDS} \rightarrow \mathbb{B} \\
  57. conforms(x, y, m) =
  58. \left\{ \begin{array}{lr}
  59. N_T(N_V(x)) == N_V(y) & if~x, y \in dom(N_V) \land (x,y) \in m \\ % Primitives
  60. True & if~x, y \in N \land x, y \not\in dom(N_V) \land (x,y) \in m \\ % Nodes
  61. conforms(x_s, y_s, m) \land conforms(x_t, y_t, m) & if~(x, y), (x_s, y_s), (x_t, y_t) \in m \land (x_s, x, x_t), (y_s, y, y_t) \in E \\ % Edges
  62. False & else \\ % Else
  63. \end{array}
  64. \right.
  65. \end{gather*}
  66. The first line is for nodes with a primitive value: a node $x$ conforms to a node $y$ if both nodes have a value, with the type of the value of node $x$ being the value of node $y$.
  67. The second line is for nodes without a primitive value: a node $x$ conforms to a node $y$ if such a mapping exists in the provided mapping.
  68. Neither node is allowed to have a primitive value.
  69. The third line is for edges: an edge $x$ conforms to an edge $y$ if their sources and targets conform to each other.
  70. It is thus basically a recursive call.
  71. However, there is no possibility for an infinite loop, because of our restriction on the IDs of edges: the source and target ID are always smaller than the ID of the edge.
  72. The final line is for all other cases (\textit{e.g.}, comparing nodes to edges, or primitives to non-primitives), in which case there is no conformance possible.
  73. Finally, $conforms_{\alpha,G}: \mathcal{G} \times \mathcal{G} \times 2^{IDS \rightarrow IDS} \rightarrow \mathbb{B}$ is the actual conformance function being called.
  74. It tries to find a mapping between the specified model and metamodel, for which the conforms function holds.
  75. \begin{gather*}
  76. conforms_{\alpha,G}(M, MM, map) = True \\
  77. \Leftrightarrow \\
  78. map' = \lbrace (a, b) \; \vert \; a \in IDS_M, b \in IDS_{MM} \rbrace \\
  79. \forall n \in N_M : \exists n' \in N_{MM} . conforms(n, n', map') \\
  80. \forall e \in IDS_{E, M} : \exists e' \in IDS_{E, MM} . conforms(e, e', map') \\
  81. \forall (a_i, b_i), (a_i, b_j) \in map' : (b_i \leq b_j) \\
  82. \forall (a_i, b_i) \in map' : (a_i \rightarrow b_k) \in map \land b_k \leq b_i \\
  83. \forall a, b \in IDS : a \leq b \land b \leq a \Rightarrow a == b
  84. \end{gather*}
  85. A map is generated which contains all possible mappings between the model and metamodel.
  86. This map is then constrained by enforcing a mapping for the nodes and edges.
  87. Source and target of the edges are recursively checked for conformance using the mapping.
  88. We finally prune the set of possible mappings by only keeping a single type mapping for every node, with the exception being subclasses.
  89. Finally, this mapping is pruned to a function by keeping the most specific (or a more specific) subclass of all present mappings.
  90. Just like a model can conform to multiple metamodels, a model can also conform to the same metamodel multiple times, with different mappings.
  91. Using this function, we can now check whether a model conforms to a specified metamodel, using a specified mapping.
  92. It is also possible to generate a set of all possible mappings between a model and a metamodel.
  93. \begin{gather*}
  94. MAP = 2^{IDS \rightarrow IDS} \\
  95. mappings_{\alpha,G} : \mathcal{G} \times \mathcal{G} \rightarrow 2^{MAP} \\
  96. mappings_{\alpha,G}(M, MM) = s \\
  97. s = \lbrace map \in MAP \; \vert \; conforms_{\alpha,G}(M, MM, map) \rbrace\\
  98. \end{gather*}
  99. \section{MMCL}
  100. \begin{lstlisting}[caption=HUTN$_\perp$ construction of the MMCL,float,label=listing:mmcl0]
  101. Node Class()
  102. Value Type(Type)
  103. Value String(String)
  104. Edge Attribute_ (Class, Type)
  105. Edge AttributeAttrs (Attribute_, Type)
  106. Edge Attribute (Class, Type)
  107. Edge Name (Attribute, String)
  108. Edge Association (Class, Class)
  109. Edge Inheritance (Class, Class)
  110. Edge inherit_association (Association, Class)
  111. Edge inherit_attribute (Attribute_, Class)
  112. \end{lstlisting}
  113. \begin{lstlisting}[caption=HUTN$_L$ construction of the MMCL,float,label=listing:mmcl1]
  114. Class Class()
  115. Type Type(Type)
  116. Type String(String)
  117. Attribute_ Attribute_ (Class, Type)
  118. Attribute_ AttributeAttrs (Attribute_, Type)
  119. Attribute_ Attribute (Class, Type)
  120. AttributeAttrs Name (Attribute, String)
  121. Association Association (Class, Class)
  122. Association Inheritance (Class, Class)
  123. Inheritance (Association, Class)
  124. Inheritance (Attribute_, Class)
  125. \end{lstlisting}
  126. We present an encoding of our MMCL, in Listing~\ref{listing:mmcl0}, using the HUTN language respecting conformance$_\perp$.
  127. The action code in this language is translated to an abstract syntax graph in the Modelverse, by a HUTN compiler.
  128. The HUTN compiler lives in a Modelverse Interface (MvI).
  129. Using this MMCL, we can now re-encode it, as in Listing~\ref{listing:mmcl1}, now using the HUTN language with conformance$_L$.
  130. Alternatively, it is possible to directly use the definition in Listing~\ref{listing:mmcl1}, as elements can directly be typed by themselves in the Modelverse.
  131. Finally, we encode our conformance checking algorithm, in Listing~\ref{listing:conforms}, using the HUTN action language.
  132. With this example we show
  133. (1) an example of modelling, as the action code is a model, and thus an element of the Modelverse;
  134. (2) an example of our action code;
  135. (3) the possibility for reflection and introspection, as the conformance check can also run on itself, to check whether or not it conforms to some kind of metamodel; and
  136. (4) the possibility for metamodelling, as type hierarchies can be built using the provided conformance function.
  137. \begin{lstlisting}[caption=HUTN conformance check algorithm,label=listing:conforms]
  138. include "primitives.al"
  139. Element function set_copy(elem : Element):
  140. Element result
  141. Integer counter
  142. Integer max
  143. result = create_node()
  144. // Expand the provided list by including all elements that need to be checked
  145. counter = 0
  146. max = read_nr_out(elem)
  147. while (integer_lt(counter, max)):
  148. set_add(result, read_edge_dst(read_out(elem, counter)))
  149. counter = integer_addition(counter, 1)
  150. return result
  151. Boolean function is_subclass_of(superclass : Element, subclass : Element, types : Element, inheritance_link : Element):
  152. Integer counter_iso
  153. Integer i
  154. Element edge
  155. Element destination
  156. if (element_eq(superclass, subclass)):
  157. return True
  158. counter_iso = read_nr_out(subclass)
  159. i = 0
  160. while (integer_lt(i, counter_iso)):
  161. edge = read_out(subclass, i)
  162. if (dict_in_node(types, edge)):
  163. if (element_eq(dict_read_node(types, edge), inheritance_link)):
  164. // It is an inheritance edge, so follow it to its destination
  165. destination = read_edge_dst(edge)
  166. if (is_subclass_of(superclass, destination, types, inheritance_link)):
  167. return True
  168. i = integer_addition(i, 1)
  169. // No link seems to have been found, so it is False
  170. return False
  171. String function conformance_scd(model : Element, extra : Element):
  172. // Initialization
  173. Element work_conf
  174. Element model_src
  175. Element metamodel_src
  176. Element model_dst
  177. Element metamodel_dst
  178. Element models
  179. Element metamodels
  180. models = set_copy(model)
  181. Element typing
  182. typing = dict_read(extra, "typing")
  183. metamodels = set_copy(dict_read_node(typing, model))
  184. Element inheritance
  185. inheritance = dict_read(extra, "inheritance")
  186. // Iterate over all model elements and check if they are typed (in "typing") and their type is in the metamodel
  187. while (integer_gt(dict_len(models), 0)):
  188. work_conf = set_pop(models)
  189. // Basic check: does the element have a type
  190. if (bool_not(dict_in_node(typing, work_conf))):
  191. return string_join("Model has no type specified: ", cast_e2s(work_conf))
  192. // Basic check: is the type of the element part of the metamodel
  193. if (bool_not(set_in(metamodels, dict_read_node(typing, work_conf)))):
  194. return string_join("Type of element not in specified metamodel: ", cast_e2s(work_conf))
  195. // Basic check: type of the value agrees with the actual type
  196. // this is always checked, as it falls back to a sane default for non-values
  197. if (bool_not(type_eq(dict_read_node(typing, work_conf), typeof(work_conf)))):
  198. output(dict_read_node(typing, work_conf))
  199. output(typeof(work_conf))
  200. return string_join("Primitive type does not agree with actual type: ", cast_e2s(work_conf))
  201. // For edges only: check whether the source is typed according to the metamodel
  202. if (is_edge(work_conf)):
  203. model_src = read_edge_src(work_conf)
  204. metamodel_src = read_edge_src(dict_read_node(typing, work_conf))
  205. if (bool_not(is_subclass_of(metamodel_src, dict_read_node(typing, model_src), typing, inheritance))):
  206. return string_join("Source of model edge not typed by source of type: ", cast_e2s(work_conf))
  207. // For edges only: check whether the destination is typed according to the metamodel
  208. if (is_edge(work_conf)):
  209. model_dst = read_edge_dst(work_conf)
  210. metamodel_dst = read_edge_dst(dict_read_node(typing, work_conf))
  211. if (bool_not(is_subclass_of(metamodel_dst, dict_read_node(typing, model_dst), typing, inheritance))):
  212. return string_join("Destination of model edge not typed by destination of type: ", cast_e2s(work_conf))
  213. return "OK"
  214. \end{lstlisting}
  215. \begin{figure}
  216. \center
  217. \includegraphics[width=0.8\textwidth]{images/conformance_petrinet.pdf}
  218. \label{fig:conformance_petrinet}
  219. \caption{Conformance example for a petri net.}
  220. \end{figure}