tagging as per http://dev.eclipse.org/ipzilla/show_bug.cgi?id=6703
diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/.classpath b/org.eclipse.viatra2.gtasm.patternmatcher.impl/.classpath
new file mode 100644
index 0000000..ad32c83
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/.project b/org.eclipse.viatra2.gtasm.patternmatcher.impl/.project
new file mode 100644
index 0000000..21cdd1e
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>org.eclipse.viatra2.gtasm.patternmatcher.impl</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.ManifestBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.SchemaBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.pde.PluginNature</nature>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>
diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.viatra2.gtasm.patternmatcher.impl/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..4a26c10
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,12 @@
+#Wed Jan 12 11:20:55 CET 2011
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/.settings/org.eclipse.jdt.ui.prefs b/org.eclipse.viatra2.gtasm.patternmatcher.impl/.settings/org.eclipse.jdt.ui.prefs
new file mode 100644
index 0000000..8835e8a
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/.settings/org.eclipse.jdt.ui.prefs
@@ -0,0 +1,5 @@
+#Mon Sep 20 14:02:58 CEST 2010

+eclipse.preferences.version=1

+internal.default.compliance=default

+org.eclipse.jdt.ui.javadoc=false

+org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?><templates><template autoinsert\="true" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\r\n * @return the ${bare_field_name}\r\n */</template><template autoinsert\="true" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\r\n * @param ${param} the ${bare_field_name} to set\r\n */</template><template autoinsert\="true" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\r\n * ${tags}\r\n */</template><template autoinsert\="false" context\="filecomment_context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">/*******************************************************************************\r\n * Copyright (c) 2004-2010 Akos Horvath, Gergely Varro and Daniel Varro\r\n * All rights reserved. This program and the accompanying materials\r\n * are made available under the terms of the Eclipse Public License v1.0\r\n * which accompanies this distribution, and is available at\r\n * http\://www.eclipse.org/legal/epl-v10.html\r\n *\r\n * Contributors\:\r\n *    Akos Horvath - initial API and implementation\r\n *******************************************************************************/\r\n</template><template autoinsert\="false" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\r\n * @author Akos Horvath\r\n *\r\n * ${tags}\r\n */</template><template autoinsert\="true" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/**\r\n * \r\n */</template><template autoinsert\="true" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\r\n * ${tags}\r\n */</template><template autoinsert\="true" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment">/* (non-Javadoc)\r\n * ${see_to_overridden}\r\n */</template><template autoinsert\="true" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment">/**\r\n * ${tags}\r\n * ${see_to_target}\r\n */</template><template autoinsert\="false" context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.newtype" name\="newtype">/*******************************************************************************\r\n * Copyright (c) 2004-2010 Akos Horvath and Daniel Varro\r\n * All rights reserved. This program and the accompanying materials\r\n * are made available under the terms of the Eclipse Public License v1.0\r\n * which accompanies this distribution, and is available at\r\n * http\://www.eclipse.org/legal/epl-v10.html\r\n *\r\n * Contributors\:\r\n *    Akos Horvath - initial API and implementation\r\n *******************************************************************************/\r\n\r\n\r\n${filecomment}\r\n${package_declaration}\r\n\r\n${typecomment}\r\n${type_declaration}</template><template autoinsert\="true" context\="classbody_context" deleted\="false" description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.classbody" name\="classbody">\r\n</template><template autoinsert\="true" context\="interfacebody_context" deleted\="false" description\="Code in new interface type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name\="interfacebody">\r\n</template><template autoinsert\="true" context\="enumbody_context" deleted\="false" description\="Code in new enum type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.enumbody" name\="enumbody">\r\n</template><template autoinsert\="true" context\="annotationbody_context" deleted\="false" description\="Code in new annotation type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name\="annotationbody">\r\n</template><template autoinsert\="true" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">// ${todo} Auto-generated catch block\r\n${exception_var}.printStackTrace();</template><template autoinsert\="true" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">// ${todo} Auto-generated method stub\r\n${body_statement}</template><template autoinsert\="true" context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}\r\n// ${todo} Auto-generated constructor stub</template><template autoinsert\="true" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="true" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template></templates>

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/.settings/org.eclipse.ltk.core.refactoring.prefs b/org.eclipse.viatra2.gtasm.patternmatcher.impl/.settings/org.eclipse.ltk.core.refactoring.prefs
new file mode 100644
index 0000000..f3391b2
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/.settings/org.eclipse.ltk.core.refactoring.prefs
@@ -0,0 +1,3 @@
+#Thu Aug 03 02:30:54 CEST 2006
+eclipse.preferences.version=1
+org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false
diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/.settings/org.eclipse.wst.validation.prefs b/org.eclipse.viatra2.gtasm.patternmatcher.impl/.settings/org.eclipse.wst.validation.prefs
new file mode 100644
index 0000000..db982d7
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/.settings/org.eclipse.wst.validation.prefs
@@ -0,0 +1,6 @@
+#Thu Aug 03 02:30:54 CEST 2006
+DELEGATES_PREFERENCE=delegateValidatorListorg.eclipse.wst.wsdl.validation.internal.eclipse.WSDLDelegatingValidator\=org.eclipse.wst.wsdl.validation.internal.eclipse.Validator;org.eclipse.wst.xsd.core.internal.validation.eclipse.XSDDelegatingValidator\=org.eclipse.wst.xsd.core.internal.validation.eclipse.Validator;
+USER_BUILD_PREFERENCE=enabledBuildValidatorListorg.eclipse.wst.wsi.ui.internal.WSIMessageValidator;org.eclipse.jst.jsp.core.internal.validation.JSPJavaValidator;org.eclipse.wst.xml.core.internal.validation.eclipse.Validator;org.eclipse.wst.dtd.core.internal.validation.eclipse.Validator;org.eclipse.wst.wsdl.validation.internal.eclipse.WSDLDelegatingValidator;org.eclipse.jst.jsp.core.internal.validation.JSPDirectiveValidator;org.eclipse.wst.html.internal.validation.HTMLValidator;org.eclipse.wst.xsd.core.internal.validation.eclipse.XSDDelegatingValidator;org.eclipse.jst.jsp.core.internal.validation.JSPELValidator;
+USER_MANUAL_PREFERENCE=enabledManualValidatorListorg.eclipse.wst.wsi.ui.internal.WSIMessageValidator;org.eclipse.jst.jsp.core.internal.validation.JSPJavaValidator;org.eclipse.wst.xml.core.internal.validation.eclipse.Validator;org.eclipse.wst.dtd.core.internal.validation.eclipse.Validator;org.eclipse.wst.wsdl.validation.internal.eclipse.WSDLDelegatingValidator;org.eclipse.jst.jsp.core.internal.validation.JSPDirectiveValidator;org.eclipse.wst.html.internal.validation.HTMLValidator;org.eclipse.wst.xsd.core.internal.validation.eclipse.XSDDelegatingValidator;org.eclipse.jst.jsp.core.internal.validation.JSPELValidator;
+USER_PREFERENCE=overrideGlobalPreferencesfalse
+eclipse.preferences.version=1
diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/META-INF/MANIFEST.MF b/org.eclipse.viatra2.gtasm.patternmatcher.impl/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..5067241
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/META-INF/MANIFEST.MF
@@ -0,0 +1,29 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: VIATRA2 R3 Pattern Matcher Implementation
+Bundle-SymbolicName: org.eclipse.viatra2.gtasm.patternmatcher.impl;singleton:=true
+Bundle-Version: 3.3.0.qualifier
+Export-Package: 
+ org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.core,
+ org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions,
+ org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.extension,
+ org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.core,
+ org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal,
+ org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.algorithms,
+ org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.callgraph,
+ org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation,
+ org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.rgg,
+ org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph,
+ org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.term
+Require-Bundle: org.eclipse.viatra2.core2,
+ org.eclipse.viatra2.gtasm.model,
+ org.eclipse.viatra2.gtasm.patternmatcher,
+ org.eclipse.viatra2.gtasm.interpreter,
+ org.eclipse.core.runtime,
+ org.eclipse.viatra2.gtasm.interpreter.term,
+ org.eclipse.viatra2.gtasm.interpreter.impl
+Bundle-Vendor: BUTE-FTSRG
+Bundle-ActivationPolicy: lazy
+Bundle-ClassPath: .
+Bundle-Activator: org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.extension.VIATRAGTMatcherPlugin
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/about.html b/org.eclipse.viatra2.gtasm.patternmatcher.impl/about.html
new file mode 100644
index 0000000..b72be18
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/about.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

+<html xmlns="http://www.w3.org/1999/xhtml">

+<head>

+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>

+<title>About</title>

+</head>

+<body lang="EN-US">

+<h2>About This Content</h2>

+ 

+<p>July 4th, 2008</p>	

+<h3>License</h3>

+

+<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;).  Unless otherwise 

+indicated below, the Content is provided to you under the org.eclipse.viatra2.gtasm.interpreter.term.rules and conditions of the

+Eclipse Public License Version 1.0 (&quot;EPL&quot;).  A copy of the EPL is available 

+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.

+For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>

+

+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is 

+being redistributed by another party (&quot;Redistributor&quot;) and different org.eclipse.viatra2.gtasm.interpreter.term.rules and conditions may

+apply to your use of any object code in the Content.  Check the Redistributor's license that was 

+provided with the Content.  If no such license exists, contact the Redistributor.  Unless otherwise

+indicated below, the org.eclipse.viatra2.gtasm.interpreter.term.rules and conditions of the EPL still apply to any source code in the Content

+and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>

+

+</body>

+</html>
\ No newline at end of file
diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/build.properties b/org.eclipse.viatra2.gtasm.patternmatcher.impl/build.properties
new file mode 100644
index 0000000..5fd9a19
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/build.properties
@@ -0,0 +1,7 @@
+bin.includes = META-INF/,\
+               plugin.xml,\
+               .,\
+               schema/
+
+source.. = src/
+src.includes = schema/
diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/plugin.xml b/org.eclipse.viatra2.gtasm.patternmatcher.impl/plugin.xml
new file mode 100644
index 0000000..72b031b
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/plugin.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>

+<?eclipse version="3.2"?>

+<plugin>

+   <extension

+         point="org.eclipse.viatra2.gtasm.patternmatcher.patternmatcher">

+      <matcherfactory

+            annotation_name="localsearch"

+            class="org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.core.LocalSearchPatternMatcherFactory"

+            id="org.eclipse.viatra2.patternmatcher.local_search"

+            name="Local Search based Pattern Matcher">

+      </matcherfactory>

+   </extension>

+   <extension

+         point="org.eclipse.viatra2.gtasm.patternmatcher.gtrulematcher">

+      <gtmatcherfactory

+            class="org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.core.LocalSearchGTRuleMatcherFactory"

+            id="org.eclipse.viatra2.gtmatcher.local_search"

+            name="Local Search based GT Rule Matcher">

+      </gtmatcherfactory>

+   </extension>

+   <extension

+         point="org.eclipse.viatra2.gtasm.patternmatcher.gtrulematcher">

+      <gtmatcherfactory

+            class="org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.core.ExtendedGTRuleMatcherwithAlternativePatternMatcherFactory"

+            id="org.eclipse.viatra2.gtmatcher.alternative"

+            name="Alternativer GT Rule Matcher which allows Alternative Pattern Matcher for the LHS">

+      </gtmatcherfactory>

+   </extension>

+</plugin>

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/schema/org.eclipse.viatra2.gtasm.patternmatcher.impl.alternativeseaarchgraph.exsd b/org.eclipse.viatra2.gtasm.patternmatcher.impl/schema/org.eclipse.viatra2.gtasm.patternmatcher.impl.alternativeseaarchgraph.exsd
new file mode 100644
index 0000000..032dfb4
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/schema/org.eclipse.viatra2.gtasm.patternmatcher.impl.alternativeseaarchgraph.exsd
@@ -0,0 +1,87 @@
+<?xml version='1.0' encoding='UTF-8'?>

+<!-- Schema file written by PDE -->

+<schema targetNamespace="org.eclipse.viatra2.gtasm.patternmatcher.impl">

+<annotation>

+      <appInfo>

+         <meta.schema plugin="org.eclipse.viatra2.gtasm.patternmatcher.impl" id="alternativeseaarchgraph" name="Alternative Search Graph"/>

+      </appInfo>

+      <documentation>

+         [Enter description of this org.eclipse.viatra2.gtasm.patternmatcher.extension point.]

+      </documentation>

+   </annotation>

+

+   <element name="org.eclipse.viatra2.gtasm.patternmatcher.extension">

+      <complexType>

+         <attribute name="point" type="string" use="required">

+            <annotation>

+               <documentation>

+                  

+               </documentation>

+            </annotation>

+         </attribute>

+         <attribute name="id" type="string">

+            <annotation>

+               <documentation>

+                  

+               </documentation>

+            </annotation>

+         </attribute>

+         <attribute name="name" type="string">

+            <annotation>

+               <documentation>

+                  

+               </documentation>

+               <appInfo>

+                  <meta.attribute translatable="true"/>

+               </appInfo>

+            </annotation>

+         </attribute>

+      </complexType>

+   </element>

+

+   <annotation>

+      <appInfo>

+         <meta.section type="since"/>

+      </appInfo>

+      <documentation>

+         [Enter the first release in which this org.eclipse.viatra2.gtasm.patternmatcher.extension point appears.]

+      </documentation>

+   </annotation>

+

+   <annotation>

+      <appInfo>

+         <meta.section type="examples"/>

+      </appInfo>

+      <documentation>

+         [Enter org.eclipse.viatra2.gtasm.patternmatcher.extension point usage example here.]

+      </documentation>

+   </annotation>

+

+   <annotation>

+      <appInfo>

+         <meta.section type="apiInfo"/>

+      </appInfo>

+      <documentation>

+         [Enter API information here.]

+      </documentation>

+   </annotation>

+

+   <annotation>

+      <appInfo>

+         <meta.section type="implementation"/>

+      </appInfo>

+      <documentation>

+         [Enter information about supplied implementation of this org.eclipse.viatra2.gtasm.patternmatcher.extension point.]

+      </documentation>

+   </annotation>

+

+   <annotation>

+      <appInfo>

+         <meta.section type="copyright"/>

+      </appInfo>

+      <documentation>

+         

+      </documentation>

+   </annotation>

+

+</schema>

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/core/ExtendedGTRuleMatcherwithAlternativePatternMatcherFactory.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/core/ExtendedGTRuleMatcherwithAlternativePatternMatcherFactory.java
new file mode 100644
index 0000000..b6aa79a
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/core/ExtendedGTRuleMatcherwithAlternativePatternMatcherFactory.java
@@ -0,0 +1,68 @@
+/*******************************************************************************

+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro

+ * All rights reserved. This program and the accompanying materials

+ * are made available under the terms of the Eclipse Public License v1.0

+ * which accompanies this distribution, and is available at

+ * http://www.eclipse.org/legal/epl-v10.html

+ *

+ * Contributors:

+ *    Akos Horvath, Gergely Varro - initial API and implementation

+ *******************************************************************************/

+
+package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.core;

+

+import org.eclipse.viatra2.gtasm.interpreter.exception.ViatraTransformationException;

+import org.eclipse.viatra2.gtasm.interpreter.executionEnvironment.IExecutionEnvironment;

+import org.eclipse.viatra2.gtasm.patternmatcher.PatternMatcherParameters;

+import org.eclipse.viatra2.gtasm.patternmatcher.extension.IGTRuleMatcherFactory;

+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTErrorStrings;

+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GraphTransformationException;

+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.ExtendedGTRuleMatcherwithAlternativePatternMatcher;

+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.term.BasicTermHandler;

+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.term.TermHandler;

+import org.eclipse.viatra2.gtasm.patternmatcher.patterns.IGTRuleMatcher;

+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.GTRule;

+

+

+/**

+ *

+ * Implements the IGTRuleMatcherFactory extension point for the viatra GTASM interpreter with Incremental pattern matching

+ * @author Akos Horvath

+ */

+public class ExtendedGTRuleMatcherwithAlternativePatternMatcherFactory implements IGTRuleMatcherFactory {

+	

+	private IGTRuleMatcher construct(GTRule gtRule, IExecutionEnvironment enviroment, PatternMatcherParameters pmParams) 

+    		throws ViatraTransformationException {

+		if (gtRule.getPrecondition() != null) {

+			// traditional type gtRule with alternative pattern matching

+			TermHandler handler = new BasicTermHandler(enviroment);

+			return new ExtendedGTRuleMatcherwithAlternativePatternMatcher(gtRule,enviroment, handler, pmParams);

+		} else {

+			enviroment.getFramework().getLogger().warning("ActionPattern type GTRule not yet supported");

+		}

+		return null;

+	}

+

+	public IGTRuleMatcher getGTMatcher(IExecutionEnvironment gtEnviroment,

+			GTRule gtRule, PatternMatcherParameters mp)

+			throws ViatraTransformationException {

+		IGTRuleMatcher gtMatcher=null;

+		if (GTRuleMatchers.getInstance().containsKey(gtRule)) {
+			// We already had it precompiled

+			gtMatcher=GTRuleMatchers.getInstance().get(gtRule);

+			gtMatcher.initGTRule(gtEnviroment);

+		} else {

+			// We need to create a new gtmatcher

+			gtMatcher = construct(gtRule, gtEnviroment,mp);

+			if (gtMatcher != null) {

+				GTRuleMatchers.getInstance().put(gtRule, gtMatcher);

+			} else {

+				String[] context = {gtRule.getName()};

+				throw new GraphTransformationException(GTErrorStrings.GTRULETYPE_NOTSUPPORTED

+						,context

+						,gtRule);
+			}

+		}

+		return gtMatcher;

+	}

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/core/GTRuleMatchers.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/core/GTRuleMatchers.java
new file mode 100644
index 0000000..de31bea
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/core/GTRuleMatchers.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.core;

+

+import java.util.Hashtable;
+
+import org.eclipse.viatra2.gtasm.patternmatcher.patterns.IGTRuleMatcher;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.GTRule;
+

+

+

+/**

+ * @author Akos Horvath

+ *

+ */

+public class GTRuleMatchers extends Hashtable<GTRule, IGTRuleMatcher> {

+	

+	/**

+	 * Stores the gt rule matchers previously created

+	 * 

+	 * @author Akos Horvath

+	 */

+	private static final long serialVersionUID = 2L;

+	private static GTRuleMatchers  _instance=new GTRuleMatchers();

+	public static GTRuleMatchers  getInstance()

+	{

+		return _instance;

+	}

+	

+	public GTRuleMatchers() {

+		super();

+	}

+

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/core/LocalSearchGTRuleMatcherFactory.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/core/LocalSearchGTRuleMatcherFactory.java
new file mode 100644
index 0000000..e399b0c
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/core/LocalSearchGTRuleMatcherFactory.java
@@ -0,0 +1,71 @@
+/*******************************************************************************

+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro

+ * All rights reserved. This program and the accompanying materials

+ * are made available under the terms of the Eclipse Public License v1.0

+ * which accompanies this distribution, and is available at

+ * http://www.eclipse.org/legal/epl-v10.html

+ *

+ * Contributors:

+ *    Akos Horvath, Gergely Varro - initial API and implementation

+ *******************************************************************************/

+

+package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.core;

+

+import org.eclipse.viatra2.gtasm.interpreter.exception.ViatraTransformationException;

+import org.eclipse.viatra2.gtasm.interpreter.executionEnvironment.IExecutionEnvironment;

+import org.eclipse.viatra2.gtasm.patternmatcher.PatternMatcherParameters;

+import org.eclipse.viatra2.gtasm.patternmatcher.extension.IGTRuleMatcherFactory;

+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTErrorStrings;

+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GraphTransformationException;

+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.TraditionalGTRuleMatcher;

+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.term.BasicTermHandler;

+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.term.TermHandler;

+import org.eclipse.viatra2.gtasm.patternmatcher.patterns.IGTRuleMatcher;

+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.GTRule;

+

+

+/**

+ * Implements the IGTRuleMatcherFactory org.eclipse.viatra2.gtasm.patternmatcher.extension point for the viatra GTASM org.eclipse.viatra2.gtasm.interpreter.impl.interpreter with Local search based pattern matching

+ * @author Akos Horvath

+ *

+ */

+public class LocalSearchGTRuleMatcherFactory implements IGTRuleMatcherFactory {

+	

+	private IGTRuleMatcher construct(GTRule gtRule, IExecutionEnvironment enviroment, PatternMatcherParameters pmParams) 

+			throws ViatraTransformationException {

+		if (gtRule.getPrecondition() != null) {

+			// traditional type gtRule with local search based pattern matching

+			TermHandler handler = new BasicTermHandler(enviroment);

+			return new TraditionalGTRuleMatcher(gtRule,enviroment, handler, pmParams);

+		} else {

+			enviroment.getFramework().getLogger().warning("ActionPattern type GTRule not yet supported");

+		}

+		return null;

+	}

+

+	public IGTRuleMatcher getGTMatcher(IExecutionEnvironment gtEnviroment,

+			GTRule gtRule, PatternMatcherParameters mp)

+			throws ViatraTransformationException {

+		IGTRuleMatcher gtMatcher=null;

+		if (GTRuleMatchers.getInstance().containsKey(gtRule)) {

+			// We already had it precompiled
+			gtMatcher=GTRuleMatchers.getInstance().get(gtRule);

+			gtMatcher.initGTRule(gtEnviroment);

+		} else {

+			// We need to make a new gtMatcher

+			// GTRuleBuilder gtBuilder = new GTRuleBuilder(gtEnviroment.getFramework().getLogger(), gtEnviroment.getFramework().getTopmodel().getModelManager(), handlerr);

+			// gtMatcher = gtBuilder.construct(gtRule, gtEnviroment,mp);

+			gtMatcher = construct(gtRule, gtEnviroment,mp);

+			if (gtMatcher != null) {

+				GTRuleMatchers.getInstance().put(gtRule, gtMatcher);

+			} else {

+				String[] context = {gtRule.getName()};

+				throw new GraphTransformationException(GTErrorStrings.GTRULETYPE_NOTSUPPORTED

+						,context

+						,gtRule);
+			}
+			

+		}

+		return gtMatcher;

+	}

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/exceptions/GTErrorStrings.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/exceptions/GTErrorStrings.java
new file mode 100644
index 0000000..025f690
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/exceptions/GTErrorStrings.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions;

+

+/**Error templates

+ * @author Akos Horvath

+ *

+ */

+public class GTErrorStrings {

+	

+	
+	public static final String INTERNAL_ERROR_INPUTPARAMS_SYMPARAMS_LENGTH = "[INTERNAL ERROR] The number of input parameter's mappingd and do not match the number of signature element.";    
+	public static final String INTERNAL_ERROR_INPUTPARAM_WITHOUT_A_VALUE = "[INTERNAL ERROR] Input parameter without value (NULL)";
+	public static final String INTERNAL_GTVALIDATION_NOT_DELETED = "[INTERNAL ERROR] No delete operation on the '{1}' deletable parameter of the LHS";
+	public static final String INTERNAL_EMPTY_VALUE = "[INTERNAL ERROR] The '{1}' element in the {2} operation has an empty value (null)";
+	public static final String INTERNAL_CREATE_ENTITY ="[INTERNAL ERROR] Entity '{1}' creation failed due to: {2} ";
+	public static final String INTERNAL_CREATE_INSTANCEOF ="[INTERNAL ERROR] InstanceOf creation failed, between Type '{1}' and Instance '{2}' due to: {3}";
+	public static final String INTERNAL_CREATE_RELATION = "[INTERNAL ERROR] Relation '{1}' creation failed due to: {2}";
+	public static final String INTERNAL_CREATE_SUPERTYPEOF ="[INTERNAL ERROR] Inheritance creation failed, between SuperType: '{1}' and Subtype '{2}' due to: {3}";
+	public static final String INTERNAL_DELETE_MODELELEMENT = "[INTERNAL ERROR] ModelElement '{1}' deletion failed due to: {2} ";
+	public static final String INTERNAL_OPERATION_NOT_SUPPORTED = "[INTERNAL ERROR] The {1} operation is not supported";
+	public static final String INTERNAL_MOVE_MODELELEMENT = "[INTERNAL ERROR] The move element under a new container operation failed, between the Element '{1}' and the Container '{2}' due to {3}";
+	public static final String INTERNAL_SET_RELATION_TARGET = "[INTERNAL ERROR] The target of the '{1}' relation could not be set to the '{2}' element due to: {3}";
+	public static final String INTERNAL_SET_RELATION_SOURCE = "[INTERNAL ERROR] The source of the '{1}' relation could not be set to the '{2}' element due to: {3}";
+	
+	public static final String NOT_AN_ENTITY = "The '{1}' element in the {2} operation is not an Entity";
+	public static final String NOT_A_RELATION = "The '{1}' element in the {2} operation is not a Relation";
+	public static final String NOT_A_MODELELEMENT = "The '{1}' element in the {2} operation is not a ModelElement (Entity or Relation)";
+	
+	public static final String GTVALIDATION_SET_TARGET= "The Target of the {1} relation is set more than once";
+	public static final String GTVALIDATION_SET_SOURCE= "The Source of the {1} relation is set more than once";
+	public static final String GTVALIDATION_SET_BOTH= "Both the source and target of the {1} relation is set more than once";
+	public static final String GTVALIDATION_KEEP_DEL = "The {1} input variable is specified to be kept and also to be deleted";
+	public static final String GTVALIDATION_MORE_THANONE_DEL = "More than one delete operation is defined over the {1} element";
+	public static final String GTVALIDATION_MORE_THANONE_CREATE = "More then one create operation is defined on the {1} element";
+	public static final String GTVALIDATION_DEL_AND_OTHEROPERATION = "Conflicting operations on the {1} element. One delete operation and additionally {2} create, {3} move and {4} set operation(s)";
+	public static final String GTVALIDATION_DEL_AND_USED = "The {1} element is deleted but also invovled in other operations";
+	public static final String GTRULETYPE_NOTSUPPORTED = "The type of the {1} GT rule is not supported by the org.eclipse.viatra2.gtasm.interpreter.impl.interpreter bundle ";
+	public static final String NO_ALTERNATIVE_PATTERN_MATCHER = "No alternative pattern matcher was available for the {1} gtRule";
+	
+	//public static final String IN_CONTAINMENT_FAILED = "The {1} parameter in the LHS has more than one 'IN' containment constraint defined over.";
+	public static final String SYMBOLIC_QUANTIFICITION = "The {1} input symbolic parameter is not quantified by the invoking rule";
+	public static final String NOT_CONTAINER = " {1} cannot be resolved as a container element (possibly not an entity).";
+	public static final String MORE_ONE_IN_CONTAINMENT = "{1} has more than 1 'IN' type containment constraints";
+	public static final String GTRULE_RHS_FAILED_CHECK = "The '{1}' consistency check operation failed on the right hand side of the {2} gtRule.";
+	public static final String GTRULE_RHS_FAILED_MANIPULATION = "The '{1}' model manipulation operation failed on the right hand side of the {2} gtRule.";
+

+	

+//	public static final String CREATE_SUPERTYPEOF = "SuperTypeOf creation failed, between: ";
+//	public static final String DELETE_INSTANCEOF = "InstanceOf deletion failed, between: ";
+//	public static final String DELETE_SUPERTYPEOF = "SuperTypeOf deletion failed, between: ";
+//	public static final String CONTAINMENT_FAILED = "Containment Constraint failed on the RHS Element between: ";
+//	public static final String INIT = " \n Error during the initialization of the gt Rule parameters: ";
+//	public static final String INIT_ACTION= " \n Error during initializing the variables for the ACTION part of the GtRule (): ";
+//	public static final String GTRULE_EXCEPTION_STRING= "Error in gtRule: ";

+//	public static final String CAST_EXCEPTION = "Not a ModelElement (Entity or Relation) type Variable (Class Cast failed)";

+//	public static final String CAST_EXCEPTION_ENTITY = "Not an Entity type Variable (Class Cast failed):";

+//	public static final String GTRULE_CONSTRUCT= "GTRULE construct failed";

+	
+	
+	
+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/exceptions/GTOperationException.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/exceptions/GTOperationException.java
new file mode 100644
index 0000000..91613ae
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/exceptions/GTOperationException.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions;

+

+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
+

+/** 
+ * The specific exception for the GT Rule execution
+ * @author Akos Horvath
+ *

+ */

+public class GTOperationException extends GraphTransformationException {

+
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = -4290690575225451930L;
+

+	public GTOperationException(String msg, String[] context,
+			AnnotatedElement element) {
+		super(msg, context, element);
+	}
+	

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/exceptions/GTRuleBuildingException.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/exceptions/GTRuleBuildingException.java
new file mode 100644
index 0000000..d482720
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/exceptions/GTRuleBuildingException.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions;

+

+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
+
+/**
+ * The specific exception of for the building of a GT Rule matcher
+ * @author Akos Horvath
+ *

+ */

+public class GTRuleBuildingException extends GraphTransformationException {

+	

+	/**

+	 * 

+	 */

+	private static final long serialVersionUID = 5766827372883906119L;

+	

+	public GTRuleBuildingException(String string,String[] context, AnnotatedElement node) {

+		super(string, context, node);

+	}

+
+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/exceptions/GraphTransformationException.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/exceptions/GraphTransformationException.java
new file mode 100644
index 0000000..4be7a14
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/exceptions/GraphTransformationException.java
@@ -0,0 +1,32 @@
+/*******************************************************************************

+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro

+ * All rights reserved. This program and the accompanying materials

+ * are made available under the terms of the Eclipse Public License v1.0

+ * which accompanies this distribution, and is available at

+ * http://www.eclipse.org/legal/epl-v10.html

+ *

+ * Contributors:

+ *    Akos Horvath, Gergely Varro - initial API and implementation

+ *******************************************************************************/

+

+package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions;

+

+import org.eclipse.viatra2.gtasm.interpreter.exception.GTASMException;

+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;

+

+

+public class GraphTransformationException extends GTASMException {

+	/**

+	 * 

+	 */

+	private static final long serialVersionUID = -9216398057977736617L;

+

+/*	public GraphTransformationException(String msg) {

+		super(msg);

+	}*/

+

+	public GraphTransformationException(String msg, String[] context, AnnotatedElement element) {

+		super(msg,context);

+		addNewStackElement(element);

+	}

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/extension/VIATRAGTMatcherPlugin.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/extension/VIATRAGTMatcherPlugin.java
new file mode 100644
index 0000000..1110611
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/extension/VIATRAGTMatcherPlugin.java
@@ -0,0 +1,138 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.extension;

+

+import org.eclipse.core.runtime.Plugin;
+import org.osgi.framework.BundleContext;
+

+/**

+ * The activator class for the GtMatcher. Holds the references for the alternative pattern matcher

+ * @author Akos Horvath

+ *

+ */

+public class VIATRAGTMatcherPlugin extends Plugin {

+

+	// The plug-in ID

+	public static final String PLUGIN_ID = "org.eclipse.viatra2.gtasm.patternmatcher.impl";

+	//Extension points

+//	public static final String PATTERN_MATCHER_EXT_ID = "org.eclipse.viatra2.gtasm.patternmatcher.impl.alternativepatternmatcher";

+//

+//	public static final String INCREMENTAL_PM_FACTORY_ID="org.eclipse.viatra2.gtasm.patternmatcher.incremental.alternativeGTmatcher";

+//	//  public static final String INCREMENTAL_PARALlEL_PM_FACTORY_ID="org.eclipse.viatra2.gtasm.patternmatcher.incremental.parallel.alternativeGTmatcher";
+//	//	public static final String LOCAL_PM_FACTORY_ID = "org.eclipse.viatra2.local_search";

+//	public static final String DEFAULT_ALTERNATIVE_PM_FACTORY_ID = INCREMENTAL_PM_FACTORY_ID;

+

+	// The shared instance

+	private static VIATRAGTMatcherPlugin  plugin;

+

+	/**

+	 * The constructor

+	 */

+	public VIATRAGTMatcherPlugin() {

+		plugin = this;

+	}

+

+	/*

+	 * (non-Javadoc)

+	 * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)

+	 */

+	@Override
+	public void start(BundleContext context) throws Exception {

+		super.start(context);

+	}

+

+	/*

+	 * (non-Javadoc)

+	 * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)

+	 */

+	@Override
+	public void stop(BundleContext context) throws Exception {

+		plugin = null;

+		super.stop(context);

+	}

+

+	/**

+	 * Returns the shared instance

+	 *

+	 * @return the shared instance

+	 */

+	public static VIATRAGTMatcherPlugin getDefault() {

+		return plugin;

+	}

+

+//	/** PATTERN MATCHER FACTORIES*/

+//	private Map<String,IAlternativePatternMatcherFactory> patternMatcherFactories;

+//

+//	public Map<String,IAlternativePatternMatcherFactory> getPatternMatcherFactories()

+//	{

+//		if (patternMatcherFactories==null)

+//		{

+//			patternMatcherFactories = initPatternMatcherFactories();

+//		}

+//		return patternMatcherFactories;

+//	}

+//

+//	/** Returns the pattern matcher registered with the input id

+//	 * @param id The id of the registered patternMatcher plugin id

+//	 * @return the IAlternativePatternMatcherFactory for the patternMatcher

+//	 */

+//	public IAlternativePatternMatcherFactory getPatternMatcherFactory(String id){

+//		if (patternMatcherFactories==null)

+//		{

+//			patternMatcherFactories = initPatternMatcherFactories();

+//		}

+//		return patternMatcherFactories.containsKey(id)? patternMatcherFactories.get(id): null;

+//	}

+//

+//

+//	private Map<String,IAlternativePatternMatcherFactory> initPatternMatcherFactories()

+//	{

+//		IExtensionRegistry reg = Platform.getExtensionRegistry();

+//		IExtensionPoint poi = reg.getExtensionPoint(PATTERN_MATCHER_EXT_ID);

+//		HashMap<String,IAlternativePatternMatcherFactory> r = new HashMap<String,IAlternativePatternMatcherFactory>();

+//		if (poi==null) return r;

+//		IExtension[] exts = poi.getExtensions();

+//		for (int i=0;i<exts.length;i++)

+//		{

+//			IConfigurationElement[] el = exts[i].getConfigurationElements();

+//			for (int j=0;j<el.length;j++)

+//			{

+//				try

+//				{

+//					Object o = el[j].createExecutableExtension("class");

+//					if (o instanceof IAlternativePatternMatcherFactory)

+//						{String id = el[j].getAttribute("id");

+//						 r.put(id,(IAlternativePatternMatcherFactory)o);

+//						}

+//				}

+//				catch (Exception e)

+//				{

+//					e.printStackTrace();

+//				}

+//			}

+//		}

+//		return r;

+//	}

+//

+//	/** Checks if there is a registered pattern matcher on the plugin

+//	 * @return

+//	 */

+//	public Boolean hasAlternativePatternMatcher(){

+//		if (patternMatcherFactories==null)

+//		{

+//			patternMatcherFactories = initPatternMatcherFactories();

+//		}

+//		return patternMatcherFactories.size() > 0;

+//	}

+

+

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/ExtendedGTRuleMatcherwithAlternativePatternMatcher.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/ExtendedGTRuleMatcherwithAlternativePatternMatcher.java
new file mode 100644
index 0000000..9deb398
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/ExtendedGTRuleMatcherwithAlternativePatternMatcher.java
@@ -0,0 +1,55 @@
+/*******************************************************************************

+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro

+ * All rights reserved. This program and the accompanying materials

+ * are made available under the terms of the Eclipse Public License v1.0

+ * which accompanies this distribution, and is available at

+ * http://www.eclipse.org/legal/epl-v10.html

+ *

+ * Contributors:

+ *    Akos Horvath, Gergely Varro - initial API and implementation

+ *******************************************************************************/

+
+package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal;

+

+import org.eclipse.viatra2.gtasm.interpreter.exception.ViatraTransformationException;

+import org.eclipse.viatra2.gtasm.interpreter.executionEnvironment.IExecutionEnvironment;

+import org.eclipse.viatra2.gtasm.patternmatcher.PatternMatcherParameters;

+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.term.ITermHandler;

+import org.eclipse.viatra2.gtasm.patternmatcher.patterns.IPatternMatcher;

+import org.eclipse.viatra2.gtasm.patternmatcher.patterns.PatternMatcherProvider;

+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.RuntimeAnnotation;

+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.GTRule;

+

+

+/**

+ * Provides a complete GT rule matcher functionality with the possibility to use alternative pattern matchers for the LHS of the GT rule

+ * @author Akos Horvath

+ *

+ */

+public class ExtendedGTRuleMatcherwithAlternativePatternMatcher extends TraditionalGTRuleMatcher {

+

+	public ExtendedGTRuleMatcherwithAlternativePatternMatcher(GTRule gt,

+			IExecutionEnvironment enviroment, ITermHandler handler,

+			PatternMatcherParameters mp) throws ViatraTransformationException {

+		super(gt, enviroment, handler, mp);

+	}

+

+	/* The only method that has to be overridden in order to enable the Alternative Pattern Matchers in case when we want to use

+	 * the already implemented Traditional GT Rule matcher

+	 * (non-Javadoc)

+	 * @see org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.TraditionalGTRuleMatcher#getPatternMatcherforPreCondition()

+	 */

+	@Override

+	protected IPatternMatcher getPatternMatcherforPreCondition() throws ViatraTransformationException{
+		// is true pseudorandom required?

+		isRandom = false;

+		for (Object annot : gtRule.getPrecondition().getCalledPattern().getRuntimeAnnotations()) {

+			if ("@random".equals(((RuntimeAnnotation) annot).getAnnotationName().toLowerCase())) {

+				isRandom = true; break;

+			}

+		}	

+		

+		return PatternMatcherProvider.getInstance().getPatternMatcher(

+				gtEnvironment, gtRule.getPrecondition().getCalledPattern());

+	}

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/GTElementMapping.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/GTElementMapping.java
new file mode 100644
index 0000000..2221911
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/GTElementMapping.java
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal;

+

+/**A mapping between the LHS and RHS input elements 

+ * @author Akos Horvath

+ *

+ */

+

+public class GTElementMapping {

+	

+	private int  lhsInputOrderIndex , rhsInputOrderIndex;

+	private GTElementMappingType mappingType;

+	//private GTElementRelationShipMapping relationShips;

+	

+

+	public GTElementMapping(int lhsInputIndex,int rhsInputIndex, GTElementMappingType type){

+		lhsInputOrderIndex = lhsInputIndex;

+		rhsInputOrderIndex = rhsInputIndex;

+		mappingType = type;

+		//relationShips = new GTElementRelationShipMapping();

+	}

+	

+	public GTElementMapping(int lhsInputIndex,int rhsInputIndex){

+		lhsInputOrderIndex = lhsInputIndex;

+		rhsInputOrderIndex = rhsInputIndex;

+		mappingType = null;

+		//relationShips = new GTElementRelationShipMapping();

+	}

+	

+	

+	/**

+	 * @return the mappingType

+	 */

+	public GTElementMappingType getMappingType() {

+		return mappingType;

+	}

+

+	/**

+	 * @param mappingType the mappingType to set

+	 */

+	public void setMappingType(GTElementMappingType mappingType) {

+		this.mappingType = mappingType;

+	}

+

+	/**

+	 * @return the rhsInputOrderIndex

+	 */

+	public int getRhsInputOrderIndex() {

+		return rhsInputOrderIndex;

+	}

+

+	/**

+	 * @param rhsInputOrderIndex the rhsInputOrderIndex to set

+	 */

+	public void setRhsInputOrderIndex(int rhsInputOrderIndex) {

+		this.rhsInputOrderIndex = rhsInputOrderIndex;

+	}

+

+	/**

+	 * @return the lhsInputOrderIndex

+	 */

+	public int getLhsInputOrderIndex() {

+		return lhsInputOrderIndex;

+	}

+

+	/**

+	 * @param lhsInputOrderIndex the lhsInputOrderIndex to set

+	 */

+	public void setLhsInputOrderIndex(int lhsInputOrderIndex) {

+		this.lhsInputOrderIndex = lhsInputOrderIndex;

+	}

+

+	/**

+	 * @return the relationShips

+	 */

+//	public GTElementRelationShipMapping getRelationShips() {

+//		return relationShips;

+//	}

+

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/GTElementMappingType.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/GTElementMappingType.java
new file mode 100644
index 0000000..351b740
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/GTElementMappingType.java
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal;

+

+/** Possible types of the LHS and RHS mapping

+ * @author Akos Horvath

+ *

+ */

+public enum GTElementMappingType {

+	

+	DEL,

+	KEEP

+

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/GTOperationContext.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/GTOperationContext.java
new file mode 100644
index 0000000..4099fb9
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/GTOperationContext.java
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal;

+

+import java.util.Collection;
+import java.util.Vector;
+
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.IUpdatePlanOperation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation.ISearchPlanOperation;
+

+

+/**Holds the non-input specific operations of a GT Rule

+ * @author Akos Horvath

+ *

+ */

+public class GTOperationContext {

+	

+	private MatchingFrame returnFrame;

+	private Collection<IUpdatePlanOperation> finalOperations; //non input specific operations

+	private Collection<ISearchPlanOperation> CheckSet; //containment check operation based on the input parameters parent constraint

+

+	public GTOperationContext(MatchingFrame returnFrame, Collection<IUpdatePlanOperation> finalOperations,

+			Collection<ISearchPlanOperation> CheckSet) {

+		this.finalOperations = finalOperations;

+		this.returnFrame = returnFrame;

+		this.CheckSet = CheckSet;

+	}

+

+	/**

+	 * @return the finalOperations

+	 */

+	public Collection<IUpdatePlanOperation> getFinalOperations() {

+		return finalOperations;

+	}

+

+	/**

+	 * @return the returnFrame

+	 */

+	public MatchingFrame getReturnFrame() {

+		return returnFrame;

+	}

+

+	/**

+	 * @param finalOperations the finalOperations to set

+	 */

+	public void setFinalOperations(Vector<IUpdatePlanOperation> finalOperations) {

+		this.finalOperations = finalOperations;

+	}

+

+	/**

+	 * @return the checkSet

+	 */

+	protected Collection<ISearchPlanOperation> getCheckSet() {

+		return CheckSet;

+	}

+

+	/**

+	 * @param checkSet the checkSet to set

+	 */

+	protected void setCheckSet(Collection<ISearchPlanOperation> checkSet) {

+		CheckSet = checkSet;

+	}

+

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/GTOperationGenerator.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/GTOperationGenerator.java
new file mode 100644
index 0000000..be17554
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/GTOperationGenerator.java
@@ -0,0 +1,480 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal;

+

+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.eclipse.viatra2.core.IEntity;
+import org.eclipse.viatra2.core.IModelManager;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTRuleBuildingException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.CreateEntity;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.CreateEntityWithConstantContainer;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.CreateEntityWithVariableContainment;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.CreateInstanceofBound2Bound;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.CreateInstanceofBound2Constant;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.CreateInstanceofConstant2Bound;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.CreateInstanceofConstant2Constant;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.CreateRelationBound2Bound;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.CreateRelationBound2Constant;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.CreateRelationConstant2Bound;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.CreateRelationConstant2Constant;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.CreateSuperTypeofBound2Bound;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.CreateSuperTypeofBound2Constant;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.CreateSuperTypeofConstant2Bound;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.CreateSuperTypeofConstant2Constant;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.ElementManipulationOperation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.IUpdatePlanOperation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.MoveBoundunderBound;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.MoveBoundunderConstant;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.SetRelationSource;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.SetRelationTarget;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.EdgeType;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.VPMModelElementType;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.algorithms.ISearchGraph;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation.BoundToBoundCheckOperation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation.BoundToConstantCheckOperation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation.ConstantToBoundCheckOperation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation.ConstantToConstantCheckOperation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation.ISearchPlanOperation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation.IsEntityorRelationCheckOperation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.ConstantSearchGraphNode;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.SearchGraphEdge;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.SearchGraphNode;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.VariableSearchGraphNode;
+

+

+/**
+ * Responsible for the generation of the GT rule based operation

+ * @author Akos Horvath

+  */

+public class GTOperationGenerator {

+	

+	 

+    /**

+     * Generates the operation related to the node element, a node can represent a vpm.entity or a vpm.relation

+     * @param node a node in the search graph

+     * @param manager the model manager of the VIATRA model space

+     * @param postSearchPlanOperations  a collection that holds the operations related to the consistency of the matching of the rule (injectivity or containment)

+     * @return a simple operation that is related with the input node element

+     * @throws GTRuleBuildingException 

+     */

+    public static ElementManipulationOperation getModelManipulationOperation(VariableSearchGraphNode node 

+    		, IModelManager manager

+    		, ArrayList<ISearchPlanOperation> checkSet

+    		, ISearchGraph searchGraph

+    		)

+    throws GTRuleBuildingException{

+    	ElementManipulationOperation operation = null;

+    	

+//    	if(!node.getTreeEdge().getSourceNode().isChecked() || node.isChecked())

+//    		return null;

+//    	

+    	if(node.getVpmModelElementType().compareTo(VPMModelElementType.ENTITY) == 0)

+    	  		{

+    			SearchGraphEdge containmentEdge= null;

+    			node.setChecked(true);

+    			

+    			//only works when a node has none or only one IN constraint

+    			for(SearchGraphEdge edge : node.getSources()){

+    				if(edge.getVPMEdgeType().compareTo(EdgeType.IN) == 0

+    						&& edge.isSource()

+    						&& !edge.isChecked()

+    						&& edge.getSourceNode().isChecked())

+	    					{if(containmentEdge == null)

+	    						{containmentEdge = edge;}

+	    					else

+	    						{
+	    						String[] context = {node.getName()};
+	    						throw new GTRuleBuildingException(GTErrorStrings.MORE_ONE_IN_CONTAINMENT
+	    								,context
+	    								,searchGraph.getGTASMRepresentation(node));
+	    						}

+	    					}

+    				//the element has below containment on it

+    				else if(edge.getVPMEdgeType().compareTo(EdgeType.BELOW) == 0

+    							&& !edge.isChecked()

+    							&& edge.isSource())

+    						{edge.setChecked(true);

+    						

+//    						if(!(edge.getSourceNode() instanceof VariableSearchGraphNode

+//    								&& edge.getVPMEdgeType().equals(EdgeType.BELOW)

+//    								&& (template.getValue(((VariableSearchGraphNode)edge.getSourceNode()).getId()) != null)

+//    								&& ((IModelElement)template.getValue(((VariableSearchGraphNode)edge.getSourceNode()).getId())).equals(manager.getRoot())))

+//    							//check that element is below root element is not needed

+    						checkSet.add(getBelowContainmentCheckOperation(manager,edge));

+    		    			}

+	    		}

+    			

+    			if(containmentEdge != null)

+    				{containmentEdge.setChecked(true);

+    				if(containmentEdge.getSourceNode() instanceof VariableSearchGraphNode) //variable type container

+    					return new CreateEntityWithVariableContainment(node.getId(),manager,((VariableSearchGraphNode)containmentEdge.getSourceNode()));

+    				else//constant node container

+    					try{

+    					return new CreateEntityWithConstantContainer(node.getId(),manager
+    							,(IEntity)manager.getElementByName(((ConstantSearchGraphNode)containmentEdge.getSourceNode()).getElement())
+    							,(ConstantSearchGraphNode)containmentEdge.getSourceNode());

+    					}catch(ClassCastException e)

+	        				{
+    						String[] context = {containmentEdge.getSourceNode().getName()};

+	        				throw new GTRuleBuildingException(GTErrorStrings.NOT_CONTAINER
+	        						,context
+	        						,searchGraph.getGTASMRepresentation(containmentEdge.getSourceNode()));

+	        				}

+    					}    			

+    			else return new CreateEntity(node.getId(),manager);

+    			}

+    	else

+    	if(node.getVpmModelElementType().compareTo(VPMModelElementType.RELATION) == 0)

+	    	{SearchGraphNode target = null;

+	    	 SearchGraphNode source = null;

+	    	 SearchGraphEdge sourceedge = null;

+	    	 SearchGraphEdge targetedge = null;

+	    	 

+	    	 //get the target and the source of the edge

+	    	 for(SearchGraphEdge edge: node.getSources())

+	    	 	{

+	    		 if(edge.getVPMEdgeType().compareTo(EdgeType.SOURCE) == 0

+	    				 && (!edge.isSource())

+	    				 && edge.getSourceNode().isChecked())

+	    		 	{source = edge.getSourceNode();

+	    		 	sourceedge = edge;

+	    		 	}

+	    		 else

+	    		 if(edge.getVPMEdgeType().compareTo(EdgeType.TARGET) == 0

+				 		&& (!edge.isSource())

+				 		&& edge.getSourceNode().isChecked()) 

+	    			 {target = edge.getSourceNode();

+	    			  targetedge = edge;

+	    			 }

+	    	 	}

+	    	 

+	    	 // creates a create operation for the relation and connects it to the target and source Elements

+	    	 if(target != null && source != null)

+	    	 	{

+	    		 if(source instanceof VariableSearchGraphNode && target instanceof VariableSearchGraphNode)

+	    				operation = new CreateRelationBound2Bound(((VariableSearchGraphNode)source).getId()

+	    							,((VariableSearchGraphNode)target).getId()

+	    							,node.getId()
+	    							, manager);

+	    			else

+	    			if(source  instanceof VariableSearchGraphNode && target instanceof ConstantSearchGraphNode )

+	    				operation = new CreateRelationBound2Constant(((VariableSearchGraphNode)source).getId()

+	    						,(ConstantSearchGraphNode)target

+	    						,node.getId()
+	    						, manager);

+	    			else

+	    			if(source  instanceof ConstantSearchGraphNode && target instanceof VariableSearchGraphNode)

+	    				operation = new CreateRelationConstant2Bound((ConstantSearchGraphNode)source

+	    						,((VariableSearchGraphNode)target).getId()

+	    						,node.getId()
+	    						, manager);

+	    			else

+	    			if(source  instanceof ConstantSearchGraphNode && target instanceof ConstantSearchGraphNode)

+	    				operation = new CreateRelationConstant2Constant((ConstantSearchGraphNode)source

+	    						,(ConstantSearchGraphNode)target

+	    						,node.getId()
+	    						, manager);

+	    		 

+	    		 node.setChecked(true);

+	    		 sourceedge.setChecked(true);

+	    		 targetedge.setChecked(true);

+	    		 return operation;

+	    	 	}

+	    	}

+    		

+    	return null;

+    }

+    

+    

+    /**

+     * Generated the operation related to the edge input parameter, an edge represents a vpm.relatinship or target/source of a vpm.relation

+     * @param edge SearchGraphEdge element of the search graph

+     * @param manager model manager of the VIATRA model space

+     * @param checkSet a collection that holds the operations related to the consistency of the matching of the rule (injectivity and containment)

+     * @return a simple operation related to the input edge parameter

+     * @throws GTRuleBuildingException

+     */

+    public static ElementManipulationOperation getModelManipulationOperation(SearchGraphEdge edge

+    		,IModelManager manager

+    		,ArrayList<ISearchPlanOperation> checkSet
+    		, ISearchGraph searchGraph) 

+    throws GTRuleBuildingException {

+    	ElementManipulationOperation operation = null;

+    	

+    	if( (!edge.getSourceNode().isChecked()) || !edge.getTargetNode().isChecked())

+    		return null;

+

+    	//supertypeof, traversed on the inverse edge

+    	if(edge.getVPMEdgeType().compareTo(EdgeType.SUPERTYPEOF) == 0 

+    			&& !edge.isSource())

+    			 //TODO: have to change to handle input parameters supertype change

+    			{

+    		

+    		//	cannot create SupertypeOf Relationships to vpm Entities or Relations

+    			if(edge.getTargetNode() instanceof ConstantSearchGraphNode && 
+    					( ((ConstantSearchGraphNode)edge.getTargetNode()).getElement().equals(ISearchGraph.VPM_RELATION_FQN)
+    							|| ((ConstantSearchGraphNode)edge.getTargetNode()).getElement().equals(ISearchGraph.VPM_ENTITY_FQN) )
+    			  )

+    			{

+    			edge.setChecked(true);

+    			return null;

+    			}	

+ 

+    			if(edge.getSourceNode() instanceof VariableSearchGraphNode && 	edge.getTargetNode() instanceof VariableSearchGraphNode)

+						operation = new CreateSuperTypeofBound2Bound(((VariableSearchGraphNode)edge.getSourceNode()).getId()

+								,((VariableSearchGraphNode)	edge.getTargetNode()).getId()

+								, manager,edge);

+				else

+				if(edge.getSourceNode()  instanceof VariableSearchGraphNode && 	edge.getTargetNode() instanceof ConstantSearchGraphNode )

+					operation = new CreateSuperTypeofBound2Constant(((VariableSearchGraphNode)edge.getSourceNode()).getId()

+							,manager.getElementByName(((ConstantSearchGraphNode)edge.getTargetNode()).getElement())

+							, manager,edge);

+				else

+				if(edge.getSourceNode()  instanceof ConstantSearchGraphNode && 	edge.getTargetNode() instanceof VariableSearchGraphNode)

+					operation = new CreateSuperTypeofConstant2Bound(manager.getElementByName(((ConstantSearchGraphNode)edge.getSourceNode()).getElement())

+							,((VariableSearchGraphNode)	edge.getTargetNode()).getId()

+							, manager,edge);

+				else

+				if(edge.getSourceNode()  instanceof ConstantSearchGraphNode && 	edge.getTargetNode() instanceof ConstantSearchGraphNode)

+					operation = new CreateSuperTypeofConstant2Constant(manager.getElementByName(((ConstantSearchGraphNode)edge.getSourceNode()).getElement())

+							,manager.getElementByName(((ConstantSearchGraphNode)edge.getTargetNode()).getElement())

+							, manager,edge);

+	    		

+		    	edge.setChecked(true);

+				return operation;

+				}

+

+    	//instanceof

+    	if(edge.getVPMEdgeType().compareTo(EdgeType.INSTANCEOF) == 0 

+    			&& edge.isSource())

+    		{	

+    				

+    		//cannot create instanceOF Relationships to vpm Entities or Relations

+			if(edge.getSourceNode() instanceof ConstantSearchGraphNode && 
+					(((ConstantSearchGraphNode)edge.getSourceNode()).getElement().equals(ISearchGraph.VPM_RELATION_FQN)
+						|| ((ConstantSearchGraphNode)edge.getSourceNode()).getElement().equals(ISearchGraph.VPM_ENTITY_FQN))
+			  )

+			{

+			edge.setChecked(true);

+			return null;

+			}	

+    		

+    		

+    		if(edge.getSourceNode() instanceof VariableSearchGraphNode && 	edge.getTargetNode() instanceof VariableSearchGraphNode)

+    				operation = new CreateInstanceofBound2Bound(((VariableSearchGraphNode)edge.getSourceNode()).getId()

+									,((VariableSearchGraphNode)	edge.getTargetNode()).getId()

+									, manager,edge);

+			else

+			if(edge.getSourceNode()  instanceof VariableSearchGraphNode && 	edge.getTargetNode() instanceof ConstantSearchGraphNode )

+					operation = new CreateInstanceofBound2Constant(((VariableSearchGraphNode)edge.getSourceNode()).getId()

+								,manager.getElementByName(((ConstantSearchGraphNode)	edge.getTargetNode()).getElement())

+								, manager,edge);

+			else

+			if(edge.getSourceNode()  instanceof ConstantSearchGraphNode && 	edge.getTargetNode() instanceof VariableSearchGraphNode)

+					operation = new CreateInstanceofConstant2Bound(manager.getElementByName(((ConstantSearchGraphNode)edge.getSourceNode()).getElement())

+								,((VariableSearchGraphNode)	edge.getTargetNode()).getId()

+								, manager,edge);

+			else

+			if(edge.getSourceNode()  instanceof ConstantSearchGraphNode && 	edge.getTargetNode() instanceof ConstantSearchGraphNode)

+					operation = new CreateInstanceofConstant2Constant(manager.getElementByName(((ConstantSearchGraphNode)edge.getSourceNode()).getElement())

+								,manager.getElementByName(((ConstantSearchGraphNode)	edge.getTargetNode()).getElement())

+								, manager,edge);

+		    		

+		    edge.setChecked(true);

+		    return operation;

+		   	}

+    	

+    	if(edge.getVPMEdgeType().compareTo(EdgeType.BELOW) == 0 

+    			&& edge.isSource())

+    			{

+	       		checkSet.add(getBelowContainmentCheckOperation(manager,edge));

+    			//Debug

+    			//logger.debug("Containment Check Below "+edge.getSourceNode().getName()+" below "+edge.getSourceNode().getName());

+    			//if move is needed for input parameters than this line have to be changed

+    			edge.setChecked(true);

+    			}

+    	

+    	if(edge.getVPMEdgeType().compareTo(EdgeType.IN) == 0 

+    			&& edge.isSource())

+    			{

+    			    		

+    			try{

+    			if(edge.getSourceNode() instanceof ConstantSearchGraphNode)

+    				operation = new MoveBoundunderConstant(manager

+    						,(IEntity)manager.getElementByName(((ConstantSearchGraphNode)edge.getSourceNode()).getElement())

+    						,((VariableSearchGraphNode)edge.getTargetNode()).getId()
+    						,edge);

+    			else

+    			if(edge.getSourceNode() instanceof VariableSearchGraphNode)

+    				operation = new MoveBoundunderBound(manager

+    						,((VariableSearchGraphNode)edge.getSourceNode()).getId()

+    						,((VariableSearchGraphNode)edge.getTargetNode()).getId()
+    						,edge);

+    			

+    			edge.setChecked(true);

+    			return operation;

+    			}catch(ClassCastException e)

+    				{
+    				String[] context = {edge.getSourceNode().getName()};
+    				throw new GTRuleBuildingException(GTErrorStrings.NOT_CONTAINER
+    						,context
+    						,searchGraph.getGTASMRepresentation(edge.getSourceNode()));

+    				}

+    			}

+    			

+//

+//    	if(edge.getVPMEdgeType().compareTo(EdgeType.SOURCE) ==0 

+//    			|| edge.getVPMEdgeType().compareTo(EdgeType.TARGET) ==0)

+//    			{//Debug

+//    			System.out.println("Relation "+edge.getName());

+//    			}

+    	

+    	//target and source (this cannot be processed as it is connected to the Relation searchgraph node creation

+   	return null;

+    }

+    

+    /**

+     * Generates containment check operation represented by the edge input parameter

+     * @param manager model manager of the viatra model space

+     * @param edge a containment edge in the search graph

+     * @return the containment check operation based on the edge input param 

+     */

+    public static ISearchPlanOperation getBelowContainmentCheckOperation(IModelManager manager,SearchGraphEdge edge) {

+    	ISearchPlanOperation sop = null;

+    

+	if(edge.getSourceNode() instanceof VariableSearchGraphNode && edge.getTargetNode() instanceof VariableSearchGraphNode)

+		sop = new BoundToBoundCheckOperation(((VariableSearchGraphNode)edge.getSourceNode()).getId()

+					,((VariableSearchGraphNode)edge.getTargetNode()).getId()

+					,edge);

+	else

+	if(edge.getSourceNode() instanceof VariableSearchGraphNode && edge.getTargetNode() instanceof ConstantSearchGraphNode )

+		sop = new BoundToConstantCheckOperation(((VariableSearchGraphNode)edge.getSourceNode()).getId()

+				,manager.getElementByName(((ConstantSearchGraphNode)edge.getTargetNode()).getElement())

+				,edge);

+	else

+	if(edge.getSourceNode() instanceof ConstantSearchGraphNode && edge.getTargetNode() instanceof VariableSearchGraphNode)

+		sop = new ConstantToBoundCheckOperation(manager.getElementByName(((ConstantSearchGraphNode)edge.getSourceNode()).getElement())

+				,((VariableSearchGraphNode)edge.getTargetNode()).getId()

+				,edge);

+	else

+	if(edge.getSourceNode() instanceof ConstantSearchGraphNode && edge.getTargetNode() instanceof ConstantSearchGraphNode)

+		sop = new ConstantToConstantCheckOperation(manager.getElementByName(((ConstantSearchGraphNode)edge.getSourceNode()).getElement())

+				,manager.getElementByName(((ConstantSearchGraphNode)edge.getTargetNode()).getElement())

+				,edge);

+	

+    return sop;}

+

+

+	/** Generates operation related to bound input parameters for the RHS.

+	 * @param node The input search graph node

+	 * @param manager Model manager of the model space

+	 * @param checkSet Collection containing the check operation for the RHS

+	 * @return The model manipulation operations related to the input node.

+	 */

+	public static Collection<IUpdatePlanOperation> getInputSpecificOperation(VariableSearchGraphNode node

+			, IModelManager manager, 

+			ArrayList<ISearchPlanOperation> checkSet) {

+		Collection<IUpdatePlanOperation> operations = new ArrayList<IUpdatePlanOperation>();

+		

+		

+		for(SearchGraphEdge edge : node.getSources()){

+		

+		/** Check Operations*/	

+		//constant instance of relation on a variable from the lhs

+		if(edge.getVPMEdgeType().compareTo(EdgeType.INSTANCEOF) == 0

+				&& edge.isSource()

+				&& edge.getSourceNode() instanceof ConstantSearchGraphNode)

+					{
+					//specific operation required when the type is vpm.entity or vpm.relation
+					if(((ConstantSearchGraphNode)edge.getSourceNode()).getElement().equals(ISearchGraph.VPM_RELATION_FQN)
+									|| ((ConstantSearchGraphNode)edge.getSourceNode()).getElement().equals(ISearchGraph.VPM_ENTITY_FQN))
+						{
+						
+						ISearchPlanOperation op = new IsEntityorRelationCheckOperation(node.getId()
+								,edge,
+								((ConstantSearchGraphNode)edge.getSourceNode()).getElement());
+						checkSet.add(op);
+						}
+					else
+						{

+						ISearchPlanOperation op = new ConstantToBoundCheckOperation(

+									manager.getElementByName(((ConstantSearchGraphNode)	edge.getSourceNode()).getElement()),

+									node.getId(),
+									edge);

+						checkSet.add(op);
+						}

+			

+					edge.setChecked(true);

+					edge.getSourceNode().setChecked(true);

+					}

+		//constant Supertype relation to an input parameter which is from the lhs pattern

+		else

+		if(edge.getVPMEdgeType().compareTo(EdgeType.SUPERTYPEOF) == 0

+				&& !edge.isSource()

+				&& edge.getSourceNode() instanceof ConstantSearchGraphNode)

+					{

+					if(((ConstantSearchGraphNode)edge.getSourceNode()).getElement().equals(ISearchGraph.VPM_RELATION_FQN)
+							|| ((ConstantSearchGraphNode)edge.getSourceNode()).getElement().equals(ISearchGraph.VPM_ENTITY_FQN))
+						{
+						ISearchPlanOperation op = new IsEntityorRelationCheckOperation(node.getId()
+								,edge,
+								((ConstantSearchGraphNode)edge.getSourceNode()).getElement());
+						checkSet.add(op);
+						
+						}
+					else
+						{
+						ISearchPlanOperation op = new ConstantToBoundCheckOperation(

+						manager.getElementByName(((ConstantSearchGraphNode)	edge.getSourceNode()).getElement()),

+						node.getId(),edge);

+						checkSet.add(op);

+						}

+					edge.setChecked(true);

+					edge.getSourceNode().setChecked(true);

+					}

+		else

+		//the relation is bound and only its source and target entites will have to be (re)set	

+		

+		if(edge.getVPMEdgeType().compareTo(EdgeType.TARGET) == 0

+				&& !edge.isSource()

+				&& edge.getSourceNode() instanceof VariableSearchGraphNode

+				&& node.getVpmModelElementType().equals(VPMModelElementType.RELATION))	

+					{	

+					IUpdatePlanOperation op = new SetRelationTarget(node.getId()

+							,((VariableSearchGraphNode)edge.getSourceNode()).getId()
+							,manager
+							,edge);

+					operations.add(op);

+					

+					edge.setChecked(true);

+					}

+		else

+		if(edge.getVPMEdgeType().compareTo(EdgeType.SOURCE) == 0

+				&& !edge.isSource()

+				&& edge.getSourceNode() instanceof VariableSearchGraphNode

+				&& node.getVpmModelElementType().equals(VPMModelElementType.RELATION))	

+					{	

+					IUpdatePlanOperation op = new SetRelationSource(node.getId()

+							,((VariableSearchGraphNode)edge.getSourceNode()).getId()
+							,manager
+							,edge);

+					operations.add(op);

+					

+					edge.setChecked(true);

+					}

+		}

+		return operations;

+	}

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/GTRuleMatcher.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/GTRuleMatcher.java
new file mode 100644
index 0000000..4e3ada1
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/GTRuleMatcher.java
@@ -0,0 +1,195 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal;

+

+
+import org.eclipse.viatra2.core.IModelManager;
+import org.eclipse.viatra2.gtasm.interpreter.exception.GTASMException;
+import org.eclipse.viatra2.gtasm.interpreter.exception.ViatraTransformationException;
+import org.eclipse.viatra2.gtasm.interpreter.executionEnvironment.IExecutionEnvironment;
+import org.eclipse.viatra2.gtasm.patternmatcher.ExecutionMode;
+import org.eclipse.viatra2.gtasm.patternmatcher.ParameterMode;
+import org.eclipse.viatra2.gtasm.patternmatcher.PatternCallSignature;
+import org.eclipse.viatra2.gtasm.patternmatcher.PatternMatcherParameters;
+import org.eclipse.viatra2.gtasm.patternmatcher.Scope;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GraphTransformationException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.term.ITermHandler;
+import org.eclipse.viatra2.gtasm.patternmatcher.patterns.IGTRuleMatcher;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.definitions.SymbolicRuleParameter;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.definitions.Variable;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.enums.ValueKind;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.terms.GTPatternCall;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.GTRule;
+import org.eclipse.viatra2.logger.Logger;
+

+/**
+ * * The class encapsulates the basic methods to initialise a GTRule matcher 

+ * @author Akos Horvath

+ */

+public abstract class GTRuleMatcher implements IGTRuleMatcher{

+	

+	protected Logger logger;

+    protected IModelManager manager;

+    protected GTRule gtRule;

+	protected IExecutionEnvironment gtEnvironment = null;

+	protected ITermHandler handler;

+	

+	// INITIALIZING methods for gt rule matching

+    

+    /**

+     * Initialize the gtRule matcher

+     * @param logger the logger of the actual modelspace

+     * @param manager viatra model space manager

+     * @param gtRule the actual rule

+     * @param gtEnviroment the execution enviroment on which the rule communicates with the org.eclipse.viatra2.gtasm.interpreter.impl.interpreter

+     * @param handler term handler for the rule

+     */

+    public GTRuleMatcher(Logger logger

+    		, IModelManager manager

+    		, GTRule gtRule

+    	//	, IGTRuleExecutionEnvironment gtEnviroment

+    		//, TermHandler handler

+    		) {

+        this.logger = logger;

+        this.manager = manager;

+        this.gtRule = gtRule;

+        //this.gtEnviroment = gtEnviroment;

+        //this.handler = handler;

+    }

+    

+    

+    //***************************************** INPUT parameter manipulation methods****************************

+

+    /**

+     * Initialize the Left hand side (matcher part) pattern of the gt rule and combinde the parameter mapping with the input parameters of the gt rule

+     * @param symSignatures mapping of the conatinment constraints of the input parameters

+     * @param symInputMapping mapping of the input parameters

+     * @param symQuantificationOrder the order of the forall and choose quantificated elements

+     * @return an inner class holding the inputmapping, the Signatures and the QuantifiationOrder

+     * @throws GTASMException

+     */

+    protected PatternMatcherParameters initLHSPattern(PatternCallSignature[] symSignatures, Object[] symInputMapping, Integer[] symQuantificationOrder) 

+    	throws ViatraTransformationException

+	{

+		//******LHS of the GTRule

+		

+		//create the PatternCall signature for the lhs call

+		PatternCallSignature[] lhsSignatures = new PatternCallSignature[gtRule.getPrecondition().getActualParameters().size()];

+		Object[] lhsInputMapping = new Object[gtRule.getPrecondition().getActualParameters().size()];

+		Integer[] lhsQuantification = new Integer[gtRule.getPrecondition().getActualParameters().size()];

+		int forallQuantificationNumber = 0;

+		

+		//copy the symbolic parameter signatures and inputMapping to the lhs signature and Value arrays		

+		for(int i = 0; i< symSignatures.length; i++)

+			{

+			SymbolicRuleParameter symParam = gtRule.getSymParameters().get(i);

+			if(symParam.getVariable().getReferences().size() > 0) //is the symParam in one of the patterns

+				{if(getActualParameterIndexofSymbolicParameter(gtRule.getPrecondition(), symParam) != -1)

+					{lhsSignatures[getActualParameterIndexofSymbolicParameter(gtRule.getPrecondition(), symParam)] = symSignatures[i];

+					 lhsInputMapping[getActualParameterIndexofSymbolicParameter(gtRule.getPrecondition(), symParam)] = symInputMapping[i];

+					

+					if(symQuantificationOrder != null)

+						{

+						// its a quantificated variable with a forall rule

+						//if(symSignatures[i].getExecutionMode().compareTo(ExecutionMode.MULTIPLE_RESULTS) == 0)

+						//	{

+							lhsQuantification[getSymQuantificationIndex(i,symQuantificationOrder)] = getActualParameterIndexofSymbolicParameter(gtRule.getPrecondition(), symParam);

+							 forallQuantificationNumber++;

+						//	}

+						//else

+						//	{lhsQuantification[getSymQuantificationIndex(i,symQuantificationOrder)] = getActualParameterIndexofSymbolicParameter(gtRule.getPrecondition(), symParam);

+						//	}

+						}

+					}

+				}

+			else

+				logger.warning(symParam.getVariable().getName()+" is never used inside "+gtRule.getName()+".");

+			}

+		//fill up the lhs signature and InputMapping arrays with the corresponding values

+		for(int j=0; j < gtRule.getPrecondition().getActualParameters().size(); j++)

+		{

+	 	 if(lhsSignatures[j] == null)

+	 	 	{lhsSignatures[j] = new PatternCallSignature();

+			 lhsSignatures[j].setExecutionMode(ExecutionMode.SINGLE_RESULT);

+			 lhsSignatures[j].setParameterMode(ParameterMode.OUTPUT);

+			 lhsSignatures[j].setParameterScope(new Scope());

+			 lhsInputMapping[j] = ValueKind.UNDEF_LITERAL;

+	 	 	 

+		 if(symQuantificationOrder != null)

+				{

+				// its a quantificated variable with a forall rule

+				lhsQuantification[forallQuantificationNumber] = j;

+				forallQuantificationNumber++;

+				}

+	 	 	} 

+		}

+		return new PatternMatcherParameters(lhsSignatures, lhsInputMapping, lhsQuantification);

+	}

+	

+	/** Returns the order of the rule from the invocation

+	 * @param symParamIndex the current index of the rule

+	 * @param symQuantificationOrder Quantification order of the invocation

+	 * @return the qunatification order of the symBolic parameter's index

+	 * @throws GTASMException

+	 */

+	private int getSymQuantificationIndex(Integer symParamIndex, Integer[] symQuantificationOrder)

+			throws ViatraTransformationException{

+		

+		for (int j = 0; j < symQuantificationOrder.length; j++) {

+			if(symQuantificationOrder[j].compareTo(symParamIndex) == 0) {

+				return j;

+			}

+		}

+		//there is an error in the input quantification order

+		String[] context = {(gtRule.getSymParameters().get(symParamIndex)).getVariable().getName(),
+				gtRule.getName()};
+		throw new GraphTransformationException(
+					GTErrorStrings.SYMBOLIC_QUANTIFICITION + gtRule.getName()
+					,context
+					,gtRule);
+	}

+

+	/** Returns the actual index of the Variable from the invocation context

+	 * @param gtPattCall the gt rule invocation

+	 * @param var a variable of the gt pattern call

+	 * @return the index of the input variable

+	 */

+	protected int getActualParameterIndexof(GTPatternCall gtPattCall, Variable var){

+		for (Object obj :var.getReferences()) {

+			if (gtPattCall.getActualParameters().contains(obj)) {

+				return gtPattCall.getActualParameters().indexOf(obj);

+			}

+		}

+		return -1;

+	}

+	

+	/** Returns the actual index of the Variable refernce's variable from the invocation context

+	 * @param gtPatt the gt rule invocation context

+	 * @param symParam the symbolic parameter of the invoked GT rule

+	 * @return the index of the symbolic parameter in the GT rules

+	 */

+	protected int getActualParameterIndexofSymbolicParameter(GTPatternCall gtPattCall, SymbolicRuleParameter symParam){

+		return getActualParameterIndexof(gtPattCall, symParam.getVariable());

+	}

+	

+	protected Object[] getOutPutSymbolicParatemerRules() 
+			throws ViatraTransformationException {
+		Object[] values = new Object[gtRule.getSymParameters().size()];

+		for (int i = 0; i < gtRule.getSymParameters().size(); i++) {
+			SymbolicRuleParameter symParam = 
+				gtRule.getSymParameters().get(i);

+			values[i] = gtEnvironment.getVariableValue(symParam.getVariable());	

+		}

+		return values;

+	}

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/RightHandSideMatcher.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/RightHandSideMatcher.java
new file mode 100644
index 0000000..1349abe
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/RightHandSideMatcher.java
@@ -0,0 +1,151 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal;

+

+import java.util.Collection;
+
+import org.eclipse.viatra2.core.IModelManager;
+import org.eclipse.viatra2.gtasm.interpreter.exception.ViatraTransformationException;
+import org.eclipse.viatra2.gtasm.patternmatcher.ParameterMode;
+import org.eclipse.viatra2.gtasm.patternmatcher.PatternCallSignature;
+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherCompileTimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTRuleBuildingException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.PatternMatcher;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.callgraph.FlattenedPattern;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.term.ITermHandler;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.enums.ValueKind;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.GTPattern;
+import org.eclipse.viatra2.logger.Logger;
+

+

+/**Specific PatternMatcher for the RHS of a GTRule.
+ * Used to create the search graph of the pattern and then generate the according operations
+ * @author Akos Horvath and Gergely Varro
+ *
+ */
+public class RightHandSideMatcher extends PatternMatcher {

+	//private IModelElement[] scopeMapping;

+	private FlattenedPattern flattenedPattern;

+	

+	RightHandSideMatcher(GTPattern pattern, Logger logger, IModelManager manager, ITermHandler termHandler) 

+    	throws ViatraTransformationException {

+		// Flattening is executed in the constructor of the superclass (PatternMatcher)

+		super(pattern,logger,manager,termHandler);

+		try{
+		flattenedPattern = root.getSingleFlattenedPattern();

+		}catch(PatternMatcherCompileTimeException e ){
+			throw e.addNewStackElement(pattern);
+		}
+		
+		
+		// Scope handling removed

+		// flattenedPattern.getSearchGraph().addScope(pattern, flattenedPattern.getFrameSize());

+		//scopeMapping = new IModelElement[pattern.getSymParameters().size()];

+	}	

+

+    /** Returns the MatchingFrame with the already bound parameters. 

+     * @param gtElementMappings The mapping the LHS and RHS elements

+     * @param inputMapping the input variable values

+     * @param signature signatures of the rhs input parameters

+     * @return

+     * @throws GTRuleBuildingException

+     */

+    public MatchingFrame generateMatchingFrameofInputContext(Collection<GTElementMapping> gtElementMappings,

+    		Object[] inputMapping,

+    		PatternCallSignature[] signature 

+    		) throws GTRuleBuildingException

+    	{

+	    	
+    	if (inputMapping.length != signature.length) 
+	    		{
+	    		 throw new GTRuleBuildingException(GTErrorStrings.INTERNAL_ERROR_INPUTPARAMS_SYMPARAMS_LENGTH
+	    				 ,null
+	    				 ,null);

+	        	}

+	

+    	MatchingFrame template = new MatchingFrame(flattenedPattern);

+			

+		// Input processing

+		for (int i = 0; i < inputMapping.length; i++) 
+			{

+				if (signature[i].getParameterMode() == ParameterMode.OUTPUT) {

+					if (inputMapping[i] == null || inputMapping[i].equals(ValueKind.UNDEF_LITERAL)) {

+							// Output parameter without value: do nothing

+					} else {

+							// Output parameter with value: a possible bug in the code

+							logger.debug("Parameter " + i +

+									" is an output parameter with value " + 

+									inputMapping[i].toString());

+					}

+				} else if (signature[i].getParameterMode() == ParameterMode.INPUT) {

+					if (inputMapping[i] != null) {

+							// Input parameter with value: test and set the value

+							template.testAndSetValue(i, inputMapping[i]);

+					} else {

+							// Input parameter without value: throw an exception

+						throw new GTRuleBuildingException(GTErrorStrings.INTERNAL_ERROR_INPUTPARAM_WITHOUT_A_VALUE
+								,null
+								,null);

+					}

+				} 

+			}

+		     // Input scope processing

+

+			/* boolean[] inConstraints =  flattenedPattern.getSearchGraph().hasinputParameterINContstraint();

+			 Vector<IUpdatePlanOperation> operations = new Vector<IUpdatePlanOperation>();

+			 Vector<ISearchPlanOperation> checkSet = new Vector<ISearchPlanOperation>();

+		     for (int i = 0; i < inputMapping.length; i++) {

+		    	 if(!(signature[i].getParameterScope().getParent().equals(Scope.DEFAULT_PARENT)

+						   && signature[i].getParameterScope().getContainmentMode().equals(Scope.DEFAULT_MODE)))

+		    	   {IModelElement element = signature[i].getParameterScope().getParent();

+		            if (element != null) 

+		            {

+		            	if(signature[i].getParameterScope().getContainmentMode().compareTo(Scope.IN) == 0)

+		            		{

+		            		if(inConstraints[i])

+		            			throw new GTRuleBuildingException(GTErrorStrings.MORE_ONE_IN_CONTAINMENT);

+		            		else // have to move the element under the container

+		            			{

+		            			operations.add(new MoveBoundunderConstant(manager,

+		            					(IEntity)element, i));

+		            			}

+		            		}

+		            	else // below type containment constraint

+		            		{

+		            			checkSet.add(new GTBelowContainmentCheckBoundUnderConstant(i,

+		            					signature[i].getParameterScope().getParent()));

+		            		}

+		            }

+		            	// template.setValue(frameSize + i, element);}

+		            else{

+		                // Input parameter scope without value: throw an exception

+		                throw new GTRuleBuildingException("Input parameter scope " + i + " does not have a value.");

+		            	}

+		    	   }

+		       }*/

+ 		    return template;

+    	}

+	

+	public GTOperationContext generateGTOperation(Collection<GTElementMapping> gtElementMappings,

+    		//Object[] inputMapping,

+    		PatternCallSignature[] signature 

+    		//Vector<RelationShipMapping> relationShipMapping

+    		) throws GTRuleBuildingException {

+    	

+		GTOperationContext finalOperations =

+			flattenedPattern.getSearchGraph().generateGTOperations(gtElementMappings, manager, signature);

+		 return finalOperations; 

+    }

+    

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/TraditionalGTRuleMatcher.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/TraditionalGTRuleMatcher.java
new file mode 100644
index 0000000..dd950b7
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/TraditionalGTRuleMatcher.java
@@ -0,0 +1,514 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal;

+

+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.eclipse.viatra2.core.IModelElement;
+import org.eclipse.viatra2.core.IModelManager;
+import org.eclipse.viatra2.gtasm.interpreter.exception.GTASMException;
+import org.eclipse.viatra2.gtasm.interpreter.exception.ViatraTransformationException;
+import org.eclipse.viatra2.gtasm.interpreter.executionEnvironment.IExecutionEnvironment;
+import org.eclipse.viatra2.gtasm.interpreter.impl.rules.RuleInterpreter;
+import org.eclipse.viatra2.gtasm.patternmatcher.IMatching;
+import org.eclipse.viatra2.gtasm.patternmatcher.ParameterMode;
+import org.eclipse.viatra2.gtasm.patternmatcher.PatternCallSignature;
+import org.eclipse.viatra2.gtasm.patternmatcher.PatternMatcherParameters;
+import org.eclipse.viatra2.gtasm.patternmatcher.Scope;
+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherCompileTimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherRuntimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTOperationException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTRuleBuildingException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GraphTransformationException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.IUpdatePlanOperation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation.ISearchPlanOperation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.term.BasicTermHandler;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.term.ITermHandler;
+import org.eclipse.viatra2.gtasm.patternmatcher.patterns.IPatternMatcher;
+import org.eclipse.viatra2.gtasm.patternmatcher.patterns.PatternMatcherProvider;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.RuntimeAnnotation;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.definitions.SymbolicRuleParameter;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.definitions.Variable;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.enums.ValueKind;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.terms.GTPatternCall;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.terms.VariableReference;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.GTRule;
+

+ 

+/**
+ *
+ * The class interprets all traditionally defined GT rule containing
+ * LHS, RHS and action part (or a subset of these elements).
+ * @author Akos Horvath

+ */

+public class TraditionalGTRuleMatcher extends GTRuleMatcher {

+	IPatternMatcher leftHandSidePatternMatcher;

+ 	RightHandSideMatcher rightHandSideMatcher;

+	boolean isRandom;
+	

+	Collection<GTElementMapping> elementMappings;

+	Collection<IUpdatePlanOperation> nonchangeableGTOperations;

+	Collection<ISearchPlanOperation> checkSet;

+	

+	public TraditionalGTRuleMatcher( GTRule gt

+			, IExecutionEnvironment enviroment

+			, ITermHandler handler

+			, PatternMatcherParameters mp) throws ViatraTransformationException {

+		super(enviroment.getFramework().getLogger()

+				, enviroment.getFramework().getTopmodel().getModelManager()

+				, gt);

+		elementMappings = new ArrayList<GTElementMapping>();

+		this.initGTRule(enviroment);

+		this.construct(manager,mp.getCallSignature());

+	}

+

+	/** 
+	 * Returns a Pattern Matcher to work with, in case of alternative pattern matchers this is the Method to override

+	 * @return Pattern matcher for the

+	 * @throws GTASMException

+	 */

+	protected IPatternMatcher getPatternMatcherforPreCondition() throws ViatraTransformationException{
+//		PatternBuilder pb = new PatternBuilder(this.logger, manager, handler);
+//		try {
+//			return pb.construct(gtRule.getPrecondition().getCalledPattern());
+//		} catch (PatternMatcherCompileTimeException e) {
+//			//logger.error(e.getMessage());
+//			throw e.addNewStackElement(gtRule);
+//		}
+		
+		return PatternMatcherProvider.getInstance().getPatternMatcher(
+				gtEnvironment, gtRule.getPrecondition().getCalledPattern());
+	}

+	
+	/**
+	 * Determines whether true pseudorandom matching is required for ChooseRules.
+	 * @return true if random is required
+	 */
+	protected boolean isLeftHandSideRandom() {
+		// is true pseudorandom required?
+		for (Object annot : gtRule.getPrecondition().getCalledPattern().getRuntimeAnnotations()) {
+			if ("@random".equals(((RuntimeAnnotation) annot).getAnnotationName().toLowerCase())) {
+				return true;
+			}
+		}	
+		return false;
+	}
+	

+	/**

+	 * Creates the GTrule matcher by constructing the search graph of the LHS and RHS (optional) part, and the operations from RHS\LHS

+	 * @param manager model manager of the VIATRA model space

+	 * @throws GTASMException

+	 */

+	private void construct(IModelManager manager, PatternCallSignature[] symSignatures) throws ViatraTransformationException{

+		

+		if(gtRule.getPostcondition() != null && gtRule.getPrecondition() == null)

+			logger.error("There is only PostCondition defined for the GTRule "+ gtRule.getName());

+		

+		if (gtRule.getPostcondition() != null) {
+			try {
+				leftHandSidePatternMatcher = getPatternMatcherforPreCondition();
+				isRandom = isLeftHandSideRandom();
+				rightHandSideMatcher =
+					new RightHandSideMatcher(gtRule.getPostcondition().getCalledPattern(), logger, manager, handler); 
+			} catch (PatternMatcherCompileTimeException e) {
+				logger.error(e.getMessage());
+				throw e.addNewStackElement(gtRule);
+			}
+			//maps the parameters between the RHS and the LHS
+			elementMappings = new ArrayList<GTElementMapping>();
+			int actualIndex = 0;
+			for(Object obj: gtRule.getPrecondition().getActualParameters()){
+				VariableReference varReference = (VariableReference) obj;
+				Variable actualVariable = varReference.getVariable();
+				if(getActualParameterIndexof(gtRule.getPostcondition(),actualVariable) != -1)
+				{
+					GTElementMapping map = new GTElementMapping(actualIndex,getActualParameterIndexof(gtRule.getPostcondition(),actualVariable));
+					elementMappings.add(map);
+				}

+				actualIndex++;
+			}
+
+			PatternCallSignature[] rhsSignatures = new PatternCallSignature[gtRule.getPostcondition().getActualParameters().size()];
+			//Input parameters from the symmetric parameters
+			if(gtRule.getPostcondition().getActualParameters().size() > 0)
+				for(int i = 0; i < symSignatures.length; i++){

+					SymbolicRuleParameter symParam = gtRule.getSymParameters().get(i);

+					if(symParam.getVariable().getReferences().size() > 0) 

+						if(getActualParameterIndexofSymbolicParameter(gtRule.getPostcondition(), symParam) != -1)

+						{
+							if(symSignatures[i].getParameterMode().compareTo(ParameterMode.INPUT) == 0)

+							{

+								PatternCallSignature sig = new PatternCallSignature();

+								sig.setParameterMode(ParameterMode.INPUT);

+								rhsSignatures[getActualParameterIndexofSymbolicParameter(gtRule.getPostcondition(), symParam)] = sig;

+							}

+							else

+								rhsSignatures[getActualParameterIndexofSymbolicParameter(gtRule.getPostcondition(), symParam)] = symSignatures[i].clone();

+						}

+				}
+
+//			//Element mapping
+			for(GTElementMapping map: elementMappings)
+				if(rhsSignatures[map.getRhsInputOrderIndex()] == null)
+				{
+					PatternCallSignature sig = new PatternCallSignature();
+					sig.setParameterMode(ParameterMode.INPUT);
+					rhsSignatures[map.getRhsInputOrderIndex()] = sig;
+				}
+				else // it is a GT Rule parameter which can be output type but as it is represented in both of the patterns
+					// to the RHS it is an input parameter
+				{
+					rhsSignatures[map.getRhsInputOrderIndex()].setParameterMode(ParameterMode.INPUT);
+				}
+			//output parameter of the RHS, which is used in the action part only
+			for(int j=0; j < gtRule.getPostcondition().getActualParameters().size(); j++)
+			{
+				if(rhsSignatures[j] == null)
+				{rhsSignatures[j] = new PatternCallSignature();
+				rhsSignatures[j].setParameterMode(ParameterMode.OUTPUT);
+				}
+			}
+			try {
+				GTOperationContext _temp = rightHandSideMatcher.generateGTOperation(elementMappings,rhsSignatures);
+				nonchangeableGTOperations = _temp.getFinalOperations();
+				checkSet = _temp.getCheckSet();
+
+			} catch (GTRuleBuildingException e) {
+				throw e.addNewStackElement(gtRule);
+			}
+		}

+		else //only a precondition is available

+		{

+			leftHandSidePatternMatcher = getPatternMatcherforPreCondition();

+			isRandom = isLeftHandSideRandom();
+			elementMappings = null;

+			nonchangeableGTOperations = null;

+		}

+	}

+	

+	@Override
+	public void initGTRule(IExecutionEnvironment actualEnvironment) throws ViatraTransformationException{

+		//sets the actual context of the gt rule invocation 

+		this.gtEnvironment = actualEnvironment;

+		this.handler = new BasicTermHandler(actualEnvironment); //handler;

+		

+		try {
+			// adds the local variables & sym parameters to the execution environment -> later only the values need to be changed

+			for(Object o:gtRule.getLocalVariables()){

+				gtEnvironment.addVariable((Variable) o, ValueKind.UNDEF_LITERAL);
+			}
+		} catch (ViatraTransformationException e) {
+			throw e.addNewStackElement(gtRule);
+			// throw new GTASMException(e.getLocalizedMessage() + GTErrorStrings.INIT+gtRule.getName(), gtRule);
+		}

+	}

+	

+	/**

+	 * Executes the GT operations created from the RHS/LHS and the optional DO part of the rule

+	 * @param symSignatures the signature of the rule

+	 * @param symInputMapping mapping of the input parameters

+	 * @param lhsFrame the signature, input mapping and the quantification order for he LHS

+	 * @return Returns the values of the rule's parameters after executing the operations constructed form the rule

+	 * @throws GTASMException

+	 */

+	protected Object[] executeGTOperations(PatternCallSignature[] symSignatures

+			, Object[] symInputMapping

+			, IMatching lhsFrame) throws ViatraTransformationException{

+		

+		GTOperationContext actualGTContext = null;

+		GTPatternCall preConditionCall = gtRule.getPrecondition();

+		GTPatternCall postConditionCall = gtRule.getPostcondition();

+		// *****RHS of the GTRule

+		logger.debug("[debug] Starting GT rule: "+ gtRule.getName());

+		

+		if (lhsFrame != null && postConditionCall != null) {
+			PatternCallSignature[] rhsSignatures = new PatternCallSignature[postConditionCall.getActualParameters().size()];

+			Object[] rhsInputMapping = new Object[postConditionCall.getActualParameters().size()];

+			

+			//Input parameters from the symmetric parameters

+			if(postConditionCall.getActualParameters().size() > 0)

+			for(int i = 0; i < symSignatures.length; i++){

+				SymbolicRuleParameter symParam = gtRule.getSymParameters().get(i);

+				if(symParam.getVariable().getReferences().size() > 0) 

+					if(getActualParameterIndexofSymbolicParameter(postConditionCall, symParam) != -1)

+						{

+						rhsInputMapping[getActualParameterIndexofSymbolicParameter(postConditionCall, symParam)] = symInputMapping[i];

+						if(symSignatures[i].getParameterMode().compareTo(ParameterMode.INPUT) == 0)

+							{

+							PatternCallSignature sig = new PatternCallSignature();

+							sig.setParameterMode(ParameterMode.INPUT);

+							sig.setParameterScope(new Scope());

+							rhsSignatures[getActualParameterIndexofSymbolicParameter(postConditionCall, symParam)] = sig;

+							}

+						else//input parameter

+							rhsSignatures[getActualParameterIndexofSymbolicParameter(postConditionCall, symParam)] = symSignatures[i];

+						}

+				}

+			

+			//Element mapping

+			for(GTElementMapping map: elementMappings)

+				if(rhsSignatures[map.getRhsInputOrderIndex()] == null)

+					{rhsInputMapping[map.getRhsInputOrderIndex()]= lhsFrame.lookup(map.getLhsInputOrderIndex()); 

+					PatternCallSignature sig = new PatternCallSignature();

+					sig.setParameterMode(ParameterMode.INPUT);

+					sig.setParameterScope(new Scope());

+					rhsSignatures[map.getRhsInputOrderIndex()] = sig;

+					}

+				else // it is a GT Rule parameter which can be any in any parametermode but as it is represented in both LHS and RHS

+					 // to the RHS it is an input parameter

+					{

+					rhsInputMapping[map.getRhsInputOrderIndex()]= lhsFrame.lookup(map.getLhsInputOrderIndex()); 

+					rhsSignatures[map.getRhsInputOrderIndex()].setParameterMode(ParameterMode.INPUT);

+					}

+			// it is an input parameter for the RHS form the GT Rule head

+			for(int j=0; j < postConditionCall.getActualParameters().size(); j++)

+				{

+			 	 if(rhsSignatures[j] == null)

+			 	 	{rhsSignatures[j] = new PatternCallSignature();

+					 rhsSignatures[j].setParameterMode(ParameterMode.OUTPUT);

+					 rhsSignatures[j].setParameterScope(new Scope());

+					 rhsInputMapping[j] = ValueKind.UNDEF_LITERAL;

+			 	 	}

+				}

+			try {

+				MatchingFrame frame = rightHandSideMatcher.generateMatchingFrameofInputContext(this.elementMappings, rhsInputMapping,rhsSignatures);

+				actualGTContext = new GTOperationContext(frame,nonchangeableGTOperations,checkSet);

+			} catch (GTRuleBuildingException e) {

+				throw e.addNewStackElement(gtRule);

+			}

+		}

+		

+		// Running the operations from the difference of the RHS and the LHS

+		if (lhsFrame != null && actualGTContext != null) {
+			logger.debug("GT Opeations of the GtRule: "+this.gtRule.getName());

+		

+			//* manipulation operations */

+			for (IUpdatePlanOperation op :actualGTContext.getFinalOperations()) {

+				try {

+					if (op.update(actualGTContext.getReturnFrame())) {

+						logger.debug(op.toString(actualGTContext.getReturnFrame()));
+					} else {
+						String[] context ={op.toString(actualGTContext.getReturnFrame()), gtRule.getName()};
+						GraphTransformationException e = 
+							new GraphTransformationException(GTErrorStrings.GTRULE_RHS_FAILED_MANIPULATION
+									,context

+									,op.getErrorfulElement(actualGTContext.getReturnFrame())); 
+						e.addNewStackElement(postConditionCall.getCalledPattern());
+						throw e.addNewStackElement(gtRule);

+					}

+				} catch (GTOperationException e) {
+					e.addNewStackElement(postConditionCall.getCalledPattern());
+					throw e.addNewStackElement(gtRule);
+				}

+			}

+			//* check operations */

+			for(ISearchPlanOperation op: actualGTContext.getCheckSet()){

+				try

+				{

+					op.preprocess(actualGTContext.getReturnFrame());

+					if(!op.execute(actualGTContext.getReturnFrame())){

+						String[] context = {op.toString(actualGTContext.getReturnFrame()), gtRule.getName()};
+						GraphTransformationException ex = 
+							new GraphTransformationException(GTErrorStrings.GTRULE_RHS_FAILED_CHECK
+									,context
+									,op.getErrorfulElement(actualGTContext.getReturnFrame()));
+						ex.addNewStackElement(postConditionCall.getCalledPattern());
+						throw ex.addNewStackElement(gtRule);  

+					}

+				} catch(PatternMatcherRuntimeException e) {

+					e.addNewStackElement(postConditionCall.getCalledPattern());
+					throw e.addNewStackElement(gtRule);

+				}

+			}

+		}

+

+		// * ACTION part of the GTRULE */

+		//there is an action part in the gtrule

+		if(gtRule.getAction() != null)

+		{	// fill up the input parameter for the action part

+			try

+			{	//The rule has only PreCondition

+				if(postConditionCall == null)

+						{	//symbolic parameter its not in the LHS

+							for(int i = 0; i< symInputMapping.length; i++)

+							{SymbolicRuleParameter symParam = gtRule.getSymParameters().get(i);

+							// its a variable which isn't in the LHS 

+							if(getActualParameterIndexofSymbolicParameter(preConditionCall, symParam) == -1)

+								{//this variable can only be founded in the action part

+							 	if(symParam.getVariable().getReferences().size() > 0)

+									 this.gtEnvironment.setVariableValue(symParam.getVariable(),symInputMapping[i]);

+							 	else

+							 	 	 logger.warning("SymbolicRuleParameter "+symParam.getName()+" in gtRule " + gtRule.getName()+ "is never used");

+								}

+							}

+							//Local variables: have to check where are they initialized at the first time

+							for(Object oVar: gtRule.getLocalVariables())

+							{	Variable actualVariable = (Variable) oVar;

+								//The variable is in the LHS Pattern

+								if(getActualParameterIndexof(preConditionCall,actualVariable) != -1)

+									{

+									Object actualValue = lhsFrame.lookup(getActualParameterIndexof(preConditionCall,actualVariable));
+									gtEnvironment.setVariableValue(actualVariable, returnValidValue(actualValue));

+									}

+							}

+						}

+				//both Pre and Post Condition

+				else

+						{

+						//symbolic parameter

+						for(int i = 0; i< symInputMapping.length; i++)

+						{SymbolicRuleParameter symParam = gtRule.getSymParameters().get(i);

+						// it is a variable which isn't in the RHS or the LHS 

+						if(getActualParameterIndexofSymbolicParameter(postConditionCall, symParam) == -1

+								&& getActualParameterIndexofSymbolicParameter(preConditionCall, symParam) == -1)

+							//this variable can only be found in the action part

+						 	if(symParam.getVariable().getReferences().size() > 0)

+								 this.gtEnvironment.setVariableValue(symParam.getVariable(),symInputMapping[i]);

+						 	else

+						 	 	 logger.warning("SymbolicRuleParameter "+symParam.getName()+" in gtRule " + gtRule.getName()+ "is never used");

+						}

+						//Local variables, have to check where are they initialized at the first time

+						for(Object oVar: gtRule.getLocalVariables())

+						{	Variable actualVariable = (Variable) oVar;

+							//The variable is in the RHS

+							if(getActualParameterIndexof(postConditionCall,actualVariable) != -1)

+									{
+									Object actualValue = actualGTContext.getReturnFrame().getValue(getActualParameterIndexof(postConditionCall,actualVariable));
+									gtEnvironment.setVariableValue(actualVariable, returnValidValue(actualValue));
+									}

+							else

+							if(getActualParameterIndexof(preConditionCall,actualVariable) != -1)

+									{
+									Object actualValue = lhsFrame.lookup(getActualParameterIndexof(preConditionCall,actualVariable));
+									gtEnvironment.setVariableValue(actualVariable, returnValidValue(actualValue));
+									}

+							}

+						}

+			}

+			catch (ViatraTransformationException e) {

+				// Variable setting failed
+				throw e.addNewStackElement(gtRule);

+				// throw new GTASMException(e.getMessage()+GTErrorStrings.INIT_ACTION+gtRule.getName(), gtRule);

+			}

+			//GTAction Execution 

+			try {
+				RuleInterpreter.getInstance().interpretRule(gtEnvironment, gtRule.getAction(),null); 
+				return getOutPutSymbolicParatemerRules();

+			} catch (ViatraTransformationException e) {
+				// GTAction Execution Failed
+				throw e.addNewStackElement(gtRule);

+			}

+		}

+		else //******** Only LHS and RHS!

+		{

+			for(int i = 0; i< symInputMapping.length; i++)

+			{SymbolicRuleParameter symParam = gtRule.getSymParameters().get(i);

+			// its a variable which isn't in the RHS or the LHS 

+			if(getActualParameterIndexofSymbolicParameter(postConditionCall, symParam) == -1

+					&& getActualParameterIndexofSymbolicParameter(preConditionCall, symParam) == -1

+					)

+				//this variable can only be founded in the action part

+			 	 if(symParam.getVariable().getReferences().size() > 0)

+					 gtEnvironment.setVariableValue(symParam.getVariable(),symInputMapping[i] );

+			 	 else

+			 	 	logger.warning("SymbolicRuleParameter "+symParam.getName()+" in gtRule " + gtRule.getName()+ "is never used");

+			}

+			if(postConditionCall != null && preConditionCall != null)

+			{

+				for(Object oVar: gtRule.getLocalVariables())

+				{	Variable actualVariable = (Variable) oVar;

+					//The variable is in the RHS

+					if(getActualParameterIndexof(postConditionCall,actualVariable) != -1)

+						{
+						Object actualValue = actualGTContext.getReturnFrame().getValue(getActualParameterIndexof(postConditionCall,actualVariable));
+						gtEnvironment.setVariableValue(actualVariable, returnValidValue(actualValue));
+						}

+					else

+					if(getActualParameterIndexof(preConditionCall,actualVariable) != -1)
+						{
+						Object actualValue = lhsFrame.lookup(getActualParameterIndexof(preConditionCall,actualVariable));
+						gtEnvironment.setVariableValue(actualVariable, returnValidValue(actualValue));
+						}

+				}

+			}

+			return getOutPutSymbolicParatemerRules();

+		}

+	}

+	
+	/** Returns a valid equivalent value (for the Viatra interpreter) of the input. For example instead of a deleted element or null pointer it returns an UNDEF literal
+	 * @param o input parameter o
+	 * @return The 
+	 */
+	private Object returnValidValue(Object obj){
+		
+		if(obj == null)
+			return ValueKind.UNDEF_LITERAL;
+		
+		if(obj instanceof IModelElement)
+			{
+			IModelElement element = (IModelElement)obj;
+			if(element.isDeleted())
+				return ValueKind.UNDEF_LITERAL;
+			}
+		
+		return obj;
+	}
+	
+	

+	/* (non-Javadoc)
+	 * @see org.eclipse.viatra2.gtasm.patternmatcher.patterns.IGTRuleMatcher#match(org.eclipse.viatra2.gtasm.patternmatcher.PatternCallSignature[], java.lang.Object[])
+	 */
+	@Override
+	public Object[] match(PatternCallSignature[] symSignatures, Object[] symInputMapping)
+		throws ViatraTransformationException{

+	

+	IMatching lhsFrame;

+	PatternMatcherParameters lhsParamters;

+	lhsParamters = initLHSPattern(symSignatures, symInputMapping, null);	

+	lhsFrame = isRandom? leftHandSidePatternMatcher.matchRandomly(lhsParamters.getInputMapping(), lhsParamters.getCallSignature()) 
+			: leftHandSidePatternMatcher.match(lhsParamters.getInputMapping(), lhsParamters.getCallSignature());

+	

+	if(lhsFrame != null)

+		return executeGTOperations( symSignatures

+			,symInputMapping

+			,lhsFrame);

+	else

+		return null;

+	}

+	

+	/* (non-Javadoc)
+	 * @see org.eclipse.viatra2.gtasm.patternmatcher.patterns.IGTRuleMatcher#initMatchAll(org.eclipse.viatra2.gtasm.patternmatcher.PatternCallSignature[], java.lang.Object[], java.lang.Integer[])
+	 */
+	@Override
+	public Collection<IMatching> initMatchAll(PatternCallSignature[] symSignatures, Object[] symInputMapping, Integer[] quantificationOrder)

+			throws ViatraTransformationException {

+		PatternMatcherParameters lhsParamters;

+		lhsParamters = initLHSPattern(symSignatures, symInputMapping,quantificationOrder);	

+		return leftHandSidePatternMatcher.matchAll(lhsParamters.getInputMapping(), lhsParamters.getCallSignature(),lhsParamters.getQuantificationOrder());	

+	}

+

+	/* (non-Javadoc)
+	 * @see org.eclipse.viatra2.gtasm.patternmatcher.patterns.IGTRuleMatcher#matchAll(org.eclipse.viatra2.gtasm.patternmatcher.IMatching, org.eclipse.viatra2.gtasm.patternmatcher.PatternCallSignature[], java.lang.Object[])
+	 */
+	@Override
+	public Object[] matchAll(IMatching LHSMatching ,PatternCallSignature[] symSignatures, Object[] symInputMapping)
+		throws ViatraTransformationException {

+		IMatching lhsFrame = LHSMatching;

+		return executeGTOperations( symSignatures

+				,symInputMapping

+				,lhsFrame);

+	}

+	

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateBound2Bound.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateBound2Bound.java
new file mode 100644
index 0000000..9a57560
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateBound2Bound.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation;

+

+import org.eclipse.viatra2.core.IModelManager;
+
+

+/**

+ * @author Akos Horvath

+ *

+ */

+public abstract class CreateBound2Bound extends CreateElement {

+	

+	protected int target,source;

+	

+	/** 

+	 * @param manager

+	 * @param variableI

+	 */

+	public CreateBound2Bound(IModelManager manager, int variableI) {

+		super(manager, variableI);

+	}

+

+	/**

+	 * @param m

+	 */

+	public CreateBound2Bound(IModelManager m) {

+		super(m);

+	}
+	
+

+	/**

+	 * @return the source

+	 */

+	public int getSource() {

+		return source;

+	}

+

+	/**

+	 * @return the target

+	 */

+	public int getTarget() {

+		return target;

+	}

+

+	/**

+	 * @param source the source to set

+	 */

+	protected void setSource(int source) {

+		this.source = source;

+	}

+

+	/**

+	 * @param target the target to set

+	 */

+	protected void setTarget(int target) {

+		this.target = target;

+	}

+

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateBound2Constant.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateBound2Constant.java
new file mode 100644
index 0000000..ad25e37
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateBound2Constant.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation;

+

+import org.eclipse.viatra2.core.IModelElement;
+import org.eclipse.viatra2.core.IModelManager;
+

+

+/**

+ * @author Akos Horvath

+ *

+ */

+public abstract class CreateBound2Constant extends CreateElement {

+

+	protected int source;

+	protected IModelElement target;

+	

+	public CreateBound2Constant(IModelManager m) {

+		super(m);

+	}

+	
+	public CreateBound2Constant(IModelManager m,int variableI) {
+		super(m,variableI);
+	}

+

+		/**

+	 * @return the source

+	 */

+	public int getSource() {

+		return source;

+	}

+

+	/**

+	 * @return the target

+	 */

+	public IModelElement getTarget() {

+		return target;

+	}

+

+	/**

+	 * @param source the source to set

+	 */

+	protected void setSource(int source) {

+		this.source = source;

+	}

+

+	/**

+	 * @param target the target to set

+	 */

+	protected void setTarget(IModelElement target) {

+		this.target = target;

+	}

+

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateConstant2Bound.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateConstant2Bound.java
new file mode 100644
index 0000000..e1bdd39
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateConstant2Bound.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation;

+

+import org.eclipse.viatra2.core.IModelElement;
+import org.eclipse.viatra2.core.IModelManager;
+

+

+/**

+ * @author Akos Horvath

+ *

+ */

+public abstract class CreateConstant2Bound extends CreateElement {

+	protected IModelElement source;

+	protected int target;

+	

+	

+	

+	/**

+	 * @param manager

+	 * @param variableI

+	 */

+	public CreateConstant2Bound(IModelManager manager, int variableI) {

+		super(manager, variableI);

+	}

+

+	/**

+	 * @param m

+	 */

+	public CreateConstant2Bound(IModelManager m) {

+		super(m);

+	}

+

+	/**

+	 * @return the source

+	 */

+	public IModelElement getSource() {

+		return source;

+	}

+

+	/**

+	 * @return the target

+	 */

+	public int getTarget() {

+		return target;

+	}

+

+	/**

+	 * @param source the source to set

+	 */

+	protected void setSource(IModelElement source) {

+		this.source = source;

+	}

+

+	/**

+	 * @param target the target to set

+	 */

+	protected void setTarget(int target) {

+		this.target = target;

+	}

+

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateConstant2Constant.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateConstant2Constant.java
new file mode 100644
index 0000000..4b5cbd0
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateConstant2Constant.java
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation;

+

+import org.eclipse.viatra2.core.IModelElement;
+import org.eclipse.viatra2.core.IModelManager;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTOperationException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+

+

+/**

+ * @author Akos Horvath

+ *

+ */

+public abstract class CreateConstant2Constant extends CreateElement {

+

+	protected IModelElement source;

+	protected IModelElement target;

+	

+	/**

+	 * @param manager

+	 * @param variableI

+	 */

+	public CreateConstant2Constant(IModelManager manager, int variableI) {

+		super(manager, variableI);

+	}

+

+	/**

+	 * @param m

+	 */

+	public CreateConstant2Constant(IModelManager m) {

+		super(m);

+	}

+	@Override

+	protected boolean create(MatchingFrame frame) throws GTOperationException {

+		return false;

+	}

+

+	/**

+	 * @return the source

+	 */

+	public IModelElement getSource() {

+		return source;

+	}

+

+	/**

+	 * @return the target

+	 */

+	public IModelElement getTarget() {

+		return target;

+	}

+

+	/**

+	 * @param source the source to set

+	 */

+	protected void setSource(IModelElement source) {

+		this.source = source;

+	}

+

+	/**

+	 * @param target the target to set

+	 */

+	protected void setTarget(IModelElement target) {

+		this.target = target;

+	}

+

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateElement.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateElement.java
new file mode 100644
index 0000000..1b92742
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateElement.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation;

+

+import org.eclipse.viatra2.core.IModelManager;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTOperationException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+

+

+/**

+ * @author Akos Horvath

+ *

+ */

+abstract public class CreateElement extends ElementManipulationOperation{

+	

+//private boolean hasBeenExecuted;

+protected IModelManager manager;

+protected int variableIndex;
+    

+    public CreateElement(IModelManager manager, int variableI) {

+        this.manager = manager;

+        this.variableIndex = variableI;

+    }

+    

+    public CreateElement(IModelManager m){

+    	this.manager = m;
+    }
+    
+    public boolean update(MatchingFrame frame) throws GTOperationException {

+        create(frame);

+        return true;

+    } 

+

+    abstract protected boolean create(MatchingFrame frame) throws GTOperationException;

+

+	/**

+	 * @return the variableIndex

+	 */

+	public int getVariableIndex() {

+		return variableIndex;

+	}

+  

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateEntity.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateEntity.java
new file mode 100644
index 0000000..c435114
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateEntity.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation;

+

+import org.eclipse.viatra2.core.IModelManager;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTOperationException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
+

+

+

+/**

+ * @author Akos Horvath

+ *

+ */

+public class CreateEntity extends CreateElement{

+

+	

+	/**

+	 * 

+	 */

+	public CreateEntity(int id, IModelManager manager){

+		super(manager,id);

+	}

+	

+	

+	@Override

+	protected boolean create(MatchingFrame frame) throws GTOperationException{

+		frame.setValue(variableIndex, manager.newEntity()); 

+

+		return true;

+	}

+    

+	 public String toString() {

+			return getClass().getSimpleName() + " : " + 

+					variableIndex;

+		}
+
+
+	public String toString(MatchingFrame frame) {
+		
+		return "Create Entity: "+ variableIndex;
+	}
+	
+	 @Override
+	public AnnotatedElement getErrorfulElement(MatchingFrame frame){
+	   	return frame.getPattern().getSearchGraph().getSearchNode(variableIndex).getTraceabilityElement().getRepresentativeEMFElement();
+	}	

+

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateEntityWithConstantContainer.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateEntityWithConstantContainer.java
new file mode 100644
index 0000000..1113b8d
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateEntityWithConstantContainer.java
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation;

+

+import org.eclipse.viatra2.core.IEntity;
+import org.eclipse.viatra2.core.IModelManager;
+import org.eclipse.viatra2.errors.VPMCoreException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTOperationException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.ConstantSearchGraphNode;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
+

+

+/**

+ * @author Akos Horvath

+ *

+ */

+public class CreateEntityWithConstantContainer extends CreateEntity {

+	

+	

+	IEntity container;
+	ConstantSearchGraphNode containerSearchGraphNode;

+	/**

+	 * @param variableIndex

+	 * @param manager
+	 * @param containerSearchGraphNode 

+	 */

+	public CreateEntityWithConstantContainer(int variableI, IModelManager manager, IEntity con, ConstantSearchGraphNode containerSearchGraphNode) {

+		super(variableI, manager);

+		this.container = con;
+		this.containerSearchGraphNode = containerSearchGraphNode;
+	}

+

+	protected boolean create(MatchingFrame frame) throws GTOperationException{

+		if(container == null)

+			{
+			String[] context = {containerSearchGraphNode.getName(),getClass().getSimpleName()};
+			throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE
+					,context
+					,containerSearchGraphNode.getTraceabilityElement().getRepresentativeEMFElement());
+			}

+		

+		try {

+			frame.setValue(variableIndex, manager.newEntity(container));

+		}  catch (VPMCoreException e) {
+			String context[] = {frame.getPattern().getSearchGraph().getSearchNode(variableIndex).getName(),e.getMessage()};

+			throw new GTOperationException(GTErrorStrings.INTERNAL_CREATE_ENTITY
+					,context
+					,frame.getPattern().getSearchGraph().getSearchNode(variableIndex).getTraceabilityElement().getRepresentativeEMFElement());

+		} 

+

+		return true;

+	}

+	

+	public String toString() {

+			return getClass().getSimpleName() + " : " + 

+	            variableIndex +" in "+container.getName();

+	}
+	
+    @Override
+	public AnnotatedElement getErrorfulElement(MatchingFrame frame){
+    	return frame.getPattern().getSearchGraph().getSearchNode(variableIndex).getTraceabilityElement().getRepresentativeEMFElement();
+    }	

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateEntityWithVariableContainment.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateEntityWithVariableContainment.java
new file mode 100644
index 0000000..d1eef87
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateEntityWithVariableContainment.java
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation;

+

+import org.eclipse.viatra2.core.IEntity;
+import org.eclipse.viatra2.core.IModelManager;
+import org.eclipse.viatra2.errors.VPMCoreException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTOperationException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.VariableSearchGraphNode;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
+

+

+/**

+ * @author Akos Horvath

+ *

+ */

+public class CreateEntityWithVariableContainment extends CreateEntity{

+	

+	VariableSearchGraphNode container;

+	/**

+	 * @param variableIndex

+	 * @param manager

+	 */

+	public CreateEntityWithVariableContainment(int variableI, IModelManager manager, VariableSearchGraphNode con) {

+		super(variableI, manager);

+		this.container = con;

+	}

+

+	protected boolean create(MatchingFrame frame) throws GTOperationException{

+		IEntity tempContainer =null;

+		

+		try{

+			tempContainer = (IEntity)frame.getValue(container.getId());

+		} catch(ClassCastException e){
+			String[] context = {container.getName(), getClass().getSimpleName()};

+			throw new GTOperationException(GTErrorStrings.NOT_AN_ENTITY

+					,context
+					,container.getTraceabilityElement().getRepresentativeEMFElement());

+		}	

+		

+		if(tempContainer == null)

+			{
+			String[] context = {container.getName(),getClass().getSimpleName()};
+			throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE
+					,context
+					,container.getTraceabilityElement().getRepresentativeEMFElement());
+			}

+		

+		try {

+			frame.setValue(variableIndex, manager.newEntity(tempContainer));

+		} catch (VPMCoreException e) {

+			String context[] = {frame.getPattern().getSearchGraph().getSearchNode(variableIndex).getName(),e.getMessage()};
+			throw new GTOperationException(GTErrorStrings.INTERNAL_CREATE_ENTITY
+					,context
+					,frame.getPattern().getSearchGraph().getSearchNode(variableIndex).getTraceabilityElement().getRepresentativeEMFElement());

+		} 

+

+		return true;

+	}

+	

+	public String toString() {

+			return getClass().getSimpleName() + " : " + 

+	            variableIndex+" in "+container;

+	}

+
+    @Override
+	public AnnotatedElement getErrorfulElement(MatchingFrame frame){
+    	return frame.getPattern().getSearchGraph().getSearchNode(variableIndex).getTraceabilityElement().getRepresentativeEMFElement();
+    }	

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateInstanceofBound2Bound.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateInstanceofBound2Bound.java
new file mode 100644
index 0000000..4d6d971
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateInstanceofBound2Bound.java
@@ -0,0 +1,101 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation;

+

+import org.eclipse.viatra2.core.IModelElement;
+import org.eclipse.viatra2.core.IModelManager;
+import org.eclipse.viatra2.errors.VPMCoreException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTOperationException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.SearchGraphEdge;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
+

+

+/**

+ * @author Akos Horvath

+ *

+ */

+public class CreateInstanceofBound2Bound extends CreateBound2Bound {

+

+	

+	/**

+	 * @param manager

+	 * @param variableI

+	 */
+	private SearchGraphEdge relatedSearchGraphEdge;
+	

+	public CreateInstanceofBound2Bound(int s, int t,IModelManager manager, SearchGraphEdge edge){

+		super(manager);

+		target = t;

+		source = s;
+		relatedSearchGraphEdge = edge;

+	}

+	

+	@Override

+	protected boolean create(MatchingFrame frame) throws GTOperationException {

+		

+		IModelElement sourceElement = null;

+        IModelElement targetElement = null;

+        try {

+            sourceElement = (IModelElement) frame.getValue(source);

+        } catch (ClassCastException e) {

+    			String[] context = {relatedSearchGraphEdge.getSourceNode().getName(), getClass().getSimpleName()};
+    			throw new GTOperationException(GTErrorStrings.NOT_A_MODELELEMENT
+    					,context
+    					,relatedSearchGraphEdge.getSourceNode().getTraceabilityElement().getRepresentativeEMFElement());
+        }

+        try {

+            targetElement = (IModelElement) frame.getValue(target);

+        } catch (ClassCastException e) {

+        	String[] context = {relatedSearchGraphEdge.getTargetNode().getName(), getClass().getSimpleName()};
+			throw new GTOperationException(GTErrorStrings.NOT_A_MODELELEMENT
+					,context
+					,relatedSearchGraphEdge.getTargetNode().getTraceabilityElement().getRepresentativeEMFElement());
+        }

+        if (sourceElement == null) {

+        	String[] context = {relatedSearchGraphEdge.getSourceNode().getName(),getClass().getSimpleName()};
+			throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE
+					,context
+					,relatedSearchGraphEdge.getSourceNode().getTraceabilityElement().getRepresentativeEMFElement());
+			

+        }

+        if (targetElement == null) {

+        	String[] context = {relatedSearchGraphEdge.getTargetNode().getName(),getClass().getSimpleName()};
+			throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE
+					,context
+					,relatedSearchGraphEdge.getTargetNode().getTraceabilityElement().getRepresentativeEMFElement());
+        }

+		

+		

+		try {

+			manager.newInstanceOf(sourceElement,targetElement);

+		}catch (VPMCoreException e) {

+			String[] context = {frame.getPattern().getSearchGraph().getSearchNode(source).getName(),frame.getPattern().getSearchGraph().getSearchNode(target).getName(), e.getMessage()};
+			throw new GTOperationException(GTErrorStrings.INTERNAL_CREATE_INSTANCEOF

+					,context
+					,relatedSearchGraphEdge.getTraceabilityElement().getRepresentativeEMFElement());

+		}

+		

+		return true;

+	}

+	

+	public String toString() {

+			return getClass().getSimpleName() + " : " + 

+	            source + "(type) -- instanceof -> " + target;

+	}
+	
+	@Override
+	public AnnotatedElement getErrorfulElement(MatchingFrame frame){
+    	return relatedSearchGraphEdge.getTraceabilityElement().getRepresentativeEMFElement();
+    }
+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateInstanceofBound2Constant.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateInstanceofBound2Constant.java
new file mode 100644
index 0000000..609531e
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateInstanceofBound2Constant.java
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation;

+

+import org.eclipse.viatra2.core.IModelElement;
+import org.eclipse.viatra2.core.IModelManager;
+import org.eclipse.viatra2.errors.VPMCoreException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTOperationException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.SearchGraphEdge;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
+

+

+/**

+ * @author Akos Horvath

+ *

+ */

+public class CreateInstanceofBound2Constant extends CreateBound2Constant {

+

+	private SearchGraphEdge relatedSearchGraphEdge;
+	

+	

+	public CreateInstanceofBound2Constant(int s, IModelElement t,IModelManager manager, SearchGraphEdge edge ){

+		super(manager);

+		target = t;

+		source = s;
+		relatedSearchGraphEdge = edge;

+	}

+	

+	@Override

+	protected boolean create(MatchingFrame frame) throws GTOperationException {

+		IModelElement sourceElement = null;

+        try {

+            sourceElement = (IModelElement) frame.getValue(source);

+        } catch (ClassCastException e) {

+        	String[] context = {relatedSearchGraphEdge.getSourceNode().getName(), getClass().getSimpleName()};
+			throw new GTOperationException(GTErrorStrings.NOT_A_MODELELEMENT
+					,context
+					,relatedSearchGraphEdge.getSourceNode().getTraceabilityElement().getRepresentativeEMFElement());
+        }

+       

+        if (sourceElement == null) {
+            	String[] context = {relatedSearchGraphEdge.getSourceNode().getName(),getClass().getSimpleName()};
+    			throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE
+    					,context
+    					,relatedSearchGraphEdge.getSourceNode().getTraceabilityElement().getRepresentativeEMFElement());
+    	} 
+        
+        if (target == null) {
+        	String[] context = {relatedSearchGraphEdge.getTargetNode().getName(),getClass().getSimpleName()};
+			throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE
+					,context
+					,relatedSearchGraphEdge.getTargetNode().getTraceabilityElement().getRepresentativeEMFElement());
+        }

+		

+		

+		try {

+			manager.newInstanceOf(sourceElement,target);

+		}catch (VPMCoreException e) {

+			String[] context = {frame.getPattern().getSearchGraph().getSearchNode(source).getName(),target.getFullyQualifiedName(), e.getMessage()};
+			throw new GTOperationException(GTErrorStrings.INTERNAL_CREATE_INSTANCEOF
+					,context
+					,relatedSearchGraphEdge.getTraceabilityElement().getRepresentativeEMFElement());
+		}

+		

+		return true;

+	}

+	

+	public String toString() {

+			return getClass().getSimpleName() + " : " + 

+	            source + "(type) -- instanceof -> " + target.getName();

+	}
+
+	@Override
+	public AnnotatedElement getErrorfulElement(MatchingFrame frame){
+    	return relatedSearchGraphEdge.getTraceabilityElement().getRepresentativeEMFElement();
+    }

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateInstanceofConstant2Bound.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateInstanceofConstant2Bound.java
new file mode 100644
index 0000000..99a38fb
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateInstanceofConstant2Bound.java
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation;

+

+import org.eclipse.viatra2.core.IModelElement;
+import org.eclipse.viatra2.core.IModelManager;
+import org.eclipse.viatra2.errors.VPMCoreException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTOperationException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.SearchGraphEdge;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
+

+

+/**

+ * @author Akos Horvath

+ *

+ */

+public class CreateInstanceofConstant2Bound extends CreateConstant2Bound {

+

+	private SearchGraphEdge relatedSearchGraphEdge;
+	
+	

+	public CreateInstanceofConstant2Bound(IModelElement s, int t,IModelManager manager, SearchGraphEdge edge ){

+		super(manager);

+		target = t;

+		source = s;
+		relatedSearchGraphEdge = edge;

+	}

+	

+	@Override

+	protected boolean create(MatchingFrame frame) throws GTOperationException {

+		IModelElement targetElement = null;

+        try {

+            targetElement = (IModelElement) frame.getValue(target);

+        } catch (ClassCastException e) {

+        	String[] context = {relatedSearchGraphEdge.getTargetNode().getName(), getClass().getSimpleName()};
+			throw new GTOperationException(GTErrorStrings.NOT_A_MODELELEMENT
+					,context
+					,relatedSearchGraphEdge.getTargetNode().getTraceabilityElement().getRepresentativeEMFElement());
+        }

+        if (source == null) {

+        	String[] context = {relatedSearchGraphEdge.getSourceNode().getName(),getClass().getSimpleName()};
+			throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE
+					,context
+					,relatedSearchGraphEdge.getSourceNode().getTraceabilityElement().getRepresentativeEMFElement());
+     

+        }

+        if (targetElement == null) {

+        	String[] context = {relatedSearchGraphEdge.getTargetNode().getName(),getClass().getSimpleName()};
+			throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE
+					,context
+					,relatedSearchGraphEdge.getTargetNode().getTraceabilityElement().getRepresentativeEMFElement());
+        }

+		

+		try {

+			manager.newInstanceOf(source,targetElement);

+		}catch (VPMCoreException e) {

+			String[] context = {source.getFullyQualifiedName(),frame.getPattern().getSearchGraph().getSearchNode(target).getName(), e.getMessage()};
+			throw new GTOperationException(GTErrorStrings.INTERNAL_CREATE_INSTANCEOF
+					,context
+					,relatedSearchGraphEdge.getTraceabilityElement().getRepresentativeEMFElement());
+		}

+		

+		return true;

+	}

+	

+	public String toString() {

+			return getClass().getSimpleName() + " : " + 

+	            source.getName() + "(type) -- instanceof -> " + target;

+	}

+	
+	@Override
+	public AnnotatedElement getErrorfulElement(MatchingFrame frame){
+	    	return relatedSearchGraphEdge.getTraceabilityElement().getRepresentativeEMFElement();
+	}

+

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateInstanceofConstant2Constant.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateInstanceofConstant2Constant.java
new file mode 100644
index 0000000..fdca641
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateInstanceofConstant2Constant.java
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation;

+

+import org.eclipse.viatra2.core.IModelElement;
+import org.eclipse.viatra2.core.IModelManager;
+import org.eclipse.viatra2.errors.VPMCoreException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTOperationException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.SearchGraphEdge;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
+

+

+/**

+ * @author Akos Horvath

+ *

+ */

+public class CreateInstanceofConstant2Constant extends CreateConstant2Constant {

+

+	private SearchGraphEdge relatedSearchGraphEdge;
+		

+	public CreateInstanceofConstant2Constant(IModelElement s,
+			IModelElement t,IModelManager manager, SearchGraphEdge edge){

+		super(manager);

+		source = s;

+		target= t;
+		relatedSearchGraphEdge = edge;

+	}

+	

+	@Override

+	protected boolean create(MatchingFrame frame)throws GTOperationException {

+		

+        if (source == null) {

+        	String[] context = {relatedSearchGraphEdge.getSourceNode().getName(),getClass().getSimpleName()};
+			throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE
+					,context
+					,relatedSearchGraphEdge.getSourceNode().getTraceabilityElement().getRepresentativeEMFElement());
+     

+        }

+        if (target == null) {

+        	String[] context = {relatedSearchGraphEdge.getTargetNode().getName(),getClass().getSimpleName()};
+			throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE
+					,context
+					,relatedSearchGraphEdge.getTargetNode().getTraceabilityElement().getRepresentativeEMFElement());
+        }

+			

+		try {

+			manager.newInstanceOf(source,target);

+		} catch (VPMCoreException e) {

+			String[] context = {source.getFullyQualifiedName(),target.getFullyQualifiedName(), e.getMessage()};
+			throw new GTOperationException(GTErrorStrings.INTERNAL_CREATE_INSTANCEOF
+					,context
+					,relatedSearchGraphEdge.getTraceabilityElement().getRepresentativeEMFElement());
+	}

+

+		return true;

+	}

+	

+	public String toString() {

+			return getClass().getSimpleName() + " : " + 

+	            source.getName() + "(type) -- instanceof -> " + target.getName();

+	}
+	 
+	@Override
+	public AnnotatedElement getErrorfulElement(MatchingFrame frame){
+	    	return relatedSearchGraphEdge.getTraceabilityElement().getRepresentativeEMFElement();
+	    }

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateRelationBound2Bound.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateRelationBound2Bound.java
new file mode 100644
index 0000000..0e289cb
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateRelationBound2Bound.java
@@ -0,0 +1,102 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation;

+

+import org.eclipse.viatra2.core.IModelElement;
+import org.eclipse.viatra2.core.IModelManager;
+import org.eclipse.viatra2.errors.VPMCoreException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTOperationException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
+

+

+/**

+ * @author Akos Horvath

+ *

+ */

+public class CreateRelationBound2Bound extends CreateBound2Bound {

+

+	

+	/**

+	 * @param manager

+	 * @param variableI

+	 */
+	
+	public CreateRelationBound2Bound(int s, int t,
+			int variableI ,IModelManager manager){

+		super(manager,variableI);

+		target = t;

+		source = s;
+	}

+	

+	@Override

+	protected boolean create(MatchingFrame frame) throws GTOperationException{

+		

+		IModelElement sourceElement = null;

+        IModelElement targetElement = null;

+        try {
+            sourceElement = (IModelElement) frame.getValue(source);
+        } catch (ClassCastException e) {
+    			String[] context = {frame.getPattern().getSearchGraph().getSearchNode(source).getName(), getClass().getSimpleName()};
+    			throw new GTOperationException(GTErrorStrings.NOT_A_MODELELEMENT
+    					,context
+    					,frame.getPattern().getSearchGraph().getSearchNode(source).getTraceabilityElement().getRepresentativeEMFElement());
+        }
+        try {
+            targetElement = (IModelElement) frame.getValue(target);
+        } catch (ClassCastException e) {
+        	String[] context = {frame.getPattern().getSearchGraph().getSearchNode(target).getName(), getClass().getSimpleName()};
+			throw new GTOperationException(GTErrorStrings.NOT_A_MODELELEMENT
+					,context
+					,frame.getPattern().getSearchGraph().getSearchNode(target).getTraceabilityElement().getRepresentativeEMFElement());
+        }
+        if (sourceElement == null) {
+        	String[] context = {frame.getPattern().getSearchGraph().getSearchNode(source).getName(),getClass().getSimpleName()};
+			throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE
+					,context
+					,frame.getPattern().getSearchGraph().getSearchNode(source).getTraceabilityElement().getRepresentativeEMFElement());
+			
+        }
+        if (targetElement == null) {
+        	String[] context = {frame.getPattern().getSearchGraph().getSearchNode(target).getName(),getClass().getSimpleName()};
+			throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE
+					,context
+					,frame.getPattern().getSearchGraph().getSearchNode(target).getTraceabilityElement().getRepresentativeEMFElement());
+        }

+        

+		try {

+			frame.setValue(variableIndex, manager.newRelation(sourceElement,targetElement));

+		}catch (VPMCoreException e) {

+			String[] context = {frame.getPattern().getSearchGraph().getSearchNode(variableIndex).getName(),e.getMessage()};
+			throw new GTOperationException(GTErrorStrings.INTERNAL_CREATE_RELATION
+					,context
+					,frame.getPattern().getSearchGraph().getSearchNode(variableIndex).getTraceabilityElement().getRepresentativeEMFElement());
+		}

+		

+		return true;

+	}

+	

+	public String toString() {

+			return getClass().getSimpleName() + " : " + 

+	            source + " -- Relation:"+ variableIndex+" -> " + target;

+	}

+	   
+	@Override
+	public AnnotatedElement getErrorfulElement(MatchingFrame frame){
+	    	return frame.getPattern().getSearchGraph().getSearchNode(variableIndex).getTraceabilityElement().getRepresentativeEMFElement();
+	    }
+}
+
+

+

+	

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateRelationBound2Constant.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateRelationBound2Constant.java
new file mode 100644
index 0000000..e5fa65a
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateRelationBound2Constant.java
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation;

+

+import org.eclipse.viatra2.core.IModelElement;
+import org.eclipse.viatra2.core.IModelManager;
+import org.eclipse.viatra2.errors.VPMCoreException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTOperationException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.ConstantSearchGraphNode;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
+

+

+/**

+ * @author Akos Horvath

+ *

+ */

+public class CreateRelationBound2Constant extends CreateBound2Constant {

+
+	ConstantSearchGraphNode targetNode;

+

+	public CreateRelationBound2Constant(int s, ConstantSearchGraphNode t,int variableI
+			,IModelManager manager){

+		super(manager,variableI);

+		source = s;
+		targetNode = t;

+		target= manager.getElementByName(t.getElement());
+	}

+

+	/* (non-Javadoc)

+	 * @see org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.CreateElement#create(org.eclipse.viatra2.gtasm.patternmatcher.internal.MatchingFrame)

+	 */

+	@Override

+	protected boolean create(MatchingFrame frame) throws GTOperationException{

+		IModelElement sourceElement = null;

+		try {
+            sourceElement = (IModelElement) frame.getValue(source);
+        } catch (ClassCastException e) {
+        	String[] context = {frame.getPattern().getSearchGraph().getSearchNode(source).getName(), getClass().getSimpleName()};
+			throw new GTOperationException(GTErrorStrings.NOT_A_MODELELEMENT
+					,context
+					,frame.getPattern().getSearchGraph().getSearchNode(source).getTraceabilityElement().getRepresentativeEMFElement());
+        }
+
+        if (sourceElement == null) {
+            	String[] context = {frame.getPattern().getSearchGraph().getSearchNode(source).getName(),getClass().getSimpleName()};
+    			throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE
+    					,context
+    					,frame.getPattern().getSearchGraph().getSearchNode(source).getTraceabilityElement().getRepresentativeEMFElement());
+    	}
+
+        if (target == null) {
+        	String[] context = {targetNode.getElement(),getClass().getSimpleName()};
+			throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE
+					,context
+					,targetNode.getTraceabilityElement().getRepresentativeEMFElement());
+        }

+

+

+		try {

+			frame.setValue(variableIndex, manager.newRelation(sourceElement,target));

+		} catch (VPMCoreException e) {

+			String[] context = {frame.getPattern().getSearchGraph().getSearchNode(variableIndex).getName(),e.getMessage()};
+			throw new GTOperationException(GTErrorStrings.INTERNAL_CREATE_RELATION
+					,context
+					,frame.getPattern().getSearchGraph().getSearchNode(variableIndex).getTraceabilityElement().getRepresentativeEMFElement());
+

+		}

+		return true;

+	}

+

+	public String toString() {

+		return getClass().getSimpleName() + " : " +

+            source + " -- Relation:"+ variableIndex+" -> " + target.getName();

+	}

+
+    @Override
+	public AnnotatedElement getErrorfulElement(MatchingFrame frame){
+    	return frame.getPattern().getSearchGraph().getSearchNode(variableIndex).getTraceabilityElement().getRepresentativeEMFElement();
+    }

+

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateRelationConstant2Bound.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateRelationConstant2Bound.java
new file mode 100644
index 0000000..711f30f
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateRelationConstant2Bound.java
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation;

+

+import org.eclipse.viatra2.core.IModelElement;
+import org.eclipse.viatra2.core.IModelManager;
+import org.eclipse.viatra2.errors.VPMCoreException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTOperationException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.ConstantSearchGraphNode;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
+

+

+/**

+ * @author Akos Horvath

+ *

+ */

+public class CreateRelationConstant2Bound extends CreateConstant2Bound {

+
+	ConstantSearchGraphNode sourceNode;
+

+	public CreateRelationConstant2Bound(ConstantSearchGraphNode s, int t
+			 ,int variableI,IModelManager manager){

+		super(manager,variableI);

+		sourceNode = s;
+		source = manager.getElementByName(s.getElement());

+		target= t;
+	}

+

+	/* (non-Javadoc)

+	 * @see org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.CreateElement#create(org.eclipse.viatra2.gtasm.patternmatcher.internal.MatchingFrame)

+	 */

+	@Override

+	protected boolean create(MatchingFrame frame) throws GTOperationException {

+		IModelElement targetElement = null;

+		try {
+            targetElement = (IModelElement) frame.getValue(target);
+        } catch (ClassCastException e) {
+        	String[] context = {frame.getPattern().getSearchGraph().getSearchNode(target).getName(), getClass().getSimpleName()};
+			throw new GTOperationException(GTErrorStrings.NOT_A_MODELELEMENT
+					,context
+					,frame.getPattern().getSearchGraph().getSearchNode(target).getTraceabilityElement().getRepresentativeEMFElement());
+        }
+        if (source == null) {
+        	String[] context = {sourceNode.getName(),getClass().getSimpleName()};
+			throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE
+					,context
+					,sourceNode.getTraceabilityElement().getRepresentativeEMFElement());
+
+        }
+        if (targetElement == null) {
+        	String[] context = {frame.getPattern().getSearchGraph().getSearchNode(target).getName(),getClass().getSimpleName()};
+			throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE
+					,context
+					,frame.getPattern().getSearchGraph().getSearchNode(target).getTraceabilityElement().getRepresentativeEMFElement());
+        }

+

+		try {

+			frame.setValue(variableIndex, manager.newRelation(source,targetElement));

+		}catch (VPMCoreException e) {

+			String[] context = {frame.getPattern().getSearchGraph().getSearchNode(variableIndex).getName(),e.getMessage()};
+			throw new GTOperationException(GTErrorStrings.INTERNAL_CREATE_RELATION
+					,context
+					,frame.getPattern().getSearchGraph().getSearchNode(variableIndex).getTraceabilityElement().getRepresentativeEMFElement());
+

+		}

+		return true;

+	}

+

+	public String toString() {

+		return getClass().getSimpleName() + " : " +

+            source.getName() + " -- Relation:"+ variableIndex+" -> " + target;

+	}
+
+    @Override
+	public AnnotatedElement getErrorfulElement(MatchingFrame frame){
+    	return frame.getPattern().getSearchGraph().getSearchNode(variableIndex).getTraceabilityElement().getRepresentativeEMFElement();
+    }

+

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateRelationConstant2Constant.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateRelationConstant2Constant.java
new file mode 100644
index 0000000..51cca04
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateRelationConstant2Constant.java
@@ -0,0 +1,80 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation;

+

+import org.eclipse.viatra2.core.IModelManager;
+import org.eclipse.viatra2.errors.VPMCoreException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTOperationException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.ConstantSearchGraphNode;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
+

+

+/**

+ * @author Akos Horvath

+ *

+ */

+//In normal cases this type of relation creating operation would not be nstanciated

+public class CreateRelationConstant2Constant extends CreateConstant2Constant {

+

+	ConstantSearchGraphNode sourceNode, targetNode;
+

+	public CreateRelationConstant2Constant(ConstantSearchGraphNode s,
+			ConstantSearchGraphNode t,  int variableI,IModelManager manager){

+		super(manager,variableI);

+		sourceNode = s;
+		targetNode = t;
+
+		source = manager.getElementByName(s.getElement());

+		target= manager.getElementByName(t.getElement());
+	}

+

+	@Override

+	protected boolean create(MatchingFrame frame)throws GTOperationException {

+		 if (source == null) {
+	        	String[] context = {sourceNode.getName(),getClass().getSimpleName()};
+				throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE
+						,context
+						,sourceNode.getTraceabilityElement().getRepresentativeEMFElement());
+
+	        }
+	        if (target == null) {
+	        	String[] context = {targetNode.getName(),getClass().getSimpleName()};
+				throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE
+						,context
+						,targetNode.getTraceabilityElement().getRepresentativeEMFElement());
+	        }

+

+		try {

+			frame.setValue(variableIndex, manager.newRelation(source,target));

+		} catch (VPMCoreException e) {

+			String[] context = {frame.getPattern().getSearchGraph().getSearchNode(variableIndex).getName(),e.getMessage()};
+			throw new GTOperationException(GTErrorStrings.INTERNAL_CREATE_RELATION
+					,context
+					,frame.getPattern().getSearchGraph().getSearchNode(variableIndex).getTraceabilityElement().getRepresentativeEMFElement());
+		}

+		return true;

+	}

+

+	public String toString() {

+		return getClass().getSimpleName() + " : " +

+            source.getName() + " -- Relation:"+ variableIndex+" -> " + target.getName();

+	}

+
+    @Override
+	public AnnotatedElement getErrorfulElement(MatchingFrame frame){
+    	return frame.getPattern().getSearchGraph().getSearchNode(variableIndex).getTraceabilityElement().getRepresentativeEMFElement();
+    }

+

+

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateSuperTypeofBound2Bound.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateSuperTypeofBound2Bound.java
new file mode 100644
index 0000000..3c70bac
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateSuperTypeofBound2Bound.java
@@ -0,0 +1,100 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation;

+

+import org.eclipse.viatra2.core.IModelElement;
+import org.eclipse.viatra2.core.IModelManager;
+import org.eclipse.viatra2.errors.VPMCoreException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTOperationException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.SearchGraphEdge;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
+

+

+/**

+ * @author Akos Horvath

+ *

+ */

+public class CreateSuperTypeofBound2Bound extends CreateBound2Bound {

+
+	private SearchGraphEdge relatedSearchGraphEdge;
+	

+	/**

+	 * @param m

+	 */

+	public CreateSuperTypeofBound2Bound(int s, int t,
+			IModelManager manager,SearchGraphEdge edge ){

+		super(manager);

+		target = t;

+		source = s;
+		relatedSearchGraphEdge = edge;

+	}

+	

+	@Override

+	protected boolean create(MatchingFrame frame) throws GTOperationException {

+		IModelElement sourceElement = null;

+        IModelElement targetElement = null;

+        try {
+            sourceElement = (IModelElement) frame.getValue(source);
+        } catch (ClassCastException e) {
+    			String[] context = {relatedSearchGraphEdge.getSourceNode().getName(), getClass().getSimpleName()};
+    			throw new GTOperationException(GTErrorStrings.NOT_A_MODELELEMENT
+    					,context
+    					,relatedSearchGraphEdge.getSourceNode().getTraceabilityElement().getRepresentativeEMFElement());
+        }
+        try {
+            targetElement = (IModelElement) frame.getValue(target);
+        } catch (ClassCastException e) {
+        	String[] context = {relatedSearchGraphEdge.getTargetNode().getName(), getClass().getSimpleName()};
+			throw new GTOperationException(GTErrorStrings.NOT_A_MODELELEMENT
+					,context
+					,relatedSearchGraphEdge.getTargetNode().getTraceabilityElement().getRepresentativeEMFElement());
+        }
+        if (sourceElement == null) {
+        	String[] context = {relatedSearchGraphEdge.getSourceNode().getName(),getClass().getSimpleName()};
+			throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE
+					,context
+					,relatedSearchGraphEdge.getSourceNode().getTraceabilityElement().getRepresentativeEMFElement());
+			
+        }
+        if (targetElement == null) {
+        	String[] context = {relatedSearchGraphEdge.getTargetNode().getName(),getClass().getSimpleName()};
+			throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE
+					,context
+					,relatedSearchGraphEdge.getTargetNode().getTraceabilityElement().getRepresentativeEMFElement());
+        }

+		

+		try {

+			manager.newSupertypeOf(sourceElement,targetElement);

+		} 

+		catch (VPMCoreException e) {

+			String[] context = {frame.getPattern().getSearchGraph().getSearchNode(source).getName(),frame.getPattern().getSearchGraph().getSearchNode(target).getName(), e.getMessage()};
+			throw new GTOperationException(GTErrorStrings.INTERNAL_CREATE_SUPERTYPEOF
+					,context
+					,relatedSearchGraphEdge.getTraceabilityElement().getRepresentativeEMFElement());
+

+		}

+		return true;

+	}
+	
+	public String toString() {
+		return getClass().getSimpleName() + " : " + 
+            source + " -- Supertypeof: -> " + target;
+	}
+	
+	@Override
+	public AnnotatedElement getErrorfulElement(MatchingFrame frame){
+    	return relatedSearchGraphEdge.getTraceabilityElement().getRepresentativeEMFElement();
+    }

+

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateSuperTypeofBound2Constant.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateSuperTypeofBound2Constant.java
new file mode 100644
index 0000000..772dc64
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateSuperTypeofBound2Constant.java
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation;

+

+import org.eclipse.viatra2.core.IModelElement;
+import org.eclipse.viatra2.core.IModelManager;
+import org.eclipse.viatra2.errors.VPMCoreException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTOperationException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.SearchGraphEdge;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
+

+

+/**

+ * @author Akos Horvath

+ *

+ */

+public class CreateSuperTypeofBound2Constant extends CreateBound2Constant{

+

+	private SearchGraphEdge relatedSearchGraphEdge;
+	

+	public CreateSuperTypeofBound2Constant(int s, IModelElement t
+			,IModelManager manager, SearchGraphEdge edge ){

+		super(manager);

+		target = t;

+		source = s;
+		relatedSearchGraphEdge = edge;

+	}

+	

+	@Override

+	protected boolean create(MatchingFrame frame) throws GTOperationException {

+		IModelElement sourceElement = null;

+		try {
+            sourceElement = (IModelElement) frame.getValue(source);
+        } catch (ClassCastException e) {
+        	String[] context = {relatedSearchGraphEdge.getSourceNode().getName(), getClass().getSimpleName()};
+			throw new GTOperationException(GTErrorStrings.NOT_A_MODELELEMENT
+					,context
+					,relatedSearchGraphEdge.getSourceNode().getTraceabilityElement().getRepresentativeEMFElement());
+        }
+       
+        if (sourceElement == null) {
+            	String[] context = {relatedSearchGraphEdge.getSourceNode().getName(),getClass().getSimpleName()};
+    			throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE
+    					,context
+    					,relatedSearchGraphEdge.getSourceNode().getTraceabilityElement().getRepresentativeEMFElement());
+    	} 
+        
+        if (target == null) {
+        	String[] context = {relatedSearchGraphEdge.getTargetNode().getName(),getClass().getSimpleName()};
+			throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE
+					,context
+					,relatedSearchGraphEdge.getTargetNode().getTraceabilityElement().getRepresentativeEMFElement());
+        }

+				

+		try {

+			manager.newSupertypeOf(sourceElement,target);

+		} catch (VPMCoreException e) {

+			String[] context = {frame.getPattern().getSearchGraph().getSearchNode(source).getName(),target.getFullyQualifiedName(), e.getMessage()};
+			throw new GTOperationException(GTErrorStrings.INTERNAL_CREATE_SUPERTYPEOF
+					,context
+					,relatedSearchGraphEdge.getTraceabilityElement().getRepresentativeEMFElement());
+

+		}

+		

+		return true;

+	}
+	
+	public String toString() {
+		return getClass().getSimpleName() + " : " + 
+            source + " -- Supertypeof: -> " + target.getName();
+	}
+	
+	@Override
+	public AnnotatedElement getErrorfulElement(MatchingFrame frame){
+    	return relatedSearchGraphEdge.getTraceabilityElement().getRepresentativeEMFElement();
+    }

+

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateSuperTypeofConstant2Bound.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateSuperTypeofConstant2Bound.java
new file mode 100644
index 0000000..86722f1
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateSuperTypeofConstant2Bound.java
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation;

+

+import org.eclipse.viatra2.core.IModelElement;
+import org.eclipse.viatra2.core.IModelManager;
+import org.eclipse.viatra2.errors.VPMCoreException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTOperationException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.SearchGraphEdge;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
+

+

+/**

+ * @author Akos Horvath

+ *

+ */

+public class CreateSuperTypeofConstant2Bound extends CreateConstant2Bound{

+	
+	private SearchGraphEdge relatedSearchGraphEdge;
+	

+	public CreateSuperTypeofConstant2Bound(IModelElement s, int t
+			,IModelManager manager, SearchGraphEdge edge ){

+		super(manager);

+		target = t;

+		source = s;
+		relatedSearchGraphEdge = edge;

+	}

+	

+	@Override

+	protected boolean create(MatchingFrame frame) throws GTOperationException {

+				IModelElement targetElement = null;

+				try {
+		            targetElement = (IModelElement) frame.getValue(target);
+		        } catch (ClassCastException e) {
+		        	String[] context = {relatedSearchGraphEdge.getTargetNode().getName(), getClass().getSimpleName()};
+					throw new GTOperationException(GTErrorStrings.NOT_A_MODELELEMENT
+							,context
+							,relatedSearchGraphEdge.getTargetNode().getTraceabilityElement().getRepresentativeEMFElement());
+		        }
+		        if (source == null) {
+		        	String[] context = {relatedSearchGraphEdge.getSourceNode().getName(),getClass().getSimpleName()};
+					throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE
+							,context
+							,relatedSearchGraphEdge.getSourceNode().getTraceabilityElement().getRepresentativeEMFElement());
+		     
+		        }
+		        if (targetElement == null) {
+		        	String[] context = {relatedSearchGraphEdge.getTargetNode().getName(),getClass().getSimpleName()};
+					throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE
+							,context
+							,relatedSearchGraphEdge.getTargetNode().getTraceabilityElement().getRepresentativeEMFElement());
+		        }

+		

+        try {

+			manager.newSupertypeOf(source,targetElement);

+		}catch (VPMCoreException e) {

+			String[] context = {source.getFullyQualifiedName(),frame.getPattern().getSearchGraph().getSearchNode(target).getName(), e.getMessage()};
+			throw new GTOperationException(GTErrorStrings.INTERNAL_CREATE_SUPERTYPEOF
+					,context
+					,relatedSearchGraphEdge.getTraceabilityElement().getRepresentativeEMFElement());
+

+		}

+		

+		return true;

+	}
+	
+	public String toString() {
+		return getClass().getSimpleName() + " : " + 
+            source.getName() + " -- Supertypeof: -> " + target;
+	}
+	
+	@Override
+	public AnnotatedElement getErrorfulElement(MatchingFrame frame){
+    	return relatedSearchGraphEdge.getTraceabilityElement().getRepresentativeEMFElement();
+    }

+

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateSuperTypeofConstant2Constant.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateSuperTypeofConstant2Constant.java
new file mode 100644
index 0000000..532c134
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/CreateSuperTypeofConstant2Constant.java
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation;

+

+import org.eclipse.viatra2.core.IModelElement;
+import org.eclipse.viatra2.core.IModelManager;
+import org.eclipse.viatra2.errors.VPMCoreException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTOperationException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.SearchGraphEdge;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
+

+

+/**

+ * @author Akos Horvath

+ *

+ */

+public class CreateSuperTypeofConstant2Constant extends CreateConstant2Constant {

+	
+	private SearchGraphEdge relatedSearchGraphEdge;
+	

+	public CreateSuperTypeofConstant2Constant(IModelElement s, IModelElement t
+			,IModelManager manager, SearchGraphEdge edge){

+		super(manager);

+		source = s;

+		target= t;
+		relatedSearchGraphEdge = edge;

+	}

+	

+	@Override

+	protected boolean create(MatchingFrame frame)throws GTOperationException{

+		  if (source == null) {
+	        	String[] context = {relatedSearchGraphEdge.getSourceNode().getName(),getClass().getSimpleName()};
+				throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE
+						,context
+						,relatedSearchGraphEdge.getSourceNode().getTraceabilityElement().getRepresentativeEMFElement());
+	     
+	        }
+	        if (target == null) {
+	        	String[] context = {relatedSearchGraphEdge.getTargetNode().getName(),getClass().getSimpleName()};
+				throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE
+						,context
+						,relatedSearchGraphEdge.getTargetNode().getTraceabilityElement().getRepresentativeEMFElement());
+	        }

+		

+		try {

+			manager.newSupertypeOf(source,target);

+		} catch (VPMCoreException e) {

+			String[] context = {source.getFullyQualifiedName(),target.getFullyQualifiedName(), e.getMessage()};
+			throw new GTOperationException(GTErrorStrings.INTERNAL_CREATE_SUPERTYPEOF
+					,context
+					,relatedSearchGraphEdge.getTraceabilityElement().getRepresentativeEMFElement());
+		}

+		return true;

+	}
+	
+	public String toString() {
+		return getClass().getSimpleName() + " : " + 
+            source.getName() + " -- Supertypeof: -> " + target.getName();
+	}
+	
+	@Override
+	public AnnotatedElement getErrorfulElement(MatchingFrame frame){
+    	return relatedSearchGraphEdge.getTraceabilityElement().getRepresentativeEMFElement();
+    }

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/DeleteElement.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/DeleteElement.java
new file mode 100644
index 0000000..9efac8c
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/DeleteElement.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation;

+

+import org.eclipse.viatra2.core.IModelManager;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTOperationException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+

+

+/**

+ * @author Akos Horvath

+ *

+ */

+abstract public class DeleteElement extends ElementManipulationOperation {

+

+//	private boolean hasBeenExecuted;

+	protected IModelManager manager;

+	protected int variableIndex;

+	    

+    public DeleteElement(IModelManager manager, int variableI) {

+//	        hasBeenExecuted = false;

+        this.manager = manager;

+        this.variableIndex = variableI;

+    }

+	    

+    public boolean update(MatchingFrame frame) throws GTOperationException{

+   		delete(frame);

+	    return true;

+    }

+

+    abstract protected boolean delete(MatchingFrame frame) throws GTOperationException;

+
+    /**

+	 * @return the variableIndex

+	 */

+	public int getVariableIndex() {

+		return variableIndex;

+	}

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/DeleteInstanceof.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/DeleteInstanceof.java
new file mode 100644
index 0000000..4794d4f
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/DeleteInstanceof.java
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation;

+

+import org.eclipse.viatra2.core.IModelElement;
+import org.eclipse.viatra2.core.IModelManager;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTOperationException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+

+

+/**

+ * @author Akos Horvath

+ *

+ */

+public class DeleteInstanceof extends DeleteRelationShip {

+

+	/**

+	 * @param manager

+	 * @param variableI

+	 */

+	

+	public DeleteInstanceof(IModelManager manager, IModelElement source, IModelElement target) {

+		super(manager,source,target);

+	}

+

+	/* (non-Javadoc)

+	 * @see org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.DeleteElement#delete(org.eclipse.viatra2.gtasm.patternmatcher.internal.MatchingFrame)

+	 */

+	@Override

+	protected boolean delete(MatchingFrame frame) throws GTOperationException{

+		// target = instance

+		// source = type

+		

+ /*       if (source == null) {

+            throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE);

+        }

+        if (target == null) {

+        	throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE);

+        }

+		

+		try {

+			manager.deleteInstanceOf(source, target );

+		} catch (VPMCoreException e) {

+			throw new GTOperationException(GTErrorStrings.DELETE_INSTANCEOF

+					+"Type: "+source.getFullyQualifiedName()

+					+"Instance: "+target.getFullyQualifiedName());

+			

+		}

+		return true;*/
+		String[] context = {getClass().getSimpleName()};
+		throw new GTOperationException(GTErrorStrings.INTERNAL_OPERATION_NOT_SUPPORTED
+				,context
+				,null);

+	}

+	

+

+    public String toString(){

+    	return "Delete "+ source.getName()+" instanceof "+target.getName();

+    }

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/DeleteModelElement.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/DeleteModelElement.java
new file mode 100644
index 0000000..016168a
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/DeleteModelElement.java
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation;

+

+import org.eclipse.viatra2.core.EDeleteSemantics;
+import org.eclipse.viatra2.core.IModelElement;
+import org.eclipse.viatra2.core.IModelManager;
+import org.eclipse.viatra2.errors.VPMCoreException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTOperationException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.enums.ValueKind;
+

+/**

+ * @author Akos Horvath

+ *

+ */

+public class DeleteModelElement extends DeleteElement {

+

+	public DeleteModelElement(IModelManager manager, int variableI) {

+		super(manager, variableI);

+	}

+

+	@Override

+	protected boolean delete(MatchingFrame frame) throws GTOperationException {

+

+		IModelElement elementToDelete = null;

+        

+        try {

+        	elementToDelete = (IModelElement) frame.getValue(this.variableIndex);

+        } catch (ClassCastException e) {

+        	String[] context = {frame.getPattern().getSearchGraph().getSearchNode(variableIndex).getName(), getClass().getSimpleName()};
+			throw new GTOperationException(GTErrorStrings.NOT_A_MODELELEMENT
+					,context
+					,frame.getPattern().getSearchGraph().getSearchNode(variableIndex).getTraceabilityElement().getRepresentativeEMFElement());
+         }

+        if (elementToDelete == null) {

+        	String[] context = {frame.getPattern().getSearchGraph().getSearchNode(variableIndex).getName(),getClass().getSimpleName()};
+			throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE
+					,context
+					,frame.getPattern().getSearchGraph().getSearchNode(variableIndex).getTraceabilityElement().getRepresentativeEMFElement());
+     

+        }

+        		

+		try {

+			manager.deleteElement(elementToDelete, EDeleteSemantics.DELETE_SEMANTICS_BRANCH_FORCE);

+			frame.setValue(variableIndex, ValueKind.UNDEF_LITERAL);

+			

+		}catch (VPMCoreException e) {

+			String context[] = {frame.getPattern().getSearchGraph().getSearchNode(variableIndex).getName(),e.getMessage()};
+			throw new GTOperationException(GTErrorStrings.INTERNAL_DELETE_MODELELEMENT
+					,context
+					,frame.getPattern().getSearchGraph().getSearchNode(variableIndex).getTraceabilityElement().getRepresentativeEMFElement());
+		}

+		return true;

+	}

+

+

+    public String toString(){

+    	return "Del: "+variableIndex;

+    }
+    
+    @Override
+	public AnnotatedElement getErrorfulElement(MatchingFrame frame){
+    	return frame.getPattern().getSearchGraph().getSearchNode(variableIndex).getTraceabilityElement().getRepresentativeEMFElement();
+    }
+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/DeleteRelationShip.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/DeleteRelationShip.java
new file mode 100644
index 0000000..b147d63
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/DeleteRelationShip.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation;

+

+import org.eclipse.viatra2.core.IModelElement;
+import org.eclipse.viatra2.core.IModelManager;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTOperationException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+

+/**

+ * @author Akos Horvath

+ *

+ */

+public abstract class DeleteRelationShip extends DeleteElement {

+

+	

+	IModelElement target, source; 

+	

+	public DeleteRelationShip(IModelManager manager, IModelElement s,IModelElement t ) {

+		super(manager, 0);

+		target = t;

+		source = s;

+	}

+

+	@Override

+	protected boolean delete(MatchingFrame frame) throws GTOperationException {

+		return false;

+	}

+

+	

+

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/DeleteSuperTypeof.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/DeleteSuperTypeof.java
new file mode 100644
index 0000000..fb13e9b
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/DeleteSuperTypeof.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation;

+

+import org.eclipse.viatra2.core.IModelElement;
+import org.eclipse.viatra2.core.IModelManager;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTOperationException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+

+

+/**

+ * @author Akos Horvath

+ *

+ */

+public class DeleteSuperTypeof extends DeleteRelationShip {

+

+	/**

+	 * @param manager

+	 * @param variableI

+	 * @param p

+	 */

+	public DeleteSuperTypeof(IModelManager manager, IModelElement target, IModelElement source) {

+		super(manager,source,target);

+	}

+

+	/* (non-Javadoc)

+	 * @see org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.DeleteElement#delete(org.eclipse.viatra2.gtasm.patternmatcher.internal.MatchingFrame)

+	 */

+	@Override

+	protected boolean delete(MatchingFrame frame) throws GTOperationException{

+		// target = supertype

+		// source = subtype

+		

+	/*	if (source == null) {

+	            throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE);

+	        }

+	    if (target == null) {

+	        	throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE);

+	        }

+			

+		

+		try {

+			manager.deleteSupertypeOf(source, target);

+		} catch (VPMCoreException e) {

+			throw new GTOperationException(GTErrorStrings.DELETE_SUPERTYPEOF

+					+"SuperType: "+source.getFullyQualifiedName()

+					+"SubType: "+target.getFullyQualifiedName());

+			

+		}

+		return true;*/
+		String[] context = {getClass().getSimpleName()};
+		throw new GTOperationException(GTErrorStrings.INTERNAL_OPERATION_NOT_SUPPORTED
+				,context
+				,null);
+

+	}

+	

+

+    public String toString(){

+    	return "Delete "+ source.getName()+" supertypeof "+target.getName();

+    }
+    
+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/ElementManipulationOperation.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/ElementManipulationOperation.java
new file mode 100644
index 0000000..8c46032
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/ElementManipulationOperation.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation;

+

+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTOperationException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
+

+

+/**The root of the manipulation operation hierarchy

+ * @author Akos Horvath

+ *

+ */

+public abstract class ElementManipulationOperation implements IUpdatePlanOperation {

+	

+	public boolean update(MatchingFrame frame) throws GTOperationException {

+		return false;

+	}

+    

+    public String toString() {

+        return getClass().getSimpleName();

+    }

+    

+    public AnnotatedElement getErrorfulElement(MatchingFrame frame){

+    	return null;

+    }
+    
+    public String toString(MatchingFrame frame) {
+		return toString();
+	}

+}
\ No newline at end of file
diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/IUpdatePlanOperation.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/IUpdatePlanOperation.java
new file mode 100644
index 0000000..5104907
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/IUpdatePlanOperation.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation;

+

+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTOperationException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
+
+

+public interface IUpdatePlanOperation {

+	/** Executes the operation
+	 * @param frame The matching frame of the invocation context
+	 * @return true if the execution finished without problems else false
+	 * @throws GTOperationException
+	 */
+	public boolean update(MatchingFrame frame) throws GTOperationException;
+	/**A detailed serialized description of the operation
+	 * @param frame The matching frame of the invocation context
+	 * @return
+	 */
+	public String toString(MatchingFrame frame);
+	/**Returns the GTASM element from which the operation was created (also which caused the error durng the execution)
+	 * @param frame The matching frame of the invocation context
+	 * @return
+	 */
+	public AnnotatedElement getErrorfulElement(MatchingFrame frame);

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/MoveBoundunderBound.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/MoveBoundunderBound.java
new file mode 100644
index 0000000..2c4ba55
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/MoveBoundunderBound.java
@@ -0,0 +1,109 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation;

+

+import org.eclipse.viatra2.core.IEntity;
+import org.eclipse.viatra2.core.IModelManager;
+import org.eclipse.viatra2.errors.VPMCoreException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTOperationException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.SearchGraphEdge;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
+

+

+/**

+ * @author Akos Horvath

+ *

+ */

+public class MoveBoundunderBound extends MoveElement{

+	

+		int container;

+		SearchGraphEdge relatedSearchGraphEdge;

+		

+	

+	    public MoveBoundunderBound(IModelManager manager, int cont
+	    		, int variable, SearchGraphEdge edge) {

+	        super(manager,variable);

+	        container = cont;
+	        relatedSearchGraphEdge = edge;

+	        

+	    }

+	    

+	    public boolean update(MatchingFrame frame) throws GTOperationException {

+	   		

+	   			IEntity containerElement = null;

+	   			IEntity variableElement = null;

+	   	        try {

+	   	        	containerElement = (IEntity) frame.getValue(container);

+	   	        } catch (ClassCastException e) {

+	   	        	String[] context = {relatedSearchGraphEdge.getSourceNode().getName(), getClass().getSimpleName()};
+	    			throw new GTOperationException(GTErrorStrings.NOT_AN_ENTITY
+	    					,context
+	    					,relatedSearchGraphEdge.getSourceNode().getTraceabilityElement().getRepresentativeEMFElement());
+	   	        }

+	   	        try {

+	   	            variableElement = (IEntity) frame.getValue(variableIndex);

+	   	        } catch (ClassCastException e) {

+	   	     	String[] context = {relatedSearchGraphEdge.getTargetNode().getName(), getClass().getSimpleName()};
+				throw new GTOperationException(GTErrorStrings.NOT_AN_ENTITY
+						,context
+						,relatedSearchGraphEdge.getTargetNode().getTraceabilityElement().getRepresentativeEMFElement());
+	   	        }

+	   	        if (containerElement == null) {

+	   	        	String[] context = {relatedSearchGraphEdge.getSourceNode().getName(),getClass().getSimpleName()};
+	   				throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE
+	   						,context
+	   						,relatedSearchGraphEdge.getSourceNode().getTraceabilityElement().getRepresentativeEMFElement());
+	   			}

+	   	        if (variableElement == null) {

+	   	        	String[] context = {relatedSearchGraphEdge.getTargetNode().getName(),getClass().getSimpleName()};
+	   				throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE
+	   						,context
+	   						,relatedSearchGraphEdge.getTargetNode().getTraceabilityElement().getRepresentativeEMFElement());
+	   	        }

+	   			

+	   			

+	   			try {

+					manager.moveEntityTo(variableElement,containerElement);

+				

+//					hasBeenExecuted = true;

+		   			return true;

+	   			}

+	   			 catch (VPMCoreException e) {

+		   			 String[] context = {frame.getPattern().getSearchGraph().getSearchNode(container).getName()
+		   					 , frame.getPattern().getSearchGraph().getSearchNode(variableIndex).getName()
+		   					 , e.getMessage()};
+		   			 
+	   				 throw new GTOperationException(GTErrorStrings.INTERNAL_MOVE_MODELELEMENT

+	   						,context
+	   						,relatedSearchGraphEdge.getTraceabilityElement().getRepresentativeEMFElement());

+				 }

+	    }

+	    

+	    public String toString() {

+			return getClass().getSimpleName() + " : " + 

+	            variableIndex + " -- move under -> " + container;

+	    }

+

+		/**

+		 * @return the container

+		 */

+		public int getContainer() {

+			return container;

+		}

+
+		@Override
+		public AnnotatedElement getErrorfulElement(MatchingFrame frame){
+	    	return relatedSearchGraphEdge.getTraceabilityElement().getRepresentativeEMFElement();
+	    }

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/MoveBoundunderConstant.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/MoveBoundunderConstant.java
new file mode 100644
index 0000000..7ed71d7
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/MoveBoundunderConstant.java
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation;

+

+import org.eclipse.viatra2.core.IEntity;
+import org.eclipse.viatra2.core.IModelManager;
+import org.eclipse.viatra2.errors.VPMCoreException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTOperationException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.SearchGraphEdge;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
+

+

+/**

+ * @author Akos Horvath

+ *

+ */

+public class MoveBoundunderConstant extends MoveElement {

+

+//	private boolean hasBeenExecuted;

+	IEntity container;

+	SearchGraphEdge relatedSearchGraphEdge;

+	

+	public MoveBoundunderConstant(IModelManager manager, IEntity cont
+			, int variable, SearchGraphEdge edge) {

+	        super(manager,variable);

+	        container = cont;

+	        relatedSearchGraphEdge = edge;

+	    }

+	    

+	    public boolean update(MatchingFrame frame) throws GTOperationException {

+	   			IEntity variableElement = null;

+	   	        try {

+	   	            variableElement = (IEntity) frame.getValue(variableIndex);

+	   	        } catch (ClassCastException e) {

+	   	        	String[] context = {relatedSearchGraphEdge.getTargetNode().getName(), getClass().getSimpleName()};
+					throw new GTOperationException(GTErrorStrings.NOT_AN_ENTITY
+							,context
+							,relatedSearchGraphEdge.getTargetNode().getTraceabilityElement().getRepresentativeEMFElement());
+		        }

+	   	        if (container == null) {

+	   	        	String[] context = {relatedSearchGraphEdge.getSourceNode().getName(),getClass().getSimpleName()};
+	   				throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE
+	   						,context
+	   						,relatedSearchGraphEdge.getSourceNode().getTraceabilityElement().getRepresentativeEMFElement());
+	   			}

+	   	        if (variableElement == null) {

+	   	        	String[] context = {relatedSearchGraphEdge.getTargetNode().getName(),getClass().getSimpleName()};
+	   				throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE
+	   						,context
+	   						,relatedSearchGraphEdge.getTargetNode().getTraceabilityElement().getRepresentativeEMFElement());
+	   	        }

+	   			

+	   			try {

+					manager.moveEntityTo(variableElement, container);

+		   			return true;

+	   			}catch (VPMCoreException e) {

+	   			 String[] context = {container.getFullyQualifiedName()
+	   					 , frame.getPattern().getSearchGraph().getSearchNode(variableIndex).getName()
+	   					 , e.getMessage()};
+	   			 
+   				 throw new GTOperationException(GTErrorStrings.INTERNAL_MOVE_MODELELEMENT
+   						,context
+   						,relatedSearchGraphEdge.getTraceabilityElement().getRepresentativeEMFElement());
+	   			}

+	    }

+	    

+	    public String toString() {

+			return getClass().getSimpleName() + " : " + 

+	            variableIndex + " -- move under -> " + container.getName();

+	    }
+	    
+	    @Override
+		public AnnotatedElement getErrorfulElement(MatchingFrame frame){
+	    	return relatedSearchGraphEdge.getTraceabilityElement().getRepresentativeEMFElement();
+	    }

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/MoveElement.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/MoveElement.java
new file mode 100644
index 0000000..10f2e9c
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/MoveElement.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation;

+

+import org.eclipse.viatra2.core.IModelManager;
+

+/**

+ * @author Akos Horvath

+ *

+ */

+public abstract class MoveElement extends ElementManipulationOperation {

+

+	protected IModelManager manager;

+	protected int variableIndex;

+	

+	protected MoveElement(IModelManager manager, int variable){

+		this.manager= manager;

+		this.variableIndex = variable;

+	}

+

+	/**

+	 * @return the variable

+	 */

+	public int getVariableIndex() {

+		return variableIndex;

+	}

+	

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/SetRelation.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/SetRelation.java
new file mode 100644
index 0000000..327cd49
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/SetRelation.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation;

+

+import org.eclipse.viatra2.core.IModelManager;
+

+/**

+ * @author Akos Horvath

+ *

+ */

+public abstract class SetRelation extends ElementManipulationOperation {

+

+	protected IModelManager manager;

+	protected int relation;

+	

+	

+	public SetRelation(IModelManager manager, int relation) {

+		this.relation = relation;

+		this.manager = manager;

+	}

+

+

+	/**

+	 * @return the relation

+	 */

+	public int getRelation() {

+		return relation;

+	}

+

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/SetRelationSource.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/SetRelationSource.java
new file mode 100644
index 0000000..386aab8
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/SetRelationSource.java
@@ -0,0 +1,85 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation;

+

+import org.eclipse.viatra2.core.IModelElement;
+import org.eclipse.viatra2.core.IModelManager;
+import org.eclipse.viatra2.core.IRelation;
+import org.eclipse.viatra2.errors.VPMCoreException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTOperationException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.SearchGraphEdge;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
+

+

+public class SetRelationSource extends SetRelation {

+	

+	SearchGraphEdge relatedSearchGraphEdge;

+	int source;

+	

+	public SetRelationSource(int rel, int source
+			,IModelManager manager, SearchGraphEdge edge) {

+		super(manager,rel);

+		this.source= source;
+		relatedSearchGraphEdge = edge;

+	}

+	

+	public boolean update(MatchingFrame frame)throws GTOperationException {

+		IModelElement sourceElement = null;

+        IRelation relationElement = null;

+		try {

+            sourceElement = (IModelElement) frame.getValue(source);

+        } catch (ClassCastException e) {

+        	String[] context = {relatedSearchGraphEdge.getSourceNode().getName(), getClass().getSimpleName()};
+			throw new GTOperationException(GTErrorStrings.NOT_A_MODELELEMENT
+					,context
+					,relatedSearchGraphEdge.getSourceNode().getTraceabilityElement().getRepresentativeEMFElement());
+        }

+        try {

+            relationElement = (IRelation) frame.getValue(relation);

+        } catch (ClassCastException e) {

+        	String[] context = {relatedSearchGraphEdge.getTargetNode().getName(), getClass().getSimpleName()};
+			throw new GTOperationException(GTErrorStrings.NOT_A_RELATION
+					,context
+					,relatedSearchGraphEdge.getTargetNode().getTraceabilityElement().getRepresentativeEMFElement());
+   	    }

+        if (sourceElement == null) {

+        	String[] context = {relatedSearchGraphEdge.getSourceNode().getName(),getClass().getSimpleName()};
+				throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE
+						,context
+						,relatedSearchGraphEdge.getSourceNode().getTraceabilityElement().getRepresentativeEMFElement());
+		}

+		

+		try {

+		if(!relationElement.getFrom().equals(sourceElement))	

+				manager.setRelationFrom(relationElement,sourceElement);

+		return true;

+		}catch (VPMCoreException e) {

+			String[] context = {relatedSearchGraphEdge.getTargetNode().getName(), relatedSearchGraphEdge.getTargetNode().getName(), e.getMessage()};
+			throw new GTOperationException(GTErrorStrings.INTERNAL_SET_RELATION_SOURCE
+					,context
+					,relatedSearchGraphEdge.getTraceabilityElement().getRepresentativeEMFElement());

+		}	

+	}

+	

+	@Override

+	public String toString() {

+		return "Relation: "+ relation+"-- set Source --> " + source; 

+	}

+

+	@Override
+	public AnnotatedElement getErrorfulElement(MatchingFrame frame){
+    	return relatedSearchGraphEdge.getTraceabilityElement().getRepresentativeEMFElement();
+    }

+

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/SetRelationTarget.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/SetRelationTarget.java
new file mode 100644
index 0000000..0852747
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/internal/operation/SetRelationTarget.java
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation;

+

+import org.eclipse.viatra2.core.IModelElement;
+import org.eclipse.viatra2.core.IModelManager;
+import org.eclipse.viatra2.core.IRelation;
+import org.eclipse.viatra2.errors.VPMCoreException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTOperationException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.SearchGraphEdge;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
+

+

+/**

+ * @author Akos Horvath

+ *

+ */

+public class SetRelationTarget extends SetRelation{

+

+	/**

+	 * 

+	 */

+	SearchGraphEdge relatedSearchGraphEdge;

+	int target;

+	

+	public SetRelationTarget(int rel, int target
+			,IModelManager manager, SearchGraphEdge edge) {

+		super(manager,rel);

+		this.target = target;
+		relatedSearchGraphEdge = edge;

+	}

+	

+	public boolean update(MatchingFrame frame)throws GTOperationException {

+		IModelElement targetElement = null;

+        IRelation relationElement = null;

+		try {

+            targetElement = (IModelElement) frame.getValue(target);

+        } catch (ClassCastException e) {

+        	String[] context = {relatedSearchGraphEdge.getSourceNode().getName(), getClass().getSimpleName()};
+			throw new GTOperationException(GTErrorStrings.NOT_A_MODELELEMENT
+					,context
+					,relatedSearchGraphEdge.getSourceNode().getTraceabilityElement().getRepresentativeEMFElement());
+        }

+        try {

+            relationElement = (IRelation) frame.getValue(relation);

+        } catch (ClassCastException e) {

+        	String[] context = {relatedSearchGraphEdge.getTargetNode().getName(), getClass().getSimpleName()};
+			throw new GTOperationException(GTErrorStrings.NOT_A_RELATION
+					,context
+					,relatedSearchGraphEdge.getTargetNode().getTraceabilityElement().getRepresentativeEMFElement());
+   	  }

+        if (targetElement == null) {

+        	String[] context = {relatedSearchGraphEdge.getTargetNode().getName(),getClass().getSimpleName()};
+			throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE
+					,context
+					,relatedSearchGraphEdge.getTargetNode().getTraceabilityElement().getRepresentativeEMFElement());
+     }

+		

+		try {

+			if(!relationElement.getTo().equals(targetElement))

+				manager.setRelationTo(relationElement,targetElement);

+			return true;

+		}catch (VPMCoreException e) {

+			String[] context = {relatedSearchGraphEdge.getTargetNode().getName(), relatedSearchGraphEdge.getTargetNode().getName(), e.getMessage()};
+			throw new GTOperationException(GTErrorStrings.INTERNAL_SET_RELATION_TARGET
+					,context
+					,relatedSearchGraphEdge.getTraceabilityElement().getRepresentativeEMFElement());
+		}	

+	}

+	

+	@Override

+	public String toString() {

+		return "Relation: "+relation + "-- set Target --> " + target; 

+	}

+	
+	@Override

+	public AnnotatedElement getErrorfulElement(MatchingFrame frame){
+    	return relatedSearchGraphEdge.getTraceabilityElement().getRepresentativeEMFElement();
+    }

+

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/validation/GTRuleValidator.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/validation/GTRuleValidator.java
new file mode 100644
index 0000000..f325734
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/validation/GTRuleValidator.java
@@ -0,0 +1,316 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.validation;

+

+

+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.viatra2.core.IModelManager;
+import org.eclipse.viatra2.core.IRelation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTRuleBuildingException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.GTElementMapping;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.GTElementMappingType;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.CreateElement;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.CreateEntity;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.CreateRelationBound2Bound;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.CreateRelationBound2Constant;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.CreateRelationConstant2Bound;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.CreateRelationConstant2Constant;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.DeleteModelElement;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.IUpdatePlanOperation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.MoveBoundunderBound;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.MoveElement;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.SetRelation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.SetRelationSource;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.SetRelationTarget;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.EdgeType;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.algorithms.ISearchGraph;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation.ISearchPlanOperation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.ConstantSearchGraphNode;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.SearchGraphEdge;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.SearchGraphNode;
+

+

+/** Encapsulates GT Rule validating operations

+ * @author Akos Horvath

+ *

+ */

+public class GTRuleValidator {

+

+	

+	private Map<Integer,GTValidationElement> validationElements;

+	

+	

+	public GTRuleValidator(){

+		validationElements = new HashMap<Integer, GTValidationElement>();

+	}

+	

+	private GTValidationElement getValidationElement(Integer i){

+		if(!validationElements.containsKey(i))

+			validationElements.put(i, new GTValidationElement());

+		

+		return validationElements.get(i);

+	}

+	

+	

+	/** Adds a collection to the validation process

+	 * @param operations  The collection of operations to add for the validation

+	 */

+	public void addElements(Collection<IUpdatePlanOperation> operations){

+		for(IUpdatePlanOperation op: operations)

+			addElement(op);

+	}

+	

+	/** Adds an operation to the validation process

+	 * @param operation The operation to add for the validation

+	 */

+	private void addElement(IUpdatePlanOperation operation){

+		

+		if(operation instanceof CreateElement)

+			{

+			if(operation instanceof CreateEntity)

+				getValidationElement(((CreateEntity)operation).getVariableIndex()).addCreateOperation(((CreateEntity)operation));

+			else 

+			if (operation instanceof CreateRelationBound2Bound)

+				{getValidationElement(((CreateRelationBound2Bound)operation).getVariableIndex()).addCreateOperation(((CreateRelationBound2Bound)operation));

+				getValidationElement(((CreateRelationBound2Bound)operation).getTarget()).addRelatedCreateOperation(((CreateRelationBound2Bound)operation));

+				getValidationElement(((CreateRelationBound2Bound)operation).getSource()).addRelatedCreateOperation(((CreateRelationBound2Bound)operation));

+				}

+			else if (operation instanceof CreateRelationBound2Constant)

+				{getValidationElement(((CreateRelationBound2Constant)operation).getVariableIndex()).addCreateOperation(((CreateRelationBound2Constant)operation));

+				 getValidationElement(((CreateRelationBound2Constant)operation).getSource()).addRelatedCreateOperation(((CreateRelationBound2Constant)operation));

+				}

+			else if (operation instanceof CreateRelationConstant2Bound)

+				{getValidationElement(((CreateRelationConstant2Bound)operation).getVariableIndex()).addCreateOperation(((CreateRelationConstant2Bound)operation));

+				getValidationElement(((CreateRelationConstant2Bound)operation).getTarget()).addRelatedCreateOperation(((CreateRelationConstant2Bound)operation));

+				}

+			else if (operation instanceof CreateRelationConstant2Constant)

+				getValidationElement(((CreateRelationConstant2Constant)operation).getVariableIndex()).addCreateOperation(((CreateRelationConstant2Constant)operation));

+			//Relationship operations are currently not used in the process

+			}

+		else if(operation instanceof DeleteModelElement)

+			getValidationElement(((DeleteModelElement)operation).getVariableIndex()).addDelOperation(((DeleteModelElement)operation));

+		else if(operation instanceof MoveElement)

+			{

+			getValidationElement(((MoveElement)operation).getVariableIndex()).addMoveOperation(((MoveElement)operation));

+			if(operation instanceof MoveBoundunderBound)

+				getValidationElement(((MoveBoundunderBound)operation).getContainer()).addRelatedMoveOperation(((MoveElement)operation));

+			}

+		else if(operation instanceof SetRelation)

+			{

+			getValidationElement(((SetRelation)operation).getRelation()).addSetOperation(((SetRelation)operation));

+			//source and target of the operation
+			//if(operation instanceof SetRelationSource)

+			//	getValidationElement(((SetRelationSource)operation).getSource()).addSetOperation(((SetRelation)operation));

+			//if(operation instanceof SetRelationTarget)

+			//	getValidationElement(((SetRelationTarget)operation).getTarget()).addSetOperation(((SetRelation)operation));

+			}

+	}

+	

+	

+	/**Simple validation algorithm on the input searchgraph
+	 * @param searchGraph
+	 * @throws GTRuleBuildingException
+	 */
+	private void basicValidation(ISearchGraph searchGraph) throws GTRuleBuildingException{

+		

+//		on all elements simple checks

+		for(Map.Entry<Integer, GTValidationElement> entry: validationElements.entrySet()){

+
+		GTValidationElement element = entry.getValue();

+			//basic operation checks 

+			if(element.getDelOperations().size()>1)

+				{
+				String[] context = {searchGraph.getSearchNode(entry.getKey()).getName()};
+				throw new GTRuleBuildingException(GTErrorStrings.GTVALIDATION_MORE_THANONE_DEL
+						,context
+						,searchGraph.getGTASMRepresentation(searchGraph.getSearchNode(entry.getKey())));
+				}

+				

+			if(element.getCreateOperations().size()>1)

+				{
+				String[] context = {searchGraph.getSearchNode(entry.getKey()).getName()};
+				throw new GTRuleBuildingException(GTErrorStrings.GTVALIDATION_MORE_THANONE_CREATE
+						,context
+						,searchGraph.getGTASMRepresentation(searchGraph.getSearchNode(entry.getKey())));
+				}
+				

+			if(element.getDelOperations().size() == 1 

+					&& 

+					(element.createOperations.size() != 0

+							|| element.moveOperations.size() != 0

+							|| element.setOperations.size() != 0))

+				{
+				String[] context = {searchGraph.getSearchNode(entry.getKey()).getName()
+						,""+element.createOperations.size()
+						,""+element.moveOperations.size()
+						,""+element.setOperations.size()};
+				throw new GTRuleBuildingException(GTErrorStrings.GTVALIDATION_DEL_AND_OTHEROPERATION
+						,context
+						,searchGraph.getGTASMRepresentation(searchGraph.getSearchNode(entry.getKey())));
+				}
+				

+			//it has to be deleted but also used in a relation/relationship/move/set create operation as a target or source of the relation

+			if((element.getRelatedCreateOperations().size() > 0 

+					|| element.getRelatedMoveOperations().size() > 0 

+					|| element.getRelatedSetOperations().size() >0)

+					&&

+					(element.getDelOperations().size() == 1))
+				{
+				String[] context = {searchGraph.getSearchNode(entry.getKey()).getName()};

+				throw new GTRuleBuildingException(GTErrorStrings.GTVALIDATION_DEL_AND_USED
+						,context
+						,searchGraph.getGTASMRepresentation(searchGraph.getSearchNode(entry.getKey())));

+				}

+		}

+

+	}

+	

+	private void gtElementMappingValidation( Collection<GTElementMapping> elementMappings,
+			Collection<ISearchPlanOperation> checkSet, ISearchGraph searchGraph) throws GTRuleBuildingException{

+		//searchGraph.getGTASMRepresentation(searchGraph.get(2));

+		for(GTElementMapping mapping: elementMappings){

+			GTValidationElement element = null; 

+			

+			if(!validationElements.containsKey(mapping.getRhsInputOrderIndex()))

+				continue;

+			

+			element= validationElements.get(mapping.getRhsInputOrderIndex());

+			

+			if(mapping.getMappingType().equals(GTElementMappingType.KEEP)){

+				if(element.getDelOperations().size() != 0)

+					{
+					String[] context = {searchGraph.getSearchNode(mapping.getRhsInputOrderIndex()).getName()};
+					throw new GTRuleBuildingException(GTErrorStrings.GTVALIDATION_KEEP_DEL
+							,context
+							,searchGraph.getGTASMRepresentation(searchGraph.getSearchNode(mapping.getRhsInputOrderIndex())));
+					
+					}

+				}

+			else

+				if(element.getDelOperations().size() != 1)

+					{
+					String[] context = {searchGraph.getSearchNode(mapping.getRhsInputOrderIndex()).getName()};
+					throw new GTRuleBuildingException(GTErrorStrings.INTERNAL_GTVALIDATION_NOT_DELETED
+							,context
+							,searchGraph.getGTASMRepresentation(searchGraph.getSearchNode(mapping.getRhsInputOrderIndex())));
+					}
+			//more then one set operation on the same relation

+			if(element.getSetOperations().size() > 1){

+				int to=0,from=0;

+				for(SetRelation setR: element.getSetOperations())

+					{

+					if(setR instanceof SetRelationSource)

+						from++;

+					else if(setR instanceof SetRelationTarget)

+						to++;

+					}

+				if(to==1 && from >1)
+				{
+					String[] context = {searchGraph.getSearchNode(mapping.getRhsInputOrderIndex()).getName()};
+					throw new GTRuleBuildingException(GTErrorStrings.GTVALIDATION_SET_SOURCE
+							,context
+							,searchGraph.getGTASMRepresentation(searchGraph.getSearchNode(mapping.getRhsInputOrderIndex())));
+				}
+				
+				if(to>1 && from == 1)
+				{
+					String[] context = {searchGraph.getSearchNode(mapping.getRhsInputOrderIndex()).getName()};
+					throw new GTRuleBuildingException(GTErrorStrings.GTVALIDATION_SET_TARGET
+							,context
+							,searchGraph.getGTASMRepresentation(searchGraph.getSearchNode(mapping.getRhsInputOrderIndex())));
+				}
+				
+				if(to>1 && from > 1)
+				{
+					String[] context = {searchGraph.getSearchNode(mapping.getRhsInputOrderIndex()).getName()};
+					throw new GTRuleBuildingException(GTErrorStrings.GTVALIDATION_SET_BOTH
+							,context
+							,searchGraph.getGTASMRepresentation(searchGraph.getSearchNode(mapping.getRhsInputOrderIndex())));
+				}

+			}

+		}

+	}

+		

+	

+	/** Validates the search plan for multiple del, set, create etc. operations on a single element
+	 * @param nonchangeableGTOperations The operations to be checked
+	 * @param checkSet the check set that contains additional check operation on elements
+	 * @param elementMappings The element mapping between the LHS nad the RHS
+	 * @param searchGraph The search graph
+	 * @throws GTRuleBuildingException
+	 */
+	public void validateOperationPlan(Collection<IUpdatePlanOperation> nonchangeableGTOperations

+			, Collection<ISearchPlanOperation> checkSet

+			, Collection<GTElementMapping> elementMappings, ISearchGraph searchGraph) throws GTRuleBuildingException{

+		

+		addElements(nonchangeableGTOperations);

+		basicValidation(searchGraph);

+		gtElementMappingValidation(elementMappings,checkSet,searchGraph);

+	}
+	
+	/** Validates the containment related elements between entities
+	 * @param node The node to be checked
+	 * @param manager The model space manager
+	 * @param hasOneInConstraint The global 'IN' type constraint store for the input elements 
+	 * @throws GTRuleBuildingException
+	 */
+	public static void validateContainment(SearchGraphNode node, IModelManager manager, Map<SearchGraphNode, Boolean> hasOneInConstraint) throws GTRuleBuildingException {
+		for(SearchGraphEdge edge: node.getSources()){ 
+			//direct IN constraints on the node
+			if(edge.getVPMEdgeType().equals(EdgeType.IN) && edge.isSource())
+				//&& edge.isChecked()
+				if(hasOneInConstraint.get(node) != null && hasOneInConstraint.get(node))
+	//				two IN constraints on the element
+				{	String[] context = {node.getName()};
+					throw new GTRuleBuildingException(GTErrorStrings.MORE_ONE_IN_CONTAINMENT
+							,context
+							,node.getTraceabilityElement().getRepresentativeEMFElement());
+				}
+				else
+					hasOneInConstraint.put(node, Boolean.TRUE);
+			
+			//edges that are aggregations
+			if(edge.getVPMEdgeType().equals(EdgeType.TARGET) && edge.isSource())
+			{
+				SearchGraphNode edgeNode = edge.getSourceNode();
+				for(SearchGraphEdge typeEdge: edgeNode.getSources())
+					{ 
+					if(typeEdge.getVPMEdgeType().equals(EdgeType.INSTANCEOF) && edge.getSourceNode() instanceof ConstantSearchGraphNode && edge.isSource())
+						{
+						String fqn = ((ConstantSearchGraphNode)edge.getSourceNode()).getElement();
+						//it can be a relation type
+						if(fqn != null && !fqn.equals(ISearchGraph.VPM_ENTITY_FQN) && !fqn.equals(ISearchGraph.VPM_RELATION_FQN))
+							{ IRelation relation = manager.getRelationByName(fqn);
+								if(relation != null && 	relation.getIsAggregation())
+									{
+									if(hasOneInConstraint.get(node) != null && hasOneInConstraint.get(node))
+									{	String[] context = {node.getName()};
+									throw new GTRuleBuildingException(GTErrorStrings.MORE_ONE_IN_CONTAINMENT
+											,context
+											,node.getTraceabilityElement().getRepresentativeEMFElement());
+									}
+									else
+										hasOneInConstraint.put(node, Boolean.TRUE);
+									}
+							}
+						}
+					}
+			}
+		}
+	}

+
+}

+

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/validation/GTValidationElement.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/validation/GTValidationElement.java
new file mode 100644
index 0000000..aa4b33b
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/gtmatcher/validation/GTValidationElement.java
@@ -0,0 +1,156 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.validation;

+

+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.CreateElement;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.DeleteElement;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.MoveElement;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.SetRelation;
+

+

+/** Holds the operations that needs to be validated

+ * @author Akos Horvath

+ *

+ */

+public class GTValidationElement {

+	

+	Collection<DeleteElement> delOperations;

+	Collection<CreateElement> createOperations;

+	Collection<MoveElement> moveOperations;

+	Collection<SetRelation> setOperations;

+	

+	//related operation, where the element is only used as a target or a source

+	//Collection<DeleteElement> relatedDelOperations;

+	Collection<CreateElement> relatedCreateOperations;

+	Collection<MoveElement> relatedMoveOperations;

+	Collection<SetRelation> relatedSetOperations;

+	

+	public GTValidationElement(){

+		delOperations = new ArrayList<DeleteElement>();

+		createOperations = new ArrayList<CreateElement>();

+		moveOperations = new ArrayList<MoveElement>();

+		setOperations = new ArrayList<SetRelation>();

+	

+		//relatedDelOperations = new ArrayList<DeleteElement>();

+		relatedCreateOperations = new ArrayList<CreateElement>();

+		relatedMoveOperations = new ArrayList<MoveElement>();

+		relatedSetOperations = new ArrayList<SetRelation>();

+	

+	}

+	

+	/**

+	 * @return the createOperations

+	 */

+	public Collection<CreateElement> getCreateOperations() {

+		return createOperations;

+	}

+	/**

+	 * @return the delOperations

+	 */

+	public Collection<DeleteElement> getDelOperations() {

+		return delOperations;

+	}

+	/**

+	 * @return the moveOperations

+	 */

+	public Collection<MoveElement> getMoveOperations() {

+		return moveOperations;

+	}

+	/**

+	 * @return the setOperations

+	 */

+	public Collection<SetRelation> getSetOperations() {

+		return setOperations;

+	}

+	/** Adds the operation to the appropriate collection

+	 * @param op

+	 */

+	public void addCreateOperation(CreateElement op){

+		createOperations.add(op);

+	}

+	/** Adds the operation to the appropriate collection

+	 * @param op

+	 */

+	public void addDelOperation(DeleteElement op){

+		delOperations.add(op);

+	}

+	/** Adds the operation to the appropriate collection

+	 * @param op

+	 */

+	public void addMoveOperation(MoveElement op){

+		moveOperations.add(op);

+	}

+	/** Adds the operation to the appropriate collection

+	 * @param op

+	 */

+	public void addSetOperation(SetRelation op){

+		setOperations.add(op);

+	}

+

+	/**

+	 * @return the relatedCreateOperations

+	 */

+	public Collection<CreateElement> getRelatedCreateOperations() {

+		return relatedCreateOperations;

+	}

+

+//	/**

+//	 * @return the relatedDelOperations

+//	 */

+//	public Collection<DeleteElement> getRelatedDelOperations() {

+//		return relatedDelOperations;

+//	}

+//

+	/**

+	 * @return the relatedMoveOperations

+	 */

+	public Collection<MoveElement> getRelatedMoveOperations() {

+		return relatedMoveOperations;

+	}

+

+	/**

+	 * @return the relatedSetOperations

+	 */

+	public Collection<SetRelation> getRelatedSetOperations() {

+		return relatedSetOperations;

+	}	

+	

+	/** Adds the operation to the appropriate collection

+	 * @param op

+	 */

+	public void addRelatedCreateOperation(CreateElement op){

+		relatedCreateOperations.add(op);

+	}

+	/** Adds the operation to the appropriate collection

+	 * @param op

+	 */

+//	public void addRelatedDelOperation(DeleteElement op){

+//		relatedDelOperations.add(op);

+//	}

+	/** Adds the operation to the appropriate collection

+	 * @param op

+	 */

+	public void addRelatedMoveOperation(MoveElement op){

+		relatedMoveOperations.add(op);

+	}

+	/** Adds the operation to the appropriate collection

+	 * @param op

+	 */

+	public void addRelatedSetOperation(SetRelation op){

+		relatedSetOperations.add(op);

+	}

+	

+

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/core/LocalSearchPatternMatcherFactory.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/core/LocalSearchPatternMatcherFactory.java
new file mode 100644
index 0000000..27251bd
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/core/LocalSearchPatternMatcherFactory.java
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.core;

+

+import org.eclipse.viatra2.gtasm.interpreter.exception.ViatraTransformationException;
+import org.eclipse.viatra2.gtasm.interpreter.executionEnvironment.IExecutionEnvironment;
+import org.eclipse.viatra2.gtasm.patternmatcher.extension.IPatternMatcherFactory;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.term.BasicTermHandler;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.term.TermHandler;
+import org.eclipse.viatra2.gtasm.patternmatcher.patterns.IPatternMatcher;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.GTPattern;
+
+

+/**

+ * Implements the IPatternMatcherFactory for org.eclipse.viatra2.gtasm.patternmatcher.extension point for the viatra GTASM intepreter

+ * @author Akos Horvath

+ *

+ */

+public class LocalSearchPatternMatcherFactory implements IPatternMatcherFactory {

+

+	/* (non-Javadoc)

+	 * @see org.eclipse.viatra2.gtasm.patternmatcher.extension.IPatternMatcherFactory#getPatternMatcher(org.eclipse.viatra2.gtasm.interpreter.executionEnvironment.IExecutionEnvironment, org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.GTPattern)

+	 */

+	public IPatternMatcher getPatternMatcher(IExecutionEnvironment executionEnvironment,

+			GTPattern gtPattern) throws ViatraTransformationException {

+		

+		IPatternMatcher patternMatcher = null;

+		if (PatternMatchers.getInstance().containsKey(gtPattern)) {

+			// We had it precompiled
+			patternMatcher=PatternMatchers.getInstance().get(gtPattern);

+		} else {

+        	TermHandler handler = 
+        		new BasicTermHandler(executionEnvironment);

+        	PatternBuilder patternBuilder = 
+        		new PatternBuilder(executionEnvironment.getFramework().getLogger(),
+        				executionEnvironment.getFramework().getTopmodel().getModelManager(),
+        				handler);

+		

+			try {

+				patternMatcher = patternBuilder.construct(gtPattern);

+				PatternMatchers.getInstance().put(gtPattern, patternMatcher);

+			} catch (ViatraTransformationException e) {
+				throw e.addNewStackElement(gtPattern);
+			}

+		}

+		return patternMatcher;

+	}

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/core/PatternBuilder.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/core/PatternBuilder.java
new file mode 100644
index 0000000..06321ec
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/core/PatternBuilder.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.core;

+

+
+import org.eclipse.viatra2.core.IModelManager;
+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherCompileTimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.PatternMatcher;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.term.ITermHandler;
+import org.eclipse.viatra2.gtasm.patternmatcher.patterns.IPatternMatcher;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.GTPattern;
+import org.eclipse.viatra2.logger.Logger;
+

+/**

+ * PatternBuilder reads the specification (i.e., a model that conforms to

+ * the GTPattern metamodel), and after an invocation graph analysis 

+ * it generates PatternMatchers, and the corresponding FlattenedPatterns 

+ * and SearchGraph structure.

+ * 

+ * @author Gergely Varro & Akos Horvath

+ */

+public class PatternBuilder {

+    private final Logger logger;

+    private final IModelManager manager;

+    private final ITermHandler termHandler;

+    

+    public PatternBuilder(Logger logger, IModelManager manager, ITermHandler termHandler) {

+        this.logger = logger;

+        this.manager = manager;

+        this.termHandler = termHandler;

+    }

+    

+    public IPatternMatcher construct(GTPattern pattern) 

+        throws PatternMatcherCompileTimeException {

+        return new PatternMatcher(pattern, logger, manager, termHandler);
+        // TODO gervarro: call graph analysis may be integrated into the parser
+        
+        //Use hacked pattern matcher with extreme caution: Can only be used if there are no containment constraints on the input parameters
+        // and the patterns is not recursively matched. Additionally it cannot be used with the Hybrid approach!
+        //return new HackedPatternMatcher(pattern, logger, manager, termHandler);

+    }

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/core/PatternMatchers.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/core/PatternMatchers.java
new file mode 100644
index 0000000..6473c29
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/core/PatternMatchers.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.core;

+

+import java.util.Hashtable;
+
+import org.eclipse.viatra2.gtasm.patternmatcher.patterns.IPatternMatcher;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.GTPattern;
+

+

+

+public class PatternMatchers extends Hashtable<GTPattern, IPatternMatcher> {

+

+	/**

+	 * Stores the pattern matchers previously created

+	 * 

+	 * @author Akos Horvath and Gergely Varro

+	 */

+	private static final long serialVersionUID = 1L;

+	private static PatternMatchers  _instance=new PatternMatchers();

+	public static PatternMatchers  getInstance()

+	{

+		return _instance;

+	}

+	

+	private PatternMatchers() {

+		super();

+	}

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/EdgeType.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/EdgeType.java
new file mode 100644
index 0000000..744d3cf
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/EdgeType.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal;

+

+/**

+ * The enumeration of the possible type of edges. These 

+ * edge types are used in the search graph and search plans.

+ */

+public enum EdgeType {

+	SUPERTYPEOF,

+	INSTANCEOF,

+	IN,

+    BELOW,

+	SOURCE,

+	TARGET,

+    NACCHECK,

+    PATTERN_CALL_PARAMETER,
+    PATTERN_CALL_STORAGE,

+    VARIABLE_ASSIGNMENT,
+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/HackedPatternMatcher.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/HackedPatternMatcher.java
new file mode 100644
index 0000000..17ad6a3
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/HackedPatternMatcher.java
@@ -0,0 +1,231 @@
+/*******************************************************************************
+ * Copyright (c) 2009-2010, Akos horvath and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Akos Horvath - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal;

+

+import java.util.Iterator;
+import java.util.List;
+import java.util.Vector;
+
+import org.eclipse.viatra2.core.IEntity;
+import org.eclipse.viatra2.core.IModelElement;
+import org.eclipse.viatra2.core.IModelManager;
+import org.eclipse.viatra2.gtasm.interpreter.exception.ViatraTransformationException;
+import org.eclipse.viatra2.gtasm.patternmatcher.ExecutionMode;
+import org.eclipse.viatra2.gtasm.patternmatcher.IMatching;
+import org.eclipse.viatra2.gtasm.patternmatcher.ParameterMode;
+import org.eclipse.viatra2.gtasm.patternmatcher.PatternCallSignature;
+import org.eclipse.viatra2.gtasm.patternmatcher.Scope;
+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherCompileTimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherRuntimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.callgraph.FlattenedPattern;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation.DummyOperation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation.SearchPlanOperation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.term.ITermHandler;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.enums.ContainmentMode;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.GTPattern;
+import org.eclipse.viatra2.logger.Logger;
+

+

+public class HackedPatternMatcher extends PatternMatcher {

+

+	FlattenedPattern[] flattenedPatterns = null;

+	

+	public HackedPatternMatcher(GTPattern pattern, Logger logger,

+			IModelManager manager, ITermHandler termHandler)

+			throws PatternMatcherCompileTimeException {

+		super(pattern, logger, manager, termHandler);

+		flattenedPatterns = root.getFlattenedPatterns(); 

+	}

+

+	@Override

+	//TODO: Can only be used when there is no Recursive call!!

+	public IMatching match(Object[] inputMapping,

+			PatternCallSignature[] signature) throws ViatraTransformationException {

+

+		for(FlattenedPattern pattern: flattenedPatterns){

+				IMatching frame = internalMatch(inputMapping, signature, pattern);

+				if(frame != null)

+					{// Checking IN/BELOW constraints on the result 

+					//TODO: Can be possible that it does not fulfil the Containment Constraints on the input parameters --> Use with caution with containment constraints! 

+					boolean constraintsFulfilled = true;

+		            for (int i = 0; constraintsFulfilled && i < signature.length; i++)

+		            	{

+		                    if (signature[i].getParameterMode() == ParameterMode.OUTPUT) { 

+		                        Scope s = signature[i].getParameterScope();

+		                        IEntity container = (IEntity) s.getParent();

+		                        Object obj = frame.lookup(i);

+		                        if (obj instanceof IModelElement) {

+		                            IModelElement me = (IModelElement) obj;

+		                            if (s.getContainmentMode() == ContainmentMode.IN) {

+		                                constraintsFulfilled = me.getNamespace().compareTo(container) == 0; 

+		                            } else if (s.getContainmentMode() == ContainmentMode.BELOW) {

+		                                constraintsFulfilled = me.isBelowNamespace(container);

+		                            }

+		                        } else {

+		                            // TODO Akos Horvath: what happens, if a formal parameter is a String, integer and it has a container constraint?

+		                        }

+		                    }

+		            	}

+		            if (constraintsFulfilled) 

+		            	return frame;

+					}

+			}

+		return null;

+	}

+	

+	//TODO: truehybrid approach does not work with the current version of the hackedpatternmacther-> do not know exactly why

+	// but does not generate the IncrementalRemote goal while it generates the incrementalpatternNode.

+	

+	private IMatching internalMatch(Object[] inputMapping,

+			PatternCallSignature[] signature,

+			FlattenedPattern flattenedPattern) throws ViatraTransformationException {

+		  for (int i = 0; i < signature.length; i++) {

+	            if (signature[i].getExecutionMode() == ExecutionMode.MULTIPLE_RESULTS) {

+					logger.debug("The method match(Object[], PatternCallSignature[] has been invoked in MULTIPLE_RESULTS execution mode.");

+					return null;

+	            }

+	        }

+	    	Integer[] quantificationOrder = new Integer[signature.length];

+	    	for (int i = 0; i < quantificationOrder.length; i++) {

+				quantificationOrder[i] = i;

+			}

+	    	

+    		// Key generator preparation based on the variables with forall quantifier

+            if (signature.length != quantificationOrder.length) {

+	            	 String[] context = {root.getPattern().getName()};

+	             	throw new PatternMatcherRuntimeException(

+	             			PatternMatcherErrorStrings.INTERNAL_QUANTIFICATION_AND_SIGNATURES_PARAMETER_MISMATCH

+	             			,context

+	             			,root.getPattern());

+	             	

+	            }

+	            int multipleUpperBound = 0;

+	            Vector<Integer> vector = new Vector<Integer>();

+	            for (int i = 0; i < quantificationOrder.length; i++) {

+	                Integer index = quantificationOrder[i];

+	                if (index < signature.length) {

+	                    if (signature[index].getExecutionMode() == ExecutionMode.MULTIPLE_RESULTS) {

+	                        if (i <= multipleUpperBound) {

+	                            vector.add(index);

+	                            multipleUpperBound++;

+	                        } else {

+	                        	 String[] context = {root.getPattern().getName()};

+	                         	throw new PatternMatcherRuntimeException(

+	                         			PatternMatcherErrorStrings.INTERNAL_QUANTIFICATION_ORDER

+	                         			,context

+	                         			,root.getPattern());

+	                        }

+	                    }

+	                } else {

+	                	 String[] context = {root.getPattern().getName()};

+                     	throw new PatternMatcherRuntimeException(

+                     			PatternMatcherErrorStrings.INTERNAL_QUANTIFICATION_ORDER

+                     			,context

+                     			,root.getPattern());

+	                }

+	            }

+	            final Integer[] keys = new Integer[vector.size()];

+	            vector.toArray(keys); 

+/*	            IKeyGenerator<MatchingKey, MatchingFrame> resultKeyGenerator = 

+	                new IKeyGenerator<MatchingKey, MatchingFrame>() {

+

+	                public MatchingKey calculateKey(MatchingFrame value) {

+	                    Object[] matchingKey = new Object[keys.length];

+	                    for (int i = 0; i < keys.length; i++) {

+	                        matchingKey[i] = value.getValue(keys[i]);

+	                    }

+	                    return new MatchingKey(matchingKey);

+	                }

+

+	    			public int size() {

+	    				return keys.length;

+	    			}

+	            };*/

+	            

+//	            // Matching table initalization

+	            

+	            MatchingFrame frame = new MatchingFrame(flattenedPattern);

+	            

+	        	// Initialization (IN/BELOW constraint processing)

+	            final Boolean[] adornment = new Boolean[signature.length]; 

+	    		Vector<Object> vec = new Vector<Object>();

+	            for (int i = 0; i < signature.length; i++) {

+	                if (signature[i].getParameterMode() == ParameterMode.INPUT) {

+	                    adornment[i] = true;

+	                    vec.add(inputMapping[i]);

+	                    frame.setValue(i, inputMapping[i]);

+	                } else {

+	                    adornment[i] = false;

+	                }

+	            }            

+	            

+	    		int strongestConstraint = 0;

+	            if (vec.size() == 0) {

+	                int largestDistance = 0;

+	                boolean hasInConstraint = false;

+	                for (int i = 0; i < signature.length; i++) {

+	                    Scope s = signature[i].getParameterScope();

+	                    int distance = 0;

+	                    IEntity parent = (IEntity) s.getParent();

+	                    for (distance = 0; !parent.equals(manager.getRoot()); distance++) {

+	                        parent = parent.getParent();

+	                    }

+

+	                    if (s.getContainmentMode() == ContainmentMode.IN) {

+	                        if (hasInConstraint && distance > largestDistance) {

+	                            largestDistance = distance;

+	                            strongestConstraint = i;

+	                        } else if (!hasInConstraint) {

+	                            hasInConstraint = true;

+	                            largestDistance = distance;

+	                            strongestConstraint = i;

+	                        }

+	                    } else if (s.getContainmentMode() == ContainmentMode.BELOW) {

+	                        if (!hasInConstraint && distance > largestDistance) {

+	                            largestDistance = distance;

+	                            strongestConstraint = i;

+	                        }

+	                    }

+	                }

+	                adornment[strongestConstraint] = true;

+	            }

+

+	            SearchPlanOperation[] t = new SearchPlanOperation[1];

+	            List<SearchPlanOperation> operations =  flattenedPattern.generateSearchPlan(adornment, manager);

+	            operations.add(new DummyOperation()); //some funky legacy code from Gergely Varro to be able to separate searchplan along recursive code

+	            

+	            SearchPlan searchPlan = new SearchPlan(operations.toArray(t)); 

+	            

+	            // no input parameter, have to create an iterator of possible choices

+	            if (vec.size() == 0) {

+	            	Scope s = signature[strongestConstraint].getParameterScope();

+	                IEntity parent = (IEntity) s.getParent();

+	            	Iterator<IModelElement> i = (s.getContainmentMode() == ContainmentMode.IN 

+	            			? parent.getElementsInNamespace().iterator()

+	            			: parent.getAllElementsInNamespace().iterator());

+	            	for (; i.hasNext();) {

+	            		MatchingFrame framenoBound = new MatchingFrame(flattenedPattern);

+	            		framenoBound.setValue(strongestConstraint, i.next());

+	            		if(searchPlan.execute(framenoBound))

+	    	           		return framenoBound;

+					}

+	            }

+	            else //there is a bound input parameter*/

+	           	if(searchPlan.execute(frame))

+	           		return frame;

+	           	else

+	           		return null;

+	            

+	            

+			return null;

+	}

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/IKeyGenerator.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/IKeyGenerator.java
new file mode 100644
index 0000000..4a94ef0
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/IKeyGenerator.java
@@ -0,0 +1,17 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal;

+

+public interface IKeyGenerator<KeyType, ValueType> {

+    public KeyType calculateKey(ValueType value);

+    public int size();

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/MatchingFrame.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/MatchingFrame.java
new file mode 100644
index 0000000..a03221c
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/MatchingFrame.java
@@ -0,0 +1,150 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal;

+

+import org.eclipse.viatra2.gtasm.patternmatcher.IMatching;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.callgraph.FlattenedPattern;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.definitions.Variable;
+

+/**

+ * MatchingFrame represents an array that contains the actual

+ * mappings of variables to constants. A MatchingFrame maintains

+ * a reference to a corresponding FlattenedPattern.

+ * 

+ * The following mappings are used by the interpreted engine:

+ * VariableType => PatternVariable

+ * ValueType    => AnyModelElement

+ */

+public class MatchingFrame implements Cloneable,IMatching {

+

+    /**

+     * An internal, array-based representation of a matching.

+     * Arrays are indexed by integers and contain values showing

+     * the actual values.

+     * 

+     * If a MatchingFrame represents a matching for a recursive

+     * FlattenedPattern, then parent points to the 

+     * matching frame which is extended to get this matching. 

+	 */

+	private MatchingFrame parent;

+

+	/**

+     * The pattern variant for which this MatchingFrame is a

+     * matching. 

+	 */

+	private FlattenedPattern pattern;

+

+	/**

+     * The array that physically holds the values.

+	 */

+    private Object[] frame;

+

+    public MatchingFrame(FlattenedPattern pattern) {

+        this.parent = null;

+        this.pattern = pattern;

+        // this.frame = (IModelElement[]) new Object[pattern.getFrameSize()];

+        this.frame = new Object[pattern.getFrameSize()];

+    }

+    

+    MatchingFrame(FlattenedPattern pattern, MatchingFrame parent) {

+        this.parent = parent;

+        this.pattern = pattern;

+        this.frame = new Object[pattern.getFrameSize()];

+    }

+

+    /**

+     * 

+     * @param position

+     * @return

+     */

+	public Object getValue(Integer position) {

+		// TODO gervarro: return (position < frame.length ? frame[position] : pattern.get);

+        return frame[position];

+	}

+    

+    /**

+     * 

+     * @param position

+     * @param value

+     */

+    public void setValue(Integer position, Object value) {

+        frame[position] = value;

+    }

+    

+    public boolean testAndSetValue(Integer position, Object value) {

+        if (frame[position] == null) {

+            frame[position] = value;

+            return true;

+        } else {

+            return frame[position].equals(value);

+        }

+    }

+    

+    /**

+     * @return the parent

+     */

+    public MatchingFrame getParent() {

+        return parent;

+    }

+

+    /**

+     * @param parent the parent to set

+     */

+    public void setParent(MatchingFrame parent) {

+        this.parent = parent;

+    }

+

+    /**

+     * @return the pattern

+     */

+    public FlattenedPattern getPattern() {

+        return pattern;

+    }

+

+    /**

+     * @param pattern the pattern to set

+     */

+    public void setPattern(FlattenedPattern pattern) {

+        this.pattern = pattern;

+    }

+    

+    public Object clone() {

+        MatchingFrame clone = new MatchingFrame(pattern, parent);

+        clone.frame = frame.clone();

+        return clone;

+    }

+    

+    public String toString() {

+    	StringBuffer buf = new StringBuffer();

+    	for (int i = 0; i < frame.length; i++) {

+			buf.append("frame[" + i + "]\t" + frame[i].toString() + "\n");

+		}

+    	return buf.toString();

+    }

+

+    public Object lookup(Variable variable) {

+        return null;

+    }

+

+    public Object lookup(int position) {

+        if (position >= 0 && position < frame.length) {

+            return frame[position];

+        } else {

+            // TODO gervarro: Exception or return null;

+            return null;

+        }

+    }

+    

+    public int size() {

+    	return frame.length;

+    }

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/MatchingKey.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/MatchingKey.java
new file mode 100644
index 0000000..cc0a800
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/MatchingKey.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal;

+

+/**

+ * VariableType will be mapped to PatternVariable in the interpreted

+ * engine.

+ **/

+public class MatchingKey {

+    Object[] keys;

+    

+    public MatchingKey(Object[] keys) {

+        this.keys = keys;

+    }

+    

+    public boolean equals(Object other) {

+        if (other != null && other instanceof MatchingKey) {

+            MatchingKey otherKey = (MatchingKey) other;

+            for (int i = 0; i < keys.length; i++) {

+                if (! keys[i].equals(otherKey.keys[i])) {

+                    return false;

+                }

+            }

+            return true;

+        } else {

+            return false;

+        }

+    }

+    

+    public int hashCode() {

+        return toString().hashCode();

+    }

+    

+    public String toString() {

+        StringBuffer key = new StringBuffer();

+        for (int i = 0; i < keys.length; i++) {

+            key.append("_" + keys[i].toString()); 

+        }

+        return key.toString();

+    }

+    

+    public Object[] toArray() {

+    	return keys;

+    }

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/MatchingTable.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/MatchingTable.java
new file mode 100644
index 0000000..a8dad76
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/MatchingTable.java
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal;

+

+import java.util.AbstractCollection;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.NoSuchElementException;
+
+import org.eclipse.viatra2.gtasm.patternmatcher.IMatching;
+

+

+

+public class MatchingTable extends AbstractCollection<IMatching> {

+    private Map<MatchingKey,Collection<MatchingFrame>> matchings;

+    

+    private class MatchingIterator implements Iterator<IMatching> {

+        Iterator<Entry<MatchingKey, Collection<MatchingFrame>>> iterator;

+        

+        private MatchingIterator() {

+            iterator = matchings.entrySet().iterator();

+        }

+

+        public boolean hasNext() {

+            return iterator.hasNext();

+        }

+

+        public IMatching next() {

+            if (hasNext()) {

+                Iterator<MatchingFrame> frameIterator = iterator.next().getValue().iterator();

+                if (frameIterator.hasNext()) {

+                    return frameIterator.next();

+                } else {

+                    throw new NoSuchElementException();

+                }

+            } else {

+                throw new NoSuchElementException();

+            }

+        }

+

+        public void remove() {

+            throw new UnsupportedOperationException();

+        }

+    }

+

+    MatchingTable() {

+        matchings = new HashMap<MatchingKey, Collection<MatchingFrame>>();

+    }

+    

+    @Override

+    public Iterator<IMatching> iterator() {

+        return new MatchingIterator();

+    }

+

+    @Override

+    public int size() {

+        return matchings.keySet().size();

+    }

+

+    void put(MatchingKey key, MatchingFrame value) {

+        Collection<MatchingFrame> coll = matchings.get(key);

+        if (coll == null) {

+            coll = new HashSet<MatchingFrame>();

+        }

+        coll.add(value);

+        matchings.put(key, coll);

+    }

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/PatternMatcher.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/PatternMatcher.java
new file mode 100644
index 0000000..3bb7e6c
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/PatternMatcher.java
@@ -0,0 +1,470 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal;

+

+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Random;
+import java.util.Vector;
+
+import org.eclipse.viatra2.core.IEntity;
+import org.eclipse.viatra2.core.IModelElement;
+import org.eclipse.viatra2.core.IModelManager;
+import org.eclipse.viatra2.gtasm.interpreter.exception.ViatraTransformationException;
+import org.eclipse.viatra2.gtasm.patternmatcher.ExecutionMode;
+import org.eclipse.viatra2.gtasm.patternmatcher.IMatching;
+import org.eclipse.viatra2.gtasm.patternmatcher.ParameterMode;
+import org.eclipse.viatra2.gtasm.patternmatcher.PatternCallSignature;
+import org.eclipse.viatra2.gtasm.patternmatcher.Scope;
+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherCompileTimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherRuntimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.callgraph.PatternNode;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.rgg.MagicSet;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.rgg.RemoteGoal;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.term.ITermHandler;
+import org.eclipse.viatra2.gtasm.patternmatcher.patterns.IPatternMatcher;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.enums.ContainmentMode;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.enums.ValueKind;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.GTPattern;
+import org.eclipse.viatra2.logger.Logger;
+

+

+

+/**

+ * PatternMatcher is the (executable) run-time equivalent

+ * of a GTPattern.

+ *

+ * The whole pattern matching engine is not represented as a single object, but

+ * the container ASM interpreter module should consist of a set of

+ * PatternMatcher objects.

+ *

+ * PatternMatcher objects (including all its subordinate data structures)

+ * are generated by PatternBuilders.

+ *

+ * @author Gergely Varro, Akos Horvath

+ */

+public class PatternMatcher implements IPatternMatcher {

+    protected Logger logger;

+    protected IModelManager manager;

+    protected ITermHandler termHandler;

+	protected PatternNode root;

+    protected Map<String,Map<String,RemoteGoal>> rggMapping;

+
+    protected Random random = null;
+
+    public PatternMatcher( Logger logger, IModelManager manager, ITermHandler termHandler)
+			throws PatternMatcherCompileTimeException {
+    	this.logger = logger;
+		this.manager = manager;
+		this.termHandler = termHandler;
+		}
+

+    public PatternMatcher(GTPattern pattern, Logger logger, IModelManager manager, ITermHandler termHandler)

+        	throws PatternMatcherCompileTimeException {

+        this.logger = logger;

+        this.manager = manager;

+        this.termHandler = termHandler;

+        this.root = new PatternNode(this, pattern);

+        this.rggMapping = new HashMap<String, Map<String,RemoteGoal>>();

+    }

+

+    public boolean match(Object[] inputMapping) throws ViatraTransformationException {

+        PatternCallSignature[] signature =

+            new PatternCallSignature[inputMapping.length];

+        for (int i = 0; i < inputMapping.length; i++) {

+            signature[i] = new PatternCallSignature();

+            signature[i].setExecutionMode(ExecutionMode.SINGLE_RESULT);

+

+            if (inputMapping[i] == null || inputMapping[i].equals(ValueKind.UNDEF_LITERAL)) {

+                signature[i].setParameterMode(ParameterMode.OUTPUT);

+            } else {

+                signature[i].setParameterMode(ParameterMode.INPUT);

+            }

+            Scope scope = new Scope(Scope.DEFAULT_MODE, manager.getRoot());

+            signature[i].setParameterScope(scope);

+        }

+        return (match(inputMapping, signature) != null);

+    }

+

+    public IMatching match(Object[] inputMapping,

+    		PatternCallSignature[] signature) throws ViatraTransformationException {

+        for (int i = 0; i < signature.length; i++) {

+            if (signature[i].getExecutionMode() == ExecutionMode.MULTIPLE_RESULTS) {

+            	String[] context = {root.getPattern().getName()};
+				throw new PatternMatcherRuntimeException(
+						PatternMatcherErrorStrings.INTERNAL_PATTERNCALL_CHOOSE_WITH_MULTIPLERESULT
+								,context
+								,root.getPattern());
+            	//logger.warning("The method match(Object[], PatternCallSignature[] has been invoked in MULTIPLE_RESULTS execution mode.");

+				//return null;

+            }

+        }

+    	Integer[] quantificationOrder = new Integer[signature.length];

+    	for (int i = 0; i < quantificationOrder.length; i++) {

+			quantificationOrder[i] = i;

+		}

+    	Collection<IMatching> solutions =

+    		matchAll(inputMapping, signature, quantificationOrder);

+    	for (IMatching matching : solutions) {

+			return matching;

+		}

+    	return null;

+    }

+

+ /*   public MatchingFrame matchFuture(Object[] inputMapping,

+            PatternCallSignature[] signature) {

+        try {

+        	// Initialization (IN/BELOW constraint processing)

+            final Boolean[] adornment = new Boolean[signature.length];

+    		Vector<Object> vec = new Vector<Object>();

+    		Vector<Integer> freeVariables = new Vector<Integer>();

+    		int strongestConstraint = 0;

+    		int smallestWeight = 0;

+    		Scope s = signature[0].getParameterScope();

+    		if (s.getContainmentMode() == ContainmentMode.IN) {

+    			smallestWeight = ((IEntity) s.getParent()).getContents().size();

+    		} else if (s.getContainmentMode() == ContainmentMode.BELOW) {

+    			smallestWeight = ((IEntity) s.getParent()).getAllComponents().size();

+    		}

+

+            for (int i = 0; i < signature.length; i++) {

+            	s = signature[i].getParameterScope();

+            	if (signature[i].getParameterMode() == ParameterMode.INPUT) {

+            		adornment[i] = true;

+            		vec.add(inputMapping[i]);

+            		if (s.getContainmentMode() == ContainmentMode.IN &&

+            				!((IEntity) s.getParent()).getContents().contains(inputMapping[i]) ||

+            				s.getContainmentMode() == ContainmentMode.BELOW &&

+            				!((IEntity) s.getParent()).getAllComponents().contains(inputMapping[i])) {

+            			logger.warning(FAILING_CONTAINMENT_CONSTRAINT);

+            			return null;

+            		}

+            	} else {

+            		adornment[i] = false;

+            		freeVariables.add(i);

+            	}

+    			if (s.getContainmentMode() == ContainmentMode.IN) {

+    	            if (smallestWeight > ((IEntity) s.getParent()).getContents().size()) {

+    	            	smallestWeight = ((IEntity) s.getParent()).getContents().size();

+    	            	strongestConstraint = i;

+    	            }

+    			} else if (s.getContainmentMode() == ContainmentMode.BELOW) {

+    	            if (smallestWeight > ((IEntity) s.getParent()).getAllComponents().size()) {

+        	            smallestWeight = ((IEntity) s.getParent()).getAllComponents().size();

+        	            strongestConstraint = i;

+    	            }

+    			}

+            }

+            adornment[strongestConstraint] = (freeVariables.size() == signature.length

+            		? true : adornment[strongestConstraint]);

+

+            // Preparing rule/goal graphs

+            Map<String, RemoteGoal> rggRoots = new HashMap<String, RemoteGoal>();

+            RemoteGoal main = root.buildRuleGoalGraph(adornment,rggRoots);

+

+            // Magic set initialization

+            if (freeVariables.size() == signature.length) {

+            	s = signature[strongestConstraint].getParameterScope();

+            	Iterator<IModelElement> i = (s.getContainmentMode() == ContainmentMode.IN

+            			? ((IEntity) s.getParent()).getContents().iterator()

+            					: ((IEntity) s.getParent()).getAllComponents().iterator());

+            	for (; i.hasNext();) {

+    				Object[] input = new Object[1];

+    				input[0] = i.next();

+    				main.getMagicSet().addArray(new MatchingKey(input));

+    			}

+            } else {

+            	Object[] input = new Object[vec.size()];

+            	vec.toArray(input);

+            	main.getMagicSet().addArray(new MatchingKey(input));

+            }

+

+            // Initial rule/goal graph synchronization

+            boolean isModified = false;

+            for (RemoteGoal goal : rggRoots.values()) {

+            	isModified = isModified || goal.synchronize();

+            }

+

+            // Pattern matching

+            /*

+            while (isModified) {

+            	isModified = false;

+            	// Calculation phase

+            	for (MatchingFrame frame = null; (frame = main.match(signature, freeVariables)) != null; ) {

+            		return frame;

+            	}

+            	for (RemoteGoal goal : rggRoots.values()) {

+            		if (!goal.equals(main)) {

+            			goal.matchAll();

+            		}

+            	}

+            	// Synchronization phase

+            	for (RemoteGoal goal : rggRoots.values()) {

+            		isModified = (goal.synchronize() ? true : isModified);

+				}

+            }

+

+        } catch (PatternMatcherRuntimeException e) {}

+        return null;

+    }*/

+

+    public Collection<IMatching> matchAll(Object[] inputMapping,

+            PatternCallSignature[] signature,

+            Integer[] quantificationOrder) throws ViatraTransformationException {

+        try {

+        	// Key generator preparation based on the variables with forall quantifier

+            if (signature.length != quantificationOrder.length)
+            	{

+                String[] context = {root.getPattern().getName()};
+            	throw new PatternMatcherRuntimeException(
+            			PatternMatcherErrorStrings.INTERNAL_QUANTIFICATION_AND_SIGNATURES_PARAMETER_MISMATCH
+            			,context
+            			,root.getPattern());

+            	}

+            int multipleUpperBound = 0;

+            Vector<Integer> vector = new Vector<Integer>();

+            for (int i = 0; i < quantificationOrder.length; i++) {

+                Integer index = quantificationOrder[i];

+                if (index < signature.length) {

+                    if (signature[index].getExecutionMode() == ExecutionMode.MULTIPLE_RESULTS) {

+                        if (i <= multipleUpperBound) {

+                            vector.add(index);

+                            multipleUpperBound++;

+                        } else {

+                            String[] context = {root.getPattern().getName()};
+                        	throw new PatternMatcherRuntimeException(
+                        			PatternMatcherErrorStrings.INTERNAL_QUANTIFICATION_ORDER
+                        			,context
+                        			,root.getPattern());

+                        }

+                    }

+                } else {

+                	 String[] context = {root.getPattern().getName()};
+                 	throw new PatternMatcherRuntimeException(
+                 			PatternMatcherErrorStrings.INTERNAL_QUANTIFICATION_ORDER
+                 			,context
+                 			,root.getPattern());

+                }

+            }

+            final Integer[] keys = new Integer[vector.size()];

+            vector.toArray(keys);

+            IKeyGenerator<MatchingKey, MatchingFrame> resultKeyGenerator =

+                new IKeyGenerator<MatchingKey, MatchingFrame>() {

+

+                public MatchingKey calculateKey(MatchingFrame value) {

+                    Object[] matchingKey = new Object[keys.length];

+                    for (int i = 0; i < keys.length; i++) {

+                        matchingKey[i] = value.getValue(keys[i]);

+                    }

+                    return new MatchingKey(matchingKey);

+                }

+

+    			public int size() {

+    				return keys.length;

+    			}

+            };

+

+            // Matching table initialization

+            MatchingTable result = new MatchingTable();

+            if (signature.length == 0) {

+            	return result;

+            }

+

+        	// Initialization (IN/BELOW constraint processing)

+            final Boolean[] adornment = new Boolean[signature.length];

+    		Vector<Object> vec = new Vector<Object>();

+            for (int i = 0; i < signature.length; i++) {

+                if (signature[i].getParameterMode() == ParameterMode.INPUT) {

+                    adornment[i] = true;

+                    vec.add(inputMapping[i]);

+                } else {

+                    adornment[i] = false;

+                }

+            }

+

+    		int strongestConstraint = 0;

+            if (vec.size() == 0) {

+                int largestDistance = 0;

+                boolean hasInConstraint = false;

+                for (int i = 0; i < signature.length; i++) {

+                    Scope s = signature[i].getParameterScope();

+                    int distance = 0;

+                    IEntity parent = (IEntity) s.getParent();

+                    for (distance = 0; !parent.equals(manager.getRoot()); distance++) {

+                        parent = parent.getParent();

+                    }

+

+                    if (s.getContainmentMode() == ContainmentMode.IN) {

+                        if (hasInConstraint && distance > largestDistance) {

+                            largestDistance = distance;

+                            strongestConstraint = i;

+                        } else if (!hasInConstraint) {

+                            hasInConstraint = true;

+                            largestDistance = distance;

+                            strongestConstraint = i;

+                        }

+                    } else if (s.getContainmentMode() == ContainmentMode.BELOW) {

+                        if (!hasInConstraint && distance > largestDistance) {

+                            largestDistance = distance;

+                            strongestConstraint = i;

+                        }

+                    }

+                }

+                adornment[strongestConstraint] = true;

+            }

+

+            // Preparing rule/goal graphs

+            String adornmentString = Arrays.deepToString(adornment);

+            Map<String, RemoteGoal> rggRoots = rggMapping.get(adornmentString);

+            if (rggRoots == null) {

+                rggRoots = new HashMap<String, RemoteGoal>();

+                root.buildRuleGoalGraph(adornment,rggRoots);

+                rggMapping.put(adornmentString, rggRoots);

+            }

+            RemoteGoal main = rggRoots.get(RemoteGoal.generateID(root, adornment));

+

+            // Magic set initialization

+            if (vec.size() == 0) {

+                MagicSet ms = main.getMagicSet();

+            	Scope s = signature[strongestConstraint].getParameterScope();

+                IEntity parent = (IEntity) s.getParent();

+            	Iterator<IModelElement> i = (s.getContainmentMode() == ContainmentMode.IN

+            			? parent.getElementsInNamespace().iterator()

+            			: parent.getAllElementsInNamespace().iterator());

+            	for (; i.hasNext();) {

+					Object[] input = new Object[1];

+					input[0] = i.next();

+					ms.addArray(new MatchingKey(input));

+				}

+            } else {

+            	Object[] input = new Object[vec.size()];

+            	vec.toArray(input);

+            	main.getMagicSet().addArray(new MatchingKey(input));

+            }

+

+            // Initial rule/goal graph synchronization

+            boolean isModified = false;

+            for (RemoteGoal goal : rggRoots.values()) {

+            	isModified = (goal.synchronize() ? true :  isModified);

+            }

+

+            // Pattern matching

+            while (isModified) {

+            	isModified = false;

+            	// Calculation phase

+            	for (RemoteGoal goal : rggRoots.values()) {

+            		goal.matchAll();

+            	}

+            	// Synchronization phase

+            	for (RemoteGoal goal : rggRoots.values()) {

+            		isModified = (goal.synchronize() ? true : isModified);

+				}

+            }

+
+            //for debug purposes
+           //System.out.println("**********Final DEBUG*********");
+            //for (RemoteGoal goal : rggRoots.values()) {
+            //    goal.debug();
+            //}
+
+

+            // Postprocessing (filling the matching table)

+            for (MatchingFrame frame : main) {

+            	boolean constraintsFulfilled = true;

+            	// Checking IN/BELOW constraints on the result

+            	for (int i = 0; constraintsFulfilled && i < signature.length; i++) {

+                    if (signature[i].getParameterMode() == ParameterMode.OUTPUT) {

+                        Scope s = signature[i].getParameterScope();

+                        IEntity container = (IEntity) s.getParent();

+                        Object obj = frame.getValue(i);

+                        if (obj instanceof IModelElement) {

+                            IModelElement me = (IModelElement) obj;

+                            if (s.getContainmentMode() == ContainmentMode.IN) {

+                                constraintsFulfilled = me.getNamespace().compareTo(container) == 0;

+                            } else if (s.getContainmentMode() == ContainmentMode.BELOW) {

+                                constraintsFulfilled = me.isBelowNamespace(container);

+                            }

+                        } else {

+                            // TODO gervarro: what happens, if a formal parameter is a String, integer and it has a container constraint?

+                        }

+                    }

+            	}

+            	if (constraintsFulfilled) {

+                 	// If all constraints are fulfilled, add the frame to the matching table

+            		result.put(resultKeyGenerator.calculateKey(frame), frame);

+            	}

+			}

+            // Clean up for all runtime data structures (except for the result)

+            for (RemoteGoal rg : rggRoots.values()) {

+                rg.init();

+            }

+            return result;

+        } catch (PatternMatcherRuntimeException e) {

+        	throw e.addNewStackElement(root.getPattern());

+        }

+    }

+	public IMatching matchRandomly(Object[] inputMapping,
+			PatternCallSignature[] signature) throws ViatraTransformationException {
+		if(random == null){
+			random = new Random();
+		}
+		// executionMode and quantification order created to mimic forall rule in matchAll
+		Integer[] quantificationOrder = new Integer[inputMapping.length];
+		int quantificationOrderMultipleIndex = 0;
+		int quantificationOrderNonMultipleIndex = signature.length-1;
+		for(int j = 0; j < signature.length; j++)
+			{
+			// output parameters are in the front of the array
+			if(signature[j].getParameterMode() == ParameterMode.OUTPUT)
+				{signature[j].setExecutionMode(ExecutionMode.MULTIPLE_RESULTS);
+				 quantificationOrder[quantificationOrderMultipleIndex] = j;
+				 quantificationOrderMultipleIndex++;
+				}
+			// other parameters in the back
+			else
+				{
+				 quantificationOrder[quantificationOrderNonMultipleIndex] = j;
+				 quantificationOrderNonMultipleIndex--;
+				}
+			}
+
+		Collection<IMatching> allMatches = matchAll(inputMapping, signature, quantificationOrder);
+		if (allMatches == null || allMatches.isEmpty()) return null;
+		// change from Math.random()
+		else return (IMatching) allMatches.toArray()[random.nextInt(allMatches.size())];
+		// TODO suboptimal
+	}
+

+    /**

+     *

+     * @return the logger

+     */

+    public Logger getLogger() {

+        return logger;

+    }

+

+    /**

+     * @return the termHandler

+     */

+    public ITermHandler getTermHandler() {

+        return termHandler;

+    }

+

+    public IModelManager getModelManager() {

+    	return manager;

+    }
+
+

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/PatternMatcherErrorStrings.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/PatternMatcherErrorStrings.java
new file mode 100644
index 0000000..3a9a125
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/PatternMatcherErrorStrings.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal;

+

+public class PatternMatcherErrorStrings {

+	
+	
+	 public static final String INTERNAL_EDGETYPE_NOT_SUPPORTED  = "[INTERNAL ERROR] The {1} SearchGraphEdge type of the {2} element is not supported by any current SearchPlanOperation.";
+	 public static final String INTERNAL_PATTERNCALLNODE_EXCEPTION = "[INTERNAL_ERROR] The call node edge of the {1} Pattern call is not checked during the search plan generation.";
+	 public static final String INTERNAL_PATTERNCALLNODE_WRONGPARAMETER_ORDER = "[INTERNAl ERROR] The pattern call edge  of the {1} call is traversed (a tree edge) before its pattern call node was traversed.";
+	 public static final String INTERNAL_PATTERNCALLNODE_EDGE_EXCEPTION = "[INTERNAL ERROR] The tree edge of the {1} unbounded input node is not its input edge to the {2} pattern call." ;
+	 public static final String INTERNAL_PATTERNCALLNODE_EDGE_TRAVERSAL_EXCEPTION = "[INTERNAL ERROR] The {1} pattern call edge is a tree edge before its corresponding {2} pattern call node was traversed.";
+	 public static final String INTERNAL_INCREMENTALLY_MATCED_PATTERN_HAS_NO_PATTERNMATCHER = "[INTERNAL ERROR] The 1{} incrementally matched pattern does not have a valid pattern matcher: {2}";
+	 public static final String INTERNAL_FORMAL_AND_ACTUAL_PARAMETER_MISMATCH = "[INTERNAL ERROR] The number of formal and actual parameters for the {1} pattern call do not match.";
+	 public static final String INTERNAL_QUANTIFICATION_AND_SIGNATURES_PARAMETER_MISMATCH = "[INTERNAL ERROR] The number of signatures and quantification orders for the {1} pattern call do not match.";
+	 public static final String INTERNAL_QUANTIFICATION_ORDER = "[INETRNAL ERROR] Error in the quantification order of the {1}'s pattern call.";
+	 public static final String INTERNAL_BODYNODE_INJECTIVITYCONSTRAINT_ALREADYUSED = "[INTERNAL ERROR] The {1}. index is already added to the injectivity check set of the {2} pattern body " ;
+	 public static final String INTERNAL_FLATTENED_PATTERN_BUILD = "[INTERNAL ERROR] An error happened during the creation of the Rule GOal GRaph of the {1} pattern.";
+	 public static final String INTERNAL_SEARCHPLAN_INIT_FAILED = "[INTERNAL ERROR] The search plan initaliziation of the {1} GT Patten failed.";
+	 public static final String INTERNAL_INCREMENTAL_PATTERNNODE_ROOT = "[INTERNAL ERROR]: THe {1} incrementally matched pattern (node) is the root of the Rule goal graph (should use incremental pattern matcher instead)";
+     public static final String INTERNAL_PATTERNCALL_ADORNED_INPUT_PARAMS = "[INTERNAL ERROR] An error happened during the evaluation of the adorned input parameters of the {1} pattern";
+     public static final String INTERNAL_PATTERNCALL_CHOOSE_WITH_MULTIPLERESULT = "[INTERNAL ERROR] An error happened during the evaluation of the {1} pattern. It was invoked in a single result mode but its input parameters are marked to be multiple results.";
+     public static final String INTERNAL_ERROR_DANGLING_RELATION_FAILED = "[INTERNAL ERROR] Dangling relation element evaluation failed: {1}";
+     public static final String INTERNAL_EMPTY_VALUE = "[INTERNAL ERROR] The '{1}' element in the {2} operation has an empty value (null)";
+   	 public static final String INTERNAL_ISRECURSIVE_ON_NONROOT = "[INTERNAL ERROR] The '{1}' pattern is monitored for recursive behaviour when it is not a root pattern element";
+     
+     public static final String INTERNAL_SEARCGRAPH_RELATION_TARGET_MISSING = "The target of the '{1}' relation cannot be resolved";
+   	 public static final String INTERNAL_SEARCGRAPH_RELATION_SOURCE_MISSING = "The source '{2}' of the '{1}' relation cannot be resolved";
+   	 public static final String INTERNAL_SEARCGRAPH_RELATIONSHIP_SOURCE_MISSING = "The source '{2}' of the '{1}' relationship cannot be resolved";
+  	 public static final String INTERNAL_SEARCGRAPH_RELATION_MISSING = "The relation '{1}' cannot be resolved";
+
+     public static final String NOT_A_MODELELEMENT_EXTEND = "Type mismatch: {2} did not evaluate to a model element (entity or relation), but to type {3} instead. Developer's note: error occurred during the '{1}' type extend operation.";
+     public static final String NOT_A_MODELELEMENT_CHECK = "Type mismatch: {2} did not evaluate to a model element (entity or relation), but to type {3} instead. Developer's note: error occurred during the '{1}' type check operation.";
+     
+     public static final String INTERNAL_ALLENTITIES = "[INTERNAL ERROR] The '{1}' element is extended through the all entites operation but its corresponding element in the search graph is not conform with this operation";
+	 public static final String INTERNAL_ALLRELATIONS = "[INTERNAL ERROR] The '{1}' element is extended through the all relation operation but its corresponding element in the search graph is not conform with this operation";
+	 
+	 public static final String INTERNAL_OPERATION_NOT_SUPPORTED = "[INTERNAL ERROR] The '{1}' type VPM edge related to the '{2}' element is not supported as a check operation.";
+	 public static final String INTERNAL_OPERATION_NOT_POSSIBLE = "[INTERNAL ERROR] The '{1}' element generates a '{2}' type operation that is not allowed.";
+	 public static final String INTERNAL_OPERATION_NOT_USED = "[INTERNAL ERROR] The operation '{1}' is not used by the current patten matcher";
+     		
+ 	 public static final String NOT_A_MODELELEMENT = "The '{1}' element in the {2} operation is not a ModelElement (Entity or Relation)";
+ 	 
+	 public static final String NO_TERM_IN_NAC_CALLS = "The {1}. input parameter in the {2} NAC call is not a Variable.";
+	 public static final String NO_TERM_IN_PATTERN_CALLS = "The {1}. input parameter in the {2} pattern call is not a Variable."; 
+	 public static final String MULTIBODY_OR_RECURSIVE_PATTERN_ON_RHS = "The pattern on the RHS of the gtRule cannot have alternative pattern bodies or be recursive.";
+	 public static final String CHECK_EXPRESSION_NOT_EVALUATED_TO_A_BOOLEAN = "The Check expression in the {1} pattern did not evaluate to a boolean";
+	 public static final String ILLEGAL_INPUT_PARAMETER = "The {1}. input parameter in the {2} GT pattern call is not a Variable.";
+	 

+	 public static final String NO_TERM_HANDLER = "Term handler has not been specified. Term evaluation will not be executed";

+	 public static final String FAILING_CONTAINMENT_CONSTRAINT = "Input parameter does not fulfill its containment constraint.";
+	 public static final String NAC_CALL_WITH_UNBOUND_PARAMETER = "False invocation of the '{1}' nac pattern. Its input '{2}' parameter is unbound and it is also an output variable for its invoking pattern. Negative patterns cannot output variables ";
+	 public static final String VARIABLE_VARIABLEASSIGMENT_MISSING = "The {1} variable of the assigment cannot be locally resolved. The LS matcher does not support this";
+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/SearchPlan.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/SearchPlan.java
new file mode 100644
index 0000000..812b186
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/SearchPlan.java
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal;

+

+

+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherRuntimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation.SearchPlanOperation;
+import org.eclipse.viatra2.logger.Logger;
+

+/**

+ * A SearchPlan is an unmodifiable array of 

+ * SearchPlanOperations. PatternSignatures are supposed

+ * to be fixed 

+ */

+public class SearchPlan {

+	private SearchPlanOperation[] operations;

+    private int currentOperation;

+	

+	public SearchPlan(SearchPlanOperation[] operations){

+		this.operations = operations;

+        this.currentOperation = -1;

+	}

+    

+    private void init(MatchingFrame frame) 

+        throws PatternMatcherRuntimeException {

+        if (currentOperation == -1) {

+            currentOperation++;

+            operations[currentOperation].preprocess(frame);

+        } else if (currentOperation == operations.length - 1) {

+            currentOperation--;

+        } else {
+        	String[] context = {frame.getPattern().getParent().getPattern().getName()};

+            throw new PatternMatcherRuntimeException(
+            		PatternMatcherErrorStrings.INTERNAL_SEARCHPLAN_INIT_FAILED
+            		,context
+            		,frame.getPattern().getParent().getPattern());

+        }

+    }

+	

+	/**

+     * Calculates the cost of the search plan.

+	 */

+	public double cost() {

+		/* default generated stub */;

+		return 0.0;

+	}

+

+    public boolean execute(MatchingFrame frame) 

+        throws PatternMatcherRuntimeException {

+        int upperBound = operations.length - 1;

+        //try {

+            init(frame);

+            while (currentOperation >= 0 && currentOperation < upperBound) {

+                if (operations[currentOperation].execute(frame)) {

+                    currentOperation++;

+                    operations[currentOperation].preprocess(frame);

+                } else {

+                    operations[currentOperation].postprocess(frame);

+                    currentOperation--;

+                }

+            }

+        //TODO: additional stack trace information can be added if needed at this point (LS search plan execution)
+        //} catch (PatternMatcherRuntimeException e) {

+        //e.addNewStackElement(operations[currentOperation].getErrorfulElement(frame));
+        //    throw e;

+        //}

+        return (currentOperation == upperBound);

+    }

+    

+    public void printDebugInformation(Logger logger) {

+        for (int i = 0; i < operations.length; i++) {

+            logger.debug("[" + i + "]\t" + operations[i].toString());

+        }

+    }

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/SearchPlanKey.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/SearchPlanKey.java
new file mode 100644
index 0000000..729e170
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/SearchPlanKey.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal;

+

+import org.eclipse.viatra2.gtasm.patternmatcher.PatternCallSignature;
+import org.eclipse.viatra2.gtasm.patternmatcher.Scope;
+

+public class SearchPlanKey {

+

+    SearchPlanKey(PatternCallSignature[] signature, Scope patternScope) {

+        

+    }

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/VPMModelElementType.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/VPMModelElementType.java
new file mode 100644
index 0000000..c05e1cc
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/VPMModelElementType.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal;

+

+/**

+ * @author Akos Horvath

+ *

+ */

+public enum VPMModelElementType {

+	

+	ENTITY,

+	RELATION,

+	OPERATION,

+//	MODELELEMENT

+

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/VariableID.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/VariableID.java
new file mode 100644
index 0000000..58214b7
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/VariableID.java
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal;

+

+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.GTPattern;
+

+public class VariableID implements Comparable {

+	private GTPattern pattern;

+	private Integer uid;

+	private String variable;

+

+    public VariableID(GTPattern pattern, int uid, String variable) {

+		this.pattern = pattern;

+		this.uid = uid;

+		this.variable = variable;

+	}

+	

+	public boolean equals(Object id) {

+        if (id != null && id instanceof VariableID) {

+            VariableID otherID = (VariableID) id;

+            return (pattern.getName().equals(otherID.pattern.getName()) &&

+                    uid == otherID.uid &&

+                    variable.equals(otherID.variable));

+        } else {

+            return false;

+        }

+	}

+    

+	// TODO not a smooth solution

+	public int hashCode() { 

+		  //return 1;

+		  return uid;

+		  // return uid+geVariableName().hashCode;

+		  

+		}

+

+    public int compareTo(Object arg0) {

+        VariableID otherID = (VariableID) arg0;

+        if(equals(arg0))

+            return 0;

+        else

+            if(uid == otherID.uid)

+                return variable.compareTo(otherID.variable);

+            else

+                return (uid < otherID.uid ? -1 : 1);

+    }

+

+	public String toString() {

+		return pattern.getName() + "_" + uid.toString() + "_" + variable;

+	}
+	
+	/** Returns the user friendly (readable) representation of the search node's name
+	 * @return
+	 */
+	public String getFancyName() {
+		return "'"+variable + " variable of pattern "+pattern.getName()+"'";
+	}

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/algorithms/ChuiEdmonds.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/algorithms/ChuiEdmonds.java
new file mode 100644
index 0000000..99c6489
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/algorithms/ChuiEdmonds.java
@@ -0,0 +1,336 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.algorithms;

+

+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.NoSuchElementException;
+import java.util.TreeMap;
+
+import org.eclipse.viatra2.core.IModelManager;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.EdgeTypeinAlgorithm;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.PseudoSearchGraphNode;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.SearchGraphEdge;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.SearchGraphNode;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.SearchGraphNodeComparator;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.VariableSearchGraphNode;
+

+

+/**

+ * Implements a variant of the Chu-Edmonds algorithm to calculate a (possibly sub-) optimal search plan

+ * @author Akos Horvath

+ *

+ */

+public class ChuiEdmonds {

+//	private IModelManager manager;

+	int min, finalizedVertexId=-1;

+	ArrayList<SearchGraphNode> sSet = new ArrayList<SearchGraphNode>();

+	

+	 public ChuiEdmonds(IModelManager manager){

+ //        this.manager = manager;

+         sSet.clear();

+         finalizedVertexId = -1;

+         min = Integer.MAX_VALUE;;

+	 }

+	 

+	 /**

+	 * Initialises the Chu-Edmonds algorithm

+	 */

+	public void init() {

+	     sSet.clear();

+	     finalizedVertexId = -1;

+	     min = Integer.MAX_VALUE;;

+	 }

+	

+

+	

+	/** Returns the SearchPlan (traversal order of the node) of the input graph 

+	 * @param iSearchGraph The search graph to work with

+	 * @return The array of the SearchGraph nodes in appropriate order

+	 */

+	public SearchGraphNode[] evaluateSearchPlan(ISearchGraph iSearchGraph) {

+		return evaluateSearchPlanInner(evaluateSearchTreeInner(iSearchGraph.getSearchNodes().values()));		

+	}

+	

+//	public Collection<SearchGraphNode> evaluateSearchTree(FlattenedPattern result) {

+//		

+//		return evaluateSearchTreeInner(result.getSearchGraph().getSearchNodes().values());		

+//		}

+	

+	/** Returns a lightest spanning tree of the input graph

+	 * @param nodes the nodes of the graph

+	 * @return The collection of the search graph's node with the defined spanning tree

+	 */

+	private Collection<SearchGraphNode> evaluateSearchTreeInner(Collection<SearchGraphNode> nodes)

+	{

+	//set the treeEdge pointer to the minimum incoming edge for all SearchGraphNodes

+	for (SearchGraphNode node : nodes) 

+		{

+		if(node instanceof VariableSearchGraphNode && (!((VariableSearchGraphNode)node).isInput()))  

+			 {min = Integer.MAX_VALUE;

+			  for( SearchGraphEdge edge :node.getSources())

+			 	 if(edge.getWeight() < min)

+			 	 {		min = edge.getWeight();

+			 	 		if(node.getTreeEdge() != null)

+			 	 			{

+			 	 			node.getTreeEdge().getSourceNode().decreaseOutgoingTreeEdgeNumber();

+			 	 			node.getTreeEdge().setEdgeTypeinAlgorithm(EdgeTypeinAlgorithm.FREE);

+			 	 			}

+					 	node.setTreeEdge(edge);

+					 	edge.getSourceNode().increaseOutgonigTreeEdgeNumber();

+					 	edge.setEdgeTypeinAlgorithm(EdgeTypeinAlgorithm.TREE);

+			 	 }

+			 }

+		}

+	for(SearchGraphNode node : nodes)

+		{	if(!sSet.contains(node))

+				findCircle(node);

+		}

+	eraseCircles();

+	return nodes;	

+	}

+	

+	/** Evaluates the actual top most virtual vertex of the input node.

+	 * @param node the node who's virtualvertex is the return parameter

+	 * @return

+	 */

+	SearchGraphNode getVirtualVertex(SearchGraphNode node)

+	{	if(node == null) return null;

+		

+		SearchGraphNode virtualnode = node;

+		if(node.getVirtualSearchGraphNode() == null )

+			return node;

+		else

+		{	virtualnode = node;

+			while(virtualnode.getVirtualSearchGraphNode() != null)

+					virtualnode = virtualnode.getVirtualSearchGraphNode();

+			

+			return virtualnode;

+		}

+	}

+	

+	/** If node is in a circle, the edge weights are recalculated along the circle, and a new treeedge is selected

+	 * @param node The node to inspect

+	 */

+	private void findCircle(SearchGraphNode node)

+	{

+		SearchGraphNode actualNode = node, previousNode= node; 

+		while( previousNode!=null && (!sSet.contains(previousNode) ))

+			{

+			sSet.add(previousNode);

+			actualNode = previousNode;

+			if(actualNode.getTreeEdge() != null)

+				previousNode = getVirtualVertex(actualNode.getTreeEdge().getSourceNode()); 

+			else

+				previousNode = null;

+			}

+		//circle is found

+		if(previousNode != null 

+			&& finalizedVertexId < sSet.indexOf(previousNode))

+				evaluateNewEdgeWeights(actualNode,previousNode);	

+		else

+		//it is not a circle

+		{finalizedVertexId = sSet.size()-1;}

+	

+	}

+	 

+	

+	/** Evaluates the new edge weights of a circle (starting with circleBeginNode and ends with circleEndNode) and selects a new tree edge

+	 * for one of the circle nodes, all information is captured by a newly created virtual vertexes

+	 * @param circleBeginNode The starter node of the circle

+	 * @param circleEndNode The end node of the circle

+	 */

+	private void evaluateNewEdgeWeights(SearchGraphNode circleBeginNode, SearchGraphNode circleEndNode) {

+		int minEdgeWeight = Integer.MAX_VALUE;

+		int minIncomingEdgeWeight = Integer.MAX_VALUE;

+		int pseudoNodeId = sSet.size();

+										

+		int smallestId = pseudoNodeId;

+		PseudoSearchGraphNode pseudoNode = new PseudoSearchGraphNode();

+		SearchGraphEdge minIncomingEdge = null;

+		//SearchGraphEdge oldPseudoTreeEdge = null;

+		SearchGraphNode actualNode = circleBeginNode;

+		//CirclebiggestId is already known as it will be the next element in the sSet

+		pseudoNode.setCircleBiggestId(pseudoNodeId-1);

+		

+		//selects the smallest tree edge in the circle and sets it's edges to "circle" type

+		do{

+			if(actualNode.getTreeEdge().getWeight() < minEdgeWeight)

+				minEdgeWeight = actualNode.getTreeEdge().getWeight();

+			

+			if(sSet.indexOf(actualNode) < smallestId)	

+				smallestId = sSet.indexOf(actualNode);

+			

+			if(actualNode instanceof PseudoSearchGraphNode && ((PseudoSearchGraphNode)actualNode).getCircleSmallestId() < smallestId)

+				smallestId = ((PseudoSearchGraphNode)actualNode).getCircleSmallestId();

+			

+			actualNode.getTreeEdge().setEdgeTypeinAlgorithm(EdgeTypeinAlgorithm.CIRCLE);

+			actualNode = getVirtualVertex(actualNode.getTreeEdge().getSourceNode());

+			

+			}

+		while(!actualNode.equals(circleBeginNode));		

+		

+		actualNode = circleBeginNode;

+		pseudoNode.setCircleSmallestId(smallestId);

+		//update the edge weights and selects the smallest incoming to the pseudo node

+		do{

+			for (SearchGraphEdge edge :actualNode.getSources() ) {

+				if(getVirtualVertex(edge.getSourceNode()).getTreeEdge() == null

+				   ||

+				   (edge.getEdgeTypeinAlgorithm()==EdgeTypeinAlgorithm.FREE && 

+				   getVirtualVertex(edge.getSourceNode()).getTreeEdge().getEdgeTypeinAlgorithm() != EdgeTypeinAlgorithm.CIRCLE))

+					{

+					edge.setWeight(edge.getWeight() + minEdgeWeight - actualNode.getTreeEdge().getWeight());

+					//selects the smallest incoming edge into the pseudo node 

+					if(edge.getWeight() < minIncomingEdgeWeight)

+					{

+							minIncomingEdge = edge;

+							minIncomingEdgeWeight = edge.getWeight();

+					}

+					//links the incoming edges to the pseudo node

+					pseudoNode.addSource(edge);

+					}

+				}

+		actualNode = getVirtualVertex(actualNode.getTreeEdge().getSourceNode());

+

+		}while(!actualNode.equals(circleBeginNode));

+

+		//Sets the virtual node to all circle elements

+		actualNode = getVirtualVertex(circleBeginNode.getTreeEdge().getSourceNode());

+		circleBeginNode.setVirtualSearchGraphNode(pseudoNode);

+		circleBeginNode = pseudoNode;

+		SearchGraphNode previousNode = null;		

+		while(!actualNode.equals(circleBeginNode)){

+			previousNode=  actualNode;

+			actualNode = getVirtualVertex(actualNode.getTreeEdge().getSourceNode());

+			previousNode.setVirtualSearchGraphNode(pseudoNode);

+		}

+		previousNode = null;

+

+		if(minIncomingEdge != null)

+			{//sets the tree edge of the target (not pseudo) 

+			pseudoNode.setTreeEdge(minIncomingEdge);

+	//		minIncomingEdge.getTargetNode().setTreeEdge(minIncomingEdge);

+			minIncomingEdge.setEdgeTypeinAlgorithm(EdgeTypeinAlgorithm.TREE);

+	//		minIncomingEdge.getSourceNode().increaseOutgonigTreeEdgeNumber();

+			}

+		pseudoNode.setName("pseudo"+pseudoNodeId);

+		findCircle(pseudoNode);

+	}

+	

+	/**

+	 * Erases the circles of the spanning tree, by evaluating the references of the virtual vertexes and the concrete nodes.

+	 */

+	private void eraseCircles(){

+		

+		for(int i = sSet.size()-1; i > -1; i--)

+			{

+			if(sSet.get(i) instanceof PseudoSearchGraphNode && (!((PseudoSearchGraphNode)sSet.get(i)).isBlocked()))

+				{

+				PseudoSearchGraphNode pnode = (PseudoSearchGraphNode)sSet.get(i);

+				SearchGraphEdge pedge = pnode.getTreeEdge();

+				//SearchGraphNode coverNode = pedge.getTargetNode();

+				int coverNodeId = sSet.indexOf(pedge.getTargetNode());

+				//erase the circle edge of the pseudo node which is 

+				//the treeedge of the Pseudo node's incoming tree edge target node

+				pedge.getTargetNode().getTreeEdge().setEdgeTypeinAlgorithm(EdgeTypeinAlgorithm.FREE);

+				pedge.getTargetNode().getTreeEdge().getSourceNode().decreaseOutgoingTreeEdgeNumber();

+				pedge.getTargetNode().setTreeEdge(pedge);

+				pedge.getSourceNode().increaseOutgonigTreeEdgeNumber();

+				//set the cover pseudo nodes to Blocked

+				for(int j = coverNodeId; j<i; j++)

+					if(sSet.get(j) instanceof PseudoSearchGraphNode)

+						{

+						PseudoSearchGraphNode innerPseudoNode = (PseudoSearchGraphNode)sSet.get(j);

+						if(coverNodeId >= innerPseudoNode.getCircleSmallestId() 

+								&& coverNodeId <= innerPseudoNode.getCircleBiggestId())

+								{

+								innerPseudoNode.setBlocked(true);

+								}

+						}

+				}

+			}

+	}

+	

+	

+	/** Returns the SearchPlan (traversal order of the node) of the input graph (with already evaluated spanning tree)

+	 * @param nodes the graph with the appropriate spannning tree

+	 * @return

+	 */

+	private SearchGraphNode[] evaluateSearchPlanInner(Collection<SearchGraphNode> nodes){

+		//the leaves of the search tree will be in the leaves arraylist

+		SearchGraphNode maxNode = null;

+		int max = Integer.MIN_VALUE;

+		int indexOfSearchPlan = nodes.size()-1;

+		int indexOfInputParameters = -1;

+		SearchGraphNode searchPlan[] = new SearchGraphNode[nodes.size()] ;  

+		SearchGraphNodeComparator comparator = new SearchGraphNodeComparator();

+		

+		//input parameters, their values are known, can be handled as Constant nodes 

+		for(SearchGraphNode node : nodes)

+			if(node instanceof VariableSearchGraphNode && ((VariableSearchGraphNode)node).isInput())

+				{

+				indexOfInputParameters++;

+				searchPlan[indexOfInputParameters]= node;

+				node.setChecked(true);

+				if(node.getTreeEdge() != null)

+					node.getTreeEdge().getSourceNode().decreaseOutgoingTreeEdgeNumber();

+				}

+		//calculate the leaves of the SearchTree

+		TreeMap<SearchGraphNode,Object> leaves = new TreeMap<SearchGraphNode, Object>(comparator); 

+			for(SearchGraphNode node : nodes){

+				if(node.getOutgoingTreeEdgeNumber() == 0 &&

+						(!(node instanceof VariableSearchGraphNode && ((VariableSearchGraphNode)node).isInput())))

+					{leaves.put(node,null);

+					 if( node.getTreeEdge() != null && max < node.getTreeEdge().getOldWeight() )

+					 	{

+						 max = node.getTreeEdge().getOldWeight();

+						 maxNode = node;

+					 	}

+					}

+			}

+	//there is no unbounded searchNode in the pattern

+	if(maxNode == null)		

+		while(indexOfSearchPlan != indexOfInputParameters)

+			{

+			maxNode = leaves.lastKey();

+			searchPlan[indexOfSearchPlan]=  maxNode;

+			indexOfSearchPlan--;

+			}

+		

+	else

+	//get the highest tree edge and put it to the search plan evaluation

+	while(indexOfSearchPlan != indexOfInputParameters)

+		{

+		searchPlan[indexOfSearchPlan]=  maxNode;

+		//to "delete" the treeedge from the tree

+		if(maxNode.getTreeEdge() != null)

+		{	maxNode.getTreeEdge().getSourceNode().decreaseOutgoingTreeEdgeNumber();

+		//if it does not hold an other element by an edge or not an input parameter then it is a leaf

+			if( maxNode.getTreeEdge().getSourceNode().getOutgoingTreeEdgeNumber() == 0 )

+				if(!(maxNode.getTreeEdge().getSourceNode() instanceof VariableSearchGraphNode

+						&& ((VariableSearchGraphNode)maxNode.getTreeEdge().getSourceNode()).isInput()))

+				leaves.put(maxNode.getTreeEdge().getSourceNode(),null);

+		}	

+		leaves.remove(maxNode); 

+		try{

+			if(leaves.isEmpty())

+				break;

+			else

+				maxNode = leaves.lastKey();

+			}

+		catch(NoSuchElementException e){break;}

+		indexOfSearchPlan--;

+		}

+	return searchPlan;

+	}

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/algorithms/ISearchGraph.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/algorithms/ISearchGraph.java
new file mode 100644
index 0000000..5da7356
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/algorithms/ISearchGraph.java
@@ -0,0 +1,105 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.algorithms;

+

+import java.util.Collection;
+import java.util.TreeMap;
+
+import org.eclipse.viatra2.core.IModelManager;
+import org.eclipse.viatra2.gtasm.patternmatcher.PatternCallSignature;
+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherCompileTimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherRuntimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTRuleBuildingException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.GTElementMapping;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.GTOperationContext;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.callgraph.BodyNode;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.callgraph.FlattenedPattern;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.callgraph.PatternReferenceNode;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation.SearchPlanOperation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.AbstractNode;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.SearchGraphEdge;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.SearchGraphNode;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.traceability.EdgeTraceabilityElement;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.traceability.NodeTraceabilityElement;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
+

+

+/**Interface for the search graph used in the optimization algorithm
+ * @author Akos Horvath
+ *
+ */
+public interface ISearchGraph {

+	

+	  

+    public static final String VPM_RELATION_FQN = "vpm.relation";

+    public static final String VPM_ENTITY_FQN = "vpm.entity";

+	public static final int VARIABLEASSIGNMENT_WEIGHT = 5;

+   

+	

+    //These are the methods that are used by the optimization algorithms

+	public TreeMap<Integer, SearchGraphNode> getSearchNodes();

+	/** Returns the search operation generated from the search graph parametrized with the input parameters adornment

+	 * @param pattern The flattened pattern to generate from

+	 * @param adornment Adornment of the input parameter

+	 * @param manager 

+	 * @return Vector of the Operation plan

+	 * @throws PatternMatcherRuntimeException 

+	 */

+	public Collection<SearchPlanOperation> generateSearchPlan(FlattenedPattern pattern, Boolean[] adornment, IModelManager manager) throws PatternMatcherRuntimeException;

+	/**

+	 * Initializes the search graph

+	 */

+	public void initSearchGraph();

+	public void add(BodyNode node, FlattenedPattern result) throws PatternMatcherCompileTimeException;

+	/** Adds a pattern invocation node to the search graph

+ 	 * @param prNode The new pattern invocation node

+	 * @param result The flattened pattern of the search graph

+	 * @throws PatternMatcherCompileTimeException

+	 */

+	public void add(PatternReferenceNode prNode, FlattenedPattern result) throws PatternMatcherCompileTimeException;

+	/** Returns the generated GTOperations and variable mapping

+	 * @param gtElementMappings The RHS-LHS parameter mapping

+	 * @param manager Model manager of the actual framework

+	 * @param signature The input parameters' signatures 

+	 * @return

+	 * @throws GTRuleBuildingException

+	 */

+	public GTOperationContext generateGTOperations(Collection<GTElementMapping> gtElementMappings, IModelManager manager, PatternCallSignature[] signature) throws GTRuleBuildingException;

+	 /** Returns the search graph element with the input id
+	 * @param key The id of the search graph element
+	 * @return
+	 */
+	public SearchGraphNode getSearchNode(Integer key);

+	/** Evaluates the dangling relations and relationships and adds them to the flattened pattern's search graph

+	 * @param pattern Flattened Pattern of the search graph

+	 * @throws PatternMatcherCompileTimeException

+	 */

+	 public void connectDanglingRelations(FlattenedPattern pattern) throws PatternMatcherCompileTimeException;
+	/**Return the EMF equivalent of the input SearchGraph element
+	 * @param node The node whose EMF representation is returned
+	 * @return
+	 */
+	public AnnotatedElement getGTASMRepresentation(AbstractNode node); 
+	
+	/**To add an edge based traceability element to the search graph
+	 * @param edge The edge whose element is added
+	 * @param element The traceability element
+	 */
+	public void addTraceabilityElement(SearchGraphEdge edge, EdgeTraceabilityElement element);	
+	
+	/**To add a node based traceability element to the search graph
+	 * @param edge The edge whose element is added
+	 * @param element The traceability element
+	 */
+	public void addTraceabilityElement(SearchGraphNode node, NodeTraceabilityElement element);
+		

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/algorithms/ISearchGraphProvider.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/algorithms/ISearchGraphProvider.java
new file mode 100644
index 0000000..d4827d0
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/algorithms/ISearchGraphProvider.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.algorithms;

+

+import org.eclipse.viatra2.core.IModelManager;
+

+/**Extension point to be able to use alternate search graphs with the algorithm
+ * @author Akos Horvath
+ *
+ */
+public interface ISearchGraphProvider {

+	

+	public ISearchGraph getSearchGraph(IModelManager manager);

+

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/algorithms/SearchGraphFactory.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/algorithms/SearchGraphFactory.java
new file mode 100644
index 0000000..ebcc3b7
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/algorithms/SearchGraphFactory.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.algorithms;

+

+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.viatra2.core.IModelManager;
+

+/**

+ * Used to return the appropriate SearchGraphProvider (uses the alternate representation if available) for the Flattened Pattern.

+ * @author Akos Horvath

+ *

+ */

+public class SearchGraphFactory{

+	

+	private static boolean useAlternate = false;

+	private static List<ISearchGraphProvider> alternateProvider = new ArrayList<ISearchGraphProvider>();

+	

+	public static ISearchGraph getSearchGraph(IModelManager manager){

+		

+		if( (!useAlternate) || alternateProvider.size() == 0) //use default

+			return new VPMBasedSearchGraph(manager);

+		else

+			return alternateProvider.get(0).getSearchGraph(manager);

+	}

+

+	/**

+	 * @return the useAlternate

+	 */

+	public static boolean isUseAlternate() {

+		return useAlternate;

+	}

+

+	/**

+	 * @param useAlternate the useAlternate to set

+	 */

+	public static void setUseAlternate(boolean useAlternate) {

+		SearchGraphFactory.useAlternate = useAlternate;

+	}

+

+	/**

+	 * @return the alternateProvider

+	 */

+	public static List<ISearchGraphProvider> getAlternateProvider() {

+		return alternateProvider;

+	}

+

+	/**

+	 * @param alternateProvider the alternateProvider to set

+	 */

+	public static void setAlternateProvider(

+			List<ISearchGraphProvider> alternateProvider) {

+		SearchGraphFactory.alternateProvider = alternateProvider;

+	}

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/algorithms/VPMBasedSearchGraph.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/algorithms/VPMBasedSearchGraph.java
new file mode 100644
index 0000000..982e9d8
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/algorithms/VPMBasedSearchGraph.java
@@ -0,0 +1,1073 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.algorithms;

+

+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.Vector;
+
+import org.eclipse.emf.common.util.TreeIterator;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.viatra2.core.IModelManager;
+import org.eclipse.viatra2.gtasm.patternmatcher.ParameterMode;
+import org.eclipse.viatra2.gtasm.patternmatcher.PatternCallSignature;
+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherCompileTimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherRuntimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTRuleBuildingException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.GTElementMapping;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.GTElementMappingType;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.GTOperationContext;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.GTOperationGenerator;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.DeleteModelElement;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.ElementManipulationOperation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.IUpdatePlanOperation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.validation.GTRuleValidator;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.EdgeType;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.PatternMatcherErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.VPMModelElementType;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.VariableID;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.callgraph.BodyNode;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.callgraph.DanglingVPMElementDTO;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.callgraph.FlattenedPattern;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.callgraph.PatternNode;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.callgraph.PatternNodeIncremental;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.callgraph.PatternReferenceNode;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation.CheckOperation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation.ISearchPlanOperation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation.SearchPlanOperation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.AbstractNode;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.ConstantSearchGraphNode;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.EdgeTypeinAlgorithm;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.PatternCallSearchGraphNode;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.SearchGraphEdge;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.SearchGraphNode;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.VariableSearchGraphNode;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.traceability.AbstractTraceabilityElement;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.traceability.ConstantNodeTraceabilityElement;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.traceability.EdgeTraceabilityElement;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.traceability.NodeTraceabilityElement;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.traceability.PatternCallNodeTraceabilityElement;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.traceability.VariableNodeTraceabilityElement;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.enums.ContainmentMode;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.terms.Constant;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.terms.Term;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.terms.VariableReference;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.ContainmentConstraint;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.GTPatternBody;
+import org.eclipse.viatra2.gtasmmodel.vpm.editmodel.Entity;
+import org.eclipse.viatra2.gtasmmodel.vpm.editmodel.ModelElement;
+import org.eclipse.viatra2.gtasmmodel.vpm.editmodel.Relation;
+import org.eclipse.viatra2.gtasmmodel.vpm.editmodel.Relationship;
+import org.eclipse.viatra2.gtasmmodel.vpm.editmodel.SupertypeOf;
+import org.eclipse.viatra2.gtasmmodel.vpm.editmodel.TypeOf;
+import org.eclipse.viatra2.gtasmmodel.vpm.editmodel.VPMElement;
+

+

+/**A search graph implementation for the VPM models
+ * @author Akos Horvath
+ *
+ */
+public class VPMBasedSearchGraph implements  ISearchGraph {

+    public static final int BELOW_WEIGHT = 40;

+    public static final int IN_WEIGHT = 10;

+    public static final int INSTANCEOF_WEIGHT = 20;

+    public static final int SUPERTYPE_WEIGHT = 10;

+    public static final int RELATION_WEIGHT = 15;

+    public static final int PATTERNCALLINV_WEIGHT = 4; //Must be the lowest weight !!!

+    public static final int PATTERNCALL_WEIGHT = 20;
+    public static final int PATTERNCALL_INCREMENTAL_WEIGHT = 9;
+    public static final int PATTERNCALL_STORAGE_INCREMENTAL_WEIGHT = 7;
+

+    private static final int VPM_ENTITY = -1;

+    private static final int VPM_RELATION = -2;

+    private static final int PATTERN_CALL_STORAGE_NODE = -3;
+    private static final int CONSTANTNODE_STARTING_ID = -4;
+    // in case the pattern has ENTITY or RELATION as Modelelement
+    // or in case the pattern call is a collector node,
+    // then  they have to added to the constantnodes collection

+

+

+    private int constantNodesNumber = CONSTANTNODE_STARTING_ID;

+

+    /**

+     * The class represents the data structure for the search plan evaluation

+     */

+    private final ChuiEdmonds alg;

+

+	private TreeMap<Integer,SearchGraphNode> searchNodes;

+    private SearchGraphNode[] searchNodeOrder = null;  //SearchGraphNode! not SearcPlanOperation!!!

+    private final TreeMap<String,Integer> constantNodes;

+    private Map<SearchGraphNode,Boolean> hasOneInConstraint;

+    private final ArrayList<DanglingVPMElementDTO> danglingElements;

+    private final Map<AbstractNode,AbstractTraceabilityElement> traceabilityMapping;
+

+    private final int constantNodeNumber = CONSTANTNODE_STARTING_ID;

+

+    public VPMBasedSearchGraph(IModelManager manager) {

+        this.alg = new ChuiEdmonds(manager);

+    	this.searchNodes = new TreeMap<Integer, SearchGraphNode>();

+    	this.constantNodes = new TreeMap<String, Integer>();

+    	this.danglingElements = new ArrayList<DanglingVPMElementDTO>();
+    	this.traceabilityMapping = new HashMap<AbstractNode, AbstractTraceabilityElement>();

+    }

+

+	public void setSearchNodes(TreeMap<Integer,SearchGraphNode> searchGraph) {

+		this.searchNodes = searchGraph;

+	}

+

+	public TreeMap<String, Integer> getConstantNodes() {

+		return constantNodes;

+	}

+

+	public TreeMap<Integer, SearchGraphNode> getSearchNodes() {

+		return searchNodes;

+	}

+

+	public int getConstantNodeNumber() {

+		return constantNodeNumber;

+	}

+

+	public SearchGraphNode getSearchNode(Integer key) {

+		return searchNodes.get(key);

+	}

+

+	public boolean containsKey(Object key) {

+		return searchNodes.containsKey(key);

+	}

+

+//	private void debug(Logger logger) {

+//	    for (SearchGraphNode node : searchNodes.values()) {

+//	        logger.debug(node.getName()+" "+node.getOutgoingTreeEdgeNumber()+ " "+ node.isChecked());

+//	        for(SearchGraphEdge edge: node.getSources()) {

+//	            logger.debug(//"  *****Name "+edge.getName()+" *****Type: "+edge.getVPMEdgeType()

+//	                    ""+"  "+edge.getSourceNode().getName()+" -> "+ edge.getTargetNode().getName()+"  "+edge.getWeight()+" "+edge.getOldWeight()+" "+edge.isChecked()+" "+ edge.getEdgeTypeinAlgorithm());

+//	        }

+//	        if(node.getTreeEdge() != null) {

+//	            logger.debug("   TREEEDGE   "+node.getTreeEdge().getName()+"  "+node.getTreeEdge().getSourceNode().getName()+" -> "+ node.getTreeEdge().getTargetNode().getName()+"  "+node.getTreeEdge().getWeight()+" "+node.getTreeEdge().getOldWeight()+" "+node.getTreeEdge().isChecked());

+//	        }

+//	    }

+//	}

+

+    // sets back the searchGraph to the beginning state

+    public void initSearchGraph() {

+    	alg.init();

+

+    	for (SearchGraphNode node : searchNodes.values()) {

+    		node.setChecked(false);

+    		node.setVirtualSearchGraphNode(null);

+    		for (SearchGraphEdge edge : node.getSources()) {

+    			edge.setEdgeTypeinAlgorithm(EdgeTypeinAlgorithm.FREE);

+    			edge.setChecked(false);

+    			edge.setWeight(edge.getOldWeight());

+    			//alg.init();

+    			//resets the outgoing tree edge number

+    			node.setOutgoingTreeEdgeNumber(0);

+    		}

+    		node.setTreeEdge(null);

+    	}//input parameter of a VariableSearchGraph is set by the FlattenedPattern

+	}

+

+    public void add(BodyNode bodyNode, FlattenedPattern result) throws PatternMatcherCompileTimeException {

+    	GTPatternBody body = bodyNode.getBody();

+		// VPM nodes and edges are mapped to SearchGraphNodes

+

+		TreeIterator<EObject> elements_iter = body.getPatternGraph().eAllContents();

+		//map the VPM relations and entites to SearchGraph nodes

+		while(elements_iter.hasNext()) {

+		    Object obj = elements_iter.next();

+		    if(obj instanceof Relation || obj instanceof Entity)

+		        evaluateModelElement((ModelElement) obj,result,bodyNode);

+		}

+

+		//maps the connections of the local VPM model elements to search graph edges

+		elements_iter = body.getPatternGraph().eAllContents();

+		while(elements_iter.hasNext()) {

+		    Object obj = elements_iter.next();

+

+		    if(obj instanceof Relation)

+		        connectElements((Relation) obj,result,bodyNode);

+		    if(obj instanceof Relationship)

+		        evaluateRelationship((Relationship) obj,result,bodyNode);

+		}

+

+		//saves the dangling relations

+		Iterator<Relation> iter_dangling = body.getDanglingRelations().iterator();

+		while(iter_dangling.hasNext())

+			danglingElements.add(new DanglingVPMElementDTO(iter_dangling.next(), bodyNode));

+

+		//saves the dangling relationships

+		Iterator<Relationship> iter_dangling_relship = body.getDanglingRelationships().iterator();

+		while(iter_dangling_relship.hasNext())

+			danglingElements.add(new DanglingVPMElementDTO(iter_dangling.next(), bodyNode));

+

+		// containment

+		ListIterator<ContainmentConstraint> containmentConstraints = body.getContainmentConstraints().listIterator();

+		while(containmentConstraints.hasNext()) {

+		    //ContainmentConstraint conCons = containmentConstraints.next();

+		    evaluateContainmentConstraints(containmentConstraints.next(),result,bodyNode);

+		}

+    }

+

+	private void evaluateContainmentConstraints(ContainmentConstraint conCons , FlattenedPattern result, BodyNode bodyNode){

+	    SearchGraphEdge edge = new SearchGraphEdge();

+	    SearchGraphEdge invedge = new SearchGraphEdge();

+	    SearchGraphNode target =  getSearchNode(result.getIndex(bodyNode.getVariableID(conCons.getVariable())));

+
+	    //traceability
+		EdgeTraceabilityElement edgeTraceability = new EdgeTraceabilityElement(edge,conCons);
+		traceabilityMapping.put(edge, edgeTraceability);
+
+	    //inverse
+	    EdgeTraceabilityElement inverseEdgeTraceability = new EdgeTraceabilityElement(invedge,conCons);
+		traceabilityMapping.put(invedge, inverseEdgeTraceability);
+

+	    if(conCons.getMode() == ContainmentMode.BELOW_LITERAL) {

+	        edge.setVPMEdgeType(EdgeType.BELOW);

+	        edge.setOldWeight(BELOW_WEIGHT);

+	        edge.setWeight(BELOW_WEIGHT);

+	        invedge.setVPMEdgeType(EdgeType.BELOW);

+	        invedge.setOldWeight(BELOW_WEIGHT*2);

+	        invedge.setWeight(BELOW_WEIGHT*2);

+	    } else {

+	        edge.setVPMEdgeType(EdgeType.IN);

+	        edge.setOldWeight(IN_WEIGHT);

+	        edge.setWeight(IN_WEIGHT);

+	        invedge.setVPMEdgeType(EdgeType.IN);

+	        invedge.setOldWeight(IN_WEIGHT*2);

+	        invedge.setWeight(IN_WEIGHT*2);

+	    }

+

+	    if(conCons.getParent() instanceof VariableReference &&

+	        result.containsIndex(bodyNode.getVariableID(((VariableReference)conCons.getParent()).getVariable())))

+	        {

+	    	VariableID parentID = bodyNode.getVariableID(((VariableReference)conCons.getParent()).getVariable());

+	        VariableSearchGraphNode source;

+

+	        if (searchNodes.containsKey(result.getIndex(parentID)))

+	        	{

+	            source = (VariableSearchGraphNode) getSearchNode(result.getIndex(

+	                    parentID));

+	        	}

+	        else

+	        	{

+	            source = new VariableSearchGraphNode();

+	            source.setVpmModelElementType(VPMModelElementType.ENTITY);

+	            source.setInput(true);

+	            source.setName(parentID.toString());

+	            source.setId(result.getIndex(parentID));

+	            searchNodes.put(source.getId(),source);			//variablereference
+
+	            //traceability
+		        VariableNodeTraceabilityElement traceability = new VariableNodeTraceabilityElement(source,conCons.getParent());
+		        traceabilityMapping.put(source, traceability);

+	        	}

+

+	        edge.setName(conCons.getVariable().getName()+"_Containment");

+	        edge.setTargetNode(target);

+	        edge.setSourceNode(source);

+	        edge.setSource(true);

+	        target.addSource(edge);

+

+	        edge.setInverseEdge(invedge);

+

+	        invedge.setName(conCons.getVariable().getName()+"_ContainmentInverse");

+	        invedge.setTargetNode(source);

+	        invedge.setSourceNode(target);

+	        invedge.setSource(false);

+	        source.addSource(invedge);

+	    } else if (conCons.getParent() instanceof Constant) {

+

+	    	ConstantSearchGraphNode source;

+	        //a bit complicated...

+	        Constant constant = ((Constant)conCons.getParent());

+

+	        if(constantNodes.containsKey(constant.getValue()))

+	 	       {

+	        	source = (ConstantSearchGraphNode) getSearchNode(constantNodes.get(constant.getValue()));

+	           }

+	        else

+	        	{

+	        	source = new ConstantSearchGraphNode();

+		        source.setElement(constant.getValue());

+		        source.setName(constant.getValue());

+		        searchNodes.put(constantNodesNumber,source);

+		        constantNodes.put(source.getName(), constantNodesNumber);

+		        constantNodesNumber--;
+
+		        //traceability
+		        ConstantNodeTraceabilityElement traceability = new ConstantNodeTraceabilityElement(source,conCons.getParent());
+		        traceabilityMapping.put(source, traceability);

+	        	}

+	        edge.setName(conCons.getVariable().getName()+"_Containment");

+	        edge.setTargetNode(target);

+	        edge.setSourceNode(source);

+	        edge.setSource(true);

+	        target.addSource(edge);

+	    } else {

+	        // general case for the Term of the containment constraint

+	        int index = result.addVariable(null);

+	        CheckOperation operation =

+	        	bodyNode.getTermEvaluationOperation(result.getTermHandler(), conCons, index);

+//                handler.getTermEvaluationOperation(parent.pattern, currentLocation, conCons.getParent(), index);

+	        result.addPreSearchPlanOperation(operation);

+

+	        VariableSearchGraphNode source = new VariableSearchGraphNode();

+            source.setInput(true);

+            source.setVpmModelElementType(VPMModelElementType.ENTITY);

+            source.setName("PROCCESEDTERM_"+index);

+            source.setId(index);

+            searchNodes.put(index,source);			//variablereference
+
+            //traceability
+	        VariableNodeTraceabilityElement traceability = new VariableNodeTraceabilityElement(source,conCons.getParent());
+	        traceabilityMapping.put(source, traceability);

+

+            edge.setName(conCons.getVariable().getName()+"_Containment");

+	        edge.setTargetNode(target);

+	        edge.setSourceNode(source);

+	        edge.setSource(true);

+	        target.addSource(edge);

+        }

+	}

+

+	private void connectElements(Relation rel, FlattenedPattern result, BodyNode bodyNode) throws PatternMatcherCompileTimeException {

+		SearchGraphNode source;

+		SearchGraphNode target;

+		SearchGraphNode relationnode;

+
+		String fromStr = rel.getFromStr();

+		String toStr = rel.getToStr();

+

+		Integer toIndex = result.getIndex(bodyNode.getVariableID(toStr));

+		Integer fromIndex = result.getIndex(bodyNode.getVariableID(fromStr));

+		Integer relIndex = result.getIndex(bodyNode.getVariableID(rel));

+

+		if(fromIndex != null

+				&& searchNodes.containsKey(fromIndex)) {

+			source =  getSearchNode(fromIndex);

+        }
+		else if(constantNodes.containsKey(fromStr))  {

+			source =  getSearchNode(constantNodes.get(fromStr));

+        }
+		else{
+			String[] context ={rel.getName(), rel.getFromStr()};
+			throw new PatternMatcherCompileTimeException(PatternMatcherErrorStrings.INTERNAL_SEARCGRAPH_RELATION_SOURCE_MISSING
+    			,context
+    			,rel);
+		}

+

+		if(toIndex != null

+				&& searchNodes.containsKey(toIndex)) {

+			target = getSearchNode(toIndex);

+        } else if(constantNodes.containsKey(toStr)) {

+			target =  getSearchNode(constantNodes.get(toStr));

+        } else {
+        	//TODO: if the target of the relation is missing it is a dangling relation but not contained in the DanlingRelations list :-)
+        	// Needs to be added to the danglingElements collection
+        	danglingElements.add(new DanglingVPMElementDTO(rel, bodyNode));
+        	return;
+//        	String[] context ={rel.getName()};
+//        	throw new PatternMatcherCompileTimeException(PatternMatcherErrorStrings.INTERNAL_SEARCGRAPH_RELATION_TARGET_MISSING
+//        			,context
+//        			,rel);
+        }

+

+        if(relIndex != null

+				&& searchNodes.containsKey(relIndex)) {

+			relationnode =  getSearchNode(relIndex);

+        } else if(constantNodes.containsKey(rel.getName())) {

+			relationnode =  getSearchNode(constantNodes.get(rel.getName()));

+        } else {
+        	String[] context ={rel.getName()};
+        	throw new PatternMatcherCompileTimeException(PatternMatcherErrorStrings.INTERNAL_SEARCGRAPH_RELATION_MISSING
+        			,context
+        			,rel);
+        }

+
+        SearchGraphEdge edgeTarget = new SearchGraphEdge();

+		SearchGraphEdge edgeTargetinverse = new SearchGraphEdge();

+

+		SearchGraphEdge edgeSource = new SearchGraphEdge();

+		SearchGraphEdge edgeSourceinverse = new SearchGraphEdge();

+

+		//		<--Source--     --Target-->

+		// Source        Relation          Target

+		//      --invSource->  <-invTarget--

+

+		//Source

+		edgeSource.setSourceNode(relationnode);

+		edgeSource.setTargetNode(source);

+		edgeSource.setSource(true);

+		edgeSource.setWeight(RELATION_WEIGHT);

+		edgeSource.setOldWeight(RELATION_WEIGHT);

+		edgeSource.setVPMEdgeType(EdgeType.SOURCE);

+		edgeSource.setName(relationnode.getName()+"->"+source.getName());

+		//edgeSource.setParentinEMF(rel);

+		source.addSource(edgeSource);

+

+		//inverse source edge

+		edgeSourceinverse.setSourceNode(source);

+		edgeSourceinverse.setTargetNode(relationnode);

+		edgeSourceinverse.setSource(false);

+		edgeSourceinverse.setWeight(RELATION_WEIGHT);

+		edgeSourceinverse.setOldWeight(RELATION_WEIGHT);

+		edgeSourceinverse.setVPMEdgeType(EdgeType.SOURCE);

+		edgeSourceinverse.setName(source.getName()+"->"+relationnode.getName());

+		//edgeSourceinverse.setParentinEMF(rel);

+		relationnode.addSource(edgeSourceinverse);

+

+		edgeSource.setInverseEdge(edgeSourceinverse);

+

+

+		//Target

+		edgeTarget.setTargetNode(target);

+		edgeTarget.setSourceNode(relationnode);

+		edgeTarget.setSource(true);

+		edgeTarget.setWeight(RELATION_WEIGHT);

+		edgeTarget.setOldWeight(RELATION_WEIGHT);

+		edgeTarget.setVPMEdgeType(EdgeType.TARGET);

+		edgeTarget.setName(relationnode.getName()+"->"+target.getName());

+		//edgeTarget.setParentinEMF(rel);

+		target.addSource(edgeTarget);

+

+		//inverse Target edge

+		edgeTargetinverse.setTargetNode(relationnode);

+		edgeTargetinverse.setSourceNode(target);

+		edgeTargetinverse.setSource(false);

+		edgeTargetinverse.setWeight(RELATION_WEIGHT);

+		edgeTargetinverse.setOldWeight(RELATION_WEIGHT);

+		edgeTargetinverse.setVPMEdgeType(EdgeType.TARGET);

+		edgeTargetinverse.setName(target.getName()+"->"+relationnode.getName());

+		//edgeTargetinverse.setParentinEMF(rel);

+		relationnode.addSource(edgeTargetinverse);

+

+		edgeTarget.setInverseEdge(edgeTargetinverse);
+
+		//traceability
+		//source
+		EdgeTraceabilityElement sourceEdgeTraceability = new EdgeTraceabilityElement(edgeSource,rel);
+		traceabilityMapping.put(edgeSource, sourceEdgeTraceability);
+
+	    //source inverse
+	    EdgeTraceabilityElement sourceInverseEdgeTraceability = new EdgeTraceabilityElement(edgeSourceinverse,rel);
+		traceabilityMapping.put(edgeSourceinverse, sourceInverseEdgeTraceability);
+
+		//target
+		EdgeTraceabilityElement targetEdgeTraceability = new EdgeTraceabilityElement(edgeTarget,rel);
+		traceabilityMapping.put(edgeTarget, targetEdgeTraceability);
+
+	    //target inverse
+	    EdgeTraceabilityElement targetInverseEdgeTraceability = new EdgeTraceabilityElement(edgeTargetinverse,rel);
+		traceabilityMapping.put(edgeTargetinverse, targetInverseEdgeTraceability);
+	}

+

+	/** True if element is a dangling edge in the bodyNode and not contained in the alreadyProcessed list

+	 * @param element The element to test

+	 * @param bodyNode Body node containing the GT pattern

+	 * @param alreadyProcessedDanglings List containing the already processed dangling edges

+	 * @return

+	 */

+	private boolean isDangling(VPMElement element,BodyNode bodyNode, List<DanglingVPMElementDTO> alreadyProcessedDanglings) {

+		GTPatternBody body = bodyNode.getBody();

+

+		if(alreadyProcessedDanglings.contains(element))

+			return Boolean.FALSE;

+

+		Iterator<Relation> iter = body.getDanglingRelations().iterator();

+		while(iter.hasNext())

+			{

+			TreeIterator<EObject> elements_iter = ((EObject)iter.next()).eAllContents();

+			while(elements_iter.hasNext())

+				{if(elements_iter.next().equals(element))

+			        return Boolean.TRUE;

+				}

+			}

+		Iterator<Relationship> iter2 = body.getDanglingRelationships().iterator();

+		while(iter.hasNext())

+			{

+			TreeIterator<EObject> elements_iter = ((EObject)iter2.next()).eAllContents();

+			while(elements_iter.hasNext())

+				{if(elements_iter.next().equals(element))

+			        return Boolean.TRUE;

+				}

+			}

+		return Boolean.FALSE;

+	}

+

+

+	/** Adds the dangling relations & relationships (and their additional relations and relationships) to the search graph

+	 * @param danglings List of Dangling model elements

+	 * @param result The Flattened pattern containing the resulting search graph

+	 * @param alreadyProcessedDanglings Dangling elements already processed during the evaluation (to check circles between dangling edges)

+	 * @throws PatternMatcherCompileTimeException

+	 */

+	private void evaluateDanglingElements(List<DanglingVPMElementDTO> danglings, FlattenedPattern result, List<DanglingVPMElementDTO> alreadyProcessedDanglings) throws PatternMatcherCompileTimeException{

+		 ArrayList<DanglingVPMElementDTO> additionalDanglingElements = new ArrayList<DanglingVPMElementDTO>();

+

+		 	for(DanglingVPMElementDTO dto: danglings){

+				VPMElement element = dto.getElement();

+				BodyNode bodyNode= dto.getBodyNode();

+

+				if(element instanceof Relation)

+					{

+					evaluateModelElement((ModelElement) element,result,bodyNode);

+					for (ModelElement elem: ((Relation)element).getType()) {

+						if(isDangling(elem,bodyNode,alreadyProcessedDanglings))

+							additionalDanglingElements.add(new DanglingVPMElementDTO(elem,bodyNode));

+					}

+					for (Relationship elem : ((Relation)element).getSuperRelationships()) {

+						if(isDangling(elem,bodyNode,alreadyProcessedDanglings))

+							additionalDanglingElements.add(new DanglingVPMElementDTO(elem,bodyNode));

+					}

+					for (Relation elem : ((Relation)element).getRelationsFrom()) {

+						if(isDangling(elem,bodyNode,alreadyProcessedDanglings))

+							additionalDanglingElements.add(new DanglingVPMElementDTO(elem,bodyNode));

+					}

+					for (Relation elem : ((Relation)element).getRelationsTo()) {

+						if(isDangling(elem,bodyNode,alreadyProcessedDanglings))

+							additionalDanglingElements.add(new DanglingVPMElementDTO(elem,bodyNode));

+						}

+

+					connectElements((Relation)element, result, bodyNode);

+

+					}

+				else if(element instanceof Relationship)

+					{
+					VariableID supplierID = bodyNode.getVariableID(((Relationship) element).getSupplierStr());
+					//supplier is a constant -> cannot be unresolvable dangling relation
+					if (!result.containsIndex(supplierID))
+						{
+						evaluateRelationship((Relationship)element, result, bodyNode);
+						}
+					else
+						{
+						//supplier is a variable input type or not defined in the actual body
+						SearchGraphNode suppliernode = getSearchNode(result.getIndex(supplierID));
+
+						//the supplier node is an unresolvable dangling element
+						if(suppliernode == null)
+							{
+							String[] context ={ element instanceof SupertypeOf ?"supertypeOf":"instanceOf",((Relationship)element).getSupplierStr() };
+							throw new PatternMatcherCompileTimeException(PatternMatcherErrorStrings.INTERNAL_SEARCGRAPH_RELATION_SOURCE_MISSING
+					    			,context
+					    			,element);
+							}
+
+						//it has a supplier can be processed
+						evaluateRelationship((Relationship)element, result, bodyNode);
+						}
+					}

+				else
+					{String[] context = {element.toString()};

+					throw new PatternMatcherCompileTimeException(PatternMatcherErrorStrings.INTERNAL_ERROR_DANGLING_RELATION_FAILED
+								,context
+								,element);
+					}

+

+				alreadyProcessedDanglings.add(dto);

+		 	}

+

+			if(additionalDanglingElements.size()!= 0)

+				evaluateDanglingElements(additionalDanglingElements, result, alreadyProcessedDanglings);

+	}

+

+	public void connectDanglingRelations(FlattenedPattern result) throws PatternMatcherCompileTimeException {

+		//TODO: is it possible to have a dangling edge with constant source or target node?

+	    if(danglingElements.size()!= 0)

+	    	evaluateDanglingElements(danglingElements, result, new ArrayList<DanglingVPMElementDTO>());

+	}

+

+	/** Creates the corresponding SearchGraphnode with type information about the input ModelElement

+	 * @param rel The model element that has to be added to the search graph

+	 * @param result Container for the search graph

+	 * @param bodyNode The body node describes the search graph that has to be built up

+	 */

+	private void evaluateModelElement(ModelElement rel, FlattenedPattern result, BodyNode bodyNode) {

+		SearchGraphEdge edge = null;

+		VariableID relID = bodyNode.getVariableID(rel);

+

+		// don't have explicit type relation, have to connect it to the Entity or relation global type

+		if(rel.getType().size() == 0) {

+			edge = new SearchGraphEdge();

+			edge.setVPMEdgeType(EdgeType.INSTANCEOF);

+			edge.setWeight(INSTANCEOF_WEIGHT*3);

+			edge.setOldWeight(INSTANCEOF_WEIGHT*3);

+			edge.setSource(true);
+			//traceability Information
+			EdgeTraceabilityElement edgeTraceability = new EdgeTraceabilityElement(edge,rel);
+			traceabilityMapping.put(edge, edgeTraceability);
+

+			//its an Entity

+			if(rel instanceof Entity) {

+			    // have to create the entity searchGraph node

+			    if( getSearchNode(VPM_ENTITY) == null) {

+			        ConstantSearchGraphNode ent = new ConstantSearchGraphNode();

+			        ent.setName("Entity");

+			        ent.setElement(VPM_ENTITY_FQN);

+			        searchNodes.put(VPM_ENTITY, ent);
+			        //traceability Information
+			        ConstantNodeTraceabilityElement traceability = new ConstantNodeTraceabilityElement(ent,rel);
+			        //TODO what to do if it is the vpm.Entity element? Currently it is the pattern variable (rel)
+			        traceabilityMapping.put(ent, traceability);

+			    }

+			    edge.setSourceNode( getSearchNode(VPM_ENTITY));

+			    edge.setName("Entity-ins->"+rel.getName());

+			} else {

+                // have to create the Relation SearchGraph node

+			    if( getSearchNode(VPM_RELATION) == null) {

+			        ConstantSearchGraphNode ent = new ConstantSearchGraphNode();

+			        ent.setName("Relation");

+			        ent.setElement(VPM_RELATION_FQN);

+			        searchNodes.put(VPM_RELATION, ent);
+
+			        //traceability Information
+			        ConstantNodeTraceabilityElement traceability = new ConstantNodeTraceabilityElement(ent,rel);
+			        //TODO what to do if it is the vpm.Relation element?
+			        traceabilityMapping.put(ent, traceability);

+			    }

+			    edge.setSourceNode( getSearchNode(VPM_RELATION));

+			    edge.setName("Relation-ins->"+rel.getName());

+			}

+		}

+

+		if(result.containsIndex(relID)) {

+		//its a variable type element

+		    if(!searchNodes.containsKey(result.getIndex(relID))) {

+		        VariableSearchGraphNode node = new VariableSearchGraphNode();

+		        node.setId(result.getIndex(relID));

+		        node.setName(relID.getFancyName());

+		        searchNodes.put(node.getId(),node);

+
+		        //traceability
+		        VariableNodeTraceabilityElement traceability = new VariableNodeTraceabilityElement(node,rel);
+		        traceabilityMapping.put(node, traceability);
+

+		        //create new else branch needed for every new IMOdelElement type

+ 		        if(rel instanceof Entity)

+		        	node.setVpmModelElementType(VPMModelElementType.ENTITY);

+ 		        if(rel instanceof Relation)

+ 		        	node.setVpmModelElementType(VPMModelElementType.RELATION);

+

+ 		        if(rel.getType().size() == 0) {

+		            edge.setTargetNode(node);

+		            node.addSource(edge);

+		        }

+		    }

+		} else

+		//its a constant node

+		if(constantNodes.containsKey(rel.getName())) {

+			ConstantSearchGraphNode node = new ConstantSearchGraphNode();

+			node.setElement(rel.getRealElement());

+			node.setName(rel.getRealElement());

+			searchNodes.put(constantNodesNumber,node);

+			constantNodes.put(node.getName(), constantNodesNumber);

+			constantNodesNumber--;

+
+			 //traceability Information
+	        ConstantNodeTraceabilityElement traceability = new ConstantNodeTraceabilityElement(node,rel);
+	        traceabilityMapping.put(node, traceability);
+

+			if(rel.getType().size() == 0) {

+			    edge.setTargetNode(node);

+			    node.addSource(edge);

+			}

+		}

+	}

+

+	private void evaluateRelationship(Relationship rel, FlattenedPattern result, BodyNode bodyNode) {

+		SearchGraphNode suppliernode = null;

+		SearchGraphEdge edge = new SearchGraphEdge();

+		SearchGraphEdge invedge = null;

+		//supplier
+		ModelElement supplier = rel.getSupplier();

+		String supplierName = rel.getSupplierStr();

+		VariableID supplierID = bodyNode.getVariableID(supplierName);
+		//client
+		//ModelElement client = rel.getClient();
+		String clientName = rel.getClientStr();
+		VariableID clientID = bodyNode.getVariableID(clientName);
+
+		VariableSearchGraphNode clientnode =(VariableSearchGraphNode)searchNodes.get(result.getIndex(clientID));
+

+		if (result.containsIndex(supplierID)) {

+		    //supplier is a variable input type or not defined in the actual body

+			suppliernode = getSearchNode(result.getIndex(supplierID));
+
+			//the supplier node is a dangling element, needs to be processed later
+			if(suppliernode == null)
+				{
+				danglingElements.add(new DanglingVPMElementDTO(rel, bodyNode));
+	        	return;
+				}

+		} else {

+            // supplier is a constant

+			if (constantNodes.containsKey(supplierName)) {

+				suppliernode =  getSearchNode(constantNodes.get(supplierName));

+			} else {

+				suppliernode = new ConstantSearchGraphNode();

+			    ((ConstantSearchGraphNode)suppliernode).setElement(supplier.getRealElement());

+			    suppliernode.setName(((ConstantSearchGraphNode)suppliernode).getElement());

+			    searchNodes.put(constantNodesNumber,suppliernode);

+			    constantNodes.put(suppliernode.getName(), constantNodesNumber);

+			    constantNodesNumber--;
+
+			    //Traceability
+			    ConstantNodeTraceabilityElement traceability = new ConstantNodeTraceabilityElement((ConstantSearchGraphNode)suppliernode,supplier);
+		        traceabilityMapping.put(suppliernode, traceability);

+			}

+		}

+

+		if (rel instanceof TypeOf) {

+			edge.setVPMEdgeType(EdgeType.INSTANCEOF);

+			edge.setTargetNode(clientnode);

+			edge.setWeight(INSTANCEOF_WEIGHT);

+			edge.setOldWeight(INSTANCEOF_WEIGHT);

+			edge.setSource(true);

+			edge.setSourceNode(suppliernode);

+			edge.setName(suppliernode.getName()+"_instanceof_"+clientnode.getName());

+			clientnode.addSource(edge);

+

+			//inverse of instanceof

+			if (suppliernode instanceof VariableSearchGraphNode) {

+				invedge = new SearchGraphEdge();

+				invedge.setVPMEdgeType(EdgeType.INSTANCEOF);

+				invedge.setTargetNode(suppliernode);

+				invedge.setWeight(INSTANCEOF_WEIGHT*2);

+				invedge.setOldWeight(INSTANCEOF_WEIGHT*2);

+				invedge.setSource(false);

+				invedge.setSourceNode(clientnode);

+				invedge.setName(suppliernode.getName()+"_instanceofINV_"+clientnode.getName());

+				suppliernode.addSource(invedge);

+

+				edge.setInverseEdge(invedge);
+
+				//traceability inverse
+				EdgeTraceabilityElement inverseEdgeTraceability = new EdgeTraceabilityElement(invedge,rel);
+				traceabilityMapping.put(invedge, inverseEdgeTraceability);

+			}

+		} else {

+			edge.setVPMEdgeType(EdgeType.SUPERTYPEOF);

+			edge.setTargetNode(suppliernode);

+			edge.setSourceNode(clientnode);

+			edge.setSource(true);

+			edge.setWeight(SUPERTYPE_WEIGHT);

+			edge.setOldWeight(SUPERTYPE_WEIGHT);

+			edge.setName(suppliernode.getName()+"_supertypeof_"+clientnode.getName());

+			//edge.setParentinEMF(rel);

+			suppliernode.addSource(edge);

+

+			//inverse

+			invedge = new SearchGraphEdge();

+			invedge.setVPMEdgeType(EdgeType.SUPERTYPEOF);

+			invedge.setTargetNode(clientnode);

+			invedge.setSourceNode(suppliernode);

+			invedge.setSource(false);

+			invedge.setWeight(SUPERTYPE_WEIGHT*2);

+			invedge.setOldWeight(SUPERTYPE_WEIGHT*2);

+			invedge.setName(suppliernode.getName()+"_supertypeof_INV"+clientnode.getName());

+			clientnode.addSource(invedge);
+
+			edge.setInverseEdge(invedge);
+
+			//inverse relationship traceability
+			EdgeTraceabilityElement inverseEdgeTraceability = new EdgeTraceabilityElement(invedge,rel);
+			traceabilityMapping.put(invedge, inverseEdgeTraceability);

+		}
+
+		//relationship traceability
+		EdgeTraceabilityElement edgeTraceability = new EdgeTraceabilityElement(edge,rel);
+		traceabilityMapping.put(edge, edgeTraceability);
+	}

+

+	public void add(PatternReferenceNode prNode, FlattenedPattern result) throws PatternMatcherCompileTimeException {

+		final PatternNode reference = prNode.getReference();

+		final List<Term> actualParameters = prNode.getActualParameters();

+		final BodyNode parent = (BodyNode) prNode.getParent();
+		int weight = PATTERNCALL_WEIGHT;

+		//the parameter order of the pattern call mapped to the id values of the searchGraphNodes

+		Integer[] parameterMapping = new Integer[actualParameters.size()];

+

+		//The pattern call node

+		PatternCallSearchGraphNode patternCallNode = new PatternCallSearchGraphNode();

+		int index = result.addVariable(null);

+
+        patternCallNode.setName("PatternCallof_"+reference.getPattern().getName());

+        patternCallNode.setId(index);

+        patternCallNode.setVpmModelElementType(VPMModelElementType.OPERATION);

+        patternCallNode.setPatternNode(reference);

+        searchNodes.put(patternCallNode.getId(),patternCallNode);

+
+
+        //traceability pattern call
+		PatternCallNodeTraceabilityElement patternCallTraceabilityElement= new PatternCallNodeTraceabilityElement(patternCallNode,prNode.getPatternCall());
+		traceabilityMapping.put(patternCallNode, patternCallTraceabilityElement);
+
+		//if it is an incrementally matched pattern call new weigh values are set and it is attached to the Storage node
+        if(prNode.getReference() instanceof PatternNodeIncremental)
+        	{//TODO: traceability of the storage node and its edge? Is it needed?
+        	weight = PATTERNCALL_INCREMENTAL_WEIGHT;
+
+        	SearchGraphEdge edge = null;
+    		edge = new SearchGraphEdge();
+    		edge.setVPMEdgeType(EdgeType.PATTERN_CALL_STORAGE);
+    		edge.setWeight(PATTERNCALL_STORAGE_INCREMENTAL_WEIGHT);
+    		edge.setOldWeight(PATTERNCALL_STORAGE_INCREMENTAL_WEIGHT);
+    		edge.setSource(true);
+    		// have to create the Storage node
+    		if( getSearchNode(PATTERN_CALL_STORAGE_NODE) == null) {
+    		       ConstantSearchGraphNode ent = new ConstantSearchGraphNode();
+    		       ent.setName("Pattern_Call_Storage_Node");
+    		       ent.setElement(VPM_ENTITY_FQN);
+    		       searchNodes.put(PATTERN_CALL_STORAGE_NODE, ent);
+    		    }
+    		//sets the target and the source nodes
+    		edge.setSourceNode( getSearchNode(PATTERN_CALL_STORAGE_NODE));
+    		edge.setName("PatternStorage-store->"+patternCallNode.getName());
+
+    		edge.setTargetNode(patternCallNode);
+    		patternCallNode.addSource(edge);
+        	}
+

+        //connecting the variables to the pattern call

+        for (int i = 0; i < actualParameters.size(); i++) {

+        	if (actualParameters.get(i) instanceof VariableReference) {

+	        	VariableReference varRef= (VariableReference) actualParameters.get(i);

+	        	SearchGraphNode inputNode = null;

+	        	//the node is already processed in the flattened pattern

+	        	Integer variableIndex = result.getIndex(parent.getVariableID(varRef.getVariable()));

+	        	if (searchNodes.containsKey(variableIndex)) {

+	        		inputNode =  getSearchNode(variableIndex);

+	        		parameterMapping[i] = ((VariableSearchGraphNode)inputNode).getId();

+	        	} else {

+	        		// new search graph node only used in the pattern call!

+	        		inputNode = new VariableSearchGraphNode();

+

+	        		int id;

+	        		inputNode.setName(parent.getVariableID(varRef.getVariable()).toString());

+	        		//recursive pattern matching call

+	        		if (result.getIndex(parent.getVariableID(varRef.getVariable())) != null) {

+	        			//the parameter is passed through the pattern

+	        			//already has an index

+	        			id = result.getIndex(parent.getVariableID(varRef.getVariable()));

+	        		} else{

+	        			//new id

+	        			id = result.addVariable(parent.getVariableID(varRef.getVariable()));

+	        		}

+

+	        		((VariableSearchGraphNode)inputNode).setId(id);

+	        		searchNodes.put(((VariableSearchGraphNode)inputNode).getId(), inputNode);

+

+	        		parameterMapping[i] = id;
+
+	        		//traceability
+			        VariableNodeTraceabilityElement traceability = new VariableNodeTraceabilityElement((VariableSearchGraphNode) inputNode,varRef);
+			        traceabilityMapping.put(inputNode, traceability);
+

+	        		//System.out.println("Pattern Call inside GT pattern with through-passed variables");

+	        	}

+	        	//connects the pattern node to its input parameter nodes

+	        	SearchGraphEdge edgePatternCall = new SearchGraphEdge();

+	    		SearchGraphEdge edgePatternCallinverse = new SearchGraphEdge();

+

+	    		//		        <--PatternCall--

+	    		// Input Variable                  Pattern Call

+	    		//              --PatternCallinverse->

+

+	    		//pattern call edge

+	    		edgePatternCall.setSourceNode(inputNode);

+	    		edgePatternCall.setTargetNode(patternCallNode);

+	    		edgePatternCall.setSource(true);

+	    		edgePatternCall.setWeight(weight);

+	    		edgePatternCall.setOldWeight(weight);

+	    		edgePatternCall.setVPMEdgeType(EdgeType.PATTERN_CALL_PARAMETER);

+	    		edgePatternCall.setName(inputNode.getName()+"->"+patternCallNode.getName());

+	    		//edgeSource.setParentinEMF();

+	    		patternCallNode.addSource(edgePatternCall);

+

+	    		//inverse pattern call edge

+	    		edgePatternCallinverse.setSourceNode(patternCallNode);

+	    		edgePatternCallinverse.setTargetNode(inputNode);

+	    		edgePatternCallinverse.setSource(false);

+	    		edgePatternCallinverse.setWeight(PATTERNCALLINV_WEIGHT);

+	    		edgePatternCallinverse.setOldWeight(PATTERNCALLINV_WEIGHT);

+	    		edgePatternCallinverse.setVPMEdgeType(EdgeType.PATTERN_CALL_PARAMETER);

+	    		edgePatternCallinverse.setName(patternCallNode.getName()+"->"+inputNode.getName());

+	    		//edgeSourceinverse.setParentinEMF(rel);

+	    		inputNode.addSource(edgePatternCallinverse);

+

+	    		edgePatternCall.setInverseEdge(edgePatternCallinverse);
+
+	    		//traceability edge
+	    		EdgeTraceabilityElement edgeTraceability = new EdgeTraceabilityElement(edgePatternCall,varRef);
+	    		traceabilityMapping.put(edgePatternCall, edgeTraceability);
+
+	    		//traceability edge
+	    		EdgeTraceabilityElement inverseEdgeTraceability = new EdgeTraceabilityElement(edgePatternCallinverse,varRef);
+	    		traceabilityMapping.put(edgePatternCallinverse, inverseEdgeTraceability);

+	        } else {
+	        	String[] context = {""+i, prNode.getPatternCall().getCalledPattern().getName()};
+	        	PatternMatcherCompileTimeException e = new PatternMatcherCompileTimeException(PatternMatcherErrorStrings.ILLEGAL_INPUT_PARAMETER
+	        			,context
+	        			,actualParameters.get(i));
+	        	throw e;
+	        }

+        }

+        patternCallNode.setInputParameterMapping(parameterMapping);

+	}

+

+	public GTOperationContext generateGTOperations(Collection<GTElementMapping> gtElementMappings

+			,IModelManager manager

+	        ,PatternCallSignature[] signatures)

+	throws GTRuleBuildingException {

+

+		initSearchGraph();

+		ArrayList<IUpdatePlanOperation> manipulationOperations = new ArrayList<IUpdatePlanOperation>();

+		ArrayList<ISearchPlanOperation> checkSet = new ArrayList<ISearchPlanOperation>();

+		Collection<IUpdatePlanOperation> postSearchPlanOperations = new Vector<IUpdatePlanOperation>();

+		ElementManipulationOperation operation = null;

+		hasOneInConstraint = new HashMap<SearchGraphNode, Boolean>();
+

+		//Adds the to delete input variables to the manipulation operation plan

+		if(gtElementMappings != null)

+		 for(GTElementMapping map: gtElementMappings)

+			//have to keep the element

+			if(searchNodes.containsKey(map.getRhsInputOrderIndex()))

+				{map.setMappingType(GTElementMappingType.KEEP);

+				//all mapped elements are input parameters for the RHS

+				((VariableSearchGraphNode) getSearchNode(map.getRhsInputOrderIndex())).setInput(true);

+				((VariableSearchGraphNode) getSearchNode(map.getRhsInputOrderIndex())).setChecked(true);

+				}

+			else//have to delete the element

+				{

+				map.setMappingType(GTElementMappingType.DEL);

+				manipulationOperations.add(new DeleteModelElement(manager, map.getRhsInputOrderIndex()));

+				}

+

+        // All input parameter specific operations + Check set are generated

+    	for (int j = 0; j < signatures.length; j++) {

+             if (searchNodes.containsKey(j) &&  getSearchNode(j) instanceof VariableSearchGraphNode) {

+            	VariableSearchGraphNode node = (VariableSearchGraphNode)  getSearchNode(j);

+                if(signatures[j].getParameterMode().equals(ParameterMode.INPUT)) {

+                	{node.setInput(true);

+                	 Collection<IUpdatePlanOperation> _temp= GTOperationGenerator.getInputSpecificOperation(node,manager,checkSet);

+                	 if(_temp != null && _temp.size() > 0)

+                		 postSearchPlanOperations.addAll(_temp);

+                	}

+                } else {

+                	node.setInput(false);

+                }

+             }

+        }

+    	//generateInit(inputMapping, signature, template,manager, gtElementMappings);

+		searchNodeOrder = alg.evaluateSearchPlan(this);

+		//boolean hasINConstraint = false;

+		for(SearchGraphNode node : searchNodeOrder) {

+			if(node instanceof ConstantSearchGraphNode) {

+				node.setChecked(true);

+            }

+			GTRuleValidator.validateContainment(node, manager,hasOneInConstraint);

+			//all not mapped variable search graph node have to be created

+			if((!node.isChecked()) && node.getTreeEdge() != null

+					&& (!node.getTreeEdge().isChecked())) {

+				 operation = GTOperationGenerator.getModelManipulationOperation((VariableSearchGraphNode)node, manager,checkSet,this);

+				 if(operation!= null) {

+				     //operation.toString();

+				     manipulationOperations.add(operation);

+				 }

+			}

+			//edges that have to be created

+			for(SearchGraphEdge edge: node.getSources()) {

+				if(edge.getSourceNode().isChecked() && edge.getTargetNode().isChecked() && !edge.isChecked()) {

+				    operation = GTOperationGenerator.getModelManipulationOperation(edge,  manager,checkSet,this);

+				    if(operation!= null) {

+				        //operation.toString();

+				        manipulationOperations.add(operation);

+				    }

+				}

+			}

+		}

+//		 have to check if there are unchecked element in the searchGraph (they must be created or simply checked)

+		boolean noUncheckedOperation = true;

+

+		do {

+		noUncheckedOperation = true;

+			for(SearchGraphNode node : searchNodeOrder) {

+				if(!node.isChecked()) {

+					//System.out.println("Node: "+node.getName());

+					operation = GTOperationGenerator.getModelManipulationOperation((VariableSearchGraphNode)node, manager , checkSet,this);

+					if(operation == null)

+						{noUncheckedOperation = false;}

+					else {

+						manipulationOperations.add(operation);

+						node.setChecked(true);

+					}

+				}

+				//edge checking

+				for(SearchGraphEdge edge : node.getSources())

+					if(!edge.isChecked()

+							&& edge.getSourceNode().isChecked()

+							&& edge.getTargetNode().isChecked())

+						{operation = GTOperationGenerator.getModelManipulationOperation(edge, manager, checkSet,this);

+						//System.out.println("Edge: "+node.getName());

+						if(operation == null)

+							{noUncheckedOperation = false;}

+						else

+							{

+							manipulationOperations.add(operation);

+							edge.setChecked(true);

+							}

+						}

+			}

+		} while(!noUncheckedOperation);

+

+		if(postSearchPlanOperations.size() != 0)

+			manipulationOperations.addAll(postSearchPlanOperations);

+

+		GTRuleValidator gtRuleValidator = new GTRuleValidator();

+		gtRuleValidator.validateOperationPlan(manipulationOperations,checkSet,gtElementMappings,this);

+

+

+		return new GTOperationContext(null,manipulationOperations,checkSet);

+	}

+

+	public Collection<SearchPlanOperation> generateSearchPlan(FlattenedPattern pattern, Boolean[] adornment, IModelManager manager) throws PatternMatcherRuntimeException{

+        // Search graph initialization and search plan generation

+    	for (int j = 0; j < adornment.length; j++) {

+    		SearchGraphNode node = getSearchNode(j);

+            if (node instanceof VariableSearchGraphNode) {

+            	((VariableSearchGraphNode) node).setInput(adornment[j]);

+            }

+        }

+    	searchNodeOrder= alg.evaluateSearchPlan(pattern.getSearchGraph());

+    	return VPMPatternOperationGenerator.evaluateVPMOperationPlan(searchNodeOrder, new MatchingFrame(pattern),manager);

+	}
+
+	public AnnotatedElement getGTASMRepresentation(AbstractNode node) {
+		return node.getTraceabilityElement().getRepresentativeEMFElement();
+	}
+
+	public void addTraceabilityElement(SearchGraphEdge edge, EdgeTraceabilityElement element){
+		traceabilityMapping.put(edge, element);
+	}
+
+	public void addTraceabilityElement(SearchGraphNode node, NodeTraceabilityElement element){
+		traceabilityMapping.put(node, element);
+	}

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/algorithms/VPMPatternOperationGenerator.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/algorithms/VPMPatternOperationGenerator.java
new file mode 100644
index 0000000..2ea0a3a
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/algorithms/VPMPatternOperationGenerator.java
@@ -0,0 +1,386 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.algorithms;

+

+import java.util.Vector;
+
+import org.eclipse.viatra2.core.IModelElement;
+import org.eclipse.viatra2.core.IModelManager;
+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherRuntimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.EdgeType;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.PatternMatcherErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation.AllEntitiesOperation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation.AllRelationsOperation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation.BoundToBoundCheckOperation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation.BoundToConstantCheckOperation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation.ConstantToBoundCheckOperation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation.ConstantToConstantCheckOperation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation.CopyValueOperation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation.ExtendBoundNodeOperation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation.ExtendConstantNodeOperation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation.IsEntityorRelationCheckOperation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation.PatternCallOperation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation.SearchPlanOperation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation.VariableAssignmentCheckOperation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.ConstantSearchGraphNode;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.PatternCallSearchGraphNode;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.SearchGraphEdge;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.SearchGraphNode;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.VariableSearchGraphNode;
+

+

+/**Generates the operations base on the search plan.

+ * @author Akos Horvath

+ *

+ */

+public class VPMPatternOperationGenerator {

+	

+	public static Vector<SearchPlanOperation> evaluateVPMOperationPlan(SearchGraphNode[] searchPlan,
+			MatchingFrame template,
+			IModelManager manager) throws PatternMatcherRuntimeException{

+		Vector<SearchPlanOperation> searchOperations = new Vector<SearchPlanOperation>();

+		SearchPlanOperation operation = null;

+		

+		for(SearchGraphNode node : searchPlan){

+			if(node instanceof ConstantSearchGraphNode)

+				node.setChecked(true);

+

+			//tree edge evaluation

+			if(node.getTreeEdge() != null && (!node.isChecked()))

+				{operation = VPMPatternOperationGenerator.treeEdgeSearchOperation(node.getTreeEdge(), template,manager);

+				if(operation!= null)

+					{	//operation.debug();

+						searchOperations.add(operation);

+					}

+				}

+			//check operation evaluation	

+			for(SearchGraphEdge edge : node.getSources()){

+				if(edge.getSourceNode().isChecked() && edge.getTargetNode().isChecked())

+					{operation = VPMPatternOperationGenerator.evaluateEdgeSearchPlanOperation(edge, template,manager);

+						if(operation != null)

+							{//operation.debug();

+							searchOperations.add(operation);

+							}

+					}

+				}

+		}

+		// have to check if there are any edges left

+		for(SearchGraphNode node : searchPlan)

+			for(SearchGraphEdge edge : node.getSources())

+				if(!edge.isChecked())

+					{

+					//oldVersion operation = checkSearchOperation(edge, template);

+					operation= VPMPatternOperationGenerator.evaluateEdgeSearchPlanOperation(edge,template,manager);

+					//operation.debug();

+					if(operation != null)

+						searchOperations.add(operation);

+					//searchOperations.add(checkSearchOperation(edge));

+					}

+		

+		

+		return searchOperations;

+	}

+	

+	

+	

+	/** Returns the corresponding search plan operation equivalent to the input search graph edge

+	 * @param edge The edge to process

+	 * @param template the Matching frame with the bound variables

+	 * @param manager Model manager of the actual model space

+	 * @return the generated operation

+	 */

+	public static SearchPlanOperation evaluateEdgeSearchPlanOperation(
+			SearchGraphEdge edge,
+			MatchingFrame template,
+			IModelManager manager) throws PatternMatcherRuntimeException

+	{SearchPlanOperation operation = null;

+		if(edge.isChecked()) return null; 

+		

+		//checking the type of the edge, for debugging

+		if(edge.getVPMEdgeType() == EdgeType.BELOW 

+				|| edge.getVPMEdgeType() == EdgeType.IN

+				|| edge.getVPMEdgeType() == EdgeType.INSTANCEOF 

+				|| edge.getVPMEdgeType() == EdgeType.SOURCE 

+				|| edge.getVPMEdgeType() == EdgeType.TARGET

+				|| edge.getVPMEdgeType() == EdgeType.SUPERTYPEOF

+				|| edge.getVPMEdgeType() == EdgeType.PATTERN_CALL_PARAMETER

+				|| edge.getVPMEdgeType() == EdgeType.VARIABLE_ASSIGNMENT) //TODO: new edge types has to be added to this check

+			{

+			operation = checkSearchOperation(edge, template,manager);

+			}

+		else

+			{
+			String[] context = {edge.getVPMEdgeType().toString(), edge.getName()};
+			throw new PatternMatcherRuntimeException(PatternMatcherErrorStrings.INTERNAL_EDGETYPE_NOT_SUPPORTED
+					,context
+					,template.getPattern().getGTASMRepresentation(edge));
+			}

+		return operation;

+	}

+	

+	

+	/** Returns the corresponding search plan operation equivalent of the input search graph edge (CHECK OPERATIONS)

+	 * @param edge The edge whose operation is generated

+	 * @param template template the Matching frame with the bound variables

+	 * @param manager model manager

+	 * @return the operation itself

+	 */

+	private static SearchPlanOperation checkSearchOperation(
+			SearchGraphEdge edge,
+			MatchingFrame template,
+			IModelManager manager)

+	throws PatternMatcherRuntimeException{

+		SearchPlanOperation operation = null;

+

+		//some of the check operations have to be skipped as they does not represent any additional constraints

+		if( edge.getSourceNode() instanceof VariableSearchGraphNode

+				&& edge.getVPMEdgeType().equals(EdgeType.BELOW)	//default Scope value

+				&& (template.getValue(((VariableSearchGraphNode)edge.getSourceNode()).getId()) != null)			//default Scope value

+				&& ((IModelElement)template.getValue(((VariableSearchGraphNode)edge.getSourceNode()).getId())).equals(manager.getRoot()))

+			{	

+			edge.setChecked(true);

+			return null;

+			}

+		

+		// in case the source is an entity or a relation a special check operation is required

+		if(	edge.getSourceNode() instanceof ConstantSearchGraphNode

+				&& edge.getVPMEdgeType().equals(EdgeType.INSTANCEOF)

+				&& ( ((ConstantSearchGraphNode)edge.getSourceNode()).getElement().equals(ISearchGraph.VPM_RELATION_FQN) 

+						|| ((ConstantSearchGraphNode)edge.getSourceNode()).getElement().equals(ISearchGraph.VPM_ENTITY_FQN) ))

+			{

+			//TODO: Can an entity have an instance relation to an entity?
+			//If yes, then can be tricked out as an entity can have an instance relation to a relation and it is not checked

+			operation = new IsEntityorRelationCheckOperation(((VariableSearchGraphNode)edge.getTargetNode()).getId()

+					,edge,

+					((ConstantSearchGraphNode)edge.getSourceNode()).getElement());

+			edge.setChecked(true);

+			return operation;

+			}	

+		/************complex operations******************/

+		//pattern call operation

+		if(edge.getTargetNode() instanceof PatternCallSearchGraphNode)

+				{
+				String[] context = {edge.getTargetNode().getName()};

+				throw new PatternMatcherRuntimeException(
+						PatternMatcherErrorStrings.INTERNAL_PATTERNCALLNODE_EXCEPTION
+						,context
+						,template.getPattern().getGTASMRepresentation(edge));

+				}

+				

+		

+		/**************simple operations*******************/

+		if(edge.getVPMEdgeType().equals(EdgeType.VARIABLE_ASSIGNMENT))

+			operation = new VariableAssignmentCheckOperation(((VariableSearchGraphNode)edge.getSourceNode()).getId(),

+					((VariableSearchGraphNode)edge.getTargetNode()).getId()
+					,edge); //TODO: does the direction counts? (inverse or not)

+		else

+		if(edge.getSourceNode() instanceof VariableSearchGraphNode && edge.getTargetNode() instanceof VariableSearchGraphNode)

+			operation = new BoundToBoundCheckOperation(((VariableSearchGraphNode)edge.getSourceNode()).getId()

+						,((VariableSearchGraphNode)edge.getTargetNode()).getId()

+						,edge);

+		else

+		if(edge.getSourceNode() instanceof VariableSearchGraphNode && edge.getTargetNode() instanceof ConstantSearchGraphNode )

+			operation = new BoundToConstantCheckOperation(((VariableSearchGraphNode)edge.getSourceNode()).getId()

+					,manager.getElementByName(((ConstantSearchGraphNode)edge.getTargetNode()).getElement())

+					,edge);

+		else

+		if(edge.getSourceNode() instanceof ConstantSearchGraphNode && edge.getTargetNode() instanceof VariableSearchGraphNode)

+			operation = new ConstantToBoundCheckOperation(manager.getElementByName(((ConstantSearchGraphNode)edge.getSourceNode()).getElement())

+					,((VariableSearchGraphNode)edge.getTargetNode()).getId()

+					,edge);

+		else

+		if(edge.getSourceNode() instanceof ConstantSearchGraphNode && edge.getTargetNode() instanceof ConstantSearchGraphNode)

+			operation = new ConstantToConstantCheckOperation(manager.getElementByName(((ConstantSearchGraphNode)edge.getSourceNode()).getElement())

+					,manager.getElementByName(((ConstantSearchGraphNode)edge.getTargetNode()).getElement())

+					,edge);

+		

+		if(operation != null)

+			edge.setChecked(true);

+		

+		return operation;

+		

+	}

+	

+	private static int getPatternCallParameterId(Integer id,
+			PatternCallSearchGraphNode callNode, MatchingFrame frame
+			) throws PatternMatcherRuntimeException {

+		Integer[] inputParameterMapping = callNode.getInputParameterMapping();
+		
+		for(int i =0; i< inputParameterMapping.length; i++)

+			if(id == inputParameterMapping[i])

+				return i;

+		
+		String[] context = {callNode.getName()};

+		throw new PatternMatcherRuntimeException(
+				PatternMatcherErrorStrings.INTERNAL_PATTERNCALLNODE_WRONGPARAMETER_ORDER
+				,context
+				,frame.getPattern().getGTASMRepresentation(callNode));

+	}

+

+	/** Returns the corresponding search plan operation equivalent of the input search graph TREE edge (EXTEND OPERATIONS)

+	 * @param edge 

+	 * @param Matchingframe containing the bound variables

+	 * @param manager model manager

+	 * @return

+	 */

+	public static SearchPlanOperation treeEdgeSearchOperation(SearchGraphEdge edge, MatchingFrame template, IModelManager manager) throws PatternMatcherRuntimeException{

+		SearchPlanOperation operation = null;

+		if(edge.getSourceNode().isChecked() && edge.getTargetNode().isChecked())

+			//the source and the target are already checked, simple checks the edge

+			operation = checkSearchOperation(edge, template,manager);

+		else//not a check type operation

+

+		/**********complex operations**********/

+		if(edge.getVPMEdgeType().equals(EdgeType.PATTERN_CALL_PARAMETER)
+				|| edge.getVPMEdgeType().equals(EdgeType.PATTERN_CALL_STORAGE))

+		{

+			if(edge.isSource()) //the edge is the tree edge of the pattern call node

+			{

+				PatternCallSearchGraphNode callNode = (PatternCallSearchGraphNode) edge.getTargetNode();

+				Boolean[] boundParameters = new Boolean[callNode.getPatternNode().getPattern().getSymParameters().size()];

+				

+					for (SearchGraphEdge callEdge:callNode.getSources())
+					{

+						//[DEBUG] error in the algorithm, one edge of the PatternCall node is already checked

+						//if(!callEdge.isChecked())

+						//	System.out.println("[ERROR] One edge of a PatternCallNode is already traversed before the PatternNode was traversed");

+

+						//if it is a bound input parameter

+						if(callEdge.getVPMEdgeType().equals(EdgeType.PATTERN_CALL_PARAMETER))
+						{	if(callEdge.getSourceNode().isChecked())

+								{

+								boundParameters[getPatternCallParameterId(((VariableSearchGraphNode)callEdge.getSourceNode()).getId()

+																		,callNode,template)] = true;

+								}

+							else//the pattern call will bound the variable

+							{	if(callEdge.getSourceNode().getTreeEdge().getSourceNode().equals(callNode))

+									{

+									boundParameters[getPatternCallParameterId(((VariableSearchGraphNode)callEdge.getSourceNode()).getId()

+											,callNode,template)] = false;

+									callEdge.getSourceNode().setChecked(true);

+									}

+								else//Error the recursive call is not the tree edge for an unbound parameter

+									{
+									String[] context = {callEdge.getSourceNode().getName(),callNode.getName()};

+									throw new PatternMatcherRuntimeException(
+											PatternMatcherErrorStrings.INTERNAL_PATTERNCALLNODE_EDGE_EXCEPTION
+											,context

+											,template.getPattern().getGTASMRepresentation(callNode));

+									}

+							}
+						}
+						//else // it is an incrementally matched pattern call -> not part of the invocation context
+
+						callEdge.setChecked(true);

+					}

+					return //PatternCallOperation patternOperation =

+						new PatternCallOperation(callNode.getPatternNode()

+							,callNode.getInputParameterMapping(),boundParameters);

+				

+			}

+			else//the edge is an outgoing edge from a pattern call node

+			{

+				//edge.getTargetNode().setChecked(true);

+				PatternCallSearchGraphNode callNode = (PatternCallSearchGraphNode) edge.getSourceNode();
+				String[] context = {edge.getName(),callNode.getName()};
+				throw new PatternMatcherRuntimeException(
+						PatternMatcherErrorStrings.INTERNAL_PATTERNCALLNODE_EDGE_TRAVERSAL_EXCEPTION
+						,context
+						,template.getPattern().getGTASMRepresentation(callNode));
+			}

+		}

+		/**************simple operations	******************/

+		else	

+		if(edge.getSourceNode().isChecked())

+				{

+				//simple operation

+				if(edge.getVPMEdgeType().equals(EdgeType.VARIABLE_ASSIGNMENT))

+					{operation = new CopyValueOperation(((VariableSearchGraphNode)edge.getSourceNode()).getId()

+							,((VariableSearchGraphNode)edge.getTargetNode()).getId()
+							,edge);

+					}

+				else

+				if(edge.getSourceNode() instanceof ConstantSearchGraphNode &&

+						((ConstantSearchGraphNode)edge.getSourceNode()).getElement().equals(ISearchGraph.VPM_ENTITY_FQN))	

+					{

+					operation = new AllEntitiesOperation(((VariableSearchGraphNode)edge.getTargetNode()).getId()

+							,edge, manager);

+					}

+				else

+				if(edge.getSourceNode() instanceof ConstantSearchGraphNode &&

+							((ConstantSearchGraphNode)edge.getSourceNode()).getElement().equals(ISearchGraph.VPM_RELATION_FQN))	

+						{

+						operation = new AllRelationsOperation(((VariableSearchGraphNode)edge.getTargetNode()).getId()

+								,edge, manager);

+						}

+				else

+				if(edge.getSourceNode() instanceof VariableSearchGraphNode && edge.getTargetNode() instanceof VariableSearchGraphNode)

+					{operation = new ExtendBoundNodeOperation(((VariableSearchGraphNode)edge.getSourceNode()).getId()

+							,((VariableSearchGraphNode)edge.getTargetNode()).getId()

+							,edge);

+					}

+				else

+					if(edge.getSourceNode() instanceof ConstantSearchGraphNode && edge.getTargetNode() instanceof VariableSearchGraphNode)

+					{operation = new ExtendConstantNodeOperation(manager.getElementByName(((ConstantSearchGraphNode)edge.getSourceNode()).getElement())

+							,((VariableSearchGraphNode)edge.getTargetNode()).getId()

+							,edge);

+					}	

+				}

+		else

+		if(edge.getTargetNode().isChecked())

+			{

+			//simple operation

+			if(edge.getVPMEdgeType().equals(EdgeType.VARIABLE_ASSIGNMENT))

+			{operation = new CopyValueOperation(((VariableSearchGraphNode)edge.getTargetNode()).getId()

+					,((VariableSearchGraphNode)edge.getSourceNode()).getId()
+					,edge);

+				}

+			if(edge.getTargetNode() instanceof ConstantSearchGraphNode &&

+					((ConstantSearchGraphNode)edge.getTargetNode()).getElement().equals(ISearchGraph.VPM_ENTITY_FQN))	

+				{

+				operation = new AllEntitiesOperation(((VariableSearchGraphNode)edge.getSourceNode()).getId()

+						,edge, manager);

+				}

+			else

+			if(edge.getTargetNode() instanceof ConstantSearchGraphNode &&

+						((ConstantSearchGraphNode)edge.getTargetNode()).getElement().equals(ISearchGraph.VPM_RELATION_FQN))	

+					{

+					operation = new AllRelationsOperation(((VariableSearchGraphNode)edge.getSourceNode()).getId()

+							,edge, manager);

+					}

+			else

+			if(edge.getSourceNode() instanceof VariableSearchGraphNode && edge.getTargetNode() instanceof VariableSearchGraphNode)

+				{operation = new ExtendBoundNodeOperation(((VariableSearchGraphNode)edge.getTargetNode()).getId()

+						,((VariableSearchGraphNode)edge.getSourceNode()).getId()

+						,edge);

+				}

+			else

+			if(edge.getSourceNode() instanceof ConstantSearchGraphNode && edge.getTargetNode() instanceof VariableSearchGraphNode)

+				{operation = new ExtendConstantNodeOperation(manager.getElementByName(((ConstantSearchGraphNode)edge.getTargetNode()).getElement())

+						,((VariableSearchGraphNode)edge.getSourceNode()).getId()

+						,edge);

+				}	

+			}

+		

+		if(operation != null)

+			{

+			edge.getSourceNode().setChecked(true);

+			edge.getTargetNode().setChecked(true);

+			edge.setChecked(true);

+			}

+		

+		return operation;

+		

+	}

+

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/callgraph/BodyNode.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/callgraph/BodyNode.java
new file mode 100644
index 0000000..1ade96a
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/callgraph/BodyNode.java
@@ -0,0 +1,482 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.callgraph;

+

+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.viatra2.core.IModelManager;
+import org.eclipse.viatra2.gtasm.interpreter.exception.ViatraTransformationException;
+import org.eclipse.viatra2.gtasm.interpreter.executionEnvironment.IExecutionEnvironment;
+import org.eclipse.viatra2.gtasm.interpreter.impl.executionEnvironment.ExecutionEnvironment;
+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherCompileTimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.core.PatternBuilder;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.EdgeType;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.PatternMatcher;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.PatternMatcherErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.VariableID;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.algorithms.ISearchGraph;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.callgraph.FlattenedPattern.Pair;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation.CheckOperation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation.NACCheckOperation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.SearchGraphEdge;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.SearchGraphNode;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.traceability.EdgeTraceabilityElement;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.term.ITermHandler;
+import org.eclipse.viatra2.gtasm.patternmatcher.patterns.IPatternMatcher;
+import org.eclipse.viatra2.gtasm.patternmatcher.patterns.PatternMatcherProvider;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.RuntimeAnnotation;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.definitions.Variable;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.terms.GTPatternCall;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.terms.Term;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.terms.VariableReference;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.ContainmentConstraint;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.GTPattern;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.GTPatternBody;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.NonInjectivityConstraint;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.PatternVariable;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.PatternVariableAssignment;
+import org.eclipse.viatra2.gtasmmodel.vpm.editmodel.ModelElement;
+import org.eclipse.viatra2.logger.Logger;
+

+

+

+public class BodyNode extends EvenLevelNode implements IFlattenedPatternElement {

+   private GTPatternBody body;

+    protected OddLevelNode[] children;

+

+    BodyNode(PatternMatcher patternMatcher,

+    		PatternNode parent, GTPatternBody body) throws PatternMatcherCompileTimeException {

+        super(parent);

+        this.body = body;

+        this.children = new OddLevelNode[body.getCalledPatterns().size()];

+

+        List<GTPatternCall> patternCalls = body.getCalledPatterns();

+        for (int i = 0; i < patternCalls.size(); i++) {

+            GTPatternCall patternCall = patternCalls.get(i);

+            PatternNode loopClosingNode = causesRecursion(patternCall.getCalledPattern());

+            if (loopClosingNode == null) {

+                if(isIncrementallyMatched(patternCall.getCalledPattern()))
+                {
+            		IExecutionEnvironment executionEnvironment = new ExecutionEnvironment(patternMatcher.getModelManager().getRoot().getModelSpace().getFramework());
+            		try {
+            			IPatternMatcher patternMatcherInc = null;
+            			patternMatcherInc =  PatternMatcherProvider.getInstance().getPatternMatcher(executionEnvironment, patternCall.getCalledPattern());
+            			PatternNode child = new PatternNodeIncremental(new PatternMatcherWrapper(patternMatcherInc,
+            					patternMatcher.getLogger(),patternMatcher.getModelManager(),
+            					patternMatcher.getTermHandler())
+            			, this, patternCall);
+                    	children[i] = new PatternReferenceNode(this,patternCall,child);
+            		} catch (ViatraTransformationException e) {
+            			// It is a Major bug if an exception is caught here. Means that an already incrementally matched pattern does not have a valid PatternMatcher!
+            			String[] context = {patternCall.getCalledPattern().getName(),e.getMessage()};
+            			throw new PatternMatcherCompileTimeException(
+            					PatternMatcherErrorStrings.INTERNAL_INCREMENTALLY_MATCED_PATTERN_HAS_NO_PATTERNMATCHER
+            					,context
+            					,patternCall);
+            		}
+
+                }
+                else
+                {
+            	PatternNode child = new PatternNode(patternMatcher, this, patternCall);

+                children[i] = child.isRoot()

+                		? new PatternReferenceNode(this, patternCall, child) : child;
+                }

+            } else {

+                children[i] = new PatternReferenceNode(this, patternCall, loopClosingNode);

+            }

+        }

+    }

+

+    /** Returns true if the input called pattern is incrementally matched
+     * @param calledPattern The called pattern to be checked
+     * @return Boolean true if incrementally checked
+     * @throws PatternMatcherCompileTimeException
+     */
+    private boolean isIncrementallyMatched(GTPattern calledPattern) throws PatternMatcherCompileTimeException{
+
+    	EList<RuntimeAnnotation> rtAnnotationsMachine = calledPattern.getNamespace().getRuntimeAnnotations();
+		boolean isMachineIncremental = false;
+    	if (rtAnnotationsMachine != null && rtAnnotationsMachine.size() > 0) {
+			for (RuntimeAnnotation an: rtAnnotationsMachine) {
+				if ("@incremental".equals(an.getAnnotationName().toLowerCase()))
+					{
+					isMachineIncremental = true;
+					}
+				 else if ("@localsearch".equals(an.getAnnotationName()
+						.toLowerCase()))
+				 	{
+					 isMachineIncremental = false;
+				 	}
+				}
+    	}
+
+    	EList<RuntimeAnnotation> rtAnnotationsPattern = calledPattern.getRuntimeAnnotations();
+
+    	if (rtAnnotationsPattern != null && rtAnnotationsPattern.size() > 0) {
+			for (RuntimeAnnotation an: rtAnnotationsPattern) {
+				if ("@incremental".equals(an.getAnnotationName().toLowerCase()))
+					return true;
+
+				if ("@localsearch".equals(an.getAnnotationName()
+							.toLowerCase()))
+					return false;
+			}
+		}
+		return isMachineIncremental; //machine default is used
+	}
+
+	protected PatternNode causesRecursion(GTPattern patternToTest) {

+        return parent.causesRecursion(patternToTest);

+    }

+

+    @Override

+    protected boolean traverse(PatternVariantIterator token) {

+        int size = children.length;

+        assert index == 0 || index == size - 1;

+        while (index >= 0 && index < size) {

+            if (children[index].traverse(token)) {

+                index++;

+            } else {

+                children[index].index = 0;

+                index--;

+            }

+        }

+        boolean result = (index == size);

+        index--;

+        return result;

+    }

+

+    public GTPatternBody getBody() {

+        return body;

+    }

+

+    public VariableID getVariableID(String name) {

+    	return new VariableID(parent.getPattern(), currentLocation, name);

+    }

+

+    public VariableID getVariableID(Variable variable) {

+    	return new VariableID(parent.getPattern(), currentLocation, variable.getName());

+    }

+

+    public VariableID getVariableID(ModelElement element) {

+        return new VariableID(parent.getPattern(), currentLocation, element.getName());

+    }

+

+    private BodyNode getCallerBody() {

+    	return (BodyNode) parent.getParent();

+    }

+

+    public void addLocalVariables(FlattenedPattern pattern) {

+        // Handling of local variables

+        for (Iterator<PatternVariable> iter = body.getLocalVariables().iterator(); iter.hasNext();) {

+            PatternVariable variable = iter.next();

+            pattern.addVariable(getVariableID(variable));

+        }

+    }

+

+    public void addFormalParameters(FlattenedPattern pattern)

+        throws PatternMatcherCompileTimeException {

+        if (parent.isRoot()) {

+            assert body.getHeader() == parent.getPattern();

+        	GTPattern firstPattern = body.getHeader();

+            List<PatternVariable> formalParameters = firstPattern.getSymParameters();

+            int numberOfFormalParameters = formalParameters.size();

+            for (Integer i = 0; i < numberOfFormalParameters; i++) {

+                // TODO gervarro: name convention for local pattern declarations is missing

+                pattern.addVariable(getVariableID(formalParameters.get(i)));

+            }

+            assert firstPattern.getSymParameters().size() == pattern.getFrameSize();

+        } else {

+            // Handling of pattern calls in FlattenedPatterns (i.e., parameter passing)

+            Integer numberOfActualParameters = parent.getActualParameters().size();

+            if (numberOfActualParameters == parent.getPattern().getSymParameters().size()) {

+                for (int j = 0; j < numberOfActualParameters; j++) {

+                    Term actualTerm = parent.getActualParameters().get(j);

+                    PatternVariable formalParameter = parent.getPattern().getSymParameters().get(j);

+                    if (actualTerm instanceof VariableReference) {

+                        VariableReference varRef = (VariableReference) actualTerm;

+                        PatternVariable actualParameter = (PatternVariable) varRef.getVariable();

+                        Integer index = pattern.getIndex(getCallerBody().getVariableID(actualParameter));

+                        pattern.setIndex(getVariableID(formalParameter), index);

+                    } else {

+                        // Based on the latest directive of Dani, terms are not allowed in inner pattern calls

+                        String[] context = {""+j, parent.getPattern().getName()};
+                    	throw new PatternMatcherCompileTimeException(
+                    			PatternMatcherErrorStrings.NO_TERM_IN_PATTERN_CALLS
+                    			,context
+                    			,actualTerm);

+                        /*

+                        // Term evaluation

+                        Integer index = pattern.addVariable(getVariableID(formalParameter));

+                        TermHandler handler = pattern.getTermHandler();

+                        AbstractTermCheckOperation operation =

+                            handler.getTermEvaluationOperation(parent.pattern, currentLocation, actualTerm, index);

+                        pattern.addPreSearchPlanOperation(operation);

+                        */

+                    }

+                }

+            } else {
+            	String[] context = {parent.getPattern().getName()};

+                throw new PatternMatcherCompileTimeException(
+                		PatternMatcherErrorStrings.INTERNAL_FORMAL_AND_ACTUAL_PARAMETER_MISMATCH
+                		,context
+                		,parent.getPattern());

+            }

+        }

+    }

+

+    public Collection<Pair> processVariableAssignments(FlattenedPattern pattern)

+        throws PatternMatcherCompileTimeException {

+    	ArrayList<Pair> pairs = null;
+    	List<PatternVariableAssignment> assigments = body.getVariableAssignments();

+        if (assigments != null) {
+        	pairs = new ArrayList<Pair>();

+            for (int i = 0; i < assigments.size(); i++) {

+                VariableID leftID = getVariableID(assigments.get(i).getLeftValue().getVariable());

+                VariableID rightID = getVariableID(assigments.get(i).getRightValue().getVariable());

+
+                int left = pattern.getIndex(leftID);
+                int right = pattern.getIndex(rightID);
+
+                //The variable assignment operation is handled here
+                SearchGraphNode leftNode = pattern.getSearchGraph().getSearchNodes().get(left);
+                SearchGraphNode rightNode = pattern.getSearchGraph().getSearchNodes().get(right);
+
+                if(leftNode == null)
+            	{
+            	String[] context = {leftID.getFancyName()};
+                throw new PatternMatcherCompileTimeException(
+                		PatternMatcherErrorStrings.VARIABLE_VARIABLEASSIGMENT_MISSING
+                		,context
+                		,assigments.get(i));
+            	}
+
+                if(rightNode == null)
+            	{//Errofull part
+            	String[] context = {rightID.getFancyName()};
+                throw new PatternMatcherCompileTimeException(
+                		PatternMatcherErrorStrings.VARIABLE_VARIABLEASSIGMENT_MISSING
+                		,context
+                		,assigments.get(i));
+            	}
+
+                pairs.add(pattern.addInjectivityExclusionPair(left, right));
+                //pattern.removeInjectivityInclusionPair(left,right);
+
+

+                SearchGraphEdge edge = new SearchGraphEdge();

+                SearchGraphEdge invedge = new SearchGraphEdge();

+

+                edge.setVPMEdgeType(EdgeType.VARIABLE_ASSIGNMENT);

+                edge.setOldWeight(ISearchGraph.VARIABLEASSIGNMENT_WEIGHT);

+                edge.setWeight(ISearchGraph.VARIABLEASSIGNMENT_WEIGHT);

+                edge.setSourceNode(leftNode);

+                edge.setTargetNode(rightNode);

+                edge.setSource(true);

+

+                edge.setName(leftNode.getName() +" variable assignment " + rightNode.getName());

+

+                invedge.setVPMEdgeType(EdgeType.VARIABLE_ASSIGNMENT);

+                invedge.setOldWeight(ISearchGraph.VARIABLEASSIGNMENT_WEIGHT);

+                invedge.setWeight(ISearchGraph.VARIABLEASSIGNMENT_WEIGHT);

+                invedge.setSourceNode(rightNode);

+                invedge.setTargetNode(leftNode);

+                invedge.setSource(false);

+                invedge.setName(rightNode.getName() +" INVERSE variable assignment " + leftNode.getName());

+                invedge.setInverseEdge(invedge);

+

+                rightNode.addSource(edge);

+                leftNode.addSource(invedge);
+
+                //traceability
+
+                EdgeTraceabilityElement edgeTraceability = new EdgeTraceabilityElement(edge,assigments.get(i));
+        		pattern.getSearchGraph().addTraceabilityElement(edge, edgeTraceability);
+
+        	    //source inverse
+        	    EdgeTraceabilityElement inverseEdgeTraceability = new EdgeTraceabilityElement(invedge,assigments.get(i));
+        	    pattern.getSearchGraph().addTraceabilityElement(invedge, inverseEdgeTraceability);

+            }

+        }

+        return pairs;

+    }
+
+    public Collection<Pair> processInjectivityAssignments(FlattenedPattern pattern)
+    throws PatternMatcherCompileTimeException {
+    ArrayList<Pair> pairs= null;
+    List<NonInjectivityConstraint> constraints = body.getNonInjectivityConstraints();
+    if (constraints != null) {
+    	pairs = new ArrayList<Pair>();
+        for (int i = 0; i < constraints.size(); i++) {
+            VariableID leftID = getVariableID(constraints.get(i).getLeftValue().getVariable());
+            VariableID rightID = getVariableID(constraints.get(i).getRightValue().getVariable());
+            int left = pattern.getIndex(leftID);
+            int right = pattern.getIndex(rightID);
+            pairs.add(pattern.addInjectivityInclusionPair(left, right));
+            // pattern.removeInjectivityExclusionPair(left, right); //have to remove from the Exclusion list as it is explicitly defined with the Injectivity assignment
+        }
+    }
+
+    return pairs;
+    }
+
+    public void generateElementInjectivityConstraints(FlattenedPattern flattenedPattern,
+    		Collection<Pair> localAdditionalExclusionInjectivityPairs,
+			Collection<Pair> localAdditionalInclusionInjectivityPairs) throws PatternMatcherCompileTimeException {
+
+    	 HashSet<Integer> bodyPatternIndexes = new HashSet<Integer>();
+    	 boolean isDistinctMatching = parent.getPattern().isDistinctMatching();
+
+    	 //local variables
+    	 for (Iterator<PatternVariable> iter = body.getLocalVariables().iterator(); iter.hasNext();) {
+             PatternVariable variable = iter.next();
+             Integer localVariableIndex = flattenedPattern.getIndex(getVariableID(variable));
+             bodyPatternIndexes.add(localVariableIndex);
+         }
+
+    	 //symbolic parameters are already attached to their actual invocation parameters
+    	 for (Iterator<PatternVariable> iter = parent.getPattern().getSymParameters().iterator(); iter.hasNext();) {
+             PatternVariable formalParemeter = iter.next();
+             Integer formalParameterIndex = flattenedPattern.getIndex(getVariableID(formalParemeter));
+             if(!bodyPatternIndexes.add(formalParameterIndex))
+            	 {
+            	 String[] context = {formalParameterIndex.toString(),parent.getPattern().getName()};
+            	 throw new PatternMatcherCompileTimeException(
+            			 PatternMatcherErrorStrings.INTERNAL_BODYNODE_INJECTIVITYCONSTRAINT_ALREADYUSED
+            			 ,context
+            			 ,body);
+            	 }
+         }
+
+    	 Collection<Pair> localTransitivePairs = flattenedPattern.getTransitiveExclusionSet(localAdditionalExclusionInjectivityPairs, null, true);
+    	 for(Integer i: bodyPatternIndexes)
+    		 for(Integer j: bodyPatternIndexes)
+    		 	if(i < j)
+    		 		{Pair pair = new Pair(i,j);
+						if(isDistinctMatching)
+    		 			{
+    		 			if(localAdditionalExclusionInjectivityPairs != null
+    		 					&& !localAdditionalExclusionInjectivityPairs.contains(pair)) {
+    		 				// inclusion is added only of transitive exclusion is not true
+    		 				if(!localTransitivePairs.contains(pair)) {
+    		 					flattenedPattern.addInjectivityInclusionPair(i, j);
+    		 				}
+    		 			}
+    		 			}
+    		 		else
+    		 			{
+    		 			if(localAdditionalInclusionInjectivityPairs != null
+    		 					&& !localAdditionalInclusionInjectivityPairs.contains(pair))
+    		 			flattenedPattern.addInjectivityExclusionPair(i, j);
+
+    		 			}
+    		 		}
+
+    	/* if(localAdditionalExclusionInjectivityPairs != null)
+    		 for(Pair p: localAdditionalExclusionInjectivityPairs)
+    			 flattenedPattern.removeInjectivityInclusionPair(p.getLeft(), p.getRight());
+
+    	 if(localAdditionalInclusionInjectivityPairs != null)
+    		 for(Pair p: localAdditionalInclusionInjectivityPairs)
+    			 flattenedPattern.removeInjectivityExclusionPair(p.getLeft(), p.getRight());
+    	*/
+
+
+    	 /*for (int j = 0; j < parent.pattern.getSymParameters().size(); j++) {
+                 Term actualTerm = parent.actualParameters.get(j);
+                 if (actualTerm instanceof VariableReference) {
+                     VariableReference varRef = (VariableReference) actualTerm;
+                     PatternVariable actualParameter = (PatternVariable) varRef.getVariable();
+                     Integer index = flattenedPattern.getIndex(getCallerBody().getVariableID(actualParameter));
+                 }
+    	 }*/
+
+	}

+

+    public void processCheckExpressions(FlattenedPattern pattern, Logger logger) {

+        List<Term> checkExpressions = body.getCheckExpressions();

+        if (checkExpressions != null) {

+            ITermHandler handler = pattern.getTermHandler();

+            if (handler != null) {

+                for (int i = 0; i < checkExpressions.size(); i++) {

+                    CheckOperation operation =

+                        handler.getTermCheckOperation(parent.getPattern(), currentLocation, checkExpressions.get(i));

+                    pattern.addPostSearchPlanOperation(operation);

+                }

+            } else {

+                logger.warning(PatternMatcherErrorStrings.NO_TERM_HANDLER);

+            }

+        }

+    }

+

+    public void processNegativeApplicationConditions(FlattenedPattern pattern, Logger logger, IModelManager manager)

+        throws PatternMatcherCompileTimeException {

+        List<GTPatternCall> negativeCalls = body.getNegativePatterns();
+        GTPattern header = body.getHeader();

+        if (negativeCalls != null && negativeCalls.size() > 0) {

+            for (int i = 0; i < negativeCalls.size(); i++) {

+                GTPatternCall call = negativeCalls.get(i);

+                PatternBuilder builder = new PatternBuilder(logger, manager, pattern.getTermHandler());

+                IPatternMatcher matcher = builder.construct(call.getCalledPattern());

+                List<Term> actualTerms = call.getActualParameters();

+                Collection<Variable> passingVariables = new ArrayList<Variable>();
+
+                int[] actualParameterMapping = new int[actualTerms.size()];

+                for (int j = 0; j < actualTerms.size(); j++) {

+                    Term term = actualTerms.get(j);

+                    if (term instanceof VariableReference) {

+                        VariableReference varRef = (VariableReference) term;

+                        actualParameterMapping[j] =

+                            pattern.getIndex(getVariableID(varRef.getVariable()));
+
+                        if(header.getSymParameters().contains(varRef.getVariable())) //it is a variable that goes into the NAC call
+                        	passingVariables.add(varRef.getVariable());
+
+                    } else {
+                    	String[] context = {""+j,call.getCalledPattern().getName()};

+                        throw new PatternMatcherCompileTimeException(

+                                PatternMatcherErrorStrings.NO_TERM_IN_NAC_CALLS
+                                ,context
+                                ,call);

+                    }

+                }
+

+                NACCheckOperation operation = new NACCheckOperation(matcher, actualParameterMapping,call,
+                			passingVariables);

+                pattern.addPostSearchPlanOperation(operation);

+            }

+        }

+    }

+
+    public void buildSearchGraph(FlattenedPattern result) throws PatternMatcherCompileTimeException{
+		try{
+    		result.getSearchGraph().add(this,result);
+		}catch (PatternMatcherCompileTimeException e) {
+			throw e.addNewStackElement(this.body);
+		}
+	}
+

+    public String toString() {

+        return getClass().getSimpleName() + " " + parent.getPattern().getName() + "_" + currentLocation;

+    }

+

+    public CheckOperation getTermEvaluationOperation(ITermHandler handler, ContainmentConstraint conCons, int resultSlot) {

+    	return handler.getTermEvaluationOperation(parent.getPattern(), currentLocation, conCons, resultSlot);

+    }
+

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/callgraph/CallGraphNode.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/callgraph/CallGraphNode.java
new file mode 100644
index 0000000..63cb171
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/callgraph/CallGraphNode.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.callgraph;

+

+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.GTPattern;
+

+// TODO gervarro: refactor (normalis DFS-t csinalni) (iterative deepening DFS-t hasznalni???)

+public abstract class CallGraphNode {

+    int index;

+    int currentLocation;

+

+    abstract protected PatternNode causesRecursion(GTPattern patternToTest);

+    abstract protected boolean traverse(PatternVariantIterator token);

+    

+    CallGraphNode() {

+        this.index = 0;

+        this.currentLocation = 0;

+    }

+    

+    public void setCurrentLocation(int currentLocation) {

+    	this.currentLocation = currentLocation;

+    }

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/callgraph/DanglingVPMElementDTO.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/callgraph/DanglingVPMElementDTO.java
new file mode 100644
index 0000000..84a420e
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/callgraph/DanglingVPMElementDTO.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.callgraph;

+

+import org.eclipse.viatra2.gtasmmodel.vpm.editmodel.VPMElement;
+

+/** Holds a dangling relation's or relationship's context information

+ * @author Akos Horvath

+ *

+ */

+public class DanglingVPMElementDTO {

+

+	VPMElement element;

+	BodyNode bodyNode;

+	public DanglingVPMElementDTO(VPMElement element, BodyNode bodyNode) {

+		this.element = element;

+		this.bodyNode = bodyNode;

+	}

+	/**

+	 * @return the bodyNode

+	 */

+	public BodyNode getBodyNode() {

+		return bodyNode;

+	}

+	/**

+	 * @param bodyNode the bodyNode to set

+	 */

+	public void setBodyNode(BodyNode bodyNode) {

+		this.bodyNode = bodyNode;

+	}

+	/**

+	 * @return the element

+	 */

+	public VPMElement getElement() {

+		return element;

+	}

+	/**

+	 * @param element the element to set

+	 */

+	public void setElement(VPMElement element) {

+		this.element = element;

+	}

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/callgraph/EvenLevelNode.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/callgraph/EvenLevelNode.java
new file mode 100644
index 0000000..218f34a
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/callgraph/EvenLevelNode.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.callgraph;

+

+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.GTPattern;
+

+public class EvenLevelNode extends CallGraphNode {

+	protected PatternNode parent;

+

+	public EvenLevelNode(PatternNode parent) {

+		this.parent = parent;

+	}

+	

+	@Override

+	protected PatternNode causesRecursion(GTPattern patternToTest) {

+		return null;

+	}

+

+	@Override

+	protected boolean traverse(PatternVariantIterator token) {

+		return false;

+	}

+	

+	public PatternNode getParent() {

+		return parent;

+	}

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/callgraph/FlattenedPattern.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/callgraph/FlattenedPattern.java
new file mode 100644
index 0000000..43e65da
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/callgraph/FlattenedPattern.java
@@ -0,0 +1,502 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.callgraph;

+

+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeMap;
+import java.util.TreeSet;
+import java.util.Vector;
+
+import org.eclipse.viatra2.core.IModelManager;
+import org.eclipse.viatra2.gtasm.patternmatcher.PatternCallSignature;
+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherCompileTimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherRuntimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.PatternMatcherErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.SearchPlan;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.SearchPlanKey;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.VariableID;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.algorithms.ISearchGraph;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.algorithms.SearchGraphFactory;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation.DummyOperation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation.InjectivityCheckOperation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation.PatternCallOperation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation.SearchPlanOperation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.rgg.IQueueContentProvider;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.rgg.IndexedRule;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.rgg.LocalGoal;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.rgg.MagicSet;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.rgg.RemoteGoal;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.rgg.UnindexedRule;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.AbstractNode;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.term.ITermHandler;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
+import org.eclipse.viatra2.logger.Logger;
+

+

+/**

+ * A FlattenedPattern corresponds to a PatternBody, in which

+ * variables from all the embedded pattern invocations are aggregated.

+ * 

+ * FlattenedPatterns are generated during the pattern invocation analysis of

+ * GTPatternBodies. If the pattern call graph is a DAG, then we have a 

+ * non-recursive FlattenedPattern consisting of all the variables that appear

+ * in the GTPatternBody itself or any patterns that are called by the 

+ * GTPatternBody.

+ * 

+ * Each branch of OR patterns obviously generate a new FlattenedPattern.

+ * 

+ * The interpreted engine uses the following mapping:

+ * VariableType => PatternVariable

+ */

+public class FlattenedPattern extends EvenLevelNode 

+	implements Comparable<FlattenedPattern> {

+    

+    private boolean isRecursionBased;

+

+    private ISearchGraph searchGraph;

+	/**

+     * The mapping of pattern variables to their location in

+     * the PatternFrames.

+	 */

+    private Map<VariableID,Integer> variableMapping;

+    private Map<Integer, Set<VariableID>> inverseVariableMapping;

+

+    private Set<Pair> injectivityExclusionSet, injectivityInclusionSet, injectivityTransitiveExclusionSet;

+    

+	/**

+     * The mapping of PatternSignatures to the SearchPlans

+     * that are available for a given PatternSignature.

+	 */

+	private Map<SearchPlanKey,Collection<SearchPlan>> searchPlanMapping;

+

+	private Vector<SearchPlanOperation> preSearchPlanOperations;

+    private Vector<SearchPlanOperation> postSearchPlanOperations;

+    

+    /**

+     * The size of the binding arrays inside the corresponding 

+     * MatchingFrames.

+	 */

+	private int frameSize;

+    private int injectivityFrameSize;

+    

+    public FlattenedPattern(PatternNode parent, List<IFlattenedPatternElement> specification) 

+        throws PatternMatcherCompileTimeException {

+    	super(parent);

+    	//this.SearchGraph = new VPMBasedSearchGraph(parent.getModelManager());

+    	this.searchGraph = SearchGraphFactory.getSearchGraph(parent.getModelManager());

+    	this.variableMapping = new HashMap<VariableID, Integer>();

+        this.inverseVariableMapping = new TreeMap<Integer, Set<VariableID>>();

+    	this.searchPlanMapping = new HashMap<SearchPlanKey, Collection<SearchPlan>>();

+      	this.preSearchPlanOperations = new Vector<SearchPlanOperation>();

+        this.postSearchPlanOperations = new Vector<SearchPlanOperation>();

+        this.isRecursionBased = false;

+        this.frameSize = 0;

+        this.injectivityFrameSize = 0;

+        this.injectivityExclusionSet = new HashSet<Pair>();
+        injectivityInclusionSet = new HashSet<Pair>();

+        injectivityTransitiveExclusionSet = new HashSet<Pair>();

+

+        Logger logger = parent.getLogger();

+        // Main loop for processing all the variables of a pattern variant

+        for (int i = 0; i < specification.size(); i++) {

+            IFlattenedPatternElement element = specification.get(i);

+            element.setCurrentLocation(i);

+            element.addFormalParameters(this);

+            element.addLocalVariables(this);

+        }

+        injectivityFrameSize = frameSize;

+        for (int i = 0; i < specification.size(); i++) {

+            IFlattenedPatternElement element = specification.get(i);

+            element.processNegativeApplicationConditions(this, logger, parent.getModelManager());

+            element.processCheckExpressions(this, logger);

+            element.buildSearchGraph(this);

+            element.generateElementInjectivityConstraints(this, 
+            		element.processVariableAssignments(this),
+            		element.processInjectivityAssignments(this));
+            

+            // element.processFormalParameterScopes(this);

+            //Scope of the input parameter is not added to the search graph

+            // element.processPatternCallScopes(this);

+        }

+        this.searchGraph.connectDanglingRelations(this);

+        addPostSearchPlanOperation(new InjectivityCheckOperation());

+

+        //TODO: in case of adaptive pattern matching the searchNodeOrder is not fix have to go back to the iSearchGraph itself

+        // the order of the nodes are calculated, it would be better to have it contained

+
+        //For debugging purpose

+//      result.searchNodeOrder= result.alg.evaulateSearchPlan(result);

+//      result.debug(); 

+//      //result.debugPL(a);

+//      result.alg.evaulateOperationPlan(result.searchNodeOrder);

+

+        printVariableMapping(logger);

+    }

+    

+    /**

+     * Adds SearchPlan plan to the set of search plans with

+     * PatternSignature signature.

+     * @param signature The key that identifies the set of search plans 

+     * to which plan has to be added. 

+     * @param plan The search plan to be added.

+     * @return true if plan has been successfully added to the

+     * search plan mapping dictionary.

+     */

+    boolean addSearchPlan(PatternCallSignature signature, SearchPlan plan) {

+        return false;

+    }

+    

+    MatchingFrame getInstance() {

+        return null;

+    }

+    

+    Collection<SearchPlan> getSearchPlansFor(SearchPlanKey key) {

+        return searchPlanMapping.get(key);

+    }

+

+    /**

+     * 

+     * @return the frameSize

+     */

+    public int getFrameSize() {

+        return frameSize;

+    }

+

+    /**

+     * @param frameSize the frameSize to set

+     */

+    public void setFrameSize(int frameSize) {

+        this.frameSize = frameSize;

+    }

+    

+    public ISearchGraph getSearchGraph() {

+    	return searchGraph;

+    }

+    

+    public void addPreSearchPlanOperation(SearchPlanOperation operation) {

+        preSearchPlanOperations.add(operation);

+    }

+    

+    public void addPostSearchPlanOperation(SearchPlanOperation operation) {

+        postSearchPlanOperations.add(operation);

+    }

+    

+    public Integer getIndex(VariableID variable) {

+        return variableMapping.get(variable);

+    }

+    

+    public Set<VariableID> getVariableIDs(Integer index) {

+        return inverseVariableMapping.get(index);

+    }

+    

+    private void addToInverseMapping(VariableID variable, Integer index) {

+        Set<VariableID> idSet = inverseVariableMapping.get(index);

+        if (idSet == null) {

+            idSet = new HashSet<VariableID>();

+            inverseVariableMapping.put(index, idSet);

+        }

+        idSet.add(variable);

+    }

+    

+    public void setIndex(VariableID variable, Integer index) {

+        variableMapping.put(variable, index);

+        addToInverseMapping(variable, index);

+    }

+    

+    public int addVariable(VariableID variable) {

+        if (variable != null) {

+            variableMapping.put(variable, frameSize);

+            addToInverseMapping(variable, frameSize);

+        }

+        return frameSize++;

+    }

+    

+    private void printVariableMapping(Logger logger) {

+        for (VariableID id : variableMapping.keySet()) {

+            logger.debug(id.toString() + " : " + variableMapping.get(id));

+        }

+        for (Integer key : inverseVariableMapping.keySet()) {

+            for (VariableID id : inverseVariableMapping.get(key)) {

+                logger.debug(key + " : " + id.toString());

+            }

+        }

+        logger.debug("Injective frame size: \t" + injectivityFrameSize);

+        logger.debug("Frame size: \t" + frameSize);

+    }

+    

+    public boolean containsIndex(VariableID variable){

+    	return variableMapping.containsKey(variable);

+    }

+

+	// Moves non-recursion based patterns ahead of recursion based patterns

+    public int compareTo(FlattenedPattern o) {

+        /*

+         * this = o : !isRecursionBased AND !o.isRecursionBased

+         * this = o : isRecursionBased AND o.isRecursionBased

+         * this > o : isRecursionBased AND !o.isRecursionBased

+         * this < o : !isRecursionBased AND o.isRecursionBased

+         */

+        if (isRecursionBased == o.isRecursionBased) {

+            return 0;

+        } else {

+            return (isRecursionBased ? 1 : -1);

+        }

+    }

+

+    /**

+     * @return the injectivityFrameSize

+     */

+    public int getInjectivityFrameSize() {

+        return injectivityFrameSize;

+    }

+

+    public ITermHandler getTermHandler() {

+        return parent.getTermHandler();

+    }

+    

+    public Collection<SearchPlanOperation> generateCoreSearchPlan(Boolean[] adornment, IModelManager manager) throws PatternMatcherRuntimeException{

+    	return searchGraph.generateSearchPlan(this, adornment, manager);

+    }

+    

+    public List<SearchPlanOperation> generateSearchPlan(Boolean[] adornment, IModelManager manager) throws PatternMatcherRuntimeException{

+    	Collection<SearchPlanOperation> vec = searchGraph.generateSearchPlan(this, adornment,manager);

+

+    	// Copies pre and post operations

+    	ArrayList<SearchPlanOperation> finalSearchPlan = new ArrayList<SearchPlanOperation>();

+    	finalSearchPlan.addAll(preSearchPlanOperations);

+    	finalSearchPlan.addAll(vec);

+    	finalSearchPlan.addAll(postSearchPlanOperations);

+    	SearchPlanOperation[] operations = new SearchPlanOperation[finalSearchPlan.size()];

+    	operations = finalSearchPlan.toArray(operations);

+    	SearchPlan splan = new SearchPlan(operations);

+    	splan.printDebugInformation(parent.getLogger());

+    	// sets the iSearchGraph back to starting state

+    	searchGraph.initSearchGraph();

+    	

+        return finalSearchPlan;

+    }

+

+    IQueueContentProvider buildSubtree(Map<String, RemoteGoal> rggRoots,

+    		MagicSet ms,

+    		List<SearchPlanOperation> searchPlan, 

+    		int upperBound, 

+    		SortedSet<Integer> preCallInterfaceVariables) throws PatternMatcherRuntimeException {

+    	//gervarro: put to the constructor of the Rule?

+        SortedSet<Integer> localVariables = new TreeSet<Integer>();

+        int i = upperBound;

+    	for (; i >= 0 && !(searchPlan.get(i) instanceof PatternCallOperation); i--) {

+			searchPlan.get(i).calculateSidewaysPassedVariables(preCallInterfaceVariables);

+			searchPlan.get(i).calculateLocalVariables(localVariables);

+    	}

+

+    	if (upperBound < 0) {

+    		// sup_i.0 :- ms_i

+    		return ms; // look up the appropriate magic set

+    	} else if (i < upperBound) {

+    		// sup_i.j :- sup_i.(j-1), local_j

+    		IQueueContentProvider left = 

+    			buildSubtree(rggRoots, ms, searchPlan, i, preCallInterfaceVariables);

+    		List<SearchPlanOperation> operations = 

+    			new Vector<SearchPlanOperation>(searchPlan.subList(i+1, upperBound+1));

+    		operations.add(new DummyOperation());

+    		SearchPlanOperation[] array = new SearchPlanOperation[operations.size()];

+    		array = operations.toArray(array);

+    		LocalGoal right = new LocalGoal(array);

+

+    		/*

+			int size = localVariables.size();

+			Integer[] localVariableMapping = new Integer[size];

+			Boolean[] adornment = new Boolean[size];

+			int counter = 0;

+			for (Integer position: localVariables) {

+				adornment[counter] = preCallInterfaceVariables.contains(position);

+				counter++;

+			}

+			localVariables.toArray(localVariableMapping);

+			*/

+

+    		return new UnindexedRule(this, left, right);

+    	} else if (i == upperBound) {

+    		// sup_i.j :- sup_i.(j-1), remote_j

+    		PatternCallOperation pco = (PatternCallOperation) searchPlan.get(i);

+    		pco.calculateSidewaysPassedVariables(preCallInterfaceVariables);

+			pco.calculateLocalVariables(localVariables);

+			

+    		IQueueContentProvider left = 

+    			buildSubtree(rggRoots, ms, searchPlan, i-1, preCallInterfaceVariables);

+

+    		String id = RemoteGoal.generateID(pco.getPatternNode(), pco.getAdornment());

+    		// If right goal exists in runtimes

+     		if (rggRoots.containsKey(id)) {

+        		// then get the runtime from runtimes

+    			RemoteGoal right = rggRoots.get(id);

+    			return new IndexedRule(this, left, right, pco.getParameterMapping(), pco.getAdornment());

+    		} else {

+        		// else generate a new runtime

+    			RemoteGoal right = pco.getPatternNode().buildRuleGoalGraph(pco.getAdornment(),rggRoots);

+    			return new IndexedRule(this, left, right, pco.getParameterMapping(), pco.getAdornment());

+    		}

+    		// ms_call :- sup_i.(j-1)

+     		// Explicitly handled by RemoteGoal 

+    	} else {
+    		String[] context = {getParent().getPattern().getName()};

+    		throw new PatternMatcherRuntimeException(
+    				PatternMatcherErrorStrings.INTERNAL_FLATTENED_PATTERN_BUILD
+    				,context
+    				,getParent().getPattern());

+    	}

+    }
+    
+    public AnnotatedElement getGTASMRepresentation(AbstractNode node){
+    	return searchGraph.getGTASMRepresentation(node);
+    }
+    
+    
+    

+    

+    public Pair addInjectivityExclusionPair(int left, int right) {

+    	Pair p = (left < right ? new Pair(left,right) : new Pair(right,left));

+    	injectivityExclusionSet.add(p);
+    	injectivityTransitiveExclusionSet.add(p);
+    	injectivityTransitiveExclusionSet.addAll(getTransitiveExclusionSet(injectivityTransitiveExclusionSet,p, true));
+    	return p;

+    }
+    
+    public void removeInjectivityExclusionPair(int left, int right) {
+    	Pair p = (left < right ? new Pair(left,right) : new Pair(right,left));
+    	if(injectivityExclusionSet.remove(p)) {
+    	// must rebuild set on remove
+				// TODO refactor may be possible by looking at injectivityInclusionSet as well
+				injectivityTransitiveExclusionSet.clear();
+				injectivityTransitiveExclusionSet.addAll(injectivityExclusionSet);
+				injectivityTransitiveExclusionSet.addAll(getTransitiveExclusionSet(injectivityExclusionSet, p, false));
+    	}
+    }

+    
+    public Pair addInjectivityInclusionPair(int left, int right) {
+     	Pair p = (left < right ? new Pair(left,right) : new Pair(right,left));
+     	//if(!injectivityTransitiveExclusionSet.contains(p)) {
+     		// outsider doesn't know about transitive exclusions
+     		injectivityInclusionSet.add(p);
+     		return p;
+     	//} else {
+     	//	return null;
+     	//}
+ 	}
+
+		/**
+		 * @param p
+		 * @param add
+		 */
+		public Collection<Pair> getTransitiveExclusionSet(Collection<Pair> initialPairing, Pair p, boolean add) {
+			boolean isModified = true;
+			Collection<Pair> pairs = new HashSet<Pair>();
+			if(initialPairing != null) {
+				pairs.addAll(initialPairing);
+			}
+			Collection<Pair> pairsToCheck = new HashSet<Pair>();
+			if(add && p != null) {
+				// p is added to the set
+				pairsToCheck.add(p);
+			} else {
+				pairsToCheck.addAll(pairs);
+			}
+			while(isModified) {
+				isModified = false;
+				Collection<Pair> newPairs = new HashSet<Pair>();
+				for(Pair check : pairsToCheck) {
+				 	for(Pair pair : pairs) {
+				 		if(pair.equals(check)) {
+				 			continue;
+				 		}
+				 		if(pair.left == check.left) {
+				 			Pair transitivePair = (pair.right < check.right ? new Pair(pair.right,check.right) : new Pair(check.right,pair.right));
+				 			isModified = (!pairs.contains(transitivePair) && newPairs.add(transitivePair)) || isModified;
+				 		} else if(pair.left == check.right) {
+				 			Pair transitivePair = (pair.right < check.left ? new Pair(pair.right,check.left) : new Pair(check.left,pair.right));
+				 			isModified = (!pairs.contains(transitivePair) && newPairs.add(transitivePair)) || isModified;
+				 		} else if(pair.right == check.left) {
+				 			Pair transitivePair = (pair.left < check.right ? new Pair(pair.left,check.right) : new Pair(check.right,pair.left));
+				 			isModified = (!pairs.contains(transitivePair) && newPairs.add(transitivePair)) || isModified;
+				 		} else if(pair.right == check.right) {
+				 			Pair transitivePair = (pair.left < check.left ? new Pair(pair.left,check.left) : new Pair(check.left,pair.left));
+				 			isModified = (!pairs.contains(transitivePair) && newPairs.add(transitivePair)) || isModified;
+				 		}
+				 	}
+				}
+				if(isModified) {
+					isModified = pairs.addAll(newPairs);
+					pairsToCheck = newPairs;
+				}
+			}
+			return pairs;
+		}
+    
+    public void removeInjectivityInclusionPair(int left, int right) {
+     	Pair p = (left < right ? new Pair(left,right) : new Pair(right,left));
+    	injectivityInclusionSet.remove(p);
+	}
+    

+    public boolean isIncludedInInjectivityCheck(int i, int j) {

+    	Pair p = (i < j ? new Pair(i,j) : new Pair(j,i));
+    	return injectivityInclusionSet.contains(p); // if it is in the Inclusion set then it has to be checked for injectivity (|| !injectivityExclusionSet.contains(p)) 

+    }

+    

+	public static class Pair {

+		public Integer getLeft() {
+			return left;
+		}
+
+		public Integer getRight() {
+			return right;
+		}
+
+		private Integer left;

+		private Integer right;

+		

+		Pair(int left, int right) {

+			this.left = left;

+			this.right = right;

+		}

+		

+		public boolean equals(Object other) {

+			if (other != null && other instanceof Pair) {

+				Pair o = (Pair) other;

+				return (left == o.left && right == o.right);

+			} else {

+				return false;

+			}

+		}

+		

+		public int hashCode() {

+			return left.hashCode() + right.hashCode();

+		}
+		
+		@Override
+		public String toString() {
+			// TODO Auto-generated method stub
+			return left + " : " + right;
+		}

+	}
+
+	
+
+	

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/callgraph/IFlattenedPatternElement.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/callgraph/IFlattenedPatternElement.java
new file mode 100644
index 0000000..80c46c6
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/callgraph/IFlattenedPatternElement.java
@@ -0,0 +1,83 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.callgraph;

+

+import java.util.Collection;
+
+import org.eclipse.viatra2.core.IModelManager;
+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherCompileTimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.callgraph.FlattenedPattern.Pair;
+import org.eclipse.viatra2.logger.Logger;
+

+

+public interface IFlattenedPatternElement {

+    /** Adds the local variables of the pattern body to the search graph of its container search graph
+     * @param pattern The container flattened pattern 
+     * @throws PatternMatcherCompileTimeException
+     */
+    void addLocalVariables(FlattenedPattern pattern)

+        throws PatternMatcherCompileTimeException;

+    /** Evaluates the passed parameters of the flattened pattern body invocation and adds them to the search graph of its container flattened pattern
+     * @param pattern the container flattened pattern
+     * @throws PatternMatcherCompileTimeException
+     */
+    void addFormalParameters(FlattenedPattern pattern)

+        throws PatternMatcherCompileTimeException;

+    /** Adds the variable assignment related elements to the search graph of its containing flattened pattern
+     * @param pattern The container flattened pattern
+     * @throws PatternMatcherCompileTimeException
+     */
+   Collection<Pair> processVariableAssignments(FlattenedPattern pattern)

+        throws PatternMatcherCompileTimeException;

+    /** Adds the NAC check operation to its flattened pattern
+     * @param pattern The container flattened pattern
+     * @param logger The logger to be used in case of execution
+     * @param manager The model manager used to match the NAC pattern
+     * @throws PatternMatcherCompileTimeException
+     * @return The collection of the assigned variables pairs
+     */
+   void processNegativeApplicationConditions(FlattenedPattern pattern, Logger logger, IModelManager manager)

+        throws PatternMatcherCompileTimeException;

+    /** Adds a check operation to the operation plan of its flattened pattern.
+     * @param pattern The container flattened pattern
+     * @param logger The logger to be used when the operation is executed
+     * @throws PatternMatcherCompileTimeException
+     */
+    void processCheckExpressions(FlattenedPattern pattern, Logger logger)

+        throws PatternMatcherCompileTimeException;

+    /**Builds the Search graph of the input flattened pattern
+     * @param pattern The flattened pattern whose search graph is created
+     * @throws PatternMatcherCompileTimeException
+     */
+    void buildSearchGraph(FlattenedPattern pattern)

+        throws PatternMatcherCompileTimeException;

+    /** Sets the current location ID to the input value
+     * @param currentLocation
+     */
+    void setCurrentLocation(int currentLocation);
+    
+    /** Adds the injectivity constraints defined in the pattern to the search operations
+     * @param pattern The container flattened pattern
+     * @throws PatternMatcherCompileTimeException
+     * @return The collection of the assigned variables pairs 
+     */
+    public Collection<Pair> processInjectivityAssignments(FlattenedPattern pattern) throws PatternMatcherCompileTimeException ;
+	
+    /**Generates the injectivity constraints based on its container graph pattern's setting (sharable) and the actual variable assignment and non equality operations
+	 * @param flattenedPattern the container flattened pattern
+     * @param localAdditionalExclusionInjectivityPairs Variable pair indexes that were included in a variable assignment operation (in the actual pattern body)
+	 * @param localAdditionalInclusionInjectivityPairs Variable pair indexes that were included in a non equality  operation (in the actual pattern body)
+   */
+	public void generateElementInjectivityConstraints(FlattenedPattern flattenedPattern,
+			Collection<Pair> localAdditionalExclusionInjectivityPairs,
+			Collection<Pair> localAdditionalInclusionInjectivityPairs) throws PatternMatcherCompileTimeException; 

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/callgraph/OddLevelNode.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/callgraph/OddLevelNode.java
new file mode 100644
index 0000000..146da17
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/callgraph/OddLevelNode.java
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.callgraph;

+

+import java.util.List;
+
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.terms.GTPatternCall;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.terms.Term;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.GTPattern;
+

+public abstract class OddLevelNode extends CallGraphNode {

+    private EvenLevelNode parent;

+    private GTPattern pattern;
+    private List<Term> actualParameters;
+    private GTPatternCall patternCall;

+

+    OddLevelNode(EvenLevelNode parent, GTPattern pattern) {

+        this(parent,pattern,null);

+    }

+    

+    OddLevelNode(EvenLevelNode parent, GTPatternCall call) {
+    	this(parent,call.getCalledPattern(),call.getActualParameters());
+    	patternCall = call;
+    }

+    

+    OddLevelNode(EvenLevelNode parent, GTPattern pattern, List<Term> parameters) {

+        super();

+        this.parent = parent;

+        this.pattern = pattern;

+        this.actualParameters = (parameters != null && parameters.size() > 0 ? parameters : null);

+    }

+    

+    public GTPattern getPattern() {

+        return pattern;

+    }
+    
+    public GTPatternCall getPatternCall() {
+        return patternCall;
+    }

+    

+    public List<Term> getActualParameters() {

+    	return actualParameters;

+    }

+    

+    public EvenLevelNode getParent() {

+    	return parent;

+    }

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/callgraph/PatternMatcherWrapper.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/callgraph/PatternMatcherWrapper.java
new file mode 100644
index 0000000..77db134
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/callgraph/PatternMatcherWrapper.java
@@ -0,0 +1,84 @@
+/*******************************************************************************

+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro

+ * All rights reserved. This program and the accompanying materials

+ * are made available under the terms of the Eclipse Public License v1.0

+ * which accompanies this distribution, and is available at

+ * http://www.eclipse.org/legal/epl-v10.html

+ *

+ * Contributors:

+ *    Akos Horvath, Gergely Varro - initial API and implementation

+ *******************************************************************************/

+package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.callgraph;

+

+import java.util.Collection;

+

+import org.eclipse.viatra2.core.IModelManager;

+import org.eclipse.viatra2.gtasm.interpreter.exception.ViatraTransformationException;

+import org.eclipse.viatra2.gtasm.patternmatcher.IMatching;

+import org.eclipse.viatra2.gtasm.patternmatcher.PatternCallSignature;

+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherCompileTimeException;

+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.PatternMatcher;

+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.term.ITermHandler;

+import org.eclipse.viatra2.gtasm.patternmatcher.patterns.IPatternMatcher;

+import org.eclipse.viatra2.logger.Logger;

+

+

+/**Used to wrap the incremental (alternate) pattern matcher PatternMatcher class in order to be used in the rule goal graph

+ * @author Akos Horvath

+ *

+ */

+public class PatternMatcherWrapper extends PatternMatcher {

+

+	IPatternMatcher alternatepatternMatcher;

+	

+	public PatternMatcherWrapper(IPatternMatcher patternMatcher, Logger logger,

+			IModelManager manager, ITermHandler termHandler)

+			throws PatternMatcherCompileTimeException {

+		super(logger, manager, termHandler);

+		alternatepatternMatcher = patternMatcher;

+	}

+

+//	public PatternMatcherWrapper(PatternMatcher patternMatcher, Logger logger,

+//			IModelManager modelManager, ITermHandler termHandler) throws PatternMatcherCompileTimeException {

+//		super(logger, modelManager, termHandler);

+//		alternatepatternMatcher = patternMatcher;

+//	}

+

+	@Override

+	public IMatching match(Object[] inputMapping,

+			PatternCallSignature[] signature) throws ViatraTransformationException{

+		if(alternatepatternMatcher != null)

+			return alternatepatternMatcher.match(inputMapping,signature);

+		else

+		return super.match(inputMapping, signature);

+	}

+

+	@Override

+	public boolean match(Object[] inputMapping)

+			throws ViatraTransformationException {

+		if(alternatepatternMatcher != null)

+			return alternatepatternMatcher.match(inputMapping);

+		else

+			return super.match(inputMapping);

+	}

+

+	@Override

+	public Collection<IMatching> matchAll(Object[] inputMapping,

+			PatternCallSignature[] signature, Integer[] quantificationOrder)

+			throws ViatraTransformationException {

+		if(alternatepatternMatcher != null)

+			return alternatepatternMatcher.matchAll(inputMapping,signature,quantificationOrder);

+		else

+		return super.matchAll(inputMapping, signature, quantificationOrder);

+	}

+

+	@Override

+	public IMatching matchRandomly(Object[] inputMapping,

+			PatternCallSignature[] signature) throws ViatraTransformationException{

+		if(alternatepatternMatcher != null)

+			return alternatepatternMatcher.matchRandomly(inputMapping, signature);

+		else

+		return super.matchRandomly(inputMapping, signature);

+	}

+

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/callgraph/PatternNode.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/callgraph/PatternNode.java
new file mode 100644
index 0000000..1ecaeac
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/callgraph/PatternNode.java
@@ -0,0 +1,211 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.callgraph;

+

+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import org.eclipse.viatra2.core.IModelManager;
+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherCompileTimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherRuntimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.PatternMatcher;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.PatternMatcherErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation.SearchPlanOperation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.rgg.RemoteGoal;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.rgg.Rule;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.term.ITermHandler;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.terms.GTPatternCall;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.GTPattern;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.GTPatternBody;
+import org.eclipse.viatra2.logger.Logger;
+

+

+public class PatternNode extends OddLevelNode 

+	implements Iterable<List<IFlattenedPatternElement>> {

+    private boolean isRoot;

+    protected PatternMatcher patternMatcher;

+    protected EvenLevelNode[] children;

+    // private boolean[] adornmentRestriction;

+    

+    protected PatternNode(BodyNode parent, GTPatternCall call){
+    	super(parent,call);
+    	isRoot = false;
+    }
+    
+    public PatternNode(PatternMatcher patternMatcher, 

+    		BodyNode parent, GTPatternCall call) throws PatternMatcherCompileTimeException {

+        super(parent,call);

+        this.isRoot = false;
+        this.patternMatcher = patternMatcher;

+        this.children = new BodyNode[getPattern().getPatternBodies().size()];

+        buildCallGraph();

+    }

+    

+    public PatternNode(PatternMatcher patternMatcher, GTPattern pattern) 

+    		throws PatternMatcherCompileTimeException {

+        super(null, pattern);

+        this.isRoot = true;

+        this.patternMatcher = patternMatcher;
+        this.children = new BodyNode[pattern.getPatternBodies().size()];

+        buildCallGraph();

+    }

+    

+  private void buildCallGraph() throws PatternMatcherCompileTimeException {

+    	// Call graph building

+        List<GTPatternBody> bodies = getPattern().getPatternBodies();

+    	for (int i = 0; i < bodies.size(); i++) {

+			children[i] = new BodyNode(patternMatcher, this, bodies.get(i));

+		}

+    	// Flattening process

+        if (isRoot) {

+        	List<FlattenedPattern> flattenedPatterns = 

+        		new ArrayList<FlattenedPattern>();

+            int index = 0;

+            for (List<IFlattenedPatternElement> patternVariant : this) {

+                printPatternVariant(patternVariant, patternMatcher.getLogger());

+
+                FlattenedPattern fp = 

+                	new FlattenedPattern(this, patternVariant);

+                flattenedPatterns.add(fp);

+                index++;

+            }

+            // Sort the flattened patterns.

+            // Collections.sort(flattenedPatterns);

+            children = new FlattenedPattern[flattenedPatterns.size()];

+            children = flattenedPatterns.toArray(children);

+        }

+    }
+    
+    protected PatternNode causesRecursion(GTPattern patternToTest) {

+        if (getPattern() == patternToTest) {

+            isRoot = true;

+            return this;

+        } else {

+            return (getParent() == null ? null : getParent().causesRecursion(patternToTest));

+        }

+    }

+

+    @Override

+    protected boolean traverse(PatternVariantIterator token) {

+        int size = children.length;

+        assert 0 <= index && index <= size;

+        if (index <= 0) {

+            BodyNode body = (BodyNode) children[index];

+            token.addLast(body);

+            index++;

+            body.index = 0;

+            return body.traverse(token);

+        } else {

+            BodyNode body = (BodyNode) children[index-1];

+            boolean successful = body.traverse(token);

+            if (successful) {

+                return true;

+            } else {

+                token.removeLast();

+                if (index < size) {

+                    body = (BodyNode) children[index];

+                    index++;

+                    token.addLast(body);

+                    body.index = 0;

+                    return body.traverse(token);

+                } else {

+                    return false;

+                }

+            }

+        }

+    }

+

+    boolean isRoot() {

+        return isRoot;

+    }

+    

+    public Iterator<List<IFlattenedPatternElement>> iterator() {

+        return new PatternVariantIterator(this);

+    }

+

+    private static void printPatternVariant(List<IFlattenedPatternElement> patternVariant, Logger logger) {

+        for (IFlattenedPatternElement element : patternVariant) {

+            logger.debug(element.toString());

+        }

+    }

+    

+    public ITermHandler getTermHandler() {

+        return patternMatcher.getTermHandler();

+    }

+    

+    public Logger getLogger() {

+        return patternMatcher.getLogger();

+    }

+

+    public IModelManager getModelManager() {

+    	return patternMatcher.getModelManager();

+    }

+    

+    // Can be be moved to a descendant of PatternNode

+    public FlattenedPattern getSingleFlattenedPattern() throws PatternMatcherCompileTimeException {

+    	if (children.length == 1 && children[0] instanceof FlattenedPattern) {

+    		return (FlattenedPattern) children[0];

+    	} else {
+    		String[] context = {};

+    		throw new PatternMatcherCompileTimeException(
+    				PatternMatcherErrorStrings.MULTIBODY_OR_RECURSIVE_PATTERN_ON_RHS
+    				,context
+    				,getPattern());

+    	}

+    }

+   

+    public FlattenedPattern[] getFlattenedPatterns() throws PatternMatcherCompileTimeException {

+    	FlattenedPattern[] result = new FlattenedPattern[children.length];

+    	for(int i = 0; i< children.length; i++){

+    		if(children[i] instanceof FlattenedPattern)

+    			result[i] = (FlattenedPattern) children[i];

+//    		else

+//    			{
+//    			String[] context = {};
+//    			throw new PatternMatcherCompileTimeException(
+//    					PatternMatcherErrorStrings.);
+//    			
+//    			}

+    	}

+    	return result;

+    }

+    

+    

+    

+    public String toString() {

+    	return getPattern().getName();

+    }

+    

+	public RemoteGoal buildRuleGoalGraph(Boolean[] adornment,

+			Map<String, RemoteGoal> rggRoots) throws PatternMatcherRuntimeException {

+		RemoteGoal result = new RemoteGoal(this, adornment);

+		rggRoots.put(RemoteGoal.generateID(this, adornment), result);

+		for (int i = 0; i < children.length; i++) {

+			FlattenedPattern fp = (FlattenedPattern) children[i];

+			List<SearchPlanOperation> finalSearchPlan = fp.generateSearchPlan(adornment,patternMatcher.getModelManager());

+	    	SortedSet<Integer> preCallInterfaceVariables = new TreeSet<Integer>();

+	    	for (int j = 0; j < adornment.length; j++) {

+				preCallInterfaceVariables.add(j);

+			}

+			Rule rule = (Rule) fp.buildSubtree(rggRoots, result.getMagicSet(), finalSearchPlan, finalSearchPlan.size() - 1, preCallInterfaceVariables);

+			// Rule rule = fp.buildRuleGoalGraph(adornment,rggRoots,result.getMagicSet());

+			result.addChild(rule, new LinkedList<MatchingFrame>());

+		}

+		return result;

+	}

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/callgraph/PatternNodeIncremental.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/callgraph/PatternNodeIncremental.java
new file mode 100644
index 0000000..7677efd
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/callgraph/PatternNodeIncremental.java
@@ -0,0 +1,70 @@
+/*******************************************************************************

+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro

+ * All rights reserved. This program and the accompanying materials

+ * are made available under the terms of the Eclipse Public License v1.0

+ * which accompanies this distribution, and is available at

+ * http://www.eclipse.org/legal/epl-v10.html

+ *

+ * Contributors:

+ *    Akos Horvath, Gergely Varro - initial API and implementation

+ *******************************************************************************/

+package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.callgraph;

+

+import java.util.Iterator;

+import java.util.List;

+import java.util.Map;

+

+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherCompileTimeException;

+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherRuntimeException;

+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.rgg.RemoteGoal;

+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.rgg.RemoteGoalIncremental;

+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.terms.GTPatternCall;

+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.GTPattern;

+

+

+

+

+public class PatternNodeIncremental extends PatternNode {

+

+	public PatternNodeIncremental(PatternMatcherWrapper patternMatcher,

+			BodyNode parent, GTPatternCall call)

+			throws PatternMatcherCompileTimeException {

+		super(parent, call);

+		 this.patternMatcher = patternMatcher;

+	     this.children = new BodyNode[0];

+	}

+

+	/*public PatternNodeIncremental(PatternMatcherWrapper patternMatcher,

+			GTPattern pattern) throws PatternMatcherCompileTimeException {

+		super(patternMatcher, pattern);

+		String[] context = {pattern.getName()};

+		throw new PatternMatcherCompileTimeException(

+				PatternMatcherErrorStrings.INTERNAL_INCREMENTAL_PATTERNNODE_ROOT

+				,context

+				,pattern);

+	}*/

+

+	@Override

+	public RemoteGoal buildRuleGoalGraph(Boolean[] adornment,

+			Map<String, RemoteGoal> rggRoots) throws PatternMatcherRuntimeException {

+		

+		RemoteGoal result = new RemoteGoalIncremental(this, adornment,patternMatcher);

+		rggRoots.put(RemoteGoal.generateID(this, adornment), result);

+		return result;

+	}

+	

+	 

+    protected PatternNode causesRecursion(GTPattern patternToTest) {

+      return null;

+    }

+

+    @Override

+    protected boolean traverse(PatternVariantIterator token) {

+    	return false;

+    }

+

+    

+    public Iterator<List<IFlattenedPatternElement>> iterator() {

+        return null;

+    }

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/callgraph/PatternReferenceNode.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/callgraph/PatternReferenceNode.java
new file mode 100644
index 0000000..9ed2e39
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/callgraph/PatternReferenceNode.java
@@ -0,0 +1,111 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.callgraph;

+

+import java.util.Collection;
+
+import org.eclipse.viatra2.core.IModelManager;
+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherCompileTimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.callgraph.FlattenedPattern.Pair;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.terms.GTPatternCall;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.GTPattern;
+import org.eclipse.viatra2.logger.Logger;
+

+

+public class PatternReferenceNode extends OddLevelNode implements

+        IFlattenedPatternElement {

+    private PatternNode reference;

+    

+    PatternReferenceNode(BodyNode parent, GTPatternCall call, PatternNode reference) {

+        super(parent,call);

+        this.reference = reference;

+    }

+    

+ //   PatternReferenceNode(PatternNode orig) {

+ //       super(orig.parent,orig.pattern,orig.actualParameters);

+ //       reference = orig;

+ //   }

+    

+    protected PatternNode causesRecursion(GTPattern patternToTest) {

+        return null;

+    }

+

+    @Override

+    protected boolean traverse(PatternVariantIterator token) {

+        assert index == 0 || index == 1;

+        if (index == 1) {

+            token.removeLast();

+            index--;

+            return false;

+        } else {

+            token.addLast(this);

+            index++;

+            return true;

+        }

+    }

+

+    public void addLocalVariables(FlattenedPattern pattern) {

+        return;

+    }

+

+    public void addFormalParameters(FlattenedPattern pattern) {

+        return;

+    }

+

+	public void buildSearchGraph(FlattenedPattern result) throws PatternMatcherCompileTimeException {

+		result.getSearchGraph().add(this, result);

+	}

+

+    public Collection<Pair> processVariableAssignments(FlattenedPattern pattern) throws PatternMatcherCompileTimeException {

+   /* 	for (int i = 1; i < actualParameters.size(); i++) {

+        	VariableReference refI = (VariableReference) actualParameters.get(i);

+        	Integer indexI = pattern.getIndex(((BodyNode) parent).getVariableID(refI.getVariable()));

+			for (int j = 0; j < i; j++) {

+	        	VariableReference refJ = (VariableReference) actualParameters.get(j);

+	        	Integer indexJ = pattern.getIndex(((BodyNode) parent).getVariableID(refJ.getVariable()));

+	        	pattern.addExclusionPair(indexI, indexJ);

+			}

+		}*/
+    	
+    	return null;

+    }

+

+    public void processCheckExpressions(FlattenedPattern pattern, Logger logger) {

+    	return;

+    }

+

+    public void processNegativeApplicationConditions(FlattenedPattern pattern, Logger logger, IModelManager manager) throws PatternMatcherCompileTimeException {

+    	return;

+    }

+    

+	public PatternNode getReference() {

+		return reference;

+	}

+

+    public String toString() {

+        return getClass().getSimpleName() + " " + getPattern().getName() + "_" + currentLocation;

+    }
+
+	public Collection<Pair> processInjectivityAssignments(FlattenedPattern pattern)
+			throws PatternMatcherCompileTimeException {
+		return null;
+	}
+
+	public void generateElementInjectivityConstraints (
+			FlattenedPattern flattenedPattern,
+			Collection<Pair> localAdditonalExclusionInjectivityPairs,
+			Collection<Pair> localAdditionalInclusionInjectivityPairs) throws  PatternMatcherCompileTimeException {
+		return;
+	}
+
+

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/callgraph/PatternVariantIterator.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/callgraph/PatternVariantIterator.java
new file mode 100644
index 0000000..8c715c9
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/callgraph/PatternVariantIterator.java
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.callgraph;

+

+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.NoSuchElementException;
+

+

+public class PatternVariantIterator implements Iterator<List<IFlattenedPatternElement>> {

+    private PatternNode root;

+    private LinkedList<IFlattenedPatternElement> solution;

+    private boolean hasNext;

+

+    public PatternVariantIterator(PatternNode root) {

+        this.root = root;

+        this.solution = new LinkedList<IFlattenedPatternElement>();

+        this.hasNext = (root.isRoot() ? root.traverse(this) : false);

+    }

+    

+    void addLast(IFlattenedPatternElement element) {

+        solution.addLast(element);

+    }

+    

+    void removeLast() {

+        solution.removeLast();

+    }

+    

+    public boolean hasNext() {

+        return hasNext;

+    }

+

+    public List<IFlattenedPatternElement> next() {

+        if (hasNext) {

+            List<IFlattenedPatternElement> result = new LinkedList<IFlattenedPatternElement>(solution);

+            hasNext = root.traverse(this);

+            return result;

+        } else {

+            throw new NoSuchElementException();

+        }

+    }

+

+    public void remove() {

+        throw new UnsupportedOperationException();

+    }

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/AllEntitiesOperation.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/AllEntitiesOperation.java
new file mode 100644
index 0000000..d804438
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/AllEntitiesOperation.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation;

+

+import org.eclipse.viatra2.core.IModelManager;
+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherRuntimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.PatternMatcherErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.SearchGraphEdge;
+

+

+/**

+ * @author Akos Horvath

+ *

+ */

+public class AllEntitiesOperation extends ExtendOperation {

+	private IModelManager manager;

+	

+	/**

+	 * @param unbound

+	 * @param edge

+	 */

+	public AllEntitiesOperation(Integer unbound, SearchGraphEdge edge, IModelManager m) {

+		super(unbound, edge);

+		manager = m;

+	}

+	

+	public void preprocess(MatchingFrame frame) throws PatternMatcherRuntimeException {

+		if(edge.isSource())

+			iterator = manager.getEntities().iterator();

+		else
+		{
+			String[] context = {frame.getPattern().getSearchGraph().getSearchNode(unbound).getName()};

+			throw new PatternMatcherRuntimeException(PatternMatcherErrorStrings.INTERNAL_ALLENTITIES
+					,context
+					,frame.getPattern().getSearchGraph().getSearchNode(unbound).getTraceabilityElement().getRepresentativeEMFElement());	
+		}
+	}

+

+	public String toString(){

+		return getClass().getSimpleName() + " : " + 

+        "ENTITY -- " + edge.getVPMEdgeType().name() + " -> " + unbound;

+	}

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/AllRelationsOperation.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/AllRelationsOperation.java
new file mode 100644
index 0000000..6937ede
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/AllRelationsOperation.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation;

+

+import org.eclipse.viatra2.core.IModelManager;
+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherRuntimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.PatternMatcherErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.SearchGraphEdge;
+

+

+/**

+ * @author Akos Horvath

+ *

+ */

+public class AllRelationsOperation extends ExtendOperation {

+

+	/**

+	 * @param unbound

+	 * @param edge

+	 */

+	public AllRelationsOperation(Integer unbound, SearchGraphEdge edge, IModelManager m) {

+		super(unbound, edge);

+		manager = m;

+	}

+	private IModelManager manager;

+	

+	public void preprocess(MatchingFrame frame) throws PatternMatcherRuntimeException{

+		if(edge.isSource())

+			iterator = manager.getRelations().iterator();

+		else
+			{

+			String[] context = {frame.getPattern().getSearchGraph().getSearchNode(unbound).getName()};
+			throw new PatternMatcherRuntimeException(PatternMatcherErrorStrings.INTERNAL_ALLRELATIONS
+					,context
+					,frame.getPattern().getSearchGraph().getSearchNode(unbound).getTraceabilityElement().getRepresentativeEMFElement());	
+			}

+	}

+

+	public String toString(){

+		return getClass().getSimpleName() + " : " + 

+        "RELATION -- " + edge.getVPMEdgeType().name() + " -> " + unbound;

+	}

+

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/BoundToBoundCheckOperation.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/BoundToBoundCheckOperation.java
new file mode 100644
index 0000000..2d2e1a8
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/BoundToBoundCheckOperation.java
@@ -0,0 +1,164 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation;

+

+import java.util.Set;
+
+import org.eclipse.viatra2.core.IModelElement;
+import org.eclipse.viatra2.core.IRelation;
+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherRuntimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.EdgeType;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.PatternMatcherErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.SearchGraphEdge;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
+

+

+/**
+ * @author Gergely Varro, Akos Horvath
+ *
+ */
+public class BoundToBoundCheckOperation extends EdgeConstraintCheckOperation {

+    private Integer source;

+    private Integer target;

+    private SearchGraphEdge  edge;

+    

+    public BoundToBoundCheckOperation(Integer source, 

+            Integer target,

+            SearchGraphEdge edge) {

+        this.source = source;

+        this.target = target;

+        this.edge = edge;

+    }

+

+    protected boolean check(MatchingFrame frame) 

+        throws PatternMatcherRuntimeException {

+        IModelElement sourceElement = null;

+        IModelElement targetElement = null;

+        try {

+            sourceElement = (IModelElement) frame.getValue(source);

+        } catch (ClassCastException e) {

+        	String[] context = {edge.getVPMEdgeType().toString(), frame.getPattern().getSearchGraph().getSearchNode(source).getName(), frame.getValue(source).getClass().getName()};
+			throw new PatternMatcherRuntimeException(PatternMatcherErrorStrings.NOT_A_MODELELEMENT_CHECK
+					,context
+					,frame.getPattern().getSearchGraph().getSearchNode(source).getTraceabilityElement().getRepresentativeEMFElement());
+        }

+        try {

+            targetElement = (IModelElement) frame.getValue(target);

+        } catch (ClassCastException e) {

+        	String[] context = {edge.getVPMEdgeType().toString(), frame.getPattern().getSearchGraph().getSearchNode(target).getName(), frame.getValue(target).getClass().getName()};
+			throw new PatternMatcherRuntimeException(PatternMatcherErrorStrings.NOT_A_MODELELEMENT_CHECK
+					,context
+					,frame.getPattern().getSearchGraph().getSearchNode(target).getTraceabilityElement().getRepresentativeEMFElement());
+  

+        }

+        if (sourceElement == null) {

+        	String[] context = {frame.getPattern().getSearchGraph().getSearchNode(source).getName(),getClass().getSimpleName()};
+			throw new PatternMatcherRuntimeException(PatternMatcherErrorStrings.INTERNAL_EMPTY_VALUE
+					,context
+					,frame.getPattern().getSearchGraph().getSearchNode(source).getTraceabilityElement().getRepresentativeEMFElement());
+	    }

+        if (targetElement == null) {

+        	String[] context = {frame.getPattern().getSearchGraph().getSearchNode(target).getName(),getClass().getSimpleName()};
+			throw new PatternMatcherRuntimeException(PatternMatcherErrorStrings.INTERNAL_EMPTY_VALUE
+					,context
+					,frame.getPattern().getSearchGraph().getSearchNode(target).getTraceabilityElement().getRepresentativeEMFElement());
+        }

+

+        if (edge.getVPMEdgeType() == EdgeType.INSTANCEOF && !edge.isSource()) {

+            //return sourceElement.getAllTypes().contains(targetElement);
+            return sourceElement.isInstanceOf(targetElement);

+        } else if (edge.getVPMEdgeType() == EdgeType.INSTANCEOF && edge.isSource()) {

+            //return sourceElement.getAllInstances().contains(targetElement);
+            return targetElement.isInstanceOf(sourceElement);

+        } else if (edge.getVPMEdgeType() == EdgeType.SUPERTYPEOF && !edge.isSource()) {

+            //return sourceElement.getAllSubtypes().contains(targetElement);
+        	return targetElement.isSubtypeOf(sourceElement);

+        } else if (edge.getVPMEdgeType() == EdgeType.SUPERTYPEOF && edge.isSource()) {
+        	return sourceElement.isSubtypeOf(targetElement);

+            //return sourceElement.getAllSupertypes().contains(targetElement);

+        } else if (edge.getVPMEdgeType() == EdgeType.SOURCE && !edge.isSource()) {

+            return (targetElement instanceof IRelation ?

+                    ((IRelation) targetElement).getFrom().equals(sourceElement) :

+                        false);

+        } else if (edge.getVPMEdgeType() == EdgeType.SOURCE && edge.isSource()) {

+            return (sourceElement instanceof IRelation ? 

+                    ((IRelation) sourceElement).getFrom().equals(targetElement) :

+                        false);

+        } else if (edge.getVPMEdgeType() == EdgeType.TARGET && !edge.isSource()) {

+            return (targetElement instanceof IRelation ? 

+                    ((IRelation) targetElement).getTo().equals(sourceElement) :

+                        false);

+        } else if (edge.getVPMEdgeType() == EdgeType.TARGET && edge.isSource()) {

+            return (sourceElement instanceof IRelation ? 

+                    ((IRelation) sourceElement).getTo().equals(targetElement) :

+                        false);

+        } else if (edge.getVPMEdgeType() == EdgeType.IN && !edge.isSource()) {

+            return sourceElement.getNamespace().compareTo(targetElement) == 0;

+        } else if (edge.getVPMEdgeType() == EdgeType.IN && edge.isSource()) {

+            return targetElement.getNamespace().compareTo(sourceElement) == 0;

+        } else if (edge.getVPMEdgeType() == EdgeType.BELOW && !edge.isSource()) {

+            return sourceElement.isBelowNamespace(targetElement);

+        } else if (edge.getVPMEdgeType() == EdgeType.BELOW && edge.isSource()) {

+            return targetElement.isBelowNamespace(sourceElement);

+        }

+       
+        String [] context = {edge.getVPMEdgeType().toString(),getClass().getSimpleName()};
+        throw new PatternMatcherRuntimeException(PatternMatcherErrorStrings.INTERNAL_OPERATION_NOT_SUPPORTED

+                ,context
+                ,edge.getTraceabilityElement().getRepresentativeEMFElement());

+    }

+

+    public String toString() {

+		return getClass().getSimpleName() + " : " + 

+            source + " -- " + edge.getVPMEdgeType().name() + " -> " + target;

+	}
+    
+    public String toString(MatchingFrame frame) {
+    	 IModelElement sourceElement = null;
+         IModelElement targetElement = null;
+         try {
+             sourceElement = (IModelElement) frame.getValue(source);
+         } catch (ClassCastException e) {
+        	 return toString();
+         }
+         try {
+             targetElement = (IModelElement) frame.getValue(target);
+         } catch (ClassCastException e) {
+        	 return toString();
+         }
+         if (sourceElement == null) return toString();
+         if (targetElement == null) return toString();
+         
+         //in which order the relation is pointing
+         if(edge.getVPMEdgeType() == EdgeType.INSTANCEOF)
+	    	 return getClass().getSimpleName() + " : " + 
+	    	 edge.getTargetNode().getName() + " -- " + edge.getVPMEdgeType().name() + " -> " + edge.getSourceNode().getName();
+         else //may require additional filtering
+        	 return getClass().getSimpleName() + " : " + 
+        	 edge.getSourceNode().getName() + " -- " + edge.getVPMEdgeType().name() + " -> " + edge.getTargetNode().getName();
+    }

+    

+    public void calculateSidewaysPassedVariables(Set<Integer> variables) {

+    	variables.add(source);

+    	variables.add(target);

+    }

+    

+    public void calculateLocalVariables(Set<Integer> variables) {

+    	variables.add(source);

+    	variables.add(target);

+    }
+
+	public AnnotatedElement getErrorfulElement(MatchingFrame frame) {
+		return edge.getTraceabilityElement().getRepresentativeEMFElement();
+	}

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/BoundToConstantCheckOperation.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/BoundToConstantCheckOperation.java
new file mode 100644
index 0000000..f30d226
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/BoundToConstantCheckOperation.java
@@ -0,0 +1,145 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation;

+

+import java.util.Set;
+
+import org.eclipse.viatra2.core.IModelElement;
+import org.eclipse.viatra2.core.IRelation;
+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherRuntimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.EdgeType;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.PatternMatcherErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.SearchGraphEdge;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
+

+

+/**
+ * @author Gergely Varro, Akos Horvath
+ *
+ */
+public class BoundToConstantCheckOperation extends EdgeConstraintCheckOperation {

+    private Integer source;

+    private IModelElement target;

+    private SearchGraphEdge  edge;

+    

+    public BoundToConstantCheckOperation (Integer source, 

+    		IModelElement target,

+            SearchGraphEdge edge) {

+        this.source = source;

+        this.target = target;

+        this.edge = edge;

+    }

+    

+    protected boolean check(MatchingFrame frame) 

+        throws PatternMatcherRuntimeException {

+        IModelElement sourceElement = null;

+        try {

+            sourceElement = (IModelElement) frame.getValue(source);

+        } catch (ClassCastException e) {

+        	String[] context = {edge.getVPMEdgeType().toString(), frame.getPattern().getSearchGraph().getSearchNode(source).getName(), frame.getValue(source).getClass().getName()};
+			throw new PatternMatcherRuntimeException(PatternMatcherErrorStrings.NOT_A_MODELELEMENT_CHECK
+					,context
+					,frame.getPattern().getSearchGraph().getSearchNode(source).getTraceabilityElement().getRepresentativeEMFElement());
+     

+        }

+        if (sourceElement == null) {

+        	String[] context = {frame.getPattern().getSearchGraph().getSearchNode(source).getName(),getClass().getSimpleName()};
+			throw new PatternMatcherRuntimeException(PatternMatcherErrorStrings.INTERNAL_EMPTY_VALUE
+					,context
+					,frame.getPattern().getSearchGraph().getSearchNode(source).getTraceabilityElement().getRepresentativeEMFElement());
+	

+        }

+        if (target == null) {

+        	String[] context = {edge.getTargetNode().getName(),getClass().getSimpleName()};
+			throw new PatternMatcherRuntimeException(PatternMatcherErrorStrings.INTERNAL_EMPTY_VALUE
+					,context
+					,edge.getTargetNode().getTraceabilityElement().getRepresentativeEMFElement());
+	    }

+

+        if (edge.getVPMEdgeType() == EdgeType.INSTANCEOF && !edge.isSource()) {

+            //return sourceElement.getAllTypes().contains(target);
+            return 	sourceElement.isInstanceOf(target);

+        } else if (edge.getVPMEdgeType() == EdgeType.INSTANCEOF && edge.isSource()) {

+            //return sourceElement.getAllInstances().contains(target);
+            return target.isInstanceOf(sourceElement);

+        } else if (edge.getVPMEdgeType() == EdgeType.SUPERTYPEOF && !edge.isSource()) {

+            return sourceElement.getAllSubtypes().contains(target);

+        } else if (edge.getVPMEdgeType() == EdgeType.SUPERTYPEOF && edge.isSource()) {

+            //return sourceElement.getAllSupertypes().contains(target);
+            return target.isSupertypeOf(sourceElement);

+        } else if (edge.getVPMEdgeType() == EdgeType.SOURCE && !edge.isSource()) {

+            return (target instanceof IRelation ? 

+                    ((IRelation) target).getFrom().equals(sourceElement) :

+                        false);

+        } else if (edge.getVPMEdgeType() == EdgeType.SOURCE && edge.isSource()) {

+            return (sourceElement instanceof IRelation ? 

+                    ((IRelation) sourceElement).getFrom().equals(target) :

+                        false);

+        } else if (edge.getVPMEdgeType() == EdgeType.TARGET && !edge.isSource()) {

+            return (target instanceof IRelation ? 

+                    ((IRelation) target).getTo().equals(sourceElement) :

+                        false);

+        } else if (edge.getVPMEdgeType() == EdgeType.TARGET && edge.isSource()) {

+            return (sourceElement instanceof IRelation ?

+                    ((IRelation) sourceElement).getTo().equals(target) :

+                        false);

+        } else if (edge.getVPMEdgeType() == EdgeType.IN && !edge.isSource()) {

+            return sourceElement.getNamespace().compareTo(target) == 0;

+        } else if (edge.getVPMEdgeType() == EdgeType.IN && edge.isSource()) {

+            return target.getNamespace().compareTo(sourceElement) == 0;

+        } else if (edge.getVPMEdgeType() == EdgeType.BELOW && !edge.isSource()) {

+            return sourceElement.isBelowNamespace(target);

+        } else if (edge.getVPMEdgeType() == EdgeType.BELOW && edge.isSource()) {

+            return target.isBelowNamespace(sourceElement);

+        }

+        String [] context = {edge.getVPMEdgeType().toString(),getClass().getSimpleName()};
+        throw new PatternMatcherRuntimeException(PatternMatcherErrorStrings.INTERNAL_OPERATION_NOT_SUPPORTED
+                ,context
+                ,edge.getTraceabilityElement().getRepresentativeEMFElement());
+    }

+

+    public String toString() {

+        return getClass().getSimpleName() + " : " +

+            source +" -- " + edge.getVPMEdgeType().name() + " -> " + target.getName();

+	}
+    
+    public String toString(MatchingFrame frame) {
+   	 IModelElement sourceElement = null;
+     try {
+           sourceElement = (IModelElement) frame.getValue(source);
+       } catch (ClassCastException e) {
+      	 return toString();
+       }
+     if (sourceElement == null) return toString();
+     
+     //in which order the relation is pointing
+     if(edge.getVPMEdgeType() == EdgeType.INSTANCEOF)
+    	 return getClass().getSimpleName() + " : " + 
+    	 edge.getTargetNode().getName() + " -- " + edge.getVPMEdgeType().name() + " -> " + edge.getSourceNode().getName();
+     else //may require additional filtering
+    	 return getClass().getSimpleName() + " : " + 
+    	 edge.getSourceNode().getName() + " -- " + edge.getVPMEdgeType().name() + " -> " + edge.getTargetNode().getName();
+   }

+    

+    public void calculateSidewaysPassedVariables(Set<Integer> variables) {

+    	variables.add(source);

+    }

+    

+    public void calculateLocalVariables(Set<Integer> variables) {

+    	variables.add(source);

+    }
+    
+    public AnnotatedElement getErrorfulElement(MatchingFrame frame) {
+		return edge.getTraceabilityElement().getRepresentativeEMFElement();
+	}

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/CheckOperation.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/CheckOperation.java
new file mode 100644
index 0000000..2d72ff2
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/CheckOperation.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation;

+

+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherRuntimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+
+

+abstract public class CheckOperation extends SearchPlanOperation {

+    private boolean hasBeenExecuted;

+    

+    public CheckOperation() {

+        hasBeenExecuted = false;

+    }

+    

+    public void preprocess(MatchingFrame frame) {

+        hasBeenExecuted = false;

+    }

+    

+    final public boolean execute(MatchingFrame frame) 

+        throws PatternMatcherRuntimeException {

+        hasBeenExecuted = (hasBeenExecuted ? false : check(frame));

+        return hasBeenExecuted;

+    }

+    

+    public void postprocess(MatchingFrame frame) {

+    	return;

+    }

+    

+    abstract protected boolean check(MatchingFrame frame)

+        throws PatternMatcherRuntimeException;

+    

+    public boolean update(MatchingFrame frame) throws PatternMatcherRuntimeException{

+        try {

+            hasBeenExecuted = false;

+            return execute(frame);

+        } catch (PatternMatcherRuntimeException e) {

+            
+        	e.printStackTrace();

+            return false;

+        }

+    }

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/ConstantToBoundCheckOperation.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/ConstantToBoundCheckOperation.java
new file mode 100644
index 0000000..75c8187
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/ConstantToBoundCheckOperation.java
@@ -0,0 +1,143 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation;

+

+import java.util.Set;
+
+import org.eclipse.viatra2.core.IModelElement;
+import org.eclipse.viatra2.core.IRelation;
+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherRuntimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.EdgeType;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.PatternMatcherErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.SearchGraphEdge;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
+

+

+public class ConstantToBoundCheckOperation extends EdgeConstraintCheckOperation {

+    private IModelElement source;

+    private Integer target;

+    private SearchGraphEdge edge;

+    

+    public ConstantToBoundCheckOperation(IModelElement source, 

+            Integer target,

+            SearchGraphEdge edge) {

+        this.source = source;

+        this.target = target;

+        this.edge = edge;

+    }

+    

+    protected boolean check(MatchingFrame frame) 

+        throws PatternMatcherRuntimeException {

+        IModelElement targetElement = null;

+        try {

+            targetElement = (IModelElement) frame.getValue(target);

+        } catch (ClassCastException e) {

+        	String[] context = {edge.getVPMEdgeType().toString(), frame.getPattern().getSearchGraph().getSearchNode(target).getName(), frame.getValue(target).getClass().getName()};
+			throw new PatternMatcherRuntimeException(PatternMatcherErrorStrings.NOT_A_MODELELEMENT_CHECK
+					,context
+					,frame.getPattern().getSearchGraph().getSearchNode(target).getTraceabilityElement().getRepresentativeEMFElement());
+     

+        }

+        if (source == null) {

+        	String[] context = {edge.getSourceNode().getName(),getClass().getSimpleName()};
+			throw new PatternMatcherRuntimeException(PatternMatcherErrorStrings.INTERNAL_EMPTY_VALUE
+					,context
+					,edge.getSourceNode().getTraceabilityElement().getRepresentativeEMFElement());
+	

+        }

+        if (targetElement == null) {

+        	String[] context = {frame.getPattern().getSearchGraph().getSearchNode(target).getName(),getClass().getSimpleName()};
+			throw new PatternMatcherRuntimeException(PatternMatcherErrorStrings.INTERNAL_EMPTY_VALUE
+					,context
+					,frame.getPattern().getSearchGraph().getSearchNode(target).getTraceabilityElement().getRepresentativeEMFElement());
+	

+        }

+

+        if (edge.getVPMEdgeType() == EdgeType.INSTANCEOF && !edge.isSource()) {

+            //return source.getAllTypes().contains(targetElement);
+            return source.isInstanceOf(targetElement);

+        } else if (edge.getVPMEdgeType() == EdgeType.INSTANCEOF && edge.isSource()) {

+        	////return source.getAllInstances().contains(targetElement);
+        	return targetElement.isInstanceOf(source);

+        } else if (edge.getVPMEdgeType() == EdgeType.SUPERTYPEOF && !edge.isSource()) {

+            //return source.getAllSubtypes().contains(targetElement);
+        	return targetElement.isSubtypeOf(source);

+        } else if (edge.getVPMEdgeType() == EdgeType.SUPERTYPEOF && edge.isSource()) {

+            //return source.getAllSupertypes().contains(targetElement);
+            return source.isSubtypeOf(targetElement);

+        } else if (edge.getVPMEdgeType() == EdgeType.SOURCE && !edge.isSource()) {

+            return (targetElement instanceof IRelation ? 

+                    ((IRelation) targetElement).getFrom().equals(source) :

+                        false);

+        } else if (edge.getVPMEdgeType() == EdgeType.SOURCE && edge.isSource()) {

+            return (source instanceof IRelation ? 

+                    ((IRelation) source).getFrom().equals(targetElement) :

+                        false);

+        } else if (edge.getVPMEdgeType() == EdgeType.TARGET && !edge.isSource()) {

+            return (targetElement instanceof IRelation ? 

+                    ((IRelation) targetElement).getTo().equals(source) :

+                        false);

+        } else if (edge.getVPMEdgeType() == EdgeType.TARGET && edge.isSource()) {

+            return (source instanceof IRelation ? 

+                    ((IRelation) source).getTo().equals(targetElement) :

+                        false);

+        } else if (edge.getVPMEdgeType() == EdgeType.IN && !edge.isSource()) {

+            return source.getNamespace().compareTo(targetElement) == 0;

+        } else if (edge.getVPMEdgeType() == EdgeType.IN && edge.isSource()) {

+            return targetElement.getNamespace().compareTo(source) == 0;

+        } else if (edge.getVPMEdgeType() == EdgeType.BELOW && !edge.isSource()) {

+            return source.isBelowNamespace(targetElement);

+        } else if (edge.getVPMEdgeType() == EdgeType.BELOW && edge.isSource()) {

+            return targetElement.isBelowNamespace(source);

+        }

+        String [] context = {edge.getVPMEdgeType().toString(),getClass().getSimpleName()};
+        throw new PatternMatcherRuntimeException(PatternMatcherErrorStrings.INTERNAL_OPERATION_NOT_SUPPORTED
+                ,context
+                ,edge.getTraceabilityElement().getRepresentativeEMFElement());
+  }

+    

+    public String toString() {

+        return getClass().getSimpleName() + " : " + 

+            source.getName() + " -- " + edge.getVPMEdgeType().name() + " -> " + target;

+	}
+    
+    public String toString(MatchingFrame frame) {
+   	    IModelElement targetElement = null;
+        try {
+            targetElement = (IModelElement) frame.getValue(target);
+        } catch (ClassCastException e) {
+       	 return toString();
+        }
+        if (targetElement == null) return toString();
+        
+        //in which order the relation is pointing
+        if(edge.getVPMEdgeType() == EdgeType.INSTANCEOF)
+        	return getClass().getSimpleName() + " : " + 
+        	edge.getTargetNode().getName() + " -- " + edge.getVPMEdgeType().name() + " -> " + edge.getSourceNode().getName();
+        else //may require additional filtering
+        	return getClass().getSimpleName() + " : " + 
+       	 	edge.getSourceNode().getName() + " -- " + edge.getVPMEdgeType().name() + " -> " + edge.getTargetNode().getName();
+	}

+

+    public void calculateSidewaysPassedVariables(Set<Integer> variableSet) {

+    	variableSet.add(target);

+    }

+    

+    public void calculateLocalVariables(Set<Integer> variableSet) {

+    	variableSet.add(target);

+    }
+    
+    public AnnotatedElement getErrorfulElement(MatchingFrame frame) {
+		return edge.getTraceabilityElement().getRepresentativeEMFElement();
+	}

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/ConstantToConstantCheckOperation.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/ConstantToConstantCheckOperation.java
new file mode 100644
index 0000000..5842eef
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/ConstantToConstantCheckOperation.java
@@ -0,0 +1,106 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation;

+

+import org.eclipse.viatra2.core.IModelElement;
+import org.eclipse.viatra2.core.IRelation;
+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherRuntimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.EdgeType;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.PatternMatcherErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.SearchGraphEdge;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
+

+

+public class ConstantToConstantCheckOperation extends EdgeConstraintCheckOperation {

+    private IModelElement source;

+    private IModelElement target;

+    private SearchGraphEdge edge;

+    

+    

+    public ConstantToConstantCheckOperation(IModelElement source, 

+    		IModelElement target,

+            SearchGraphEdge edge) {

+        this.source = source;

+        this.target = target;

+        this.edge = edge;

+    }

+

+    protected boolean check(MatchingFrame frame) 

+        throws PatternMatcherRuntimeException {

+        if (source == null) {

+        	String[] context = {edge.getTargetNode().getName(),getClass().getSimpleName()};
+			throw new PatternMatcherRuntimeException(PatternMatcherErrorStrings.INTERNAL_EMPTY_VALUE
+					,context
+					,edge.getTargetNode().getTraceabilityElement().getRepresentativeEMFElement());
+	

+        }

+        if (target == null) {

+        	String[] context = {edge.getTargetNode().getName(),getClass().getSimpleName()};
+			throw new PatternMatcherRuntimeException(PatternMatcherErrorStrings.INTERNAL_EMPTY_VALUE
+					,context
+					,edge.getTargetNode().getTraceabilityElement().getRepresentativeEMFElement());
+	

+        }

+

+        if (edge.getVPMEdgeType() == EdgeType.INSTANCEOF && !edge.isSource()) {

+            //return source.getAllTypes().contains(target);
+            return source.isInstanceOf(target);

+        } else if (edge.getVPMEdgeType() == EdgeType.INSTANCEOF && edge.isSource()) {

+            //return source.getAllInstances().contains(target);
+        	return target.isInstanceOf(source);

+        } else if (edge.getVPMEdgeType() == EdgeType.SUPERTYPEOF && !edge.isSource()) {

+            //return source.getAllSubtypes().contains(target);
+            return target.isSubtypeOf(source);

+        } else if (edge.getVPMEdgeType() == EdgeType.SUPERTYPEOF && edge.isSource()) {

+            //return source.getAllSupertypes().contains(target);
+        	return source.isSubtypeOf(target);

+        } else if (edge.getVPMEdgeType() == EdgeType.SOURCE && !edge.isSource()) {

+        	return (target instanceof IRelation ? 

+                    ((IRelation) target).getFrom().equals(source) :

+                        false);

+        } else if (edge.getVPMEdgeType() == EdgeType.SOURCE && edge.isSource()) {

+            return (source instanceof IRelation ?

+                    ((IRelation) source).getFrom().equals(target) :

+                        false);

+        } else if (edge.getVPMEdgeType() == EdgeType.TARGET && !edge.isSource()) {

+            return (target instanceof IRelation ?

+                    ((IRelation) target).getTo().equals(source) :

+                        false);

+        } else if (edge.getVPMEdgeType() == EdgeType.TARGET && edge.isSource()) {

+            return (source instanceof IRelation ? 

+                    ((IRelation) source).getTo().equals(target) : 

+                        false);

+        } else if (edge.getVPMEdgeType() == EdgeType.IN && !edge.isSource()) {

+            return source.getNamespace().compareTo(target) == 0;

+        } else if (edge.getVPMEdgeType() == EdgeType.IN && edge.isSource()) {

+            return target.getNamespace().compareTo(source) == 0;

+        } else if (edge.getVPMEdgeType() == EdgeType.BELOW && !edge.isSource()) {

+            return source.isBelowNamespace(target);

+        } else if (edge.getVPMEdgeType() == EdgeType.BELOW && edge.isSource()) {

+            return target.isBelowNamespace(source);

+        }

+        String [] context = {edge.getVPMEdgeType().toString(),getClass().getSimpleName()};
+        throw new PatternMatcherRuntimeException(PatternMatcherErrorStrings.INTERNAL_OPERATION_NOT_SUPPORTED
+                ,context
+                ,edge.getTraceabilityElement().getRepresentativeEMFElement());
+    }

+

+    public String toString() {

+		return getClass().getSimpleName() + " : " +

+            source.getName() + " -- " + edge.getVPMEdgeType().name()+ " -> " + target.getName();

+	}
+    
+    public AnnotatedElement getErrorfulElement(MatchingFrame frame) {
+		return edge.getTraceabilityElement().getRepresentativeEMFElement();
+	}

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/CopyValueOperation.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/CopyValueOperation.java
new file mode 100644
index 0000000..f3a4ebe
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/CopyValueOperation.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation;

+

+import java.util.Set;
+
+import org.eclipse.viatra2.core.IModelElement;
+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherRuntimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.PatternMatcherErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.SearchGraphEdge;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
+

+public class CopyValueOperation extends CheckOperation {

+    private Integer bound;

+    private Integer unbound;
+    private SearchGraphEdge relatedSearchGraphEdge;

+    

+	public CopyValueOperation(Integer bound, Integer unbound, SearchGraphEdge edge) {

+	    this.bound = bound;

+	    this.unbound = unbound;
+	    relatedSearchGraphEdge = edge;

+	}

+	

+	@Override

+	protected boolean check(MatchingFrame frame) throws PatternMatcherRuntimeException {

+        IModelElement boundElement = null;

+        try {

+            boundElement = (IModelElement) frame.getValue(bound);

+        } catch (ClassCastException e) {
+        	String[] context = {frame.getPattern().getSearchGraph().getSearchNode(bound).getName(), getClass().getSimpleName()};

+            throw new PatternMatcherRuntimeException(PatternMatcherErrorStrings.NOT_A_MODELELEMENT
+            		,context
+            		,frame.getPattern().getSearchGraph().getSearchNode(bound).getTraceabilityElement().getRepresentativeEMFElement());

+        }

+        if (boundElement == null) {

+        	String[] context = {frame.getPattern().getSearchGraph().getSearchNode(bound).getName(),getClass().getSimpleName()};
+			throw new PatternMatcherRuntimeException(PatternMatcherErrorStrings.INTERNAL_EMPTY_VALUE
+					,context
+					,frame.getPattern().getSearchGraph().getSearchNode(bound).getTraceabilityElement().getRepresentativeEMFElement());
+        }

+        frame.setValue(unbound, boundElement);

+		return true;

+	}

+    

+    public String toString() {

+        return getClass().getSimpleName() + " : " + bound + " -> " + unbound;

+	}

+    

+    public void calculateSidewaysPassedVariables(Set<Integer> variableSet) {

+    	variableSet.add(bound);

+    	variableSet.remove(unbound);

+    }

+    

+    public void calculateLocalVariables(Set<Integer> variableSet) {

+    	variableSet.add(bound);

+    }
+
+	public AnnotatedElement getErrorfulElement(MatchingFrame frame) {
+		return frame.getPattern().getGTASMRepresentation(relatedSearchGraphEdge);
+	}

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/DummyOperation.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/DummyOperation.java
new file mode 100644
index 0000000..6a73a7d
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/DummyOperation.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation;

+

+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherRuntimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
+
+

+public class DummyOperation extends SearchPlanOperation {

+

+	@Override

+	public boolean execute(MatchingFrame frame) throws PatternMatcherRuntimeException {

+		return false;

+	}

+

+	@Override

+	public void postprocess(MatchingFrame frame) throws PatternMatcherRuntimeException {

+		return;

+	}

+

+	@Override

+	public void preprocess(MatchingFrame frame) throws PatternMatcherRuntimeException {

+		return;

+	}
+
+	public AnnotatedElement getErrorfulElement(MatchingFrame frame) {
+		return null;
+	}
+	
+	public String toString(MatchingFrame frame) {
+		return "Dummy operation";
+	}

+

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/EdgeConstraintCheckOperation.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/EdgeConstraintCheckOperation.java
new file mode 100644
index 0000000..d7b64ef
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/EdgeConstraintCheckOperation.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation;

+

+/**

+ * Represents an operation, which checks the existence of

+ * a model edge leading between two nodes that have already

+ * been bound.

+ */

+public abstract class EdgeConstraintCheckOperation 

+	extends CheckOperation //implements IUpdatePlanOperation 

+	{

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/ExtendBoundNodeOperation.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/ExtendBoundNodeOperation.java
new file mode 100644
index 0000000..11d0bbe
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/ExtendBoundNodeOperation.java
@@ -0,0 +1,126 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation;

+

+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.viatra2.core.IModelElement;
+import org.eclipse.viatra2.core.IRelation;
+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherRuntimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.EdgeType;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.PatternMatcherErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.SearchGraphEdge;
+

+/**

+ * The ExtendBoundNodeOperation is an ExtendOperation

+ * where the fixed node has been bound in an earlier phase 

+ * of the algorithm. 

+ */

+public class ExtendBoundNodeOperation extends ExtendOperation {

+    private Integer bound;

+    

+	/**

+	 * @param bound the bound pattern variable.

+	 * @param unbound the unbound pattern variable.

+	 * @param edgeType type of the edge.

+	 * @param isSrc true, if the bound node is the source of the edge.

+	 */

+	public ExtendBoundNodeOperation(Integer bound, Integer unbound,

+			SearchGraphEdge edge) {

+        super(unbound, edge);

+	    this.bound = bound;

+	}

+	

+    public void preprocess(MatchingFrame frame) 

+        throws PatternMatcherRuntimeException {

+        IModelElement boundElement = null;

+        try {

+            boundElement = (IModelElement) frame.getValue(bound);

+        } catch (ClassCastException e) {

+        	String[] context = {edge.getVPMEdgeType().toString(), frame.getPattern().getSearchGraph().getSearchNode(bound).getName(), frame.getValue(bound).getClass().getName()};
+			throw new PatternMatcherRuntimeException(PatternMatcherErrorStrings.NOT_A_MODELELEMENT_EXTEND
+					,context
+					,frame.getPattern().getSearchGraph().getSearchNode(bound).getTraceabilityElement().getRepresentativeEMFElement());
+        }

+        if (boundElement == null) {

+        	String[] context = {frame.getPattern().getSearchGraph().getSearchNode(bound).getName(),getClass().getSimpleName()};
+			throw new PatternMatcherRuntimeException(PatternMatcherErrorStrings.INTERNAL_EMPTY_VALUE
+					,context
+					,frame.getPattern().getSearchGraph().getSearchNode(bound).getTraceabilityElement().getRepresentativeEMFElement());
+	

+        }

+        

+            if (edge.getVPMEdgeType() == EdgeType.INSTANCEOF && !edge.isSource()) {

+                iterator = boundElement.getAllTypes().iterator();

+            } else if (edge.getVPMEdgeType() == EdgeType.INSTANCEOF && edge.isSource()) {

+                iterator = boundElement.getAllInstances().iterator();

+            } else if (edge.getVPMEdgeType() == EdgeType.SUPERTYPEOF && !edge.isSource()) {

+                iterator = boundElement.getAllSubtypes().iterator();

+            } else if (edge.getVPMEdgeType() == EdgeType.SUPERTYPEOF && edge.isSource()) {

+                iterator = boundElement.getAllSupertypes().iterator();

+            } else if (edge.getVPMEdgeType() == EdgeType.SOURCE && !edge.isSource()) {

+                iterator = boundElement.getRelationsFrom().iterator();

+            } else if (edge.getVPMEdgeType() == EdgeType.SOURCE && edge.isSource()) {

+                Collection<IModelElement> coll = new HashSet<IModelElement>();

+                if (boundElement instanceof IRelation) {

+                    coll.add(((IRelation) boundElement).getFrom());

+                }

+                iterator = coll.iterator();

+            } else if (edge.getVPMEdgeType() == EdgeType.TARGET && !edge.isSource()) {

+                iterator = boundElement.getRelationsTo().iterator();

+            } else if (edge.getVPMEdgeType() == EdgeType.TARGET && edge.isSource()) {

+                Collection<IModelElement> coll = new HashSet<IModelElement>();

+                if (boundElement instanceof IRelation) {

+                    coll.add(((IRelation) boundElement).getTo());

+                }

+                iterator = coll.iterator();

+            } else if (edge.getVPMEdgeType() == EdgeType.IN && edge.isSource()) {

+                iterator = boundElement.getElementsInNamespace().iterator();

+            } else if (edge.getVPMEdgeType() == EdgeType.BELOW && edge.isSource()) {

+                iterator = boundElement.getAllElementsInNamespace().iterator();

+            } else if (edge.getVPMEdgeType() == EdgeType.IN && !edge.isSource()) {

+            	Collection<IModelElement> coll = new HashSet<IModelElement>();

+                if(boundElement.getNamespace() != null)
+                	coll.add(boundElement.getNamespace());

+            	
+                iterator = coll.iterator();

+            } else if (edge.getVPMEdgeType() == EdgeType.BELOW && !edge.isSource()) {

+                String[] context = {frame.getPattern().getSearchGraph().getSearchNode(unbound).getName(),edge.getVPMEdgeType().toString()};
+            	throw new PatternMatcherRuntimeException(PatternMatcherErrorStrings.INTERNAL_OPERATION_NOT_POSSIBLE
+            			,context
+            			,edge.getTraceabilityElement().getRepresentativeEMFElement());

+            } else if (edge.getVPMEdgeType() == EdgeType.NACCHECK) {

+            	String[] context = {frame.getPattern().getSearchGraph().getSearchNode(unbound).getName(),edge.getVPMEdgeType().toString()};
+            	throw new PatternMatcherRuntimeException(PatternMatcherErrorStrings.INTERNAL_OPERATION_NOT_POSSIBLE
+            			,context
+            			,edge.getTraceabilityElement().getRepresentativeEMFElement());
+           

+            }

+    }

+    

+    public String toString() {

+        return getClass().getSimpleName() + " : " + 

+            bound + " -- " + edge.getVPMEdgeType().name() + " -> " + unbound;

+	}

+    

+    public void calculateSidewaysPassedVariables(Set<Integer> variableSet) {

+    	variableSet.add(bound);

+    	super.calculateSidewaysPassedVariables(variableSet);

+    }

+    

+    public void calculateLocalVariables(Set<Integer> variableSet) {

+    	variableSet.add(bound);

+    }

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/ExtendConstantNodeOperation.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/ExtendConstantNodeOperation.java
new file mode 100644
index 0000000..0276161
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/ExtendConstantNodeOperation.java
@@ -0,0 +1,107 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation;

+

+import java.util.Collection;
+import java.util.HashSet;
+
+import org.eclipse.viatra2.core.IModelElement;
+import org.eclipse.viatra2.core.IRelation;
+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherRuntimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.EdgeType;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.PatternMatcherErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.SearchGraphEdge;
+

+

+/**

+ * ExtendConstantNodeOperation is an ExtendOperation where

+ * the bound node is a constant node.

+ */

+public class ExtendConstantNodeOperation extends ExtendOperation {

+    private IModelElement bound;

+    

+	/**

+	 * @param bound The constant node to be extended.

+	 * @param unbound The unbound pattern variable.

+	 * @param edgeType The type of the edge.

+	 * @param isSrc true, if the constant node is the source of the 

+     * edge.

+	 */

+	public ExtendConstantNodeOperation(IModelElement bound, Integer unbound,

+			SearchGraphEdge edge) {

+        super(unbound,edge);

+        this.bound = bound;

+	}

+	

+    public void preprocess(MatchingFrame frame) 

+        throws PatternMatcherRuntimeException {

+        if (bound == null) {

+        	String[] context = {edge.getSourceNode().getName(),getClass().getSimpleName()};
+			throw new PatternMatcherRuntimeException(PatternMatcherErrorStrings.INTERNAL_EMPTY_VALUE
+					,context
+					,edge.getSourceNode().getTraceabilityElement().getRepresentativeEMFElement());
+        }

+        

+            if (edge.getVPMEdgeType() == EdgeType.INSTANCEOF && !edge.isSource()) {

+                iterator = bound.getAllTypes().iterator();

+            } else if (edge.getVPMEdgeType() == EdgeType.INSTANCEOF && edge.isSource()) {

+                iterator = bound.getAllInstances().iterator();

+            } else if (edge.getVPMEdgeType() == EdgeType.SUPERTYPEOF && !edge.isSource()) {

+                iterator = bound.getAllSubtypes().iterator();

+            } else if (edge.getVPMEdgeType() == EdgeType.SUPERTYPEOF && edge.isSource()) {

+                iterator = bound.getAllSupertypes().iterator();

+            } else if (edge.getVPMEdgeType() == EdgeType.SOURCE && !edge.isSource()) {

+                iterator = bound.getRelationsFrom().iterator();

+            } else if (edge.getVPMEdgeType() == EdgeType.SOURCE && edge.isSource()) {

+                Collection<IModelElement> coll = new HashSet<IModelElement>();

+                if (bound instanceof IRelation) {

+                    coll.add(((IRelation) bound).getFrom());

+                }

+                iterator = coll.iterator();

+            } else if (edge.getVPMEdgeType() == EdgeType.TARGET && !edge.isSource()) {

+                iterator = bound.getRelationsTo().iterator();

+            } else if (edge.getVPMEdgeType() == EdgeType.TARGET && edge.isSource()) {

+                Collection<IModelElement> coll = new HashSet<IModelElement>();

+                if (bound instanceof IRelation) {

+                    coll.add(((IRelation) bound).getTo());

+                }

+                iterator = coll.iterator();

+            } else if (edge.getVPMEdgeType() == EdgeType.IN && edge.isSource()) {

+                iterator = bound.getElementsInNamespace().iterator();

+            } else if (edge.getVPMEdgeType() == EdgeType.BELOW && edge.isSource()) {

+                iterator = bound.getAllElementsInNamespace().iterator();

+            } else if (edge.getVPMEdgeType() == EdgeType.IN && !edge.isSource()) {

+            	Collection<IModelElement> coll = new HashSet<IModelElement>();

+            	if(bound.getNamespace() != null)
+            		coll.add(bound.getNamespace());

+            	
+            	iterator = coll.iterator();

+            } else if (edge.getVPMEdgeType() == EdgeType.BELOW && !edge.isSource()) {

+            	String[] context = {frame.getPattern().getSearchGraph().getSearchNode(unbound).getName(),edge.getVPMEdgeType().toString()};
+            	throw new PatternMatcherRuntimeException(PatternMatcherErrorStrings.INTERNAL_OPERATION_NOT_POSSIBLE
+            			,context
+            			,edge.getTraceabilityElement().getRepresentativeEMFElement());
+           

+            } else if (edge.getVPMEdgeType() == EdgeType.NACCHECK) {

+            	String[] context = {frame.getPattern().getSearchGraph().getSearchNode(unbound).getName(),edge.getVPMEdgeType().toString()};
+            	throw new PatternMatcherRuntimeException(PatternMatcherErrorStrings.INTERNAL_OPERATION_NOT_POSSIBLE
+            			,context
+            			,edge.getTraceabilityElement().getRepresentativeEMFElement());
+            }

+    }

+

+    public String toString() {

+        return getClass().getSimpleName() + " : " + 

+            bound.getName() + " -- " + edge.getVPMEdgeType().name() + " -> " + unbound;

+	}

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/ExtendOperation.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/ExtendOperation.java
new file mode 100644
index 0000000..98d83fa
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/ExtendOperation.java
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation;

+

+import java.util.Iterator;
+import java.util.Set;
+
+import org.eclipse.viatra2.core.IModelElement;
+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherRuntimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.PatternMatcherErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.SearchGraphEdge;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
+

+

+/**

+ * The ExtendOperation is a SearchPlanOperation, where

+ * an already bound node is extended towards 

+ * an unbound node.

+ */

+public abstract class ExtendOperation extends SearchPlanOperation {

+    protected Integer unbound;

+    protected SearchGraphEdge edge;

+   

+    protected Iterator iterator;

+    

+    public ExtendOperation(Integer unbound, SearchGraphEdge edge) {

+        this.unbound = unbound;

+        this.edge = edge;

+        this.iterator = null;

+    }

+    

+    public void postprocess(MatchingFrame frame) {

+        frame.setValue(unbound, null);

+        iterator = null;

+    }

+    

+    public boolean execute(MatchingFrame frame) 

+        throws PatternMatcherRuntimeException {
+    	Object next = "";

+        try {

+            if (iterator.hasNext()) {
+            	next = iterator.next();

+                IModelElement modelElement = (IModelElement) next;

+                frame.setValue(unbound, modelElement);

+                return true;

+            } else {

+                return false;

+            }

+        } catch (ClassCastException e) {

+        	String[] context = {edge.getVPMEdgeType().toString(), frame.getPattern().getSearchGraph().getSearchNode(unbound).getName(), next.getClass().getName()};
+			throw new PatternMatcherRuntimeException(PatternMatcherErrorStrings.NOT_A_MODELELEMENT_EXTEND
+					,context
+					,frame.getPattern().getSearchGraph().getSearchNode(unbound).getTraceabilityElement().getRepresentativeEMFElement());
+        }

+    }

+    

+    public void calculateSidewaysPassedVariables(Set<Integer> variableSet) {

+    	variableSet.remove(unbound);

+    }
+    
+    public AnnotatedElement getErrorfulElement(MatchingFrame frame) {
+		return frame.getPattern().getSearchGraph().getSearchNode(unbound).getTraceabilityElement().getRepresentativeEMFElement();
+	}

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/ISearchPlanOperation.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/ISearchPlanOperation.java
new file mode 100644
index 0000000..7cd202e
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/ISearchPlanOperation.java
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation;

+

+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherRuntimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
+
+

+public interface ISearchPlanOperation {

+	/** The pre execution operations are handled
+	 * @param frame The matching frame of the invocation context 
+	 * @throws PatternMatcherRuntimeException
+	 */
+	public void preprocess(MatchingFrame frame) 

+    	throws PatternMatcherRuntimeException;

+

+	/** The post execution operations are handled
+	 * @param frame The matching frame of the invocation context 
+	 * @throws PatternMatcherRuntimeException
+	 */
+	public void postprocess(MatchingFrame frame) 

+    	throws PatternMatcherRuntimeException;

+

+	/**Executes the search operation
+	 * @param frame The matching frame of the invocation context
+	 * @return true if the execution was successful else false
+	 * @throws PatternMatcherRuntimeException
+	 */
+	public boolean execute(MatchingFrame frame) 

+    	throws PatternMatcherRuntimeException;
+	
+	/**Returns the GTASM element from which the operation was created (also which caused the error durng the execution)
+	 * @param frame The matching frame of the invocation context
+	 * @return
+	 */
+	public AnnotatedElement getErrorfulElement(MatchingFrame frame);
+	
+	/**A detailed serialized description of the operation
+	 * @param frame The matching frame of the invocation context
+	 * @return
+	 */
+	public String toString(MatchingFrame frame);
+	
+	

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/InjectivityCheckOperation.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/InjectivityCheckOperation.java
new file mode 100644
index 0000000..0200b01
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/InjectivityCheckOperation.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation;

+

+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.callgraph.FlattenedPattern;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
+
+

+public class InjectivityCheckOperation extends CheckOperation {

+    protected boolean check(MatchingFrame frame) {

+    	FlattenedPattern pattern = frame.getPattern();

+        int size = pattern.getInjectivityFrameSize();

+        for (int i = 1; i < size; i++) {

+            for (int j = 0; j < i; j++) {

+                // TODO refactor frame.getValue(j) -> frame.frame[j] as it may be faster

+                if(frame.getValue(j) != null && frame.getValue(i) != null ) //TODO: akinator: this is just a hack because of NAC and injectivity check!!! have to be fixed

+            	if (pattern.isIncludedInInjectivityCheck(j, i) && 

+                		frame.getValue(j).equals(frame.getValue(i))) {

+                    return false;

+                }

+            }

+        }

+        return true;

+    }
+
+	public AnnotatedElement getErrorfulElement(MatchingFrame frame) {
+		return frame.getPattern().getParent().getPattern();
+	}

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/InputCheckOperation.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/InputCheckOperation.java
new file mode 100644
index 0000000..fe5e104
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/InputCheckOperation.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation;

+

+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherRuntimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.PatternMatcherErrorStrings;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
+
+

+public class InputCheckOperation extends CheckOperation {

+    private int index;

+    private Object value;

+    

+    public InputCheckOperation(int index, Object value) {

+        this.index = index;

+        this.value = value;

+    }

+    

+    @Override

+    protected boolean check(MatchingFrame frame) throws PatternMatcherRuntimeException{

+        /*if (value != null) {

+            return frame.testAndSetValue(index, value);

+        } else {

+            return false;

+        }*/
+    	
+    	String[] context = {getClass().getSimpleName()};
+    	throw new PatternMatcherRuntimeException(PatternMatcherErrorStrings.INTERNAL_OPERATION_NOT_USED
+    			,context
+    			,null);

+    }
+
+	public AnnotatedElement getErrorfulElement(MatchingFrame frame) {
+		return null;
+	}

+

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/IsEntityorRelationCheckOperation.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/IsEntityorRelationCheckOperation.java
new file mode 100644
index 0000000..a572d55
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/IsEntityorRelationCheckOperation.java
@@ -0,0 +1,83 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation;

+

+import org.eclipse.viatra2.core.IModelElement;
+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherRuntimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.PatternMatcherErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.algorithms.ISearchGraph;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.SearchGraphEdge;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
+

+

+/**

+ * @author Akos Horvath

+ *

+ */

+public class IsEntityorRelationCheckOperation extends CheckOperation {

+

+	private Integer source;

+	private SearchGraphEdge relatedSearchGraphEdge;

+	private String type;

+	

+	/**

+	 * 

+	 */

+	public IsEntityorRelationCheckOperation(Integer source, 

+            SearchGraphEdge edge,

+            String type) {

+        this.source = source;

+        this.relatedSearchGraphEdge = edge;

+        this.type = type;

+	}

+

+	@Override

+	protected boolean check(MatchingFrame frame)

+			throws PatternMatcherRuntimeException {

+		IModelElement sourceElement = null;

+		try{

+	           sourceElement = (IModelElement) frame.getValue(source);

+	    }catch (ClassCastException e) {

+	         	String[] context = {relatedSearchGraphEdge.getSourceNode().getName(), getClass().getSimpleName()};
+				throw new PatternMatcherRuntimeException(GTErrorStrings.NOT_A_MODELELEMENT
+						,context
+						,relatedSearchGraphEdge.getSourceNode().getTraceabilityElement().getRepresentativeEMFElement());
+	    }
+	    

+	    if (sourceElement == null) {

+	    	String[] context = {relatedSearchGraphEdge.getSourceNode().getName(),getClass().getSimpleName()};
+			throw new PatternMatcherRuntimeException(PatternMatcherErrorStrings.INTERNAL_EMPTY_VALUE
+					,context
+					,relatedSearchGraphEdge.getSourceNode().getTraceabilityElement().getRepresentativeEMFElement());
+	    }

+		

+	    if(ISearchGraph.VPM_ENTITY_FQN.equals(type))

+	    	return sourceElement.isEntity();

+	    

+	    if(ISearchGraph.VPM_RELATION_FQN.equals(type))

+	    	return sourceElement.isRelation();

+	    

+		return false;

+	}

+	

+	public String toString(){

+		return getClass().getSimpleName() + " : " + 

+        type+"-- " + relatedSearchGraphEdge.getVPMEdgeType().name() + "- CHECK -> " + source;

+	}
+
+	public AnnotatedElement getErrorfulElement(MatchingFrame frame) {
+		return relatedSearchGraphEdge.getTraceabilityElement().getRepresentativeEMFElement();
+	}

+

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/NACCheckOperation.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/NACCheckOperation.java
new file mode 100644
index 0000000..ee74b9f
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/NACCheckOperation.java
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation;

+

+import java.util.Collection;
+
+import org.eclipse.viatra2.gtasm.interpreter.exception.ViatraTransformationException;
+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherRuntimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.PatternMatcherErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.patterns.IPatternMatcher;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.definitions.Variable;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.enums.ValueKind;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.terms.GTPatternCall;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.terms.VariableReference;
+
+

+/**

+ * NACCheckOperation checks an embedded negative pattern.

+ */

+public class NACCheckOperation extends CheckOperation {

+    private IPatternMatcher patternMatcher;

+    private int[] actualParameterMapping;
+    private Collection<Variable> passingVariables;
+    private GTPatternCall nacCall;

+

+    public NACCheckOperation(IPatternMatcher matcher,

+            int[] actualParameterMapping, GTPatternCall call, Collection<Variable> passingVariables) {

+        this.patternMatcher = matcher;

+        this.actualParameterMapping = actualParameterMapping;
+        nacCall = call;
+        this.passingVariables = passingVariables;
+    }

+

+    protected boolean check(MatchingFrame frame) throws PatternMatcherRuntimeException{

+        Object[] actualParameters = new Object[actualParameterMapping.length];

+
+
+        for (int i = 0; i < actualParameterMapping.length; i++) {

+        	actualParameters[i] = frame.getValue(actualParameterMapping[i]);
+            if(actualParameters[i] == null
+            		|| actualParameters[i].equals(ValueKind.UNDEF_LITERAL))
+            		{
+            		if(passingVariables.contains(((VariableReference)nacCall.getActualParameters().get(i)).getVariable()))
+            			{
+            			String[] context =
+	            			{nacCall.getCalledPattern().getName()
+	            				,nacCall.getCalledPattern().getSymParameters().get(i).getName()};
+	            		throw new PatternMatcherRuntimeException(
+							PatternMatcherErrorStrings.NAC_CALL_WITH_UNBOUND_PARAMETER
+									,context
+									,nacCall);
+	            		}
+            		//TODO: else? it is a local variable that is only used in the NAC call
+            		}

+        }

+        try {

+			return !patternMatcher.match(actualParameters);

+		} catch (ViatraTransformationException e) {

+			throw new PatternMatcherRuntimeException(e,nacCall);

+		}

+    }
+
+	public AnnotatedElement getErrorfulElement(MatchingFrame frame) {
+		return nacCall;
+	}

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/PatternCallOperation.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/PatternCallOperation.java
new file mode 100644
index 0000000..96d4421
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/PatternCallOperation.java
@@ -0,0 +1,103 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation;

+

+import java.util.Set;
+
+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherRuntimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.callgraph.PatternNode;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
+

+

+/**

+ * Represents a pattern call operation in a recursive pattern

+ * variant. Such operation is contained by only non-recursive

+ * FlattenedPatterns.

+ */

+public class PatternCallOperation extends SearchPlanOperation {

+	private PatternNode calledPattern = null;

+	private Integer[] callFormalToActualMapping = null;

+	private Boolean[] adornment = null;

+	

+	public PatternCallOperation(PatternNode calledPattern, 

+			Integer[] parameterMapping, 

+			Boolean[] boundParameters) {

+		assert parameterMapping.length == boundParameters.length;

+		this.calledPattern = calledPattern;

+		this.callFormalToActualMapping = parameterMapping;

+		this.adornment = boundParameters;

+	}

+	

+	public void calculateSidewaysPassedVariables(Set<Integer> variableSet) {

+		for (int i = 0; i < callFormalToActualMapping.length; i++) {

+			variableSet.add(callFormalToActualMapping[i]);

+			if (!adornment[i]) {

+				variableSet.remove(callFormalToActualMapping[i]);

+			}

+		}

+	}

+	

+	public void calculateLocalVariables(Set<Integer> variableSet) {

+		for (int i = 0; i < callFormalToActualMapping.length; i++) {

+			variableSet.add(callFormalToActualMapping[i]);

+		}

+	}

+	

+	public PatternNode getPatternNode() {

+		return calledPattern;

+	}

+	

+	public Boolean[] getAdornment() {

+		return adornment;

+	}

+

+	public Integer[] getParameterMapping() {

+		return callFormalToActualMapping;

+	}

+	

+	public String toString(){

+		StringBuffer b = new StringBuffer();

+		b.append(getClass().getSimpleName());

+		b.append(" : ");

+		b.append(calledPattern.getPattern().getName());

+		b.append("^");

+		

+		StringBuffer params = new StringBuffer();

+		assert adornment.length == callFormalToActualMapping.length;

+		for (int i = 0; i < adornment.length; i++) {

+			b.append((adornment[i] ? 'b' : 'f'));

+			params.append(callFormalToActualMapping[i]);

+		}

+		b.append("(");

+		b.append(params);

+		b.append(")");

+		return b.toString();

+	}

+

+	@Override

+	public boolean execute(MatchingFrame frame) throws PatternMatcherRuntimeException {

+		return false;

+	}

+

+	@Override

+	public void postprocess(MatchingFrame frame) throws PatternMatcherRuntimeException {

+	}

+

+	@Override

+	public void preprocess(MatchingFrame frame) throws PatternMatcherRuntimeException {

+	}
+
+	public AnnotatedElement getErrorfulElement(MatchingFrame frame) {
+		return null;
+	}

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/SearchPlanOperation.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/SearchPlanOperation.java
new file mode 100644
index 0000000..55e1da0
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/SearchPlanOperation.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation;

+

+import java.util.Set;
+
+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherRuntimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+

+

+/**

+ * The root of the search plan operation hierarchy.

+ */

+public abstract class SearchPlanOperation implements ISearchPlanOperation{

+	abstract public void preprocess(MatchingFrame frame) 

+        throws PatternMatcherRuntimeException;

+

+	abstract public void postprocess(MatchingFrame frame) 

+        throws PatternMatcherRuntimeException;

+

+	abstract public boolean execute(MatchingFrame frame) 

+        throws PatternMatcherRuntimeException;

+	

+    public boolean update(MatchingFrame frame) throws PatternMatcherRuntimeException {

+            return execute(frame);

+    }

+    

+    public String toString() {

+        return getClass().getSimpleName();

+    }

+

+    public void calculateSidewaysPassedVariables(Set<Integer> variables) {

+		/* default generated stub */;

+		

+	}

+    

+    public void calculateLocalVariables(Set<Integer> variables) {

+		/* default generated stub */;

+    	

+    }
+    
+    public String toString(MatchingFrame frame) {
+		return toString();
+	}

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/TermCheckOperation.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/TermCheckOperation.java
new file mode 100644
index 0000000..69c4e45
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/TermCheckOperation.java
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation;

+

+
+import org.eclipse.viatra2.gtasm.interpreter.exception.ViatraTransformationException;
+import org.eclipse.viatra2.gtasm.interpreter.executionEnvironment.IExecutionEnvironment;
+import org.eclipse.viatra2.gtasm.interpreter.term.rules.TermEvaluator;
+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherRuntimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.PatternMatcherErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.term.AbstractTermCheckOperation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.term.TermCheckExecutionEnvironment;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.terms.Term;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.GTPattern;
+
+

+public class TermCheckOperation extends AbstractTermCheckOperation {

+	private IExecutionEnvironment parentEnv;

+    private GTPattern pattern;

+    private int uid;

+    private Term term;

+    

+    public TermCheckOperation(IExecutionEnvironment parentEnv, 

+    		GTPattern pattern, int uid, Term term) {

+    	this.parentEnv = parentEnv;

+        this.pattern = pattern;

+        this.uid = uid;

+        this.term = term;

+    }

+    

+    public boolean check(MatchingFrame frame) throws PatternMatcherRuntimeException{

+        TermCheckExecutionEnvironment env = new TermCheckExecutionEnvironment(parentEnv, pattern, uid, frame);

+        Boolean result = false;

+        try {

+            result = (Boolean) TermEvaluator.getInstance().evaluate(env, term);

+        } catch (ViatraTransformationException e) {

+        	throw new PatternMatcherRuntimeException(e,term); 

+        } catch (ClassCastException e) {

+        	String[] context = {pattern.getName()};
+        	throw new PatternMatcherRuntimeException(
+        			PatternMatcherErrorStrings.CHECK_EXPRESSION_NOT_EVALUATED_TO_A_BOOLEAN
+        			,context
+        			,term);

+        }

+        return result;

+    }
+
+	public AnnotatedElement getErrorfulElement(MatchingFrame frame) {
+		return term;
+	}

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/TermEvaluationOperation.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/TermEvaluationOperation.java
new file mode 100644
index 0000000..13e4695
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/TermEvaluationOperation.java
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation;

+

+
+import org.eclipse.viatra2.gtasm.interpreter.exception.ViatraTransformationException;
+import org.eclipse.viatra2.gtasm.interpreter.executionEnvironment.IExecutionEnvironment;
+import org.eclipse.viatra2.gtasm.interpreter.term.rules.TermEvaluator;
+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherRuntimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.term.AbstractTermCheckOperation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.term.TermCheckExecutionEnvironment;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.terms.Term;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.ContainmentConstraint;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.GTPattern;
+
+

+public class TermEvaluationOperation extends AbstractTermCheckOperation {

+	private IExecutionEnvironment parentEnv;

+    private GTPattern pattern;

+    private int uid;

+    private Term term;

+    private int resultSlot;
+    private ContainmentConstraint containmentConstraint;

+    

+    public TermEvaluationOperation(IExecutionEnvironment parentEnv, 
+    		GTPattern pattern, int uid, Term term, int resultSlot) {
+    	this.parentEnv = parentEnv;
+        this.pattern = pattern;
+        this.uid = uid;
+        this.term = term;
+        this.containmentConstraint = null;
+        this.resultSlot = resultSlot;
+    }
+    
+    public TermEvaluationOperation(IExecutionEnvironment parentEnv, 

+    		GTPattern pattern, int uid, ContainmentConstraint conCons, int resultSlot) {

+    	this.parentEnv = parentEnv;

+        this.pattern = pattern;

+        this.uid = uid;

+        this.term = conCons.getParent();
+        this.containmentConstraint = conCons;

+        this.resultSlot = resultSlot;

+    }

+    

+    protected boolean check(MatchingFrame frame)throws PatternMatcherRuntimeException{

+        TermCheckExecutionEnvironment env = new TermCheckExecutionEnvironment(parentEnv, pattern, uid, frame);

+        Object result = null;

+        try {

+            result = TermEvaluator.getInstance().evaluate(env, term);

+        } catch (ViatraTransformationException e) {

+        	throw new PatternMatcherRuntimeException(e,containmentConstraint != null? containmentConstraint: term); 

+        }

+        return (result != null ? frame.testAndSetValue(resultSlot, result) : false);

+    }
+
+	public AnnotatedElement getErrorfulElement(MatchingFrame frame) {
+		return containmentConstraint != null? containmentConstraint: term;
+	}

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/VariableAssignmentCheckOperation.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/VariableAssignmentCheckOperation.java
new file mode 100644
index 0000000..e0f4f5d
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/operation/VariableAssignmentCheckOperation.java
@@ -0,0 +1,94 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation;

+

+import java.util.Set;
+
+import org.eclipse.viatra2.core.IModelElement;
+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherRuntimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.PatternMatcherErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.SearchGraphEdge;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
+

+

+public class VariableAssignmentCheckOperation extends CheckOperation {

+    private Integer source;

+    private Integer target;
+    private SearchGraphEdge relatedSearchGraphEdge;

+    

+    public VariableAssignmentCheckOperation(Integer source, 

+            Integer target, SearchGraphEdge edge) {

+        this.source = source;

+        this.target = target;
+        this.relatedSearchGraphEdge = edge;

+    }

+

+    protected boolean check(MatchingFrame frame) 

+        throws PatternMatcherRuntimeException {

+        IModelElement sourceElement = null;

+        IModelElement targetElement = null;

+        try {

+            sourceElement = (IModelElement) frame.getValue(source);

+        } catch (ClassCastException e) {

+        	String[] context = {relatedSearchGraphEdge.getSourceNode().getName(), getClass().getSimpleName()};
+			throw new PatternMatcherRuntimeException(GTErrorStrings.NOT_A_MODELELEMENT
+					,context
+					,relatedSearchGraphEdge.getSourceNode().getTraceabilityElement().getRepresentativeEMFElement());
+

+        }

+        try {

+            targetElement = (IModelElement) frame.getValue(target);

+        } catch (ClassCastException e) {

+        	String[] context = {relatedSearchGraphEdge.getTargetNode().getName(), getClass().getSimpleName()};
+			throw new PatternMatcherRuntimeException(GTErrorStrings.NOT_A_MODELELEMENT
+					,context
+					,relatedSearchGraphEdge.getTargetNode().getTraceabilityElement().getRepresentativeEMFElement());
+

+        }

+        if (sourceElement == null) {

+        	String[] context = {relatedSearchGraphEdge.getSourceNode().getName(),getClass().getSimpleName()};
+			throw new PatternMatcherRuntimeException(PatternMatcherErrorStrings.INTERNAL_EMPTY_VALUE
+					,context
+					,relatedSearchGraphEdge.getSourceNode().getTraceabilityElement().getRepresentativeEMFElement());
+	

+        }

+        if (targetElement == null) {

+        	String[] context = {relatedSearchGraphEdge.getTargetNode().getName(),getClass().getSimpleName()};
+			throw new PatternMatcherRuntimeException(PatternMatcherErrorStrings.INTERNAL_EMPTY_VALUE
+					,context
+					,relatedSearchGraphEdge.getTargetNode().getTraceabilityElement().getRepresentativeEMFElement());
+	

+        }

+        return sourceElement.equals(targetElement);

+    }

+

+    public String toString() {

+		return getClass().getSimpleName() + " : " + 

+            source + " == " + target;

+	}

+    

+    public void calculateSidewaysPassedVariables(Set<Integer> variables) {

+    	variables.add(source);

+    	variables.add(target);

+    }

+    

+    public void calculateLocalVariables(Set<Integer> variables) {

+    	variables.add(source);

+    	variables.add(target);

+    }
+
+	public AnnotatedElement getErrorfulElement(MatchingFrame frame) {
+		return relatedSearchGraphEdge.getTraceabilityElement().getRepresentativeEMFElement();
+	}

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/rgg/Goal.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/rgg/Goal.java
new file mode 100644
index 0000000..6783ff6
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/rgg/Goal.java
@@ -0,0 +1,16 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.rgg;

+

+abstract public class Goal extends RuleGoalGraphNode {

+	

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/rgg/HistoryList.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/rgg/HistoryList.java
new file mode 100644
index 0000000..9c6f4ed
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/rgg/HistoryList.java
@@ -0,0 +1,86 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.rgg;

+

+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
+
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.IKeyGenerator;
+

+

+public class HistoryList<KeyType, ValueType> extends LinkedList<ValueType> {

+	private static final long serialVersionUID = 4033836249907829630L;

+	private IKeyGenerator<KeyType, ValueType> keyGenerator;

+	private Map<KeyType, List<ValueType>> map;

+	

+	public HistoryList(IKeyGenerator<KeyType, ValueType> keyGenerator) {

+		this.keyGenerator = keyGenerator;

+		this.map = new HashMap<KeyType, List<ValueType>>();

+	}

+	

+	public List<ValueType> get(KeyType key) {

+		return map.get(key);

+	}

+

+	public void init() {

+		clear();

+		map.clear();

+	}

+	

+	public Iterator<ValueType> iterator() {

+		return new Itr(super.iterator());

+	}

+	

+	private class Itr implements Iterator<ValueType> {

+		private Iterator<ValueType> backingIterator;

+		private ValueType lastReturned;

+

+		private Itr(Iterator<ValueType> i) {

+			backingIterator = i;

+			lastReturned = null;

+		}

+		

+		public boolean hasNext() {

+			return backingIterator.hasNext();

+		}

+

+		public ValueType next() {

+			try {

+				lastReturned = backingIterator.next();

+				return lastReturned;

+			} catch (NoSuchElementException e) {

+				lastReturned = null;

+				throw e;

+			}

+		}

+

+		public void remove() {

+			if (lastReturned != null) {

+				KeyType key = keyGenerator.calculateKey(lastReturned);

+				List<ValueType> list = map.get(key);

+				if (list == null) {

+					list = new LinkedList<ValueType>();

+				}

+				list.add(lastReturned);

+				map.put(key, list);

+				backingIterator.remove();

+				lastReturned = null;

+			} else {

+				throw new IllegalStateException();

+			}

+		}

+	}

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/rgg/IQueueContentProvider.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/rgg/IQueueContentProvider.java
new file mode 100644
index 0000000..a5f7c40
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/rgg/IQueueContentProvider.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.rgg;

+

+import java.util.Queue;
+
+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherRuntimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+

+

+public interface IQueueContentProvider {

+	/*

+	public void initalizeSingleTraversal(Queue<MatchingFrame> queue, MatchingFrame template);

+	public MatchingFrame traverse() throws PatternMatcherRuntimeException;

+	*/

+	public void traverseAll(Queue<MatchingFrame> queue, MatchingFrame template)

+		throws PatternMatcherRuntimeException;

+	public void synchronize();
+	public void init();

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/rgg/IndexedRule.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/rgg/IndexedRule.java
new file mode 100644
index 0000000..84b9289
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/rgg/IndexedRule.java
@@ -0,0 +1,131 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.rgg;

+

+import java.util.Queue;
+import java.util.Vector;
+
+import org.eclipse.viatra2.gtasm.patternmatcher.IMatching;
+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherRuntimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.IKeyGenerator;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingKey;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.PatternMatcherErrorStrings;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.callgraph.FlattenedPattern;
+

+

+public class IndexedRule extends Rule {

+	private RemoteGoal right;

+	private HistoryList<MatchingKey, MatchingFrame> leftInputQueue;

+	private Integer[] parameterMapping;

+	private Boolean[] adornment;

+	private int arraySize;

+	private IKeyGenerator<MatchingKey, MatchingFrame> keyGenerator;

+

+	public IndexedRule(FlattenedPattern pattern,

+			IQueueContentProvider left,

+			RemoteGoal right,

+			Integer[] parameterMapping,

+			Boolean[] adornment) {

+		super(pattern, left);

+

+		arraySize = 0;

+		Vector<Integer> v = new Vector<Integer>();

+		for (int i = 0; i < adornment.length; i++) {

+			if (adornment[i]) {

+				v.add(parameterMapping[i]);

+				arraySize++;

+			}

+		}

+		final Integer[] keys = new Integer[arraySize];

+		v.toArray(keys);

+		keyGenerator = new IKeyGenerator<MatchingKey, MatchingFrame>() {

+

+			public MatchingKey calculateKey(MatchingFrame value) {

+				Object[] matchingKey = new Object[keys.length];

+				for (int i = 0; i < keys.length; i++) {

+					matchingKey[i] = value.getValue(keys[i]);

+				}

+				return new MatchingKey(matchingKey);

+			}

+

+			public int size() {

+				return keys.length;

+			}

+		};

+		this.right = right;

+		this.leftInputQueue = new HistoryList<MatchingKey, MatchingFrame>(keyGenerator);

+		this.parameterMapping = parameterMapping;

+		this.adornment = adornment;

+	}

+	

+	public void traverseAll(Queue<MatchingFrame> resultQueue, MatchingFrame template) throws PatternMatcherRuntimeException {

+		left.traverseAll(leftInputQueue, template);

+		right.calculateAllDeltas(this, resultQueue);

+	}

+	

+	MatchingKey getBoundHeader(MatchingFrame frame) {

+		return keyGenerator.calculateKey(frame);

+	}

+	

+	void merge(MatchingFrame result, IMatching other) 

+		throws PatternMatcherRuntimeException {

+		
+		assert parameterMapping.length == adornment.length;

+		for (int i = 0; i < parameterMapping.length; i++) {

+			if (adornment[i]) {

+				if (!result.getValue(parameterMapping[i]).equals(other.lookup(i))) {

+					{
+					String[] context = {pattern.getParent().getPattern().getName()};
+					throw new PatternMatcherRuntimeException(
+							PatternMatcherErrorStrings.INTERNAL_PATTERNCALL_ADORNED_INPUT_PARAMS
+							,context
+							,pattern.getParent().getPattern());
+					}

+				}

+			} else {

+				result.setValue(parameterMapping[i], other.lookup(i));

+			}

+		}

+	}

+	

+	HistoryList<MatchingKey, MatchingFrame> getQueue() {

+		return leftInputQueue;

+	}

+

+	@Override

+	public void synchronize() {

+		left.synchronize();

+		leftInputQueue.clear();

+	}

+	@Override
+	public void init(){
+		leftInputQueue.init();
+		left.init(); // cannot be initialized (again) as it creates an infinite loop
+		//right.init();
+	}

+	/*

+	public MatchingFrame traverse(Queue<MatchingFrame> resultQueue, MatchingFrame template) throws PatternMatcherRuntimeException {

+		// left.traverse(leftInputQueue, template);

+		// right.calculateDelta(this, resultQueue);

+		return null;

+	}

+

+	public void initalizeSingleTraversal(Queue<MatchingFrame> queue, MatchingFrame template) {

+		left.initalizeSingleTraversal(leftInputQueue, template);

+	}

+

+	public MatchingFrame traverse(MatchingFrame template) throws PatternMatcherRuntimeException {

+		return null;

+	}

+	*/

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/rgg/LocalGoal.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/rgg/LocalGoal.java
new file mode 100644
index 0000000..799f9e5
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/rgg/LocalGoal.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.rgg;

+

+import java.util.Iterator;
+import java.util.Queue;
+
+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherRuntimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.SearchPlan;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation.SearchPlanOperation;
+

+

+public class LocalGoal extends Goal {

+	private SearchPlan searchPlan;

+	

+	public LocalGoal(SearchPlanOperation[] operations) {

+		this.searchPlan = new SearchPlan(operations);

+	}

+	

+	public void calculateAllDeltas(UnindexedRule parent, Queue<MatchingFrame> output) 

+	throws PatternMatcherRuntimeException {

+		Queue<MatchingFrame> input = parent.getQueue();

+		for (Iterator<MatchingFrame> i = input.iterator(); i.hasNext();) {

+			MatchingFrame frame = i.next();

+	        while (searchPlan.execute(frame)) {

+	            MatchingFrame newFrame = (MatchingFrame) frame.clone();

+	            output.offer(newFrame);

+	        }

+	        i.remove();

+		}

+	}

+

+	public boolean calculateDelta(MatchingFrame frame) throws PatternMatcherRuntimeException {

+		return searchPlan.execute(frame);

+	}

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/rgg/MagicSet.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/rgg/MagicSet.java
new file mode 100644
index 0000000..19369c8
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/rgg/MagicSet.java
@@ -0,0 +1,107 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.rgg;

+

+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Queue;
+
+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherRuntimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingKey;
+

+

+public class MagicSet extends RuleGoalGraphNode 

+	implements IQueueContentProvider {

+	private ArrayList<MatchingKey> old;

+	private List<MatchingKey> next;

+	//private int firstNew;

+	private Boolean[] adornment;   
+	private HashSet<MatchingKey> cache;

+	

+	public MagicSet(Boolean[] adornment) {

+		this.old = new ArrayList<MatchingKey>();

+		this.next = new LinkedList<MatchingKey>();

+		//this.firstNew = 0;

+		this.adornment = adornment;
+		this.cache = new HashSet<MatchingKey>(); //stores the old values already matched, only one instance per matching

+	}

+

+	public void traverseAll(Queue<MatchingFrame> queue, MatchingFrame template) 

+	throws PatternMatcherRuntimeException {

+		//ListIterator<MatchingKey> li = old.listIterator(firstNew);

+		Iterator<MatchingKey> li = old.iterator();
+		while (li.hasNext()) {

+			Object[] array = li.next().toArray();

+			MatchingFrame frame = (MatchingFrame) template.clone();

+			int counter = 0;

+			for (int i = 0; i < adornment.length; i++) {

+				if (adornment[i]) {

+					frame.setValue(i, array[counter++]);

+				}

+			}

+			queue.offer(frame);

+		}
+	}

+	

+	public void addArray(MatchingKey array) {

+		next.add(array);

+	}

+	

+	public void synchronize() {}

+	

+	boolean synchronizeFromGoal() {

+		boolean result = false;
+		old.clear();

+	//	firstNew = old.size();
+		for (MatchingKey element : next) {

+			if (!cache.contains(element)) {
+//			if (!old.contains(element)) {
+

+				old.add(element);
+				cache.add(element);

+				result = true;

+			}

+		}

+		next.clear();

+		return result;

+	}

+

+	public void initalizeSingleTraversal(Queue<MatchingFrame> queue, MatchingFrame template) {

+		//ListIterator<MatchingKey> li = old.listIterator(firstNew);
+		Iterator<MatchingKey> li = old.iterator();

+		while (li.hasNext()) {

+			Object[] array = li.next().toArray();

+			MatchingFrame frame = (MatchingFrame) template.clone();

+			int counter = 0;

+			for (int i = 0; i < adornment.length; i++) {

+				if (adornment[i]) {

+					frame.setValue(i, array[counter++]);

+				}

+			}

+			queue.offer(frame);

+		}
+	}

+

+	public MatchingFrame traverse() throws PatternMatcherRuntimeException {

+		return null;

+	}

+    

+    public void init() {

+       // firstNew = 0;
+        cache.clear();

+        old.clear();

+    }

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/rgg/RemoteGoal.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/rgg/RemoteGoal.java
new file mode 100644
index 0000000..f93bb03
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/rgg/RemoteGoal.java
@@ -0,0 +1,302 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.rgg;

+

+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.Queue;
+import java.util.Vector;
+
+import org.eclipse.viatra2.gtasm.interpreter.exception.ViatraTransformationException;
+import org.eclipse.viatra2.gtasm.patternmatcher.IMatching;
+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherRuntimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.IKeyGenerator;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingKey;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.callgraph.PatternNode;
+

+

+public class RemoteGoal extends Goal implements Iterable<MatchingFrame> {

+	protected String id;

+	protected PatternNode pattern;

+	private Vector<Rule> children;

+	private Vector<Queue<MatchingFrame>> queues;
+	private Map<MatchingKey, List<MatchingFrame>> mapWithAdornedIndex;
+	private Map<MatchingKey, List<MatchingFrame>> map;
+	private Queue<MatchingFrame> newFrames;
+		
+	protected MagicSet ms;
+	protected Boolean[] adornment;
+	protected IKeyGenerator<MatchingKey, IMatching> adornedKeyGenerator;

+	protected IKeyGenerator<MatchingKey, IMatching> keyGenerator;

+	

+	public RemoteGoal(PatternNode pattern, Boolean[] adornment) {

+		this.pattern = pattern;

+		this.id = generateID(pattern, adornment);

+		this.children = new Vector<Rule>();

+		this.queues = new Vector<Queue<MatchingFrame>>();

+		this.newFrames = new LinkedList<MatchingFrame>();

+		this.adornment = adornment;

+		this.mapWithAdornedIndex = new HashMap<MatchingKey, List<MatchingFrame>>();

+		this.map = new HashMap<MatchingKey, List<MatchingFrame>>();

+		ms = new MagicSet(adornment);

+		

+		Vector<Integer> adornedVector = new Vector<Integer>();

+		Vector<Integer> vector = new Vector<Integer>();

+		for (int i = 0; i < adornment.length; i++) {

+			if (adornment[i]) {

+				adornedVector.add(i);

+			}

+			vector.add(i);

+		}

+    	final Integer[] key1 = new Integer[adornedVector.size()]; 

+    	adornedVector.toArray(key1);

+        adornedKeyGenerator = new IKeyGenerator<MatchingKey, IMatching>() {

+

+            public MatchingKey calculateKey(IMatching value) {

+                Object[] matchingKey = new Object[key1.length];

+                for (int i = 0; i < key1.length; i++) {

+                    matchingKey[i] = value.lookup(key1[i]);

+                }

+                return new MatchingKey(matchingKey);

+            }

+

+			public int size() {

+				return key1.length;

+			}

+        };

+        

+    	final Integer[] key2 = new Integer[vector.size()];

+    	vector.toArray(key2);

+    	keyGenerator = new IKeyGenerator<MatchingKey, IMatching>() {

+

+            public MatchingKey calculateKey(IMatching value) {

+                Object[] matchingKey = new Object[key2.length];

+                for (int i = 0; i < key2.length; i++) {

+                    matchingKey[i] = value.lookup(key2[i]);

+                }

+                return new MatchingKey(matchingKey);

+            }

+

+			public int size() {

+				return key2.length;

+			}

+        };

+

+	}

+

+	public static String generateID(PatternNode pattern, Boolean[] adornment) {

+		StringBuffer b = new StringBuffer();

+		for (int i = 0; i < adornment.length; i++) {

+			b.append(adornment[i] ? 'b' : 'f');

+		}

+		return pattern.getPattern().getName() + "^" + b.toString();

+	}

+	

+	public void calculateAllDeltas(IndexedRule parent, Queue<MatchingFrame> output) throws PatternMatcherRuntimeException {

+		//      --->

+		// left |><| right

+		Queue<MatchingFrame> input = parent.getQueue();

+		for (Iterator<MatchingFrame> i = input.iterator(); i.hasNext();) {

+			MatchingFrame leftFrame = i.next();

+			MatchingKey keyForLeftFrame = parent.getBoundHeader(leftFrame);

+			List<MatchingFrame> list = mapWithAdornedIndex.get(keyForLeftFrame);

+			if (list != null) {

+				for (MatchingFrame rightFrame : list) {

+		            MatchingFrame newFrame = (MatchingFrame) leftFrame.clone();

+		            parent.merge(newFrame, rightFrame);

+		            output.offer(newFrame);

+				}

+			}

+	        ms.addArray(keyForLeftFrame);

+	        i.remove();

+		}

+		

+		//      <---

+		// left |><| right

+		for (Iterator<MatchingFrame> j = newFrames.iterator(); j.hasNext();) {

+			MatchingFrame rightFrame = j.next();

+			Vector<Object> v = new Vector<Object>();

+			int size = 0;

+			for (int i = 0; i < adornment.length; i++) {

+				if (adornment[i]) {

+					v.add(rightFrame.getValue(i));

+					size++;

+				}

+			}

+			final Object[] key = new Object[size];

+			v.toArray(key);

+			HistoryList<MatchingKey, MatchingFrame> queue = 

+				parent.getQueue();

+			List<MatchingFrame> list = queue.get(new MatchingKey(key));

+			if (list != null) {

+				for (MatchingFrame leftFrame : list) {

+		            MatchingFrame newFrame = (MatchingFrame) leftFrame.clone();

+		            parent.merge(newFrame, rightFrame);

+		            output.offer(newFrame);

+				}

+			}

+		}

+	}

+	

+	public MagicSet getMagicSet() {

+		return ms;

+	}

+	

+	public void addChild(Rule child, Queue<MatchingFrame> queue) {

+		children.add(child);

+		queues.add(queue);

+	}

+	

+	public boolean equals(Object other) {

+		if (other != null && other instanceof RemoteGoal) {

+			RemoteGoal rg = (RemoteGoal) other;

+			return id.equals(rg.id);

+		} else {

+			return false;

+		}

+	}

+	

+	public String toString() {

+		return id;

+	}

+	

+	public boolean synchronize() throws ViatraTransformationException {

+		boolean result = false;

+		for (Iterator<MatchingFrame> i = newFrames.iterator(); i.hasNext();) {

+			MatchingFrame frame = i.next();

+			MatchingKey keyForFrame = adornedKeyGenerator.calculateKey(frame);

+			List<MatchingFrame> currentList = 

+				mapWithAdornedIndex.get(keyForFrame);

+			if (currentList == null) {

+				currentList = new LinkedList<MatchingFrame>();

+			}

+			currentList.add(frame);

+			mapWithAdornedIndex.put(keyForFrame, currentList);

+			i.remove();

+		}

+

+		assert newFrames.isEmpty();

+		for (Queue<MatchingFrame> queue : queues) {

+			for (Iterator<MatchingFrame> i = queue.iterator(); i.hasNext();) {

+				MatchingFrame frame = i.next();

+				MatchingKey keyForFrame = keyGenerator.calculateKey(frame);

+				List<MatchingFrame> currentList = map.get(keyForFrame);

+				if (currentList == null) {

+					currentList = new LinkedList<MatchingFrame>();

+					newFrames.add(frame);

+					result = true;

+				} 

+				currentList.add(frame);

+				map.put(keyForFrame, currentList);

+				i.remove();

+			}

+		}

+		for (Rule rule : children) {

+			rule.synchronize();

+		}

+		return (ms.synchronizeFromGoal() ? true : result);

+	}

+	

+	public void init() {

+        ms.init();

+		map.clear();

+		mapWithAdornedIndex.clear();

+		for (Queue<MatchingFrame> queue : queues) {

+			queue.clear();

+		}

+		newFrames.clear();
+		
+		//TODO akos: HistoryList in the IndexedRule-s are not properly initialised
+		//and always saves information after pattern matching! In some cases multiple times!
+		for(Rule r:children)
+			r.init();

+	}

+	

+	/*

+	public MatchingFrame match(PatternCallSignature[] signature, Vector<Integer> freeVariables) throws PatternMatcherRuntimeException {

+		// init();

+		assert children.size() == queues.size();

+		for (int i = 0; i < children.size(); i++) {

+			Rule rule = children.get(i);

+			MatchingFrame template = new MatchingFrame(rule.pattern);

+			MatchingFrame frame = rule.traverse(queues.get(i), template);

+			

+    		for (Integer varID : freeVariables) {

+    			Scope s = signature[varID].getParameterScope();

+    			if (s.getContainmentMode() == ContainmentMode.IN && 

+    					!((IEntity) s.getParent()).getContents().contains(frame.getValue(varID)) ||

+    					s.getContainmentMode() == ContainmentMode.BELOW &&

+    					!((IEntity) s.getParent()).getAllComponents().contains(frame.getValue(varID))) {

+    				break;

+    			}

+    			return frame;

+    		}

+		}

+		return null;

+	}

+	*/

+

+	public void matchAll() throws PatternMatcherRuntimeException {

+		// init();

+		assert children.size() == queues.size();

+		for (int i = 0; i < children.size(); i++) {

+			Rule rule = children.get(i);

+			MatchingFrame template = new MatchingFrame(rule.pattern);

+			rule.traverseAll(queues.get(i), template);

+		}

+	}

+

+	public Iterator<MatchingFrame> iterator() {

+		return new ResultFrameIterator();

+	}

+	

+	private class ResultFrameIterator implements Iterator<MatchingFrame> {

+		Iterator<List<MatchingFrame>> listIterator;

+		Iterator<MatchingFrame> frameIterator;

+		

+		private ResultFrameIterator() {

+			listIterator = map.values().iterator();

+			frameIterator = (listIterator.hasNext() ? listIterator.next().iterator() : null);

+		}

+		

+		public boolean hasNext() {

+			while (frameIterator != null && !frameIterator.hasNext()) {

+				frameIterator = (listIterator.hasNext() ? listIterator.next().iterator() : null);

+			}

+			return frameIterator != null;

+		}

+

+		public MatchingFrame next() {

+			if (hasNext()) {

+				return frameIterator.next();

+			} else {

+				throw new NoSuchElementException();

+			}

+		}

+

+		public void remove() {

+			throw new UnsupportedOperationException();

+		}

+		

+	}
+
+	public void debug() {
+		for(Rule rule: children)
+			if(rule instanceof UnindexedRule)
+					((UnindexedRule)rule).debug();
+	}

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/rgg/RemoteGoalIncremental.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/rgg/RemoteGoalIncremental.java
new file mode 100644
index 0000000..280c294
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/rgg/RemoteGoalIncremental.java
@@ -0,0 +1,283 @@
+/*******************************************************************************

+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro

+ * All rights reserved. This program and the accompanying materials

+ * are made available under the terms of the Eclipse Public License v1.0

+ * which accompanies this distribution, and is available at

+ * http://www.eclipse.org/legal/epl-v10.html

+ *

+ * Contributors:

+ *    Akos Horvath, Gergely Varro - initial API and implementation

+ *******************************************************************************/

+

+

+package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.rgg;

+

+

+import java.util.Collection;

+import java.util.HashMap;

+import java.util.Iterator;

+import java.util.LinkedList;

+import java.util.List;

+import java.util.Map;

+import java.util.Queue;

+import java.util.Vector;

+

+import org.eclipse.viatra2.gtasm.interpreter.exception.ViatraTransformationException;

+import org.eclipse.viatra2.gtasm.patternmatcher.ExecutionMode;

+import org.eclipse.viatra2.gtasm.patternmatcher.IMatching;

+import org.eclipse.viatra2.gtasm.patternmatcher.ParameterMode;

+import org.eclipse.viatra2.gtasm.patternmatcher.PatternCallSignature;

+import org.eclipse.viatra2.gtasm.patternmatcher.Scope;

+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherRuntimeException;

+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;

+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingKey;

+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.callgraph.PatternNode;

+import org.eclipse.viatra2.gtasm.patternmatcher.patterns.IPatternMatcher;

+

+

+public class RemoteGoalIncremental extends RemoteGoal {

+

+	private IPatternMatcher patternMatcher;

+	private boolean isFirstTimeSync,isFirstTimeDelta;

+	private Map<MatchingKey, List<IMatching>> mapWithAdornedIndex;

+	private Map<MatchingKey, List<IMatching>> map;

+	private Collection<IMatching> matchings;

+	

+	public RemoteGoalIncremental(PatternNode pattern, Boolean[] adornment, IPatternMatcher patternMatcher) {

+		super(pattern, adornment);

+		isFirstTimeSync = true;

+		isFirstTimeDelta = true;

+		this.patternMatcher = patternMatcher;

+		mapWithAdornedIndex = new HashMap<MatchingKey, List<IMatching>>();

+		map = new HashMap<MatchingKey, List<IMatching>>();

+

+	}

+	

+	public void calculateAllDeltas(IndexedRule parent, Queue<MatchingFrame> output) throws PatternMatcherRuntimeException {

+		//      --->

+		// left |><| right

+		

+		//debug

+		//System.out.println("Pre CaclutaeDelta: ");

+		//this.debug();

+		

+		Queue<MatchingFrame> input = parent.getQueue();

+		for (Iterator<MatchingFrame> i = input.iterator(); i.hasNext();) {

+			MatchingFrame leftFrame = i.next();

+			MatchingKey keyForLeftFrame = parent.getBoundHeader(leftFrame);

+			List<IMatching> list = mapWithAdornedIndex.get(keyForLeftFrame);

+			if (list != null) {

+				for (IMatching rightFrame : list) {

+		            MatchingFrame newFrame = (MatchingFrame) leftFrame.clone();

+		            parent.merge(newFrame, rightFrame);

+		            output.offer(newFrame);

+				}

+			}

+	        ms.addArray(keyForLeftFrame);

+	        i.remove();

+		}

+		

+		//      <---

+		// left |><| right will have to evaluate only once at the first run!

+		if(isFirstTimeDelta && matchings  != null)

+			{isFirstTimeDelta = false;

+			for(List<IMatching> matchings:map.values())

+				for(IMatching rightFrame :matchings){

+				//IMatching rightFrame = j.next();

+				Vector<Object> v = new Vector<Object>();

+				int size = 0;

+				for (int i = 0; i < adornment.length; i++) {

+					if (adornment[i]) {

+						v.add(rightFrame.lookup(i));

+						size++;

+					}

+				}

+				final Object[] key = new Object[size];

+				v.toArray(key);

+				HistoryList<MatchingKey, MatchingFrame> queue = 

+					parent.getQueue();

+				List<MatchingFrame> list = queue.get(new MatchingKey(key));

+				if (list != null) 

+					{

+					for (MatchingFrame leftFrame : list) {

+				           MatchingFrame newFrame = (MatchingFrame) leftFrame.clone();

+				           parent.merge(newFrame, rightFrame);

+				           output.offer(newFrame);

+						}

+					}	

+				}

+			}

+		

+		//debug

+		//System.out.println("Post CaclutaeDelta: ");

+		//this.debug();

+	}

+	

+	public boolean synchronize() throws ViatraTransformationException {

+		

+		//System.out.println("Pre Synch: ");

+		this.debug();

+

+		

+		boolean result = false;

+		//have to be activated the first time when the matchings are available and only once then

+		if(isFirstTimeSync 

+				//&& matchings != null

+				)

+			{isFirstTimeSync = false;

+			

+			//if(matchings == null){

+			Object[] inputMapping = new Object[adornment.length];

+			Integer[] quantificationOrder = new Integer[adornment.length];

+			PatternCallSignature[] signature = new PatternCallSignature[adornment.length];

+			

+			for(int i= 0; i<signature.length; i++){

+				PatternCallSignature _p = new PatternCallSignature();

+				_p.setExecutionMode(ExecutionMode.MULTIPLE_RESULTS);

+				_p.setParameterMode(ParameterMode.OUTPUT);

+				_p.setParameterScope(new Scope());

+				signature[i] = _p;

+				}

+			

+			try {

+				matchings = patternMatcher.matchAll(inputMapping, signature, quantificationOrder);

+				//for(IMatching matching:matchings){

+					//MatchingKey keyforFrame = adornedKeyGenerator.calculateKey(matching);

+					//after the first match all elements are present in the ms

+					//ms.addArray(keyforFrame);

+				//	}

+				

+			} catch (ViatraTransformationException e) {

+				throw e.addNewStackElement(this.pattern.getPattern());

+			}

+			

+			

+			for(IMatching matching: matchings){

+				MatchingKey keyForFrameAdorned = adornedKeyGenerator.calculateKey(matching);

+				List<IMatching> currentList = 

+					mapWithAdornedIndex.get(keyForFrameAdorned);

+				if (currentList == null) {

+					currentList = new LinkedList<IMatching>();

+				}

+				currentList.add(matching);

+				mapWithAdornedIndex.put(keyForFrameAdorned, currentList);

+				ms.addArray(keyForFrameAdorned);

+				

+				MatchingKey keyForFrame = keyGenerator.calculateKey(matching);

+				currentList = map.get(keyForFrame);

+				if (currentList == null) {

+					currentList = new LinkedList<IMatching>();

+					//newFrames.add(frame);

+					result = true;

+				} 

+				currentList.add(matching);

+				map.put(keyForFrame, currentList);

+				}

+			}

+		

+//		for (Iterator<MatchingFrame> i = newFrames.iterator(); i.hasNext();) {

+//			MatchingFrame frame = i.next();

+//			MatchingKey keyForFrame = adornedKeyGenerator.calculateKey(frame);

+//			List<IMatching> currentList = 

+//				mapWithAdornedIndex.get(keyForFrame);

+//			if (currentList == null) {

+//				currentList = new LinkedList<IMatching>();

+//			}

+//			currentList.add(frame);

+//			mapWithAdornedIndex.put(keyForFrame, currentList);

+//			i.remove();

+//		}

+

+//		assert newFrames.isEmpty();

+//		//for (Queue<MatchingFrame> queue : queues) {

+//			//for (Iterator<MatchingFrame> i = queue.iterator(); i.hasNext();) {

+//				//MatchingFrame frame = i.next();

+//		MatchingFrame frame = null; 

+//		MatchingKey keyForFrame = keyGenerator.calculateKey(frame);

+//		List<IMatching> currentList = map.get(keyForFrame);

+//		if (currentList == null) {

+//			currentList = new LinkedList<IMatching>();

+//			newFrames.add(frame);

+//			result = true;

+//		} 

+//		currentList.add(frame);

+//		map.put(keyForFrame, currentList);

+	//	i.remove();

+	//		}

+	//	}

+		//for (Rule rule : children) {

+		//	rule.synchronize();

+		//}

+		

+		//debug

+		//will have to evaluate that are we ready or there are new matches avvailable

+		//System.out.println("Post Synch: ");

+		//this.debug();

+

+		return (ms.synchronizeFromGoal() ? true : result);

+	}

+	

+	public void init() {

+        ms.init();

+		map.clear();

+		matchings = null;

+		mapWithAdornedIndex.clear();

+		isFirstTimeSync = true;

+		isFirstTimeDelta = true;

+		

+		

+		

+		

+		//for (Queue<MatchingFrame> queue : queues) {

+		//	queue.clear();

+		//}

+//		newFrames.clear();

+	}

+	

+	/*

+	public MatchingFrame match(PatternCallSignature[] signature, Vector<Integer> freeVariables) throws PatternMatcherRuntimeException {

+		// init();

+		assert children.size() == queues.size();

+		for (int i = 0; i < children.size(); i++) {

+			Rule rule = children.get(i);

+			MatchingFrame template = new MatchingFrame(rule.pattern);

+			MatchingFrame frame = rule.traverse(queues.get(i), template);

+			

+    		for (Integer varID : freeVariables) {

+    			Scope s = signature[varID].getParameterScope();

+    			if (s.getContainmentMode() == ContainmentMode.IN && 

+    					!((IEntity) s.getParent()).getContents().contains(frame.getValue(varID)) ||

+    					s.getContainmentMode() == ContainmentMode.BELOW &&

+    					!((IEntity) s.getParent()).getAllComponents().contains(frame.getValue(varID))) {

+    				break;

+    			}

+    			return frame;

+    		}

+		}

+		return null;

+	}

+	*/

+

+	public void matchAll() throws PatternMatcherRuntimeException {

+		

+		//TODO: can only be invoked from the PatternMatcher -> exception

+		//throw new PatternMatcherRuntimeException(PatternMatcherRuntimeException.INTERNAL_PATTERNMATCHER_INCREMENTALWITHREMOTEGOAL_MATCHALL_ERROR);

+		// init();

+		//assert children.size() == queues.size();

+		//for (int i = 0; i < children.size(); i++) {

+		//	Rule rule = children.get(i);

+		//	MatchingFrame template = new MatchingFrame(rule.pattern);

+		//	rule.traverseAll(queues.get(i), template);

+		

+		//first call of the matchall after an init

+		

+	}

+

+	@Override

+	public void debug() {

+		//this.

+	}

+}

+	

+	

+

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/rgg/Rule.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/rgg/Rule.java
new file mode 100644
index 0000000..30e56d9
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/rgg/Rule.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.rgg;

+

+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.callgraph.FlattenedPattern;
+

+abstract public class Rule extends RuleGoalGraphNode 

+		implements IQueueContentProvider, Comparable<Rule> {

+	FlattenedPattern pattern;

+	IQueueContentProvider left;

+	

+	public Rule(FlattenedPattern pattern, 

+			IQueueContentProvider left) {

+		this.pattern = pattern;

+		this.left = left;

+	}

+	

+	abstract public void synchronize();

+	abstract public void init();
+	

+	public int compareTo(Rule o) {

+		return pattern.compareTo(o.pattern);

+	}

+} 

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/rgg/RuleGoalGraphNode.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/rgg/RuleGoalGraphNode.java
new file mode 100644
index 0000000..8304098
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/rgg/RuleGoalGraphNode.java
@@ -0,0 +1,15 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.rgg;

+

+public abstract class RuleGoalGraphNode {

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/rgg/UnindexedRule.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/rgg/UnindexedRule.java
new file mode 100644
index 0000000..f8532e6
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/rgg/UnindexedRule.java
@@ -0,0 +1,93 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.rgg;

+

+import java.util.LinkedList;
+import java.util.Queue;
+
+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherRuntimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.callgraph.FlattenedPattern;
+

+

+public class UnindexedRule extends Rule {

+	private LocalGoal right;

+	private LinkedList<MatchingFrame> leftInputQueue;

+	

+	public UnindexedRule(FlattenedPattern pattern,

+			IQueueContentProvider left,

+			LocalGoal right) {

+		super(pattern, left);

+		this.right = right;

+		this.leftInputQueue = new LinkedList<MatchingFrame>();

+	}

+	

+	public void traverseAll(Queue<MatchingFrame> resultQueue, MatchingFrame template) 

+	throws PatternMatcherRuntimeException {

+		left.traverseAll(leftInputQueue, template);

+		right.calculateAllDeltas(this, resultQueue);

+	}

+

+	public Queue<MatchingFrame> getQueue() {

+		return leftInputQueue;

+	}

+

+	@Override

+	public void synchronize() {

+		left.synchronize();

+		leftInputQueue.clear();

+	}

+
+	@Override
+	public void init() {
+		left.init();
+	}

+	/*

+	public void initalizeSingleTraversal(Queue<MatchingFrame> queue, MatchingFrame template) {

+		left.initalizeSingleTraversal(leftInputQueue, template);

+	}

+

+	public MatchingFrame traverse() throws PatternMatcherRuntimeException {

+		return null;

+		// return new MatchingFrameMemo();

+	}

+	

+	private class MatchingFrameMemo {

+		private MatchingFrame lastReturned;

+		

+		MatchingFrameMemo() throws PatternMatcherRuntimeException {

+			this.lastReturned = left.traverse();

+		}

+		

+		public boolean hasNext() {

+			return lastReturned != null;

+		}

+		

+		public MatchingFrame next() throws PatternMatcherRuntimeException {

+			MatchingFrame result = lastReturned;

+			while (lastReturned != null) {

+				if (right.calculateDelta(lastReturned)) {

+					return result;

+				} else {

+					lastReturned = left.traverse();

+				}

+			}

+			return null;

+		}

+	}

+	*/
+
+	public void debug() {
+		System.out.println("  Unindexed Rule left input queue size: "+leftInputQueue.size());
+		
+	}

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/searchgraph/AbstractNode.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/searchgraph/AbstractNode.java
new file mode 100644
index 0000000..2913357
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/searchgraph/AbstractNode.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph;

+
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.traceability.AbstractTraceabilityElement;
+

+public abstract class AbstractNode{

+	private String name;

+	private boolean checked = false;
+	

+	public String getName() {

+		return name;

+	}

+	public void setName(String name) {

+		this.name = name;

+	}

+	public boolean isChecked() {

+		return checked;

+	}

+	public void setChecked(boolean checked) {

+		this.checked = checked;

+	}

+	

+	public void clear()

+	{

+		checked = false;		

+	}
+	
+	public abstract AbstractTraceabilityElement getTraceabilityElement();
+

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/searchgraph/ConstantSearchGraphNode.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/searchgraph/ConstantSearchGraphNode.java
new file mode 100644
index 0000000..2294840
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/searchgraph/ConstantSearchGraphNode.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph;

+
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.traceability.ConstantNodeTraceabilityElement;
+

+public class ConstantSearchGraphNode extends SearchGraphNode {

+    private String element;
+    private ConstantNodeTraceabilityElement traceabilityElement;

+

+	public String getElement() {

+		return element;

+	}

+

+	public void setElement(String element) {

+		this.element = element;

+	}
+
+	@Override
+	public ConstantNodeTraceabilityElement getTraceabilityElement() {
+		return traceabilityElement;
+	}
+	
+	public void setTraceabilityElement(ConstantNodeTraceabilityElement element) {
+		traceabilityElement = element;
+	}

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/searchgraph/EdgeTypeinAlgorithm.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/searchgraph/EdgeTypeinAlgorithm.java
new file mode 100644
index 0000000..c7d8e36
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/searchgraph/EdgeTypeinAlgorithm.java
@@ -0,0 +1,20 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph;

+

+public enum EdgeTypeinAlgorithm {

+	

+	TREE,

+	FREE,

+	CIRCLE

+

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/searchgraph/PatternCallSearchGraphNode.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/searchgraph/PatternCallSearchGraphNode.java
new file mode 100644
index 0000000..9f2fb41
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/searchgraph/PatternCallSearchGraphNode.java
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph;

+

+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.callgraph.PatternNode;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.traceability.PatternCallNodeTraceabilityElement;
+
+

+/**

+ * @author Akos Horvath

+ *

+ */

+public class PatternCallSearchGraphNode extends VariableSearchGraphNode {

+

+	/**

+	 * 

+	 */

+	

+	private Integer[] inputParameterMapping;

+	private PatternNode patternNode = null;

+	private PatternCallNodeTraceabilityElement traceabilityElement;

+	

+	

+	public PatternCallSearchGraphNode(int size) {

+		inputParameterMapping = new Integer[size];

+		

+	}

+

+	public PatternCallSearchGraphNode() {

+		super();

+		inputParameterMapping = null;

+	}

+

+	public Integer[] getInputParameterMapping() {

+		return inputParameterMapping;

+	}

+

+	public void setInputParameterMapping(Integer[] inputParameterMapping) {

+		this.inputParameterMapping = inputParameterMapping;

+	}

+

+	public PatternNode getPatternNode() {

+		return patternNode;

+	}

+

+	public void setPatternNode(PatternNode patternNode) {

+		this.patternNode = patternNode;

+	}
+	
+/*	@Override
+	public PatternCallNodeTraceabilityElement getTraceabilityElement() {
+		return traceabilityElement;
+	}
+	
+	public void setTraceabilityElement(PatternCallNodeTraceabilityElement element) {
+		traceabilityElement = element;
+	}

+*/

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/searchgraph/PseudoSearchGraphNode.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/searchgraph/PseudoSearchGraphNode.java
new file mode 100644
index 0000000..0dbc713
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/searchgraph/PseudoSearchGraphNode.java
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph;

+
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.traceability.AbstractTraceabilityElement;
+

+/**

+ * @author Akos Horvath

+ *

+ */

+public class PseudoSearchGraphNode extends SearchGraphNode {

+	

+	private int circleSmallestId = -1, circleBiggestId = -1;

+	private boolean isBlocked = false;

+/**

+	 * @return the circleBiggestId

+	 */

+	public int getCircleBiggestId() {

+		return circleBiggestId;

+	}

+

+	/**

+	 * @param circleBiggestId the circleBiggestId to set

+	 */

+	public void setCircleBiggestId(int circleBiggestId) {

+		this.circleBiggestId = circleBiggestId;

+	}

+

+	/**

+	 * @return the circleSmallestId

+	 */

+	public int getCircleSmallestId() {

+		return circleSmallestId;

+	}

+

+	/**

+	 * @param circleSmallestId the circleSmallestId to set

+	 */

+	public void setCircleSmallestId(int circleSmallestId) {

+		this.circleSmallestId = circleSmallestId;

+	}

+

+	/**

+	 * @return the isBlocked

+	 */

+	public boolean isBlocked() {

+		return isBlocked;

+	}

+

+	/**

+	 * @param isBlocked the isBlocked to set

+	 */

+	public void setBlocked(boolean isBlocked) {

+		this.isBlocked = isBlocked;

+	}
+
+	@Override
+	public AbstractTraceabilityElement getTraceabilityElement() {
+		return null;
+	}

+

+

+	

+

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/searchgraph/SearchGraphEdge.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/searchgraph/SearchGraphEdge.java
new file mode 100644
index 0000000..eb7a888
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/searchgraph/SearchGraphEdge.java
@@ -0,0 +1,145 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph;

+

+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.EdgeType;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.traceability.EdgeTraceabilityElement;
+

+

+public class SearchGraphEdge extends AbstractNode {

+    private int oldWeight = -1, weight = -1, idinSearchPath= -1;

+	private EdgeTypeinAlgorithm type = EdgeTypeinAlgorithm.FREE;

+	private SearchGraphNode targetNode, sourceNode;

+	private EdgeType vpmEdgetype;

+	private SearchGraphEdge inverseEdge = null;

+	private boolean isSource; 
+	private EdgeTraceabilityElement traceabilityElement;

+	

+	public int getOldWeight() {

+		return oldWeight;

+	}

+

+	public void setOldWeight(int oldWeight) {

+		this.oldWeight = oldWeight;

+	}

+

+	public int getWeight() {

+		return weight;

+	}

+

+	public void setWeight(int weight) {

+		this.weight = weight;

+	}

+

+	public EdgeTypeinAlgorithm getEdgeTypeinAlgorithm() {

+		return type;

+	}

+

+	public void setEdgeTypeinAlgorithm(EdgeTypeinAlgorithm type) {

+		this.type = type;

+	}

+

+	public int getIdinSearchPath() {

+		return idinSearchPath;

+	}

+

+	public void setIdinSearchPath(int idinSearchPath) {

+		this.idinSearchPath = idinSearchPath;

+	}

+

+	public SearchGraphNode getSourceNode() {

+		return sourceNode;

+	}

+

+	public void setSourceNode(SearchGraphNode sourceNode) {

+		this.sourceNode = sourceNode;

+	}

+

+	public SearchGraphNode getTargetNode() {

+		return targetNode;

+	}

+

+	public void setTargetNode(SearchGraphNode targetNode) {

+		this.targetNode = targetNode;

+	}

+

+	public EdgeType getVPMEdgeType() {

+		return vpmEdgetype;

+	}

+

+	public void setVPMEdgeType(EdgeType vpmEdgetype) {

+		this.vpmEdgetype = vpmEdgetype;

+	}

+

+	public boolean isSource() {

+		return isSource;

+	}

+

+	public void setSource(boolean isSource) {

+		this.isSource = isSource;

+	}

+

+	/**

+	 * @return the inverseEdge

+	 */

+	public SearchGraphEdge getInverseEdge() {

+		return inverseEdge;

+	}

+

+	/**

+	 * @param inverseEdge the inverseEdge to set

+	 */

+	public void setInverseEdge(SearchGraphEdge inverseEdge) {

+		this.inverseEdge = inverseEdge;

+		inverseEdge.NonRecursiveInverseEdgeSet(this);

+	}

+

+	/**

+	 * @param inverseEdge the inverseEdge to set

+	 */

+	private void NonRecursiveInverseEdgeSet(SearchGraphEdge inverseEdge) {

+		this.inverseEdge = inverseEdge;

+	}

+	/* (non-Javadoc)

+	 * @see org.eclipse.viatra2.gtasm.patternmatcher.internal.AbstractNode#setChecked(boolean)

+	 */

+	@Override

+	public void setChecked(boolean checked) {

+		super.setChecked(checked);

+		if(inverseEdge != null)

+			inverseEdge.nonRecursiveSetChecked(checked);

+	}

+	

+	private void nonRecursiveSetChecked(boolean checked) {

+		super.setChecked(checked);

+		

+	}

+

+	/* (non-Javadoc)

+	 * @see org.eclipse.viatra2.gtasm.patternmatcher.internal.AbstractNode#clear()

+	 */

+	@Override

+	public void clear() {

+		//super.clear();

+		setChecked(false);

+	}
+
+	@Override
+	public EdgeTraceabilityElement getTraceabilityElement() {
+		return traceabilityElement;
+	}
+	
+	public void setTraceabilityElement(EdgeTraceabilityElement element) {
+		traceabilityElement = element;
+	}

+	

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/searchgraph/SearchGraphNode.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/searchgraph/SearchGraphNode.java
new file mode 100644
index 0000000..8cf0198
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/searchgraph/SearchGraphNode.java
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph;

+

+import java.util.Vector;
+

+

+public abstract class SearchGraphNode extends AbstractNode implements Comparable{

+	

+	

+	private Vector<SearchGraphEdge> Sources;

+	private SearchGraphEdge treeEdge = null;

+	private SearchGraphNode VirtualSearchGraphNode = null;

+	private int outgoingTreeEdgeNumber = 0;

+	

+	public SearchGraphNode() {

+		super();

+		Sources = new Vector<SearchGraphEdge>();

+		outgoingTreeEdgeNumber = 0;

+

+	}

+	public void addSource(SearchGraphEdge enode){

+		this.Sources.add(enode);

+	}

+	public Vector<SearchGraphEdge> getSources(){

+		return Sources;

+	}

+	public SearchGraphNode getVirtualSearchGraphNode() {

+		return VirtualSearchGraphNode;

+	}

+	public void setVirtualSearchGraphNode(SearchGraphNode virtualVertex) {

+		this.VirtualSearchGraphNode = virtualVertex;

+	}

+	public SearchGraphEdge getTreeEdge() {

+		return treeEdge;

+	}

+	public void setTreeEdge(SearchGraphEdge treeEdge) {

+		this.treeEdge = treeEdge;

+	}

+	public int getOutgoingTreeEdgeNumber() {

+		return outgoingTreeEdgeNumber;

+	}

+	public void setOutgoingTreeEdgeNumber(int outgoingTreeEdge) {

+		this.outgoingTreeEdgeNumber = outgoingTreeEdge;

+	}

+	public void increaseOutgonigTreeEdgeNumber(){

+		outgoingTreeEdgeNumber++;

+	}

+

+	public void decreaseOutgoingTreeEdgeNumber(){

+		outgoingTreeEdgeNumber--;

+	}

+	public int compareTo(Object o) {

+		if (o instanceof SearchGraphNode)

+		{SearchGraphNode node = (SearchGraphNode) o;

+			if(this.treeEdge.getOldWeight() < node.getTreeEdge().getOldWeight())

+				return -1;

+			else

+			if(this.treeEdge.getOldWeight() == node.getTreeEdge().getOldWeight())

+				//because of the set there can be no matching

+				return 0;

+			else

+				return 1;

+		}

+		

+		return 0;

+	}
+		

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/searchgraph/SearchGraphNodeComparator.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/searchgraph/SearchGraphNodeComparator.java
new file mode 100644
index 0000000..1f657c5
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/searchgraph/SearchGraphNodeComparator.java
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph;

+

+import java.io.Serializable;
+import java.util.Comparator;
+

+/**

+ * @author Akos Horvath

+ *

+ */

+public class SearchGraphNodeComparator implements Comparator<SearchGraphNode>, Serializable {

+

+	/**

+	 * 

+	 */

+	private static final long serialVersionUID = 4964712646210992592L;

+

+	/* (non-Javadoc)

+	 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)

+	 */

+	public int compare(SearchGraphNode node0, SearchGraphNode node1) {

+		if(node1.equals(node0))

+			return 0;

+		else		

+		if(node0.getTreeEdge() == null && node1.getTreeEdge() == null)

+			{

+			if(node0 instanceof ConstantSearchGraphNode && node1 instanceof ConstantSearchGraphNode)

+					return node0.getName().compareTo(node1.getName());

+			else 

+			if(node0 instanceof ConstantSearchGraphNode && node1 instanceof VariableSearchGraphNode)

+				return -1;	

+			else

+			if(node0 instanceof VariableSearchGraphNode && node1 instanceof ConstantSearchGraphNode)

+				return 1;

+			else //both are variable constant nodes

+				return ((VariableSearchGraphNode)node0).getId().compareTo( ((VariableSearchGraphNode)node1).getId() );

+			}

+		else

+		if(node0.getTreeEdge()== null)

+			return -1;

+		else

+		if(node1.getTreeEdge() == null)

+			return 1;

+		else

+			//the normal comapre

+		if(node0.getTreeEdge().getOldWeight() < node1.getTreeEdge().getOldWeight())

+			return -1; 

+		else

+		if(node0.getTreeEdge().getOldWeight() > node1.getTreeEdge().getOldWeight())

+			return 1;

+		else

+			

+			//this is not a smooth solution

+		if(node0.getTreeEdge().getOldWeight() == node1.getTreeEdge().getOldWeight())

+			{if(node0 instanceof ConstantSearchGraphNode && node1 instanceof ConstantSearchGraphNode)

+					return node0.getName().compareTo(node1.getName());

+			else 

+			if(node0 instanceof ConstantSearchGraphNode && node1 instanceof VariableSearchGraphNode)

+				return -1;	

+			else

+			if(node0 instanceof VariableSearchGraphNode && node1 instanceof ConstantSearchGraphNode)

+				return 1;

+			else //both are variable constant nodes

+				return ((VariableSearchGraphNode)node0).getId().compareTo( ((VariableSearchGraphNode)node1).getId());

+			

+			}

+		

+		return -1;

+	}

+

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/searchgraph/VariableSearchGraphNode.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/searchgraph/VariableSearchGraphNode.java
new file mode 100644
index 0000000..0d7212b
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/searchgraph/VariableSearchGraphNode.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph;

+

+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.VPMModelElementType;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.traceability.VariableNodeTraceabilityElement;
+
+

+public class VariableSearchGraphNode extends SearchGraphNode {

+    private Integer id;

+    private boolean isInput = false;

+    private VPMModelElementType vpmModelElementType;
+    private VariableNodeTraceabilityElement traceabilityElement;

+    

+	public void clear(){

+	super.clear();

+		isInput = false;

+	}

+

+	public Integer getId() {

+		return id;

+	}

+

+	public void setId(Integer id) {

+		this.id = id;

+	}

+

+	/**

+	 * @return the isInput

+	 */

+	public boolean isInput() {

+		return isInput;

+	}

+

+	/**

+	 * @param isInput the isInput to set

+	 */

+	public void setInput(boolean isInput) {

+		this.isInput = isInput;

+	}

+

+	/**

+	 * @return the vpmModelElementType

+	 */

+	public VPMModelElementType getVpmModelElementType() {

+		return vpmModelElementType;

+	}

+

+	/**

+	 * @param vpmModelElementType the vpmModelElementType to set

+	 */

+	public void setVpmModelElementType(VPMModelElementType vpmModelElementType) {

+		this.vpmModelElementType = vpmModelElementType;

+	}
+
+	@Override
+	public VariableNodeTraceabilityElement getTraceabilityElement() {
+		return traceabilityElement;
+	}
+	
+	public void setTraceabilityElement(VariableNodeTraceabilityElement element) {
+		traceabilityElement = element;
+	}

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/searchgraph/traceability/AbstractTraceabilityElement.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/searchgraph/traceability/AbstractTraceabilityElement.java
new file mode 100644
index 0000000..d46741e
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/searchgraph/traceability/AbstractTraceabilityElement.java
@@ -0,0 +1,77 @@
+/*******************************************************************************

+ * Copyright (c) 2004-2009 Akos Horvath and Daniel Varro

+ * All rights reserved. This program and the accompanying materials

+ * are made available under the terms of the Eclipse Public License v1.0

+ * which accompanies this distribution, and is available at

+ * http://www.eclipse.org/legal/epl-v10.html

+ *

+ * Contributors:

+ *    Akos Horvath - initial API and implementation

+ *******************************************************************************/

+

+

+/**

+ * 

+ */

+package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.traceability;

+

+import java.util.ArrayList;

+

+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;

+

+

+/**

+ * For each VPM search graph element a traceability Element is created that can point to multiple GTASM element 

+ * and its corresponding operation (either pattern or gtRule)

+ * @author Akos Horvath

+ *

+ */

+public abstract class AbstractTraceabilityElement<VPMType> {

+	

+	private ArrayList<AnnotatedElement> emfElements;

+	

+	public AbstractTraceabilityElement(){

+		emfElements = new ArrayList<AnnotatedElement>();

+	}

+	

+	public AbstractTraceabilityElement(AnnotatedElement element){

+		emfElements = new ArrayList<AnnotatedElement>();

+		if(element != null)

+			emfElements.add(0, element);

+	}

+	

+	/** Adds an EMF element to the traceability node. If it is the first one than it will become the representative one

+	 * @param element

+	 */

+	public void addEMFElement(AnnotatedElement element){

+		if(element != null)

+			emfElements.add(element);

+	}

+	

+	/** Adds the representative EMF element to the traceability node

+	 * @param element

+	 */

+	public void addRepresentativeElement(AnnotatedElement element){

+		if(element != null)

+		{

+			if(emfElements.get(0) != null)

+				{

+				AnnotatedElement _temp = emfElements.get(0);

+				emfElements.add(0, element);

+				emfElements.add(_temp);

+				}

+			else

+				emfElements.add(0,element);

+		}

+	}

+	

+	/** Return the representative EMF element. 

+	 * @return

+	 */

+	public AnnotatedElement getRepresentativeEMFElement(){

+		return emfElements.get(0);

+	}

+	

+	public abstract VPMType getVPMElement();

+	

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/searchgraph/traceability/ConstantNodeTraceabilityElement.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/searchgraph/traceability/ConstantNodeTraceabilityElement.java
new file mode 100644
index 0000000..38362ef
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/searchgraph/traceability/ConstantNodeTraceabilityElement.java
@@ -0,0 +1,41 @@
+/*******************************************************************************

+ * Copyright (c) 2004-2009 Akos Horvath and Daniel Varro

+ * All rights reserved. This program and the accompanying materials

+ * are made available under the terms of the Eclipse Public License v1.0

+ * which accompanies this distribution, and is available at

+ * http://www.eclipse.org/legal/epl-v10.html

+ *

+ * Contributors:

+ *    Akos Horvath - initial API and implementation

+ *******************************************************************************/

+

+

+/**

+ * 

+ */

+package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.traceability;

+

+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.ConstantSearchGraphNode;

+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;

+

+

+/**

+ * @author Akos Horvath

+ *

+ */

+public class ConstantNodeTraceabilityElement extends NodeTraceabilityElement {

+

+	ConstantSearchGraphNode constantSearchGraphNode;

+	

+	public ConstantNodeTraceabilityElement(ConstantSearchGraphNode node, AnnotatedElement element){

+		super(element);

+		constantSearchGraphNode = node;

+		constantSearchGraphNode.setTraceabilityElement(this);

+	}

+	

+	@Override

+	public ConstantSearchGraphNode getVPMElement() {

+		return constantSearchGraphNode;

+	}

+

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/searchgraph/traceability/EdgeTraceabilityElement.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/searchgraph/traceability/EdgeTraceabilityElement.java
new file mode 100644
index 0000000..428c20d
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/searchgraph/traceability/EdgeTraceabilityElement.java
@@ -0,0 +1,40 @@
+/*******************************************************************************

+ * Copyright (c) 2004-2009 Akos Horvath and Daniel Varro

+ * All rights reserved. This program and the accompanying materials

+ * are made available under the terms of the Eclipse Public License v1.0

+ * which accompanies this distribution, and is available at

+ * http://www.eclipse.org/legal/epl-v10.html

+ *

+ * Contributors:

+ *    Akos Horvath - initial API and implementation

+ *******************************************************************************/

+

+

+/**

+ * 

+ */

+package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.traceability;

+

+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.SearchGraphEdge;

+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;

+

+

+/**

+ * @author Akos Horvath

+ *

+ */

+public class EdgeTraceabilityElement extends AbstractTraceabilityElement<SearchGraphEdge> {

+	

+	SearchGraphEdge searchGraphEdge;

+	

+	public EdgeTraceabilityElement(SearchGraphEdge edge, AnnotatedElement element){

+		super(element);

+		searchGraphEdge = edge;

+		searchGraphEdge.setTraceabilityElement(this);

+	}

+	

+	public SearchGraphEdge getVPMElement() {

+		return searchGraphEdge;

+	}

+

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/searchgraph/traceability/NodeTraceabilityElement.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/searchgraph/traceability/NodeTraceabilityElement.java
new file mode 100644
index 0000000..843f6a9
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/searchgraph/traceability/NodeTraceabilityElement.java
@@ -0,0 +1,37 @@
+/*******************************************************************************

+ * Copyright (c) 2004-2009 Akos Horvath and Daniel Varro

+ * All rights reserved. This program and the accompanying materials

+ * are made available under the terms of the Eclipse Public License v1.0

+ * which accompanies this distribution, and is available at

+ * http://www.eclipse.org/legal/epl-v10.html

+ *

+ * Contributors:

+ *    Akos Horvath - initial API and implementation

+ *******************************************************************************/

+

+

+/**

+ * 

+ */

+package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.traceability;

+

+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.SearchGraphNode;

+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;

+

+

+

+/**

+ * @author Akos Horvath

+ *

+ */

+public abstract class NodeTraceabilityElement extends AbstractTraceabilityElement<SearchGraphNode> {

+

+	public NodeTraceabilityElement(){

+		super();

+	}

+	

+	public NodeTraceabilityElement(AnnotatedElement element){

+		super(element);

+	}

+	

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/searchgraph/traceability/PatternCallNodeTraceabilityElement.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/searchgraph/traceability/PatternCallNodeTraceabilityElement.java
new file mode 100644
index 0000000..97e82c3
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/searchgraph/traceability/PatternCallNodeTraceabilityElement.java
@@ -0,0 +1,33 @@
+/*******************************************************************************

+ * Copyright (c) 2004-2009 Akos Horvath and Daniel Varro

+ * All rights reserved. This program and the accompanying materials

+ * are made available under the terms of the Eclipse Public License v1.0

+ * which accompanies this distribution, and is available at

+ * http://www.eclipse.org/legal/epl-v10.html

+ *

+ * Contributors:

+ *    Akos Horvath - initial API and implementation

+ *******************************************************************************/

+

+

+package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.traceability;

+

+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.PatternCallSearchGraphNode;

+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;

+

+

+/**A simple traceability element 

+ * @author Akos Horvath

+ *

+ */

+public class PatternCallNodeTraceabilityElement extends VariableNodeTraceabilityElement {

+

+	public PatternCallNodeTraceabilityElement(PatternCallSearchGraphNode node, AnnotatedElement element) {

+		super(node,element);

+	}

+	

+	public PatternCallSearchGraphNode getVPMElement() {

+		return (PatternCallSearchGraphNode)variableSearchGraphNode;

+	}

+	

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/searchgraph/traceability/VariableNodeTraceabilityElement.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/searchgraph/traceability/VariableNodeTraceabilityElement.java
new file mode 100644
index 0000000..36af2b7
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/internal/searchgraph/traceability/VariableNodeTraceabilityElement.java
@@ -0,0 +1,42 @@
+/*******************************************************************************

+ * Copyright (c) 2004-2009 Akos Horvath and Daniel Varro

+ * All rights reserved. This program and the accompanying materials

+ * are made available under the terms of the Eclipse Public License v1.0

+ * which accompanies this distribution, and is available at

+ * http://www.eclipse.org/legal/epl-v10.html

+ *

+ * Contributors:

+ *    Akos Horvath - initial API and implementation

+ *******************************************************************************/

+

+

+/**

+ * 

+ */

+package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.traceability;

+

+

+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.VariableSearchGraphNode;

+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;

+

+

+/**

+ * @author Akos Horvath

+ *

+ */

+public class VariableNodeTraceabilityElement extends NodeTraceabilityElement {

+	

+	VariableSearchGraphNode variableSearchGraphNode;

+	

+	

+	public VariableNodeTraceabilityElement(VariableSearchGraphNode node, AnnotatedElement element){

+		super(element);

+		variableSearchGraphNode = node;

+		variableSearchGraphNode.setTraceabilityElement(this);

+	}

+

+	@Override

+	public VariableSearchGraphNode getVPMElement() {

+		return variableSearchGraphNode;

+	}

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/term/AbstractTermCheckOperation.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/term/AbstractTermCheckOperation.java
new file mode 100644
index 0000000..8e4294e
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/term/AbstractTermCheckOperation.java
@@ -0,0 +1,21 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.term;

+

+import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherRuntimeException;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation.CheckOperation;
+
+

+public abstract class AbstractTermCheckOperation extends CheckOperation {

+    abstract protected boolean check(MatchingFrame frame) throws PatternMatcherRuntimeException;

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/term/BasicTermHandler.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/term/BasicTermHandler.java
new file mode 100644
index 0000000..0dfe0e5
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/term/BasicTermHandler.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.term;

+

+import org.eclipse.viatra2.gtasm.interpreter.executionEnvironment.IExecutionEnvironment;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation.TermCheckOperation;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation.TermEvaluationOperation;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.terms.Term;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.ContainmentConstraint;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.GTPattern;
+
+

+public class BasicTermHandler extends TermHandler {

+	private IExecutionEnvironment parentEnv;

+	

+	public BasicTermHandler(IExecutionEnvironment parentEnv) {

+		this.parentEnv = parentEnv;

+	}

+	

+    @Override

+    public AbstractTermCheckOperation getTermCheckOperation(GTPattern pattern, int uid, 

+    		Term term) {

+        return new TermCheckOperation(parentEnv, pattern, uid, term);

+    }

+

+    @Override //currentyl not used as TermEvaluation is only nedded in case of constant parent element in containment constraints

+    public AbstractTermCheckOperation getTermEvaluationOperation(GTPattern pattern, 

+    		int uid, Term term, int resultSlot) {

+        return new TermEvaluationOperation(parentEnv, pattern, uid, term, resultSlot);

+    }
+
+  public AbstractTermCheckOperation getTermEvaluationOperation(
+			GTPattern pattern, int uid, ContainmentConstraint conCons,
+			int resultSlot) {
+		return new TermEvaluationOperation(parentEnv, pattern, uid, conCons, resultSlot);
+	}

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/term/ITermHandler.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/term/ITermHandler.java
new file mode 100644
index 0000000..c46a0e2
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/term/ITermHandler.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.term;

+

+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.terms.Term;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.ContainmentConstraint;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.GTPattern;
+

+public interface ITermHandler {

+

+	public AbstractTermCheckOperation getTermEvaluationOperation(

+			GTPattern pattern, int uid, ContainmentConstraint conCons, int resultSlot);

+

+	public AbstractTermCheckOperation getTermCheckOperation(GTPattern pattern,

+			int uid, Term term);

+

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/term/TermCheckExecutionEnvironment.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/term/TermCheckExecutionEnvironment.java
new file mode 100644
index 0000000..8cb6b16
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/term/TermCheckExecutionEnvironment.java
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.term;

+

+import java.util.HashMap;
+import java.util.Map;
+import java.util.Vector;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.viatra2.framework.IFramework;
+import org.eclipse.viatra2.gtasm.interpreter.exception.ViatraTransformationException;
+import org.eclipse.viatra2.gtasm.interpreter.executionEnvironment.IExecutionEnvironment;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
+import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.VariableID;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.definitions.ASMFunction;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.definitions.Variable;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.terms.Term;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.GTPattern;
+

+public class TermCheckExecutionEnvironment implements IExecutionEnvironment {
+	private IExecutionEnvironment parent;

+    private GTPattern pattern;

+    private int uid;

+    private MatchingFrame frame;

+

+    public TermCheckExecutionEnvironment(IExecutionEnvironment parent, GTPattern pattern, int uid, MatchingFrame frame) {

+        this.parent = parent;

+        this.pattern = pattern;

+        this.uid = uid;

+        this.frame = frame;

+    }

+

+    public Object getVariableValue(Variable variable) {

+        Integer index = frame.getPattern().getIndex(new VariableID(pattern,uid,variable.getName()));

+        return frame.getValue(index);

+    }
+
+	public void addVariable(Variable key, Object value) throws ViatraTransformationException {
+		// Do nothing
+	}
+
+	public void fetchVariableVariations(HashMap<Variable, Vector<Object>> possibleVariableValues, Term termToBeEvaluated) {
+		parent.fetchVariableVariations(possibleVariableValues, termToBeEvaluated);
+	}
+
+	public IFramework getFramework() {
+		return parent.getFramework();
+	}
+
+	public Object getValueOfASMFunction(ASMFunction asmFunction, EList<Object> location) {
+		return parent.getValueOfASMFunction(asmFunction, location);
+	}
+
+	public Map<Variable, Object> getVariableValues() {
+		return parent.getVariableValues();
+	}
+
+	public void setVariableValue(Variable variable, Object value) throws ViatraTransformationException {
+		// Do nothing
+	}
+
+	public void updateASMFunction(ASMFunction asmFunction, EList<Object> location, Object value) throws ViatraTransformationException {
+		parent.updateASMFunction(asmFunction, location, value);
+	}

+}

diff --git a/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/term/TermHandler.java b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/term/TermHandler.java
new file mode 100644
index 0000000..dcd4081
--- /dev/null
+++ b/org.eclipse.viatra2.gtasm.patternmatcher.impl/src/org/eclipse/viatra2/gtasm/patternmatcher/impl/patternmatcher/term/TermHandler.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Akos Horvath, Gergely Varro - initial API and implementation
+ *******************************************************************************/
+
+ package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.term;

+

+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.terms.Term;
+import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.GTPattern;
+

+public abstract class TermHandler implements ITermHandler {

+    /* (non-Javadoc)

+	 * @see org.eclipse.viatra2.gtasm.patternmatcher.term.ITermHandler#getTermEvaluationOperation(org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.GTPattern, int, org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.terms.Term, int)

+	 */

+    abstract public AbstractTermCheckOperation getTermEvaluationOperation(GTPattern pattern, int uid, Term term, int resultSlot);

+    /* (non-Javadoc)

+	 * @see org.eclipse.viatra2.gtasm.patternmatcher.term.ITermHandler#getTermCheckOperation(org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.GTPattern, int, org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.terms.Term)

+	 */

+    abstract public AbstractTermCheckOperation getTermCheckOperation(GTPattern pattern, int uid, Term term);

+}