Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » VIATRA2 » Can't Use 'iterate'
Can't Use 'iterate' [message #1229934] Fri, 10 January 2014 10:32 Go to next message
Huseyin Ergin is currently offline Huseyin Ergin
Messages: 4
Registered: January 2014
Junior Member
Hi everyone. When I try to execute a rule with iterate (to make it as long as possible), I get an error that says the 'in parameters' can not be undefined. But I am doing exactly the same thing from the tutorial pdf of Viatra2. Does anyone has an idea what happened?

This is the full error:

org.eclipse.viatra2.gtasm.interpreter.impl.machine.ASMInterpreterException: The value of the N1 variable can not be 'UNDEF' as it is an INPUT parameter for the immediateLink gtRule


This is my gtrule:

pattern isDirectConnected(N1, N2) =
{
node(N1);
node(N2);
node.next(NXT,N1,N2);
}

gtrule immediateLink(in N1, in N2, out T, out SRC, out TGT) =
{
precondition pattern lhs(N1, N2) =
{
find isDirectConnected(N1,N2);
}
action
{
new(node2node(T));
new(node2node.src(SRC,T,N1));
new(node2node.target(TGT,T,N2));
}
}


This is my execution under main:

let T=undef,SRC=undef,TGT=undef in
iterate
choose N1 below tree.models, N2 below tree.models
with apply immediateLink(N1,N2,T,SRC,TGT);
Re: Can't Use 'iterate' [message #1230266 is a reply to message #1229934] Sat, 11 January 2014 08:49 Go to previous messageGo to next message
Abel Hegedus is currently offline Abel Hegedus
Messages: 88
Registered: July 2009
Member
Hi Ergin,

first of all welcome to the VIATRA2 forums.

Can you point out which tutorial pdf you are using? Unfortunately, it may be outdated, as the pdf version of these materials are not kept up to date.

The error message is correct, the problem is that the GT rule needs a value for N1, but it is undef (since it is defined in the choose). If you would like to use an iterate over all possible values of N1, N2 and apply the immediateLink rule, you can do it like this:

iterate choose N1 below tree.models, N2 below tree.models with find isDirectConnected(N1,N2) do
  let T=undef, SRC=undef, TGT=undef in try choose with apply immediateLink(N1,N2,T,SRC,TGT) do skip;


If you need additional details or have further questions, it helps a lot to attach at least a VPML and a VTCL file so we can reproduce your issue. The VPML is needed both to see your metamodel (and parse the VTCL) and the instance model (to execute the VTCL).

Finally, if you did not already, please take a look at our new project EMF-IncQuery, which is the very efficient, incremental query evaluation framework of VIATRA2 adopted to EMF models with a nice development tooling and many extensions.
Re: Can't Use 'iterate' [message #1230652 is a reply to message #1230266] Sun, 12 January 2014 12:57 Go to previous messageGo to next message
Huseyin Ergin is currently offline Huseyin Ergin
Messages: 4
Registered: January 2014
Junior Member
Yes you are right. The pdf is dated as "May 29, 2006".

But I checked what you suggested and I could execute my rules that has as long as possible meaning succesfully. Thanks.

Now my question is: Do I have to put a "find" before "do" because it seems what I write with "find" should totaly be same as precondition pattern of the rule?


	pattern preconditionOfImmediateLink(N1, N2) =
	{
		node(N1);
		node(N2);
		node.next(NXT,N1,N2);
		neg find isGenericConnected(N1,N2);
	}
	
	pattern isGenericConnected(N1, N2) =
	{
		node(N1);
		node(N2);
		node2node(T);
		node2node.src(SRC,T,N1);
		node2node.target(TGT,T,N2);
	}
	
	gtrule immediateLink(in N1, in N2, out T, out SRC, out TGT) =
	{
		precondition pattern lhs(N1, N2) =
		{
			find preconditionOfImmediateLink(N1,N2);
		}
		action
		{
			new(node2node(T));
			new(node2node.src(SRC,T,N1));
			new(node2node.target(TGT,T,N2));
		}
	}

	rule main() = seq {

		iterate choose N1 below tree.models, N2 below tree.models with find preconditionOfImmediateLink(N1, N2) do
			let T=undef,SRC=undef,TGT=undef in
				try choose with apply immediateLink(N1,N2,T,SRC,TGT) do seq {
					rename(T,"trace("+name(N1)+":"+name(N2)+")");
					move(T,treeTrace.models);
				}
	}
Re: Can't Use 'iterate' [message #1231355 is a reply to message #1230652] Tue, 14 January 2014 07:58 Go to previous messageGo to next message
Abel Hegedus is currently offline Abel Hegedus
Messages: 88
Registered: July 2009
Member
If your GT rule has INPUT parameter, you have to include the find (or set the value of the variable in an other way).

You can set the parameter to OUTPUT, in which case your original version works as well. However, in this case you cannot bind the value of the output parameter, only use choose or forall to iterate on possible values.

I don't know exactly why are the semantics defined like this, I guess it may have to do with interpretation issues.
Re: Can't Use 'iterate' [message #1233948 is a reply to message #1231355] Mon, 20 January 2014 17:31 Go to previous message
Huseyin Ergin is currently offline Huseyin Ergin
Messages: 4
Registered: January 2014
Junior Member
Ok thanks. I think it doesnt matter. It is working. I just have to use the precondition of the rule twice. Or I am guessing I can just use a generic pattern to feed the input of the rules.

[Updated on: Mon, 20 January 2014 17:32]

Report message to a moderator

Previous Topic:Model Importer Skeleton for API
Next Topic:Looping Structure
Goto Forum:
  


Current Time: Wed Jul 23 16:12:06 EDT 2014

Powered by FUDForum. Page generated in 0.02026 seconds