• Nem Talált Eredményt

3.2 A Novel Approach for Experimenting with Multi-Level ConstructsMulti-Level Constructs

3.2.1 Formal Specification of Multi-Level Constructs

Although multi-level approaches often build upon different formalism and underlying theory, if we examine them at a higher abstraction level, we can grasp the essential concepts that we can use to describe the different approaches in a unified way. The described formalism is not a replacement for any of the approaches, but rather the foundation of a multi-level modeling playground that can be used to experiment with different concepts and ideas in multi-level modeling. The formalism specifies the essence of the different constructs, allowing them to be compared, combined, analyzed, and to be experimented with. We differentiate between two components of a multi-level construct: i) structure and ii) semantics. We use Abstract State Machines for describing both, aiming to achieve a general way to describe the essence of multi-level constructs.

Underlying Structure

The structure of a multi-level construct consists of the underlying modeling structure (e.g., nodes, edges, fields) and of the construct itself (e.g., classic potency, leap potency). Multi-level constructs are usually interpreted over a defined modeling structure like the OCA [AK02], hence the distinction of the underlying structure.

The structure is represented as a Labeled Directed Graph [EEPT06]; an Abstract State Machine (ASM) operates on the graph as its data structure.

Definition 3.2.1. The superuniverse |A| of state A consists of the following uni-verses:

• Ubool consisting of the boolean constants true and f alse

• Unumber consisting of integer numbers {N} and the symbol ∞ representing infinity

• Ustring consisting of finite length character sequences

• UID consisting of valid identifiers

• Ubase =Ubool∪Unumber∪Ustring∪UID, defined only as an auxiliary universe Definition 3.2.2. The nodes of the Labeled Directed Graph partially consist of structural entities with a unique identifier and a structural meta type repre-senting the multi-level nature of the model. A structural entity can contain struc-tural attributesthat also have an identifier and a structural meta type, in addition to being able to contain a value. Complex structural attributes can also con-tain other structural attributes. The nodes of the graph consist also of structural attributes. Both structural entities and structural attributes are capable of holding annotations and annotation definitions.

Remark. As we will see later, containment relations are realized using identifiers.

For example, the label structure of a structural entity contains the identifiers of all of its structural attributes. Moreover, structural attributes are not atomic data, they appear as virtual nodes in the graph, with the structural entity containing them being the root node. The values of structural attributes however consist of elements from

|A|. Virtual nodes are nodes that are not part of the core label structure, yet are still represented as nodes in the graph.

The following is the label structure used by both structural entities and structural attributes, notated byEAttN:

• EAttID: the globally unique ID of the element the value is taken fromUID

• EAttN ame: the locally unique ID of the element the value is taken fromUID

• EAttM eta: the structural meta type of the element the value is taken fromUID

• EAttAttributes: the list of structural attributes of the element the values are taken from UID

• EAttAnnotations: the list of annotations assigned to the element the values are taken from UID

• EAttAnnDef s: the list of annotation definitions that can be assigned to the element

the values are taken from UID

• EAttT ype: the specified type of the element the value is taken fromUID

• EAttIsArray: whether the type of the element is also an array the value is taken fromUbool

• EAttV alue: the value of the element the value is taken fromUbase

• EAttIsEntity: whether the element is a structural entity (or a structural at-tribute)

the value is taken fromUbool

• EAttIsDomain: whether the element is a part of a domain model the value is taken fromUbool

Remark. TheEAttID label is a globally unique identifier, while the EAttN ame label is a locally unique identifier of the element. For example, assuming that structural entities A and B both have a structural attribute C, the local identifier (EAttN ame) would be C in both cases, while the global identifiers (EAttID) would be A.C and B.C. The semantics of global and local uniqueness are defined later.

Remark. The purpose of the EAttIsDomain label might require some clarification:

entities that are part of domain models have a value of true. Domain models are considered to be the experiments, the previously defined structure and semantics of multi-level modeling constructs are used here. Domain elements are related to non-domain elements via the EAttM eta label, meaning that domain elements are direct or indirect instances of non-domain elements.

Definition 3.2.3. Annotations are defined by annotation definitions. An an-notation definition consists of the following:

• a uniqueidentifier

• the mathematicalrangefrom which the value of an annotation is taken; values in the range consist of elements from|A|

• a mutability which defines whether the value can or cannot be different in the instance of a targeted element

• thetargeted elementsreferring to structural entities or attributes that define the elements to which the annotation can be assigned to; the target of an annotation must be a direct or indirect instance of one of the targeted elements

• anoptionality that determines if the annotation must have a value for every target or not

The nodes of the Labeled Directed Graph consist also of annotation definitions and annotations.

Remark. The definition suggests that annotations are essentially instances of anno-tation definitions. This is not technically accurate as the term instantiation refers to a different concept, but annotations are indeed based on annotation definitions and in a sense can be considered to be instances. However, annotations also have a meta element that is present in actual instantiation. For example, if annotation a is assigned to structural entity x, and annotation b is assigned to structural entity y such that y is an instance of x, then b is always an instance of a.

As an example, let us assume that an annotation definition is defined with an arbitrary ID, a range consisting of natural numbers, is mutable, has only the N ode structural entity as a targeted element, and is optional. This means that annotations based on this definition take their value from the range of natural numbers. Due to being mutable, the value can change upon instantiation. For example, in the annotation assigned node A the value could be 3, but in the annotation assigned to node B - which is an instance of A - the value could be 2. Annotations can only be assigned to N ode instances, and finally, they may not have a value at every node due to optionality. Later - when specifying the semantics of a construct - it can be defined exactly when an annotation can have a value.

The label structure used by annotation definitions is as follows, notated by AnnDefN:

• AnnDefID: the unique ID of the annotation definition the value is taken from UID

• AnnDefRange: the range (consisting of a list of values) of the annotation defi-nition

the values are taken from Ubase

• AnnDefIsM utable: the mutability of the annotation definition the value is taken from Ubool

• AnnDefT argeted: the list of targeted elements of the annotation definition the values are taken from UID

• AnnDefIsOptional: the optionality of the annotation definition the value is taken from Ubool

According to the definition, an annotation has the following structure, notated by AnnN:

• AnnID: the unique ID of the annotation the value is taken from UID

• AnnDef inition: the annotation definition the annotation is based on the value is taken from UID

• AnnT arget: the concrete element the annotation is assigned to the value is taken from UID

• AnnV alue: the value of the annotation, taken from the range of its definition the value is taken from Ubase

Definition 3.2.4. The setSEAttcontains every node of the Labeled Directed Graph conforming to the EAttN label structure. Similarly, the sets SAnnDef and SAnn

contain every node conforming to label structuresAnnDefN andAnnN respectively.

These sets will be referred to when defining the semantics of the model.

Pre-defined Nodes

In order to support the specification of arbitrary types and values - like for fields - we specify some pre-defined nodes in the graph. When specifying the nodes, we will use the following notation (the remaining labels are omitted for reasons of compactness since their values are either ∅ orundef):

EAtt{EAttID, EAttN ame, EAttM eta, EAttIsEntity, EAttIsDomain}. When defining se-mantics and model validity, we will refer to these nodes, assigning semantic meaning to them.

Thebasenode (EAtt{base, base, undef, true, f alse}) is responsible for being the meta element of the following nodes representing primitive types:

• EAtt{bool, bool,base, true, f alse}

• EAtt{number, number,base, true, f alse}

• EAtt{string, string,base, true, f alse}

Semantics and Model Validity

There exist restrictions that must always apply to a stateA of the ASM, regarding the inherent behavior of structural concepts, the mechanisms of instantiation, and construct-specific semantic rules. In other words, the validity of a state of the model depends on certain criteria that must always be true. These are represented by derived functions (ΦX and ΨX), which we will soon discuss.

Definition 3.2.5. State A is invalid if any of the derived functions ΦX for any valid input inA return f alse. Every ΦX function returning trueis a necessary but not sufficient condition toA being valid.

Note that sufficient conditions of validity will be specified later. Next, in or-der to improve the expressive power of or-derived functions, additional constructs are introduced.

Definition 3.2.6. The select construct filters the elements in a collection based on a predicate condition. Its inputs are i) a collection and ii) a predicate condition;

its output is the collection of filtered elements. The construct iterates over every element in the collection and applies the predicate condition, returning elements to which the predicate returnstrue. The select construct uses the following notation:

select(variable:collection|predicate), where variable can of course be referred to in thepredicate.

Remark. For example,select(ad:e.EAttAnnotationDef s |ad.AnnDefIsM utable)filters every mutable ad annotation definition of e.

Definition 3.2.7. Theclosureconstruct collects the transitive closure of a starting element, based on a traversal expression. Its inputs are i) a starting element and ii) a traversal expression; its output is the collection of traversed elements. The construct starts with the starting element and then uses the traversal expression to traverse elements until it reaches the starting element again or until the traversal expression cannot be evaluated. Theclosure construct uses the following notation:

closure(element|expression).

Remark. For example, closure(e|XAttribute(e,0)) traverses the attribute of e at index 0, doing the same with the result and so on, until it reaches e again. It then returns the collection of traversed elements.

Definition 3.2.8. The count,min,max, avg,sum constructs serve as aggregate functions performing simple operations (count, minimum, maximum, average, sum) on a collection of elements. Its inputs are i) a collection and ii) an operating expres-sion; its output is a number resulting from the operation. The constructs iterate over every element in the collection and perform their respective operation based on the operating expression. The count construct uses the following notation, with the other constructs using a similar one: count(variable : collection | expression), where variable can of course be referred to in the expression.

Remark. For example, sum(a : e.EAttAttributes | a.EAttV alue) summarizes the values of every attribute of e, assuming that the attributes take their values from Unumber.

There exist derived functions in signature P

that are not a part of ΦX or ΨX, instead, their purpose is to be helper functions. The following helper functions return an appropriate element from SEAtt,SAnnDef, or SAnn by their ID:

EAttByID(id:UID) :SEAtt=def select(e:SEAtt |e.EAttID =id) (3.4)

AnnDef ByID(id:UID) :SAnnDef =def

select(e:SAnnDef |e.AnnDefID =id) (3.5) AnnByID(id :UID) :SAnn=def select(e:SAnn |e.AnnID =id) (3.6) The following helper functions decide if an element (EAtt) is a direct or indirect (transitive) instance of another one:

IsInstance(e:EAtt, m:EAtt) :Ubool=def e.EAttM eta=m.EAttID (3.7)

IsT ransitiveInstance(e:EAtt, m:EAtt) :Ubool =def m6=undef∧

(IsInstance(e, m)∨IsT ransitiveInstance(EAttByID(e.EAttM eta), m)) (3.8) TheAnnotationByDef function is a helper function with the purpose of return-ing an annotation (Ann) conformreturn-ing to a specified annotation definition (ad) on a specified structural entity or attribute (EAtt):

AnnotationByDef(e:EAtt, ad:AnnDef) :SAnn =def

select(a :e.EAttAnnotations |AnnByID(a).AnnDef inition =ad)[0] (3.9) Remark. Since ΦA3 (specified later) defines that there cannot be multiple annota-tions conforming to the same annotation definition assigned to an element, we can be sure that there will be at most one element in the collection returned by the select construct. If the collection is empty, then indexing it will result in undef, in which case is also the return value of the function.

Before presenting the ΦX functions, let us summarize the shared and derived functions of the ASM, that can be used in the definition of ΦX (and later, ΨX) functions. The following shared functions are used to access or modify the values of the EAtt, AnnDef, andAnn label structures:

• EAttN ame(id:UID) :UID

• EAttM eta(id:UID) :UID

• EAttAttribute(id:UID, index:Unumber) :UID

• EAttAnnotation(id:UID, index:Unumber) :UID

• EAttAnnDef(id:UID, index:Unumber) :UID

• EAttT ype(id:UID) :UID

• EAttIsArray(id:UID) :Ubool

• EAttV alue(id :UID) :Ubase

• EAttIsEntity(id:UID) :Ubool

• EAttIsDomain(id:UID) :Ubool

• AnnDef Range(id:UID, index:Unumber) :Ubase

• AnnDef IsM utable(id :UID) :Ubool

• AnnDef T argeted(id:UID, index:Unumber) :UID

• AnnDef IsOptional(id:UID) :Ubool

• AnnDef inition(id:UID) :UID

• AnnT arget(id :UID) :UID

• AnnV alue(id:UID) :Ubase

The following are the helper (derived) functions of the ASM that are always available as they are pre-defined:

• EAttByID(id:UID) :SEAtt

• AnnDef ByID(id:UID) :SAnnDef

• AnnByID(id:UID) :SAnn

• IsInstance(e:EAtt, m:EAtt) :Ubool

• IsT ransitiveInstance(e:EAtt, m:EAtt) :Ubool

• AnnotationByDef(e:EAtt, ad:AnnDef) :SAnn

Finally, the following constructs that are used to extend the expressive power of the formalism are also available for use:

• select(variable:collection|predicate)

• closure(element|expression)

• count(variable:collection |expression)

• min(variable:collection |expression)

• max(variable:collection|expression)

• avg(variable:collection|expression)

• sum(variable:collection|expression)

In the following, we present the ΦX derived functions that are always a part of signature P

of the ASM. According to the definition, return values are all taken fromUbool. First, the semantics of global and local uniqueness are specified. Every EAtt, AnnDef, and Ann label structure must have a globally unique identifier (EAttID, AnnDefID, AnnID):

ΦGlobalEA(g :EAtt) =def (@e∈SEAtt:e6=g∧g.EAttID =e.EAttID)∧

(@ad∈SAnnDef :ad6=g∧g.EAttID=ad.AnnDefID)∧

(@a∈SAnn :a6=g∧g.EAttID =a.AnnID) (3.10)

ΦGlobalAD(g :AnnDef) =def (@e∈SEAtt :e6=g∧g.AnnDefID =e.EAttID)∧

(@ad∈SAnnDef :ad 6=g∧g.AnnDefID =ad.AnnDefID)∧

(@a∈SAnn :a6=g∧g.AnnDefID =a.AnnID) (3.11) ΦGlobalA(g :Ann) =def (@e∈SEAtt:e6=g∧g.AnnID =e.EAttID)∧

(@ad∈SAnnDef :ad 6=g∧g.AnnID =ad.AnnDefID)∧

(@a ∈SAnn :a6=g∧g.AnnID =a.AnnID) (3.12) The elements in theEAttAttributes label must always be locally unique:

ΦLocal(e:EAtt) =def ∀a ∈e.EAttAttributes :@a2∈e.EAttAttributes :

a26=a∧EAttByID(a).EAttN ame =EAttByID(a2).EAttN ame (3.13) Since self meta references are usually not allowed in modeling, they are forbidden:

ΦSelf M eta(e:EAtt) =def e.EAttM eta6=e.EAttID (3.14) The EAttT ype, EAttIsArray and EAttV alue labels cannot be interpreted on struc-tural entities, as opposed to strucstruc-tural attributes:

ΦEntity(e :EAtt) =def e.EAttIsEntity =⇒

e.EAttT ype =undef ∧e.EAttIsArray =undef ∧e.EAttV alue=undef (3.15) ΦAttribute1(e:EAtt) =def ¬e.EAttIsEntity =⇒

e.EAttT ype6=undef ∧e.EAttIsArray 6=undef (3.16) The EAttV alue label is only interpreted on domain attributes that are not com-plex (ΦAttribute2 and ΦAttribute3). Moreover, only domain attributes can be complex attributes (ΦAttribute4 and ΦAttribute5):

ΦAttribute2(e:EAtt) =def ¬e.EAttIsEntity∧ ¬e.EAttIsDomain =⇒

e.EAttV alue=undef (3.17) ΦAttribute3(e:EAtt) =def ¬e.EAttIsEntity∧e.EAttIsDomain∧ ¬e.EAttIsArray =⇒

e.EAttV alue6=undef (3.18) ΦAttribute4(e:EAtt) =def ¬e.EAttIsEntity∧ ¬e.EAttIsDomain =⇒

e.EAttAttributes =∅ (3.19) ΦAttribute5(e:EAtt) =def e.EAttIsArray∧e.EAttIsDomain =⇒

e.EAttAttributes 6=∅ (3.20) Annotations (EAttAnnotations) can only be assigned to entities or attributes with EAttIsDomain =true:

ΦDomainA(e:EAtt) =def ¬e.EAttIsDomain =⇒ e.EAttAnnotations =∅ (3.21)

Attributes have to conform to the meta hierarchy, namely, for every attribute in the meta element, an instance attribute must be present in the attributes of the instance element:

ΦAttributeM eta(e:EAtt) =def e.EAttM eta6=undef =⇒

∀a ∈EAttByID(e.EAttM eta).EAttAttributes :

∃a2∈e.EAttAttributes :a2.EAttM eta =a (3.22) If the structural meta type of a structural attribute is not an array (EAttIsArray), then the attributes of the element must be empty. Also note that due to ΦAttribute3, only domain attributes can actually contain other attributes:

ΦArray1(e :EAtt) =def e.EAttM eta 6=undef∧

¬EAttByID(e.EAttM eta).EAttIsArray =⇒ e.EAttAttributes =∅ (3.23) The array nature of a structural attribute cannot be broken in an instantiation chain; if the meta attribute is an array, then the instance must be an array as well:

ΦArray2(e :EAtt) =def e.EAttM eta 6=undef∧

EAttByID(e.EAttM eta).EAttIsArray =⇒ e.EAttIsArray (3.24) Certain labels are not allowed to haveundef as a value, but since every universe of |A|contains undef by definition, these labels have to be constrained:

ΦU ndef EA(e:EAtt) =def e.EAttID 6=undef ∧e.EAttN ame 6=undef∧

e.EAttIsEntity 6=undef ∧e.EAttIsDomain 6=undef (3.25) ΦU ndef AD(ad:AnnDef) =def ad.AnnDefID 6=undef∧

ad.AnnDefIsM utable 6=undef ∧ad.AnnDefIsOptional 6=undef (3.26) ΦU ndef A(a:Ann) =def a.AnnID 6=undef ∧a.AnnDef inition 6=undef

∧a.AnnT arget 6=undef (3.27) Remark. The value (AnnV alue) of an annotation can beundef since optional anno-tations may not always have a value. Labels consisting of a collection of values (e.g., EAttAnnotations) cannot have undef as their value due to the nature of collections.

Instead, they can take the value of ∅.

The following ΦX functions further constraint the set of IDs certain labels can take their value(s) from in order to be semantically accurate:

ΦID1(e:EAtt) =def e.EAttM eta 6=undef =⇒

∃m ∈SEAtt :m.EAttID =e.EAttM eta (3.28) ΦID2(e:EAtt) =def ∀a∈e.EAttAttributes :∃e2∈SEAtt :e2.EAttID =a (3.29) ΦID3(e:EAtt) =def ∀a ∈e.EAttAnnotations :

∃ad∈SAnnDef :ad.AnnDefID =a (3.30)

ΦID4(ad:AnnDef) =def ∀a∈ad.AnnDefT argeted :

∃e∈SEAtt :e.EAttID=a (3.31) ΦID5(a:Ann) =def ∃ad∈SAnnDef :ad.AnnDefID =a.AnnDef inition (3.32) ΦID6(a:Ann) =def ∃e∈SEAtt:e.EAttID =a.AnnT arget (3.33) The following ΦX functions deal with annotations and annotation definitions.

ΦA1 defines that an annotation must be present in the EAttAnnotations label of its target and that EAttIsDomain must always be true for the target:

ΦA1(a :Ann) =def a∈EAttByID(a.AnnT arget).EAttAnnotations

EAttByID(a.AnnT arget).EAttIsDomain (3.34) The target of an assigned annotation must be a transitive instance of at least one of the targeted elements of the associated annotation definition:

ΦA2(a :Ann) =def ∃e∈AnnDef ByID(a.AnnDef inition).AnnDefT argeted :

IsT ransitiveInstance(EAttByID(a.AnnT arget), EAttByID(e)) (3.35) There must not be multiple annotations with the same annotation definition assigned to the same target (e.g., there cannot be two ”potency” annotations on the same structural entity or attribute):

ΦA3(a :Ann) =def @a2∈EAttByID(a.AnnT arget).EAttAnnotations :

a26=a.AnnID∧a.AnnDef inition =AnnByID(a2).AnnDef inition (3.36) The value of an annotation must be taken from the range of the associated annotation definition:

ΦA4(a :Ann) =def a.AnnV alue

AnnDef ByID(a.AnnDef inition).AnnDefRange (3.37) If an annotation is not optional (mandatory), then it must always have a value other thanundef (ΦA5). Moreover, a mandatory annotation must always be present in the EAttAnnotations label of its targeted elements (ΦA6):

ΦA5(a :Ann) =def ¬AnnDef ByID(a.AnnDef inition).AnnDefIsOptional =⇒

a.AnnV alue6=undef (3.38) ΦA6(a :Ann) =def ¬AnnDef ByID(a.AnnDef inition).AnnDefIsOptional =⇒

∀t∈AnnDef ByID(a.AnnDef inition).AnnDefT argeted :∀e∈SEAtt:e.EAttIsDomain∧ IsT ransitiveInstance(e, EAttByID(t)) =⇒ a.AnnID ∈e.EAttAnnotations (3.39) If an annotation is immutable, then its value must always be equal to the value of the annotation of the meta element of the target:

ΦA7(a :Ann) =def ¬AnnDef ByID(a.AnnDef inition).AnnDefIsM utable

AnnotationByDef(EAttByID(a.AnnT arget).EAttM eta, a.AnnDef inition)6=undef

=⇒ a.AnnV alue=AnnotationByDef(EAttByID(a.AnnT arget).EAttM eta, a.AnnDef inition).AnnV alue (3.40)

An annotation definition must be present in theEAttAnnDef s label of its target:

ΦA8(ad:AnnDef) =def ∀t∈ad.AnnDefT argeted :

ad∈EAttByID(t).EAttAnnDef s (3.41) The annotation definitions of the meta element must also be present in the annotation definitions of the instance element:

ΦA9(e:EAtt) =def e.EAttM eta6=undef =⇒

∀ad∈EAttByID(e.EAttM eta).EAttAnnDef s :ad∈e.EAttAnnDef s (3.42) The following ΦX functions define the built-in primitive types a structural tribute can have, in correlation with the relevant universes (e.g., a structural at-tribute with a type ofbool must have a value taken from Ubool):

ΦT ypeBool(e:EAtt) =def e.EAttT ype =bool∧e.EAttIsDomain =⇒

e.EAttV alue∈Ubool (3.43)

ΦT ypeString(e:EAtt) =def e.EAttT ype=string∧e.EAttIsDomain =⇒

e.EAttV alue ∈Ustring (3.44)

ΦT ypeN umber(e :EAtt) =def e.EAttT ype =number∧e.EAttIsDomain =⇒

e.EAttV alue∈Unumber (3.45) IfEAttT ype is not a primitive type, then both the type and value must refer to a valid identifier and the value must be a transitive instance of the type. For example, if the type is N ode, then there must be a structural entity or attribute with the ID N odeand EAttV alue must be a transitive instance of N ode:

ΦT ypeID(e:EAtt) =def e.EAttT ype ∈ {bool, number, string, base}∧/

e.EAttIsDomain =⇒ ∃e2∈SEAtt :e2.EAttID =e.EAttT ype∧ ∃e3∈SEAtt: e3.EAttID =e.EAttV alue

IsT ransitiveInstance(EAttByID(e.EAttV alue), EAttByID(e.EAttT ype)) (3.46) The ”base” type imposes no restrictions, meaning that the value of the attribute comes from Ubase. Note that ΨX functions can still introduce restrictions on at-tributes with the ”base” type.

Instantiation in our approach is aimed to be as flexible as possible in order to be able to specify different interpretations in the literature. Every element must have exactly one meta element. Rules constraining instantiation can be added by specifying ΨX derived functions that describe the semantics of a particular construct.

These functions can constrain the process of instantiation and introduce semantics to the model. Thus, specifying a construct with the formalism consists of two steps:

i) defining the structure - labeled nodes in the graph; and ii) defining the semantics - the ΨX functions that can also refer to the newly defined structure.

Definition 3.2.9. State Aof the ASM is validif and only if all of the ΦX and ΨX

derived functions return true for all valid input in A.

Definition 3.2.10. A domain model consists of i) structural entities and at-tributes (EAtt) with EAttDomain =true and ii) annotations (Ann). ΨX functions are only evaluated on domain models. Domain models are considered to be the scientific experiments in our approach.

Remark. In the ΦX functions, we often differentiated between domain entities and attributes (based on the value of EAttIsDomain) in order to constrain domain models.

In theΨX functions, this differentiation is not necessary as they are only interpreted over domain models. This means that the semantics of a multi-level construct are enforced only in the actual experiments, it is not possible to alter the underlying semantics of the formalism specified by the ΦX functions.