Home » Archived » M2M (model-to-model transformation) » Problem when creating output objects using Called Rules
Problem when creating output objects using Called Rules [message #12070] |
Tue, 23 January 2007 22:06 ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: jairson.gmail.com
Hello All,
I am trying to do a very simple transformation that does the following:
from: p(X,2)
generates: p(X,Z) AND Z=2
p is an instance of metaclass Udc (user-defined constraint) with args X
and 2, X is a Variable, 2 is a Constant and X=2 is a Bic instance (Bic
stands for built-in constraint) with args X and 2 and symbol "=" (Equality).
So this is all encapsulated (as references not containment) in metaclass
SimpagationRule. And a collection of SimpagationRule(s) is encapsulated
by a CHRProgram metaclass that also contains all the variables and
constants. So we say that:
CHRProgram -> * SimpagationRule
SimpagationRule -> * Udc AND
SimpagationRule -> * Bic AND
Udc and Bic ->* Variable/Constant
Below I paste the somewhat simplified rules:
rule CHRProg2CHRProg
{
from
p : CHR!CHRProgram
to
h : CHR!CHRProgram (
constraintSymbols <- p.constraintSymbols,
variables <- p.variables->union(p.constantSymbols->collect(e |
thisModule.resolveTemp(e, 'vo'))),
constantSymbols <- p.constantSymbols->collect(e |
thisModule.resolveTemp(e, 'co')),
functionSymbols <- p.functionSymbols,
rules <- p.rules->collect(r |
thisModule.simpagation2simpagation(r,p.variables))
)
}
so This first rule generates the variables ok, including the new
variables corresponding to the contantSymbols as shown from the excerpt
below:
p.variables->union(p.constantSymbols->collect(e |
thisModule.resolveTemp(e, 'vo')))
Problem comes next when it goes further transforming each SimpagationRule:
rule simpagation2simpagation (r : CHR!Simpagation,v :
Sequence(CHR!VariableSymbol))
{
using {
co : Sequence(CHR!ConstantSymbol) =
thisModule.allConstantSymbols(r.keep->union(r.remove));
new_vs : Sequence(CHR!VariableSymbol) = v->select(va |
va.name.startsWith('_vj '));
}
to
ro : CHR!Simpagation (
name <- r.name,
keep <- r.keep,
remove <- r.remove,
guard <- r.guard->union(co->iterate(c; acc : CHR!Bic = Sequence{} |
acc->including(thisModule.newBic(c,new_vs->at(co->indexOf(c)))))),
disjunctiveBody <- r.disjunctiveBody
)
do {
ro; --returns an instance of a new output Simpagation rule
}
}
So ´guard´ is the attribute of Simpagation that will contain the new
Bic(s). In our example just ´Z=2´. It iterates over the collection of
Constants and is supposed to create new built-ins via the called rule
below: (which does not create any Bic instance.)
rule newBic(c : CHR!ConstantSymbol, v : CHR!VariableSymbol)
{
using {
cs : CHR!ConstraintSymbol = thisModule.getEquality();
}
to
nb : CHR!Bic (
args<-Sequence{v,c},
symbol <- cs
)
do
{
nb;
}
}
The above rule just gets a Constant and a Variable and makes a new
Equality. Unfortunately it is not working at all. Could somebody spot
what I should be doing wrong? Here are some additional helpers that I
use throughout the rules:
helper def: counter : Integer = 101;
helper def: newVariableName() : String = '_vj' +
thisModule.counter.toString();
helper def : allConstantSymbols (s : Sequence(CHR!Udc)): Sequence
(CHR!ConstantSymbol) =
s->iterate(u; acc : CHR!ConstantSymbol = Sequence{} |
acc->union(u.args->select(a | a.oclIsTypeOf(CHR!ConstantSymbol))));
helper def : getEquality () : CHR!ConstraintSymbol =
CHR!ConstraintSymbol->allInstances()->select(e | e.name='equality');
Thanks a lot.
Jairson Vitorino
|
|
|
Re: Problem when creating output objects using Called Rules [message #12088 is a reply to message #12070] |
Wed, 24 January 2007 09:09 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: mikael.barbero.gmail.com
Hi Jairson,
Did you try to use the debug() function ? For instance, if i were you, i
would try to use it on the "new_vs->at(co->indexOf(c))":
new_vs->at(co->indexOf(c)).debug('DEBUG HERE')
Then, you can look at the ATL console and see if you are getting the
value as you expect.
Regars,
Mikael
Jairson wrote:
> Hello All,
>
> I am trying to do a very simple transformation that does the following:
>
> from: p(X,2)
>
> generates: p(X,Z) AND Z=2
>
> p is an instance of metaclass Udc (user-defined constraint) with args X
> and 2, X is a Variable, 2 is a Constant and X=2 is a Bic instance (Bic
> stands for built-in constraint) with args X and 2 and symbol "="
> (Equality).
>
> So this is all encapsulated (as references not containment) in metaclass
> SimpagationRule. And a collection of SimpagationRule(s) is encapsulated
> by a CHRProgram metaclass that also contains all the variables and
> constants. So we say that:
>
> CHRProgram -> * SimpagationRule
> SimpagationRule -> * Udc AND
> SimpagationRule -> * Bic AND
> Udc and Bic ->* Variable/Constant
>
> Below I paste the somewhat simplified rules:
>
> rule CHRProg2CHRProg
> {
> from
> p : CHR!CHRProgram
> to
> h : CHR!CHRProgram (
>
> constraintSymbols <- p.constraintSymbols,
> variables <- p.variables->union(p.constantSymbols->collect(e
> | thisModule.resolveTemp(e, 'vo'))),
> constantSymbols <- p.constantSymbols->collect(e |
> thisModule.resolveTemp(e, 'co')),
> functionSymbols <- p.functionSymbols,
> rules <- p.rules->collect(r |
> thisModule.simpagation2simpagation(r,p.variables))
> )
>
> }
>
> so This first rule generates the variables ok, including the new
> variables corresponding to the contantSymbols as shown from the excerpt
> below:
>
> p.variables->union(p.constantSymbols->collect(e |
> thisModule.resolveTemp(e, 'vo')))
>
> Problem comes next when it goes further transforming each SimpagationRule:
>
> rule simpagation2simpagation (r : CHR!Simpagation,v :
> Sequence(CHR!VariableSymbol))
> {
> using {
> co : Sequence(CHR!ConstantSymbol) =
> thisModule.allConstantSymbols(r.keep->union(r.remove));
> new_vs : Sequence(CHR!VariableSymbol) = v->select(va |
> va.name.startsWith('_vj '));
> }
> to
> ro : CHR!Simpagation (
> name <- r.name,
> keep <- r.keep,
> remove <- r.remove,
>
> guard <- r.guard->union(co->iterate(c; acc : CHR!Bic = Sequence{} |
> acc->including(thisModule.newBic(c,new_vs->at(co->indexOf(c)))))),
> disjunctiveBody <- r.disjunctiveBody
> )
> do {
>
> ro; --returns an instance of a new output
> Simpagation rule
>
> }
>
> }
>
> So ´guard´ is the attribute of Simpagation that will contain the new
> Bic(s). In our example just ´Z=2´. It iterates over the collection of
> Constants and is supposed to create new built-ins via the called rule
> below: (which does not create any Bic instance.)
>
> rule newBic(c : CHR!ConstantSymbol, v : CHR!VariableSymbol)
> {
> using {
> cs : CHR!ConstraintSymbol = thisModule.getEquality();
> }
> to
> nb : CHR!Bic (
>
> args<-Sequence{v,c},
> symbol <- cs
> )
> do
> {
>
> nb;
>
> }
> }
>
> The above rule just gets a Constant and a Variable and makes a new
> Equality. Unfortunately it is not working at all. Could somebody spot
> what I should be doing wrong? Here are some additional helpers that I
> use throughout the rules:
>
> helper def: counter : Integer = 101;
>
> helper def: newVariableName() : String = '_vj' +
> thisModule.counter.toString();
>
> helper def : allConstantSymbols (s : Sequence(CHR!Udc)): Sequence
> (CHR!ConstantSymbol) =
> s->iterate(u; acc : CHR!ConstantSymbol = Sequence{} |
> acc->union(u.args->select(a | a.oclIsTypeOf(CHR!ConstantSymbol))));
>
> helper def : getEquality () : CHR!ConstraintSymbol =
> CHR!ConstraintSymbol->allInstances()->select(e | e.name='equality');
>
>
> Thanks a lot.
>
> Jairson Vitorino
--
Mikaël Barbero - PhD Candidate
ATLAS Group (INRIA & LINA) - University of Nantes
2, rue de la Houssinière
44322 Nantes Cedex 3 - France
tel. +33 2 51 12 58 08 /\ cell.+33 6 07 63 19 00
email: Mikael.Barbero@{gmail.com, univ-nantes.fr}
http://www.sciences.univ-nantes.fr/lina/atl/
|
|
|
Re: Problem when creating output objects using Called Rules [message #12127 is a reply to message #12088] |
Wed, 24 January 2007 17:04 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: jairson.gmail.com
Hello Mikaël,
Thanks for the tip. I debugged the code and discovered that the error is
in the following rule:
rule CHRProg2CHRProg
{
from
p : CHR!CHRProgram
to
h : CHR!CHRProgram (
variables <- p.variables->union(p.constantSymbols->collect(e |
thisModule.resolveTemp(e, 'vo'))),
rules <- p.rules->collect(r |
thisModule.simpagation2simpagation(r,h.variables))
(...)
Quick remind: I transform p(X,2) to
p(X,Z) AND Z=2, being Z the new variable.
The exact problem is that the two assignments above are done in
sequential order, BUT in rule execution time p.variables does not yet
refer to the new variables created by the instruction:
p.constantSymbols->collect(e |
thisModule.resolveTemp(e, 'vo')
So when I send the p.variables as a parameter in
thisModule.simpagation2simpagation(r,h.variables), it does not include
the recently created output variables and I see an out of bound error in
the console. I tried:
thisModule.simpagation2simpagation(r,variables))
(without the p, but I got a syntax error).
Then I tried p.variables, but it did not work either as one would´ve
expected.
Finally I pasted all the assignments in an imperative clause, which made
matters worse. So I am kind of stuck here.
I wonder if there is some way around this issue.
regards,
Jairson Vitorino
Mikaël Barbero wrote:
> Hi Jairson,
>
> Did you try to use the debug() function ? For instance, if i were you, i
> would try to use it on the "new_vs->at(co->indexOf(c))":
>
> new_vs->at(co->indexOf(c)).debug('DEBUG HERE')
>
> Then, you can look at the ATL console and see if you are getting the
> value as you expect.
>
> Regars,
> Mikael
>
> Jairson wrote:
>> Hello All,
>>
>> I am trying to do a very simple transformation that does the following:
>>
>> from: p(X,2)
>>
>> generates: p(X,Z) AND Z=2
>>
>> p is an instance of metaclass Udc (user-defined constraint) with args
>> X and 2, X is a Variable, 2 is a Constant and X=2 is a Bic instance
>> (Bic stands for built-in constraint) with args X and 2 and symbol "="
>> (Equality).
>>
>> So this is all encapsulated (as references not containment) in
>> metaclass SimpagationRule. And a collection of SimpagationRule(s) is
>> encapsulated by a CHRProgram metaclass that also contains all the
>> variables and constants. So we say that:
>>
>> CHRProgram -> * SimpagationRule
>> SimpagationRule -> * Udc AND
>> SimpagationRule -> * Bic AND
>> Udc and Bic ->* Variable/Constant
>>
>> Below I paste the somewhat simplified rules:
>>
>> rule CHRProg2CHRProg
>> {
>> from
>> p : CHR!CHRProgram
>> to
>> h : CHR!CHRProgram (
>> constraintSymbols <- p.constraintSymbols,
>> variables <-
>> p.variables->union(p.constantSymbols->collect(e |
>> thisModule.resolveTemp(e, 'vo'))),
>> constantSymbols <- p.constantSymbols->collect(e |
>> thisModule.resolveTemp(e, 'co')),
>> functionSymbols <- p.functionSymbols,
>> rules <- p.rules->collect(r |
>> thisModule.simpagation2simpagation(r,p.variables))
>> )
>>
>> }
>>
>> so This first rule generates the variables ok, including the new
>> variables corresponding to the contantSymbols as shown from the
>> excerpt below:
>>
>> p.variables->union(p.constantSymbols->collect(e |
>> thisModule.resolveTemp(e, 'vo')))
>>
>> Problem comes next when it goes further transforming each
>> SimpagationRule:
>>
>> rule simpagation2simpagation (r : CHR!Simpagation,v :
>> Sequence(CHR!VariableSymbol))
>> {
>> using {
>> co : Sequence(CHR!ConstantSymbol) =
>> thisModule.allConstantSymbols(r.keep->union(r.remove));
>> new_vs : Sequence(CHR!VariableSymbol) = v->select(va |
>> va.name.startsWith('_vj '));
>> }
>> to
>> ro : CHR!Simpagation (
>> name <- r.name,
>> keep <- r.keep,
>> remove <- r.remove,
>>
>> guard <- r.guard->union(co->iterate(c; acc : CHR!Bic = Sequence{} |
>> acc->including(thisModule.newBic(c,new_vs->at(co->indexOf(c)))))),
>> disjunctiveBody <- r.disjunctiveBody
>> )
>> do {
>>
>> ro; --returns an instance of a new output
>> Simpagation rule
>> }
>> }
>>
>> So ´guard´ is the attribute of Simpagation that will contain the new
>> Bic(s). In our example just ´Z=2´. It iterates over the collection of
>> Constants and is supposed to create new built-ins via the called rule
>> below: (which does not create any Bic instance.)
>>
>> rule newBic(c : CHR!ConstantSymbol, v : CHR!VariableSymbol)
>> {
>> using {
>> cs : CHR!ConstraintSymbol = thisModule.getEquality();
>> }
>> to
>> nb : CHR!Bic (
>> args<-Sequence{v,c},
>> symbol <- cs
>> )
>> do
>> {
>> nb;
>> }
>> }
>>
>> The above rule just gets a Constant and a Variable and makes a new
>> Equality. Unfortunately it is not working at all. Could somebody spot
>> what I should be doing wrong? Here are some additional helpers that I
>> use throughout the rules:
>>
>> helper def: counter : Integer = 101;
>>
>> helper def: newVariableName() : String = '_vj' +
>> thisModule.counter.toString();
>>
>> helper def : allConstantSymbols (s : Sequence(CHR!Udc)): Sequence
>> (CHR!ConstantSymbol) =
>> s->iterate(u; acc : CHR!ConstantSymbol = Sequence{} |
>> acc->union(u.args->select(a |
>> a.oclIsTypeOf(CHR!ConstantSymbol))));
>>
>> helper def : getEquality () : CHR!ConstraintSymbol =
>> CHR!ConstraintSymbol->allInstances()->select(e | e.name='equality');
>>
>>
>> Thanks a lot.
>>
>> Jairson Vitorino
>
>
>
|
|
|
Re: [ATL] Problem when creating output objects using Called Rules [message #12140 is a reply to message #12127] |
Wed, 24 January 2007 18:56 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Frédéric Jouault![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=frederic.jouault%40univ-nantes.fr) Messages: 572 Registered: July 2009 |
Senior Member |
|
|
Hello Jairson,
Firstly, could you please stick to the rule of prefixing the subject of
your post with [ATL] for ATL-related questions?
I know this is a bit annoying, and relatively easy to forget. However,
it clearly identifies the M2M component, about which the question is.
This will become increasingly useful when several components are available.
Secondly, regarding your problem:
it seems that you navigate the target model (h.variable, where h is a
target element). This is not valid ATL code: target models are write-only.
A common solution is to use an attribute helper. You can for instance
replace the following incorrect code:
rule A2B {
from
s : MMa!A
to
t : MMb!B (
prop1 <- <expression1>(s)
prop2 <- <expression2>(t.prop1)
)
}
, where the initialization expression for prop2 refers to t.prop1,
by:
-- remark: you should replace the OclAny by a more appropriate type
helper context MMa!A def: expression1 : OclAny =
<expression1>(self);
rule A2B {
from
s : MMa!A
to
t : MMb!B (
prop1 <- s.expression1,
prop2 <- <expression2>(s.expression1)
)
}
Another possibility (when <expression1> does not use resolveTemp) would
be to use rule variables:
rule A2B {
from
s : MMa!A
using {
-- remark: you should replace the OclAny by a more appropriate type
-- WARNING: this solution does not work if <expression1> uses
-- thisModule.resolveTemp(...)
expression1 : OclAny = <expression1>(s);
}
to
t : MMb!B (
prop1 <- expression1,
prop2 <- <expression2>(expression1)
)
}
Regards,
Frédéric Jouault
Jairson wrote:
> Hello Mikaël,
>
> Thanks for the tip. I debugged the code and discovered that the error is
> in the following rule:
>
> rule CHRProg2CHRProg
> {
> from
> p : CHR!CHRProgram
> to
> h : CHR!CHRProgram (
>
> variables <- p.variables->union(p.constantSymbols->collect(e |
> thisModule.resolveTemp(e, 'vo'))),
> rules <- p.rules->collect(r |
> thisModule.simpagation2simpagation(r,h.variables))
> (...)
>
> Quick remind: I transform p(X,2) to
> p(X,Z) AND Z=2, being Z the new variable.
>
> The exact problem is that the two assignments above are done in
> sequential order, BUT in rule execution time p.variables does not yet
> refer to the new variables created by the instruction:
> p.constantSymbols->collect(e |
> thisModule.resolveTemp(e, 'vo')
>
> So when I send the p.variables as a parameter in
> thisModule.simpagation2simpagation(r,h.variables), it does not include
> the recently created output variables and I see an out of bound error in
> the console. I tried:
>
> thisModule.simpagation2simpagation(r,variables))
>
> (without the p, but I got a syntax error).
>
> Then I tried p.variables, but it did not work either as one would´ve
> expected.
>
> Finally I pasted all the assignments in an imperative clause, which made
> matters worse. So I am kind of stuck here.
>
> I wonder if there is some way around this issue.
>
> regards,
>
> Jairson Vitorino
>
>
> Mikaël Barbero wrote:
>> Hi Jairson,
>>
>> Did you try to use the debug() function ? For instance, if i were you,
>> i would try to use it on the "new_vs->at(co->indexOf(c))":
>>
>> new_vs->at(co->indexOf(c)).debug('DEBUG HERE')
>>
>> Then, you can look at the ATL console and see if you are getting the
>> value as you expect.
>>
>> Regars,
>> Mikael
>>
>> Jairson wrote:
>>> Hello All,
>>>
>>> I am trying to do a very simple transformation that does the following:
>>>
>>> from: p(X,2)
>>>
>>> generates: p(X,Z) AND Z=2
>>>
>>> p is an instance of metaclass Udc (user-defined constraint) with args
>>> X and 2, X is a Variable, 2 is a Constant and X=2 is a Bic instance
>>> (Bic stands for built-in constraint) with args X and 2 and symbol "="
>>> (Equality).
>>>
>>> So this is all encapsulated (as references not containment) in
>>> metaclass SimpagationRule. And a collection of SimpagationRule(s) is
>>> encapsulated by a CHRProgram metaclass that also contains all the
>>> variables and constants. So we say that:
>>>
>>> CHRProgram -> * SimpagationRule
>>> SimpagationRule -> * Udc AND
>>> SimpagationRule -> * Bic AND
>>> Udc and Bic ->* Variable/Constant
>>>
>>> Below I paste the somewhat simplified rules:
>>>
>>> rule CHRProg2CHRProg
>>> {
>>> from
>>> p : CHR!CHRProgram
>>> to
>>> h : CHR!CHRProgram (
>>> constraintSymbols <- p.constraintSymbols,
>>> variables <-
>>> p.variables->union(p.constantSymbols->collect(e |
>>> thisModule.resolveTemp(e, 'vo'))),
>>> constantSymbols <- p.constantSymbols->collect(e |
>>> thisModule.resolveTemp(e, 'co')),
>>> functionSymbols <- p.functionSymbols,
>>> rules <- p.rules->collect(r |
>>> thisModule.simpagation2simpagation(r,p.variables))
>>> )
>>>
>>> }
>>>
>>> so This first rule generates the variables ok, including the new
>>> variables corresponding to the contantSymbols as shown from the
>>> excerpt below:
>>>
>>> p.variables->union(p.constantSymbols->collect(e |
>>> thisModule.resolveTemp(e, 'vo')))
>>>
>>> Problem comes next when it goes further transforming each
>>> SimpagationRule:
>>>
>>> rule simpagation2simpagation (r : CHR!Simpagation,v :
>>> Sequence(CHR!VariableSymbol))
>>> {
>>> using {
>>> co : Sequence(CHR!ConstantSymbol) =
>>> thisModule.allConstantSymbols(r.keep->union(r.remove));
>>> new_vs : Sequence(CHR!VariableSymbol) = v->select(va |
>>> va.name.startsWith('_vj '));
>>> }
>>> to
>>> ro : CHR!Simpagation (
>>> name <- r.name,
>>> keep <- r.keep,
>>> remove <- r.remove,
>>>
>>> guard <- r.guard->union(co->iterate(c; acc : CHR!Bic = Sequence{} |
>>> acc->including(thisModule.newBic(c,new_vs->at(co->indexOf(c)))))),
>>> disjunctiveBody <- r.disjunctiveBody
>>> )
>>> do {
>>>
>>> ro; --returns an instance of a new output
>>> Simpagation rule
>>> }
>>> }
>>>
>>> So ´guard´ is the attribute of Simpagation that will contain the new
>>> Bic(s). In our example just ´Z=2´. It iterates over the collection of
>>> Constants and is supposed to create new built-ins via the called rule
>>> below: (which does not create any Bic instance.)
>>>
>>> rule newBic(c : CHR!ConstantSymbol, v : CHR!VariableSymbol)
>>> {
>>> using {
>>> cs : CHR!ConstraintSymbol = thisModule.getEquality();
>>> }
>>> to
>>> nb : CHR!Bic (
>>> args<-Sequence{v,c},
>>> symbol <- cs
>>> )
>>> do
>>> {
>>> nb;
>>> }
>>> }
>>>
>>> The above rule just gets a Constant and a Variable and makes a new
>>> Equality. Unfortunately it is not working at all. Could somebody spot
>>> what I should be doing wrong? Here are some additional helpers that I
>>> use throughout the rules:
>>>
>>> helper def: counter : Integer = 101;
>>>
>>> helper def: newVariableName() : String = '_vj' +
>>> thisModule.counter.toString();
>>>
>>> helper def : allConstantSymbols (s : Sequence(CHR!Udc)): Sequence
>>> (CHR!ConstantSymbol) =
>>> s->iterate(u; acc : CHR!ConstantSymbol = Sequence{} |
>>> acc->union(u.args->select(a |
>>> a.oclIsTypeOf(CHR!ConstantSymbol))));
>>>
>>> helper def : getEquality () : CHR!ConstraintSymbol =
>>> CHR!ConstraintSymbol->allInstances()->select(e | e.name='equality');
>>>
>>>
>>> Thanks a lot.
>>>
>>> Jairson Vitorino
>>
>>
>>
|
|
|
Re: [ATL] Problem when creating output objects using Called Rules [message #12153 is a reply to message #12140] |
Thu, 25 January 2007 12:09 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: jairson.gmail.com
Hello Frédéric
Thanks for your explanation. I am sorry I did not use [ATL] in the
subject, I must have missed the e-mail that explained the rules of the
newsgroup. In the future I will stick to it.
I did what you advised me, but as I launched the transformation I got
the following error message:
"An internal error occurred during: launching"
Nothing was in the console, but in the Error log I got a
java.Util.ArrayList exception.
So I did the debug and found out that my helper apparently do not return
a valid object. Here what I did:
helper context CHR!CHRProgram def : generateVars :
Sequence(CHR!VariableSymbol) = self.constantSymbols->collect(e |
thisModule.resolveTemp(e, 'vo'));
So this helper is supposed to return a collection of variables, each one
corresponding to a constant in the input model. The rule below is
supposed to do just that:
rule constantSymbol2constantSymbol
{
from
c : CHR!ConstantSymbol
to
co : CHR!ConstantSymbol (
name <- c.name),
vo : CHR!VariableSymbol
(
name <- thisModule.newVariableName()
)
do {
thisModule.counter <- thisModule.counter + 1;
}
}
I changed my ´main´ rule to follow the scheme you advised me:
rule CHRProg2CHRProg
{
from
p : CHR!CHRProgram
to
h : CHR!CHRProgram (
variables <- p.variables->union(p.generateVars),
constantSymbols <- p.constantSymbols->collect(e |
thisModule.resolveTemp(e, 'co')),
rules <- p.rules->collect(r |
thisModule.simpagation2simpagation(r,p.generateVars))
)
}
When I debugged that, I inspected the parameter v corresponding to
p.generateVars in the rule below:
rule simpagation2simpagation (r : CHR!Simpagation,v :
Sequence(CHR!VariableSymbol))
{
using {
co : Sequence(CHR!ConstantSymbol) =
thisModule.allConstantSymbols(r.keep->union(r.remove));
}
to
ro : CHR!Simpagation (
guard <- r.guard->union(co->iterate(c; acc : CHR!Bic =
Sequence{} |
acc->including(thisModule.newBic(c,v->at(co->indexOf(c)))))),
)
do {
ro; --returns an instance of a new output Simpagation rule
}
}
And I found that v was a variable but it´s 'name' attribute referred not
to a String but to 'Object 903' in the debug variable view (whereas the
other instances of variables 'name' attributes were referring to Strings).
I suspected then that the Launch error is connected to the operation
v->(co->indexOf(c)) that I do in this rule. I spent the whole morning to
figure out what might be wrong with my adaptation of your advice but it
seems to me that I should have everything right. Do you have any idea
why this helper is not working?
Thanks a lot !
Jairson Vitorino
Frédéric Jouault wrote:
> Hello Jairson,
>
>
> Firstly, could you please stick to the rule of prefixing the subject of
> your post with [ATL] for ATL-related questions?
>
> I know this is a bit annoying, and relatively easy to forget. However,
> it clearly identifies the M2M component, about which the question is.
> This will become increasingly useful when several components are available.
>
>
>
> Secondly, regarding your problem:
> it seems that you navigate the target model (h.variable, where h is a
> target element). This is not valid ATL code: target models are write-only.
>
> A common solution is to use an attribute helper. You can for instance
> replace the following incorrect code:
>
> rule A2B {
> from
> s : MMa!A
> to
> t : MMb!B (
> prop1 <- <expression1>(s)
> prop2 <- <expression2>(t.prop1)
> )
> }
>
> , where the initialization expression for prop2 refers to t.prop1,
> by:
>
> -- remark: you should replace the OclAny by a more appropriate type
> helper context MMa!A def: expression1 : OclAny =
> <expression1>(self);
>
> rule A2B {
> from
> s : MMa!A
> to
> t : MMb!B (
> prop1 <- s.expression1,
> prop2 <- <expression2>(s.expression1)
> )
> }
>
> Another possibility (when <expression1> does not use resolveTemp) would
> be to use rule variables:
>
> rule A2B {
> from
> s : MMa!A
> using {
> -- remark: you should replace the OclAny by a more appropriate type
> -- WARNING: this solution does not work if <expression1> uses
> -- thisModule.resolveTemp(...)
> expression1 : OclAny = <expression1>(s);
> }
> to
> t : MMb!B (
> prop1 <- expression1,
> prop2 <- <expression2>(expression1)
> )
> }
>
>
> Regards,
>
> Frédéric Jouault
>
>
> Jairson wrote:
>> Hello Mikaël,
>>
>> Thanks for the tip. I debugged the code and discovered that the error
>> is in the following rule:
>>
>> rule CHRProg2CHRProg
>> {
>> from
>> p : CHR!CHRProgram
>> to
>> h : CHR!CHRProgram (
>>
>> variables <- p.variables->union(p.constantSymbols->collect(e |
>> thisModule.resolveTemp(e, 'vo'))),
>> rules <- p.rules->collect(r |
>> thisModule.simpagation2simpagation(r,h.variables))
>> (...)
>>
>> Quick remind: I transform p(X,2) to
>> p(X,Z) AND Z=2, being Z the new variable.
>>
>> The exact problem is that the two assignments above are done in
>> sequential order, BUT in rule execution time p.variables does not yet
>> refer to the new variables created by the instruction:
>> p.constantSymbols->collect(e |
>> thisModule.resolveTemp(e, 'vo')
>>
>> So when I send the p.variables as a parameter in
>> thisModule.simpagation2simpagation(r,h.variables), it does not include
>> the recently created output variables and I see an out of bound error
>> in the console. I tried:
>>
>> thisModule.simpagation2simpagation(r,variables))
>>
>> (without the p, but I got a syntax error).
>>
>> Then I tried p.variables, but it did not work either as one would´ve
>> expected.
>>
>> Finally I pasted all the assignments in an imperative clause, which
>> made matters worse. So I am kind of stuck here.
>>
>> I wonder if there is some way around this issue.
>>
>> regards,
>>
>> Jairson Vitorino
>>
>>
>> Mikaël Barbero wrote:
>>> Hi Jairson,
>>>
>>> Did you try to use the debug() function ? For instance, if i were
>>> you, i would try to use it on the "new_vs->at(co->indexOf(c))":
>>>
>>> new_vs->at(co->indexOf(c)).debug('DEBUG HERE')
>>>
>>> Then, you can look at the ATL console and see if you are getting the
>>> value as you expect.
>>>
>>> Regars,
>>> Mikael
>>>
>>> Jairson wrote:
>>>> Hello All,
>>>>
>>>> I am trying to do a very simple transformation that does the following:
>>>>
>>>> from: p(X,2)
>>>>
>>>> generates: p(X,Z) AND Z=2
>>>>
>>>> p is an instance of metaclass Udc (user-defined constraint) with
>>>> args X and 2, X is a Variable, 2 is a Constant and X=2 is a Bic
>>>> instance (Bic stands for built-in constraint) with args X and 2 and
>>>> symbol "=" (Equality).
>>>>
>>>> So this is all encapsulated (as references not containment) in
>>>> metaclass SimpagationRule. And a collection of SimpagationRule(s) is
>>>> encapsulated by a CHRProgram metaclass that also contains all the
>>>> variables and constants. So we say that:
>>>>
>>>> CHRProgram -> * SimpagationRule
>>>> SimpagationRule -> * Udc AND
>>>> SimpagationRule -> * Bic AND
>>>> Udc and Bic ->* Variable/Constant
>>>>
>>>> Below I paste the somewhat simplified rules:
>>>>
>>>> rule CHRProg2CHRProg
>>>> {
>>>> from
>>>> p : CHR!CHRProgram
>>>> to
>>>> h : CHR!CHRProgram (
>>>> constraintSymbols <- p.constraintSymbols,
>>>> variables <-
>>>> p.variables->union(p.constantSymbols->collect(e |
>>>> thisModule.resolveTemp(e, 'vo'))),
>>>> constantSymbols <- p.constantSymbols->collect(e |
>>>> thisModule.resolveTemp(e, 'co')),
>>>> functionSymbols <- p.functionSymbols,
>>>> rules <- p.rules->collect(r |
>>>> thisModule.simpagation2simpagation(r,p.variables))
>>>> )
>>>>
>>>> }
>>>>
>>>> so This first rule generates the variables ok, including the new
>>>> variables corresponding to the contantSymbols as shown from the
>>>> excerpt below:
>>>>
>>>> p.variables->union(p.constantSymbols->collect(e |
>>>> thisModule.resolveTemp(e, 'vo')))
>>>>
>>>> Problem comes next when it goes further transforming each
>>>> SimpagationRule:
>>>>
>>>> rule simpagation2simpagation (r : CHR!Simpagation,v :
>>>> Sequence(CHR!VariableSymbol))
>>>> {
>>>> using {
>>>> co : Sequence(CHR!ConstantSymbol) =
>>>> thisModule.allConstantSymbols(r.keep->union(r.remove));
>>>> new_vs : Sequence(CHR!VariableSymbol) = v->select(va |
>>>> va.name.startsWith('_vj '));
>>>> }
>>>> to
>>>> ro : CHR!Simpagation (
>>>> name <- r.name,
>>>> keep <- r.keep,
>>>> remove <- r.remove,
>>>>
>>>> guard <- r.guard->union(co->iterate(c; acc : CHR!Bic = Sequence{} |
>>>> acc->including(thisModule.newBic(c,new_vs->at(co->indexOf(c)))))),
>>>> disjunctiveBody <- r.disjunctiveBody
>>>> )
>>>> do {
>>>>
>>>> ro; --returns an instance of a new output
>>>> Simpagation rule
>>>> }
>>>> }
>>>>
>>>> So ´guard´ is the attribute of Simpagation that will contain the new
>>>> Bic(s). In our example just ´Z=2´. It iterates over the collection
>>>> of Constants and is supposed to create new built-ins via the called
>>>> rule below: (which does not create any Bic instance.)
>>>>
>>>> rule newBic(c : CHR!ConstantSymbol, v : CHR!VariableSymbol)
>>>> {
>>>> using {
>>>> cs : CHR!ConstraintSymbol = thisModule.getEquality();
>>>> }
>>>> to
>>>> nb : CHR!Bic (
>>>> args<-Sequence{v,c},
>>>> symbol <- cs
>>>> )
>>>> do
>>>> {
>>>> nb;
>>>> }
>>>> }
>>>>
>>>> The above rule just gets a Constant and a Variable and makes a new
>>>> Equality. Unfortunately it is not working at all. Could somebody
>>>> spot what I should be doing wrong? Here are some additional helpers
>>>> that I use throughout the rules:
>>>>
>>>> helper def: counter : Integer = 101;
>>>>
>>>> helper def: newVariableName() : String = '_vj' +
>>>> thisModule.counter.toString();
>>>>
>>>> helper def : allConstantSymbols (s : Sequence(CHR!Udc)): Sequence
>>>> (CHR!ConstantSymbol) =
>>>> s->iterate(u; acc : CHR!ConstantSymbol = Sequence{} |
>>>> acc->union(u.args->select(a |
>>>> a.oclIsTypeOf(CHR!ConstantSymbol))));
>>>>
>>>> helper def : getEquality () : CHR!ConstraintSymbol =
>>>> CHR!ConstraintSymbol->allInstances()->select(e | e.name='equality');
>>>>
>>>>
>>>> Thanks a lot.
>>>>
>>>> Jairson Vitorino
>>>
>>>
>>>
|
|
|
Re: [ATL] Problem when creating output objects using Called Rules [message #12915 is a reply to message #12153] |
Fri, 26 January 2007 15:19 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: jairson.gmail.com
Hello all,
It turned out that there was nothing wrong whit the helpers and rules of
my last email. Mikaël pointed what I was doing wrong, which is the rule
below:
rule newBic(c : CHR!ConstantSymbol, v : CHR!VariableSymbol)
>>>>> {
>>>>> using {
>>>>> cs : CHR!ConstraintSymbol = thisModule.getEquality();
>>>>> }
>>>>> to
>>>>> nb : CHR!Bic (
>>>>> args<-Sequence{v,c},
>>>>> symbol <- cs
>>>>> )
>>>>> do
>>>>> {
>>>>> nb;
>>>>> }
>>>>> }
>>>>>
I was trying to bind (<-) a ConstraintSymbol (with name equality) from
the source model to a target model element. One have to create it in the
target !!! So Mikaël sent me the correct version of the rule, which is
below:
rule newBic(c : CHR!ConstantSymbol, v : CHR!VariableSymbol)
{
to
nb : CHR!Bic (
args<-Sequence{v,c},
symbol <- equality
),
equality : CHR!ConstraintSymbol (
name <- 'equality'
)
do
{
nb;
}
}
I´m very grateful to Frédéric and Mikaël that saved me many hours of
work trying to figure out all this be myself.
regards,
Jairson Vitorino
Jairson wrote:
> Hello Frédéric
>
> Thanks for your explanation. I am sorry I did not use [ATL] in the
> subject, I must have missed the e-mail that explained the rules of the
> newsgroup. In the future I will stick to it.
>
> I did what you advised me, but as I launched the transformation I got
> the following error message:
>
> "An internal error occurred during: launching"
>
> Nothing was in the console, but in the Error log I got a
> java.Util.ArrayList exception.
>
> So I did the debug and found out that my helper apparently do not return
> a valid object. Here what I did:
>
> helper context CHR!CHRProgram def : generateVars :
> Sequence(CHR!VariableSymbol) = self.constantSymbols->collect(e |
> thisModule.resolveTemp(e, 'vo'));
>
> So this helper is supposed to return a collection of variables, each one
> corresponding to a constant in the input model. The rule below is
> supposed to do just that:
>
> rule constantSymbol2constantSymbol
> {
> from
> c : CHR!ConstantSymbol
> to
> co : CHR!ConstantSymbol (
> name <- c.name),
> vo : CHR!VariableSymbol
> (
> name <- thisModule.newVariableName()
> )
> do {
> thisModule.counter <- thisModule.counter + 1;
>
> }
>
> }
>
> I changed my ´main´ rule to follow the scheme you advised me:
>
> rule CHRProg2CHRProg
> {
> from
> p : CHR!CHRProgram
> to
> h : CHR!CHRProgram (
> variables <- p.variables->union(p.generateVars),
> constantSymbols <- p.constantSymbols->collect(e |
> thisModule.resolveTemp(e, 'co')),
>
> rules <- p.rules->collect(r |
> thisModule.simpagation2simpagation(r,p.generateVars))
> )
>
> }
>
> When I debugged that, I inspected the parameter v corresponding to
> p.generateVars in the rule below:
>
> rule simpagation2simpagation (r : CHR!Simpagation,v :
> Sequence(CHR!VariableSymbol))
> {
> using {
> co : Sequence(CHR!ConstantSymbol) =
> thisModule.allConstantSymbols(r.keep->union(r.remove));
>
> }
> to
> ro : CHR!Simpagation (
>
> guard <-
> r.guard->union(co->iterate(c; acc : CHR!Bic =
> Sequence{} |
> acc->including(thisModule.newBic(c,v->at(co->indexOf(c)))))),
>
> )
> do {
>
> ro; --returns an instance of a new output
> Simpagation rule
> }
>
> }
>
> And I found that v was a variable but it´s 'name' attribute referred not
> to a String but to 'Object 903' in the debug variable view (whereas the
> other instances of variables 'name' attributes were referring to Strings).
>
> I suspected then that the Launch error is connected to the operation
> v->(co->indexOf(c)) that I do in this rule. I spent the whole morning to
> figure out what might be wrong with my adaptation of your advice but it
> seems to me that I should have everything right. Do you have any idea
> why this helper is not working?
>
> Thanks a lot !
>
> Jairson Vitorino
>
> Frédéric Jouault wrote:
>> Hello Jairson,
>>
>>
>> Firstly, could you please stick to the rule of prefixing the subject
>> of your post with [ATL] for ATL-related questions?
>>
>> I know this is a bit annoying, and relatively easy to forget. However,
>> it clearly identifies the M2M component, about which the question is.
>> This will become increasingly useful when several components are
>> available.
>>
>>
>>
>> Secondly, regarding your problem:
>> it seems that you navigate the target model (h.variable, where h is a
>> target element). This is not valid ATL code: target models are
>> write-only.
>>
>> A common solution is to use an attribute helper. You can for instance
>> replace the following incorrect code:
>>
>> rule A2B {
>> from
>> s : MMa!A
>> to
>> t : MMb!B (
>> prop1 <- <expression1>(s)
>> prop2 <- <expression2>(t.prop1)
>> )
>> }
>>
>> , where the initialization expression for prop2 refers to t.prop1,
>> by:
>>
>> -- remark: you should replace the OclAny by a more appropriate type
>> helper context MMa!A def: expression1 : OclAny =
>> <expression1>(self);
>>
>> rule A2B {
>> from
>> s : MMa!A
>> to
>> t : MMb!B (
>> prop1 <- s.expression1,
>> prop2 <- <expression2>(s.expression1)
>> )
>> }
>>
>> Another possibility (when <expression1> does not use resolveTemp)
>> would be to use rule variables:
>>
>> rule A2B {
>> from
>> s : MMa!A
>> using {
>> -- remark: you should replace the OclAny by a more appropriate type
>> -- WARNING: this solution does not work if <expression1> uses
>> -- thisModule.resolveTemp(...)
>> expression1 : OclAny = <expression1>(s);
>> }
>> to
>> t : MMb!B (
>> prop1 <- expression1,
>> prop2 <- <expression2>(expression1)
>> )
>> }
>>
>>
>> Regards,
>>
>> Frédéric Jouault
>>
>>
>> Jairson wrote:
>>> Hello Mikaël,
>>>
>>> Thanks for the tip. I debugged the code and discovered that the error
>>> is in the following rule:
>>>
>>> rule CHRProg2CHRProg
>>> {
>>> from
>>> p : CHR!CHRProgram
>>> to
>>> h : CHR!CHRProgram (
>>>
>>> variables <- p.variables->union(p.constantSymbols->collect(e |
>>> thisModule.resolveTemp(e, 'vo'))),
>>> rules <- p.rules->collect(r |
>>> thisModule.simpagation2simpagation(r,h.variables))
>>> (...)
>>>
>>> Quick remind: I transform p(X,2) to
>>> p(X,Z) AND Z=2, being Z the new variable.
>>>
>>> The exact problem is that the two assignments above are done in
>>> sequential order, BUT in rule execution time p.variables does not yet
>>> refer to the new variables created by the instruction:
>>> p.constantSymbols->collect(e |
>>> thisModule.resolveTemp(e, 'vo')
>>>
>>> So when I send the p.variables as a parameter in
>>> thisModule.simpagation2simpagation(r,h.variables), it does not
>>> include the recently created output variables and I see an out of
>>> bound error in the console. I tried:
>>>
>>> thisModule.simpagation2simpagation(r,variables))
>>>
>>> (without the p, but I got a syntax error).
>>>
>>> Then I tried p.variables, but it did not work either as one would´ve
>>> expected.
>>>
>>> Finally I pasted all the assignments in an imperative clause, which
>>> made matters worse. So I am kind of stuck here.
>>>
>>> I wonder if there is some way around this issue.
>>>
>>> regards,
>>>
>>> Jairson Vitorino
>>>
>>>
>>> Mikaël Barbero wrote:
>>>> Hi Jairson,
>>>>
>>>> Did you try to use the debug() function ? For instance, if i were
>>>> you, i would try to use it on the "new_vs->at(co->indexOf(c))":
>>>>
>>>> new_vs->at(co->indexOf(c)).debug('DEBUG HERE')
>>>>
>>>> Then, you can look at the ATL console and see if you are getting the
>>>> value as you expect.
>>>>
>>>> Regars,
>>>> Mikael
>>>>
>>>> Jairson wrote:
>>>>> Hello All,
>>>>>
>>>>> I am trying to do a very simple transformation that does the
>>>>> following:
>>>>>
>>>>> from: p(X,2)
>>>>>
>>>>> generates: p(X,Z) AND Z=2
>>>>>
>>>>> p is an instance of metaclass Udc (user-defined constraint) with
>>>>> args X and 2, X is a Variable, 2 is a Constant and X=2 is a Bic
>>>>> instance (Bic stands for built-in constraint) with args X and 2 and
>>>>> symbol "=" (Equality).
>>>>>
>>>>> So this is all encapsulated (as references not containment) in
>>>>> metaclass SimpagationRule. And a collection of SimpagationRule(s)
>>>>> is encapsulated by a CHRProgram metaclass that also contains all
>>>>> the variables and constants. So we say that:
>>>>>
>>>>> CHRProgram -> * SimpagationRule
>>>>> SimpagationRule -> * Udc AND
>>>>> SimpagationRule -> * Bic AND
>>>>> Udc and Bic ->* Variable/Constant
>>>>>
>>>>> Below I paste the somewhat simplified rules:
>>>>>
>>>>> rule CHRProg2CHRProg
>>>>> {
>>>>> from
>>>>> p : CHR!CHRProgram
>>>>> to
>>>>> h : CHR!CHRProgram (
>>>>> constraintSymbols <- p.constraintSymbols,
>>>>> variables <-
>>>>> p.variables->union(p.constantSymbols->collect(e |
>>>>> thisModule.resolveTemp(e, 'vo'))),
>>>>> constantSymbols <- p.constantSymbols->collect(e |
>>>>> thisModule.resolveTemp(e, 'co')),
>>>>> functionSymbols <- p.functionSymbols,
>>>>> rules <- p.rules->collect(r |
>>>>> thisModule.simpagation2simpagation(r,p.variables))
>>>>> )
>>>>>
>>>>> }
>>>>>
>>>>> so This first rule generates the variables ok, including the new
>>>>> variables corresponding to the contantSymbols as shown from the
>>>>> excerpt below:
>>>>>
>>>>> p.variables->union(p.constantSymbols->collect(e |
>>>>> thisModule.resolveTemp(e, 'vo')))
>>>>>
>>>>> Problem comes next when it goes further transforming each
>>>>> SimpagationRule:
>>>>>
>>>>> rule simpagation2simpagation (r : CHR!Simpagation,v :
>>>>> Sequence(CHR!VariableSymbol))
>>>>> {
>>>>> using {
>>>>> co : Sequence(CHR!ConstantSymbol) =
>>>>> thisModule.allConstantSymbols(r.keep->union(r.remove));
>>>>> new_vs : Sequence(CHR!VariableSymbol) = v->select(va |
>>>>> va.name.startsWith('_vj '));
>>>>> }
>>>>> to
>>>>> ro : CHR!Simpagation (
>>>>> name <- r.name,
>>>>> keep <- r.keep,
>>>>> remove <- r.remove,
>>>>>
>>>>> guard <- r.guard->union(co->iterate(c; acc : CHR!Bic = Sequence{}
>>>>> | acc->including(thisModule.newBic(c,new_vs->at(co->indexOf(c)))))),
>>>>> disjunctiveBody <- r.disjunctiveBody
>>>>> )
>>>>> do {
>>>>>
>>>>> ro; --returns an instance of a new output
>>>>> Simpagation rule
>>>>> }
>>>>> }
>>>>>
>>>>> So ´guard´ is the attribute of Simpagation that will contain the
>>>>> new Bic(s). In our example just ´Z=2´. It iterates over the
>>>>> collection of Constants and is supposed to create new built-ins via
>>>>> the called rule below: (which does not create any Bic instance.)
>>>>>
>>>>> rule newBic(c : CHR!ConstantSymbol, v : CHR!VariableSymbol)
>>>>> {
>>>>> using {
>>>>> cs : CHR!ConstraintSymbol = thisModule.getEquality();
>>>>> }
>>>>> to
>>>>> nb : CHR!Bic (
>>>>> args<-Sequence{v,c},
>>>>> symbol <- cs
>>>>> )
>>>>> do
>>>>> {
>>>>> nb;
>>>>> }
>>>>> }
>>>>>
>>>>> The above rule just gets a Constant and a Variable and makes a new
>>>>> Equality. Unfortunately it is not working at all. Could somebody
>>>>> spot what I should be doing wrong? Here are some additional helpers
>>>>> that I use throughout the rules:
>>>>>
>>>>> helper def: counter : Integer = 101;
>>>>>
>>>>> helper def: newVariableName() : String = '_vj' +
>>>>> thisModule.counter.toString();
>>>>>
>>>>> helper def : allConstantSymbols (s : Sequence(CHR!Udc)): Sequence
>>>>> (CHR!ConstantSymbol) =
>>>>> s->iterate(u; acc : CHR!ConstantSymbol = Sequence{} |
>>>>> acc->union(u.args->select(a |
>>>>> a.oclIsTypeOf(CHR!ConstantSymbol))));
>>>>>
>>>>> helper def : getEquality () : CHR!ConstraintSymbol =
>>>>> CHR!ConstraintSymbol->allInstances()->select(e | e.name='equality');
>>>>>
>>>>>
>>>>> Thanks a lot.
>>>>>
>>>>> Jairson Vitorino
>>>>
>>>>
>>>>
|
|
|
Goto Forum:
Current Time: Sat Aug 31 23:36:47 GMT 2024
Powered by FUDForum. Page generated in 0.06988 seconds
|