Home » Modeling » VIATRA » Model refinement with viatra
|
Re: Model refinement with viatra [message #1801200 is a reply to message #1801150] |
Tue, 15 January 2019 08:47 |
Zoltan Ujhelyi Messages: 392 Registered: July 2015 |
Senior Member |
|
|
Hi Hana,
first of all, thanks for your interest in VIATRA. In general, VIATRA is capable of running both exogenous and endogenous transformations, but preconditions and/or rules have to be written a specific way if the used types are not enough to distinguish between source and target model elements. More specifically, the rules should be able to distinguish between elements that need to be transformed/updated and ones that not. There are multiple ways to achieve this:
a) You can write your precondition patterns in a way that they only match on non-refined model elements. This approach is used by the very simple Petri net simulator transformation [1], where the rules are triggered with transitions that are fireable; and this property is changed by the rule execution.
b) You can add filters to the transformation rules (in case of batch transformations, you could define such filters with the statements; in case of event-driven transformations, you could add them to the rule definitions themselves). In this case, you can write Java code that identifies whether an element needs to be refined.
c) Thirdly, if your output model has the same metamodel, but is a new instance model file, you could limit the engine not to consider the output model by filtering the indexed parts of the model [2], however, this needs to be used with care, as model elements filtered this way will not be considered as matches for any patterns.
In general, we recommend to go with approach a) as this results in the cleanest code and the fewest surprises in the long term, furthermore, if all rules are written like this, the transformation becomes incremental: the transformations can be safely re-executed if the input model is updated, and the output part will be updated.
One more remark: if you are doing in-place transformation, the defined AADL2AADLRef metamodel should be unnecessary - that was part of the CPS example to provide traceability between the source and target model elements; however, in case of in-place transformations the source and target references of these records should be the same elements, thus making the record superfluous.
Hope this was helpful, if you still have some questions, feel free to ask them.
Best regards,
Zoltán
[1] https://git.eclipse.org/c/viatra/org.eclipse.viatra.examples.git/tree/transformation/petrinet-simulator-maven
[2] https://www.eclipse.org/viatra/documentation/query-api.html#_using_filtered_input_models_during_pattern_matching
|
|
|
Re: Model refinement with viatra [message #1801838 is a reply to message #1801200] |
Mon, 28 January 2019 09:24 |
Hana Mkaouar Messages: 7 Registered: January 2019 |
Junior Member |
|
|
Hi,
Thank you for your response,
Indeed, we choose the a) approach and we use the AADL2AADLRef metamode with traces.
The transformation works well for the first time, based on the query Q1, which find a connection in the AADL model (input model) and its equivalence in the AADLRef model (output model). The connection is then transformed and added in the traces.
About the incremental behavior, I need to transform new connections added in the AADL model, so I add a new query Q2 to find new connections that exist in the AADL model, do not exist in the AADLRef model and do not exist in traces.
The problem is that the Q2 query finds all connections even whose have traces.
// Connections exist in AADL and in AADLRef
pattern Q1 (
aadl2aadlref : AADL2AADLRef,
system : SystemInstance,
system_ref : SystemInstance,
portconnection_ref : ConnectionInstance,
portconnection : ConnectionInstance,
id : java String
) {
AADL2AADLRef.AADLRef (aadl2aadlref, system_ref);
SystemInstance.connectionInstance (system_ref,portconnection_ref);
AADL2AADLRef.AADL (aadl2aadlref, system);
SystemInstance.connectionInstance (system,portconnection);
// same id
ConnectionInstance.name (portconnection, id);
ConnectionInstance.name (portconnection_ref, id);
}
// Connections exist in traces
pattern is_in_trace(
aadl2aadlref : AADL2AADLRef,
trace : AADL2AADLRefTrace,
aadlElement : InstanceObject,
aadlrefElement : InstanceObject
) {
AADL2AADLRef.traces(aadl2aadlref, trace);
AADL2AADLRefTrace.AADL(trace, aadlElement);
AADL2AADLRefTrace.AADLRef(trace, aadlrefElement);
}
// Connections exist only in AADL
pattern Q2 (
trace : AADL2AADLRefTrace,
aadl2aadlref : AADL2AADLRef,
system : SystemInstance,
portconnection : ConnectionInstance
) {
AADL2AADLRef.AADL (aadl2aadlref, system);
SystemInstance.connectionInstance (system,portconnection);
AADL2AADLRef.traces(aadl2aadlref, trace);
neg find is_in_trace (aadl2aadlref, trace,portconnection,_);
neg find is_portconnection_ref (aadl2aadlref,system,_,_,portconnection,_);
}
|
|
|
Re: Model refinement with viatra [message #1801847 is a reply to message #1801838] |
Mon, 28 January 2019 11:38 |
Zoltan Ujhelyi Messages: 392 Registered: July 2015 |
Senior Member |
|
|
Hi Hana,
I had a quick look at your patterns, and although I am not entirely familiar with your metamodels, I see a potential issue with the usage of the `trace` parameter in the Q2 pattern. More specifically, consider the following two constraints:
`` `
AADL2AADLRef.traces(aadl2aadlref, trace);
neg find is_in_trace (aadl2aadlref, trace,portconnection,_);
```
The first one tries to enumerate all possible trace objects related to the AADL2AADLRef instance; while the second one states that the _specific_ trace object is not connected to the portconnection variable. If you want to ensure _no_ trace object exists to the portconnection variable, you must not bind it via another constraint, but use something as follows:
```
neg find is_in_trace(aadl2aadlref, _, portconnection, _); // Note that the trace parameter is unbound
```
Hope this was helpful,
Zoltán
[Updated on: Mon, 28 January 2019 11:43] Report message to a moderator
|
|
| |
Goto Forum:
Current Time: Fri Apr 19 11:11:20 GMT 2024
Powered by FUDForum. Page generated in 0.02027 seconds
|