From 36ca60e5b6bd047a4f444d96241bd60a01bbab17 Mon Sep 17 00:00:00 2001 From: ArenBabikian Date: Mon, 27 Apr 2020 10:45:28 -0400 Subject: rename Pledge Case Studies and add familyTree case study --- .../case.study.familyTree.run/.classpath | 8 + .../case.study.familyTree.run/.project | 40 + .../.settings/org.eclipse.jdt.core.prefs | 7 + .../case.study.familyTree.run/META-INF/MANIFEST.MF | 14 + .../bin/queries/.FamilyTreeConstraints.java._trace | Bin 0 -> 333 bytes .../bin/queries/.MemberIsItsOwnParent.java._trace | Bin 0 -> 3544 bytes .../bin/queries/familyTreeConstraints.vql | 24 + .../case.study.familyTree.run/build.properties | 6 + .../inputs/familytree.ecore | 17 + .../inputs/familytreeGen.vsconfig | 23 + .../outputs/debug/generated3valued.vql_deactivated | 672 +++++++++++++ .../outputs/debug/generation.logicproblem | 190 ++++ .../outputs/debug/init.partialmodel | 51 + .../case.study.familyTree.run/outputs/log.txt | 1 + .../case.study.familyTree.run/outputs/models/1.gml | 1011 ++++++++++++++++++++ .../case.study.familyTree.run/outputs/models/1.png | Bin 0 -> 93940 bytes .../case.study.familyTree.run/outputs/models/1.xmi | 8 + .../case.study.familyTree.run/plugin.xml | 7 + .../queries/.FamilyTreeConstraints.java._trace | Bin 0 -> 333 bytes .../queries/.MemberIsItsOwnParent.java._trace | Bin 0 -> 3544 bytes .../src-gen/queries/FamilyTreeConstraints.java | 53 + .../src-gen/queries/MemberIsItsOwnParent.java | 577 +++++++++++ .../src/queries/familyTreeConstraints.vql | 24 + .../src/run/FamilyTreeGen.java | 13 + 24 files changed, 2746 insertions(+) create mode 100644 Tests/MODELS2020-CaseStudies/case.study.familyTree.run/.classpath create mode 100644 Tests/MODELS2020-CaseStudies/case.study.familyTree.run/.project create mode 100644 Tests/MODELS2020-CaseStudies/case.study.familyTree.run/.settings/org.eclipse.jdt.core.prefs create mode 100644 Tests/MODELS2020-CaseStudies/case.study.familyTree.run/META-INF/MANIFEST.MF create mode 100644 Tests/MODELS2020-CaseStudies/case.study.familyTree.run/bin/queries/.FamilyTreeConstraints.java._trace create mode 100644 Tests/MODELS2020-CaseStudies/case.study.familyTree.run/bin/queries/.MemberIsItsOwnParent.java._trace create mode 100644 Tests/MODELS2020-CaseStudies/case.study.familyTree.run/bin/queries/familyTreeConstraints.vql create mode 100644 Tests/MODELS2020-CaseStudies/case.study.familyTree.run/build.properties create mode 100644 Tests/MODELS2020-CaseStudies/case.study.familyTree.run/inputs/familytree.ecore create mode 100644 Tests/MODELS2020-CaseStudies/case.study.familyTree.run/inputs/familytreeGen.vsconfig create mode 100644 Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/debug/generated3valued.vql_deactivated create mode 100644 Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/debug/generation.logicproblem create mode 100644 Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/debug/init.partialmodel create mode 100644 Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/log.txt create mode 100644 Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/models/1.gml create mode 100644 Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/models/1.png create mode 100644 Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/models/1.xmi create mode 100644 Tests/MODELS2020-CaseStudies/case.study.familyTree.run/plugin.xml create mode 100644 Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src-gen/queries/.FamilyTreeConstraints.java._trace create mode 100644 Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src-gen/queries/.MemberIsItsOwnParent.java._trace create mode 100644 Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src-gen/queries/FamilyTreeConstraints.java create mode 100644 Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src-gen/queries/MemberIsItsOwnParent.java create mode 100644 Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src/queries/familyTreeConstraints.vql create mode 100644 Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src/run/FamilyTreeGen.java (limited to 'Tests/MODELS2020-CaseStudies/case.study.familyTree.run') diff --git a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/.classpath b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/.classpath new file mode 100644 index 00000000..4cc715d5 --- /dev/null +++ b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/.project b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/.project new file mode 100644 index 00000000..98c56323 --- /dev/null +++ b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/.project @@ -0,0 +1,40 @@ + + + case.study.familyTree.run + + + + + + org.eclipse.viatra.query.tooling.ui.projectbuilder + + + + + org.eclipse.xtext.ui.shared.xtextBuilder + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + org.eclipse.viatra.query.projectnature + org.eclipse.xtext.ui.shared.xtextNature + + diff --git a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/.settings/org.eclipse.jdt.core.prefs b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..295926d9 --- /dev/null +++ b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/META-INF/MANIFEST.MF b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/META-INF/MANIFEST.MF new file mode 100644 index 00000000..3f4abc65 --- /dev/null +++ b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/META-INF/MANIFEST.MF @@ -0,0 +1,14 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: case.study.familyTree.run +Bundle-SymbolicName: case.study.familyTree.run;singleton:=true +Bundle-Version: 0.0.1.qualifier +Export-Package: queries +Require-Bundle: org.eclipse.emf.ecore, + org.eclipse.viatra.query.runtime, + org.eclipse.viatra.query.runtime.rete, + org.eclipse.viatra.query.runtime.localsearch, + org.eclipse.xtext.xbase.lib, + case.study.familyTree.model;bundle-version="1.0.0" +Import-Package: hu.bme.mit.inf.dslreasoner.application.execution, + org.apache.log4j diff --git a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/bin/queries/.FamilyTreeConstraints.java._trace b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/bin/queries/.FamilyTreeConstraints.java._trace new file mode 100644 index 00000000..80158bd8 Binary files /dev/null and b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/bin/queries/.FamilyTreeConstraints.java._trace differ diff --git a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/bin/queries/.MemberIsItsOwnParent.java._trace b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/bin/queries/.MemberIsItsOwnParent.java._trace new file mode 100644 index 00000000..1b0dca98 Binary files /dev/null and b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/bin/queries/.MemberIsItsOwnParent.java._trace differ diff --git a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/bin/queries/familyTreeConstraints.vql b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/bin/queries/familyTreeConstraints.vql new file mode 100644 index 00000000..1b9b6659 --- /dev/null +++ b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/bin/queries/familyTreeConstraints.vql @@ -0,0 +1,24 @@ +package queries + +import "http://www.example.org/familytree" + +@Constraint(message="memberIsItsOwnParent", severity="error", key={m}) +pattern memberIsItsOwnParent(m: Member) = { + FamilyTree.members(_, m); + Member.parents(m, p); + m == p; +} + +//@Constraint(message="parentTooYoung", severity="error", key={m, p}) +//pattern parentTooYoung(m: Member, p: Member) = { +// FamilyTree.members(_, m); +// Member.parents(m, p); +// Member.age(m, mAge); +// Member.age(p, pAge); +// check (mAge <= (pAge + 12)); +//} + + + + + diff --git a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/build.properties b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/build.properties new file mode 100644 index 00000000..efae4b07 --- /dev/null +++ b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/build.properties @@ -0,0 +1,6 @@ +bin.includes = META-INF/,\ + . +source.. = src/,\ + src-gen/,\ + src-gen/ +output.. = bin/ diff --git a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/inputs/familytree.ecore b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/inputs/familytree.ecore new file mode 100644 index 00000000..f2e51f65 --- /dev/null +++ b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/inputs/familytree.ecore @@ -0,0 +1,17 @@ + + + + + + + + + + + + diff --git a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/inputs/familytreeGen.vsconfig b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/inputs/familytreeGen.vsconfig new file mode 100644 index 00000000..140523bf --- /dev/null +++ b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/inputs/familytreeGen.vsconfig @@ -0,0 +1,23 @@ +import epackage "inputs/familytree.ecore" +import viatra "src/queries/familyTreeConstraints.vql" + +generate { + metamodel = { package familytree } + constraints = { package queries} + solver = ViatraSolver + scope = { + #node = 6, + #int = {1,2,3,4,5} + } + + config = { + runtime = 10000, + log-level = normal + } + + runs = 1 + + debug = "outputs/debug" + log = "outputs/log.txt" + output = "outputs/models" +} \ No newline at end of file diff --git a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/debug/generated3valued.vql_deactivated b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/debug/generated3valued.vql_deactivated new file mode 100644 index 00000000..bbaa6a26 --- /dev/null +++ b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/debug/generated3valued.vql_deactivated @@ -0,0 +1,672 @@ +import epackage "http://www.bme.hu/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage" +import epackage "http://www.bme.hu/mit/inf/dslreasoner/logic/model/problem" +import epackage "http://www.bme.hu/mit/inf/dslreasoner/logic/model/language" + +////////// +// 0. Util +////////// +private pattern interpretation(problem:LogicProblem, interpretation:PartialInterpretation) { + PartialInterpretation.problem(interpretation,problem); +} + +///////////////////////// +// 0.1 Existence +///////////////////////// +/** [[exist(element)]]=1 */ +private pattern mustExist(problem:LogicProblem, interpretation:PartialInterpretation, element:DefinedElement) { + find interpretation(problem,interpretation); + LogicProblem.elements(problem,element); +} or { + find interpretation(problem,interpretation); + PartialInterpretation.newElements(interpretation,element); +} + +/** [[exist(element)]]>=1/2 */ +private pattern mayExist(problem:LogicProblem, interpretation:PartialInterpretation, element:DefinedElement) { + find mustExist(problem,interpretation,element); +} or { + find interpretation(problem,interpretation); + neg find elementCloseWorld(element); + PartialInterpretation.openWorldElements(interpretation,element); +} + +private pattern elementCloseWorld(element:DefinedElement) { + PartialInterpretation.openWorldElements(i,element); + PartialInterpretation.maxNewElements(i,0); +} or { + Scope.targetTypeInterpretation(scope,interpretation); + PartialTypeInterpratation.elements(interpretation,element); + Scope.maxNewElements(scope,0); +} + +//////////////////////// +// 0.2 Equivalence +//////////////////////// +pattern mayEquivalent(problem:LogicProblem, interpretation:PartialInterpretation, a: DefinedElement, b: DefinedElement) +// For non-primitive type. Boolean types always must equivalent or cannot equivalent +{ + find mayExist(problem,interpretation,a); + find mayExist(problem,interpretation,b); + a == b; +} or { + find mayExist(problem,interpretation,a); + find mayExist(problem,interpretation,b); + IntegerElement(a); + IntegerElement(b); + PrimitiveElement.valueSet(a,false); +} or { + find mayExist(problem,interpretation,a); + find mayExist(problem,interpretation,b); + IntegerElement(a); + IntegerElement(b); + PrimitiveElement.valueSet(b,false); +} or { + find mayExist(problem,interpretation,a); + find mayExist(problem,interpretation,b); + RealElement(a); + RealElement(b); + PrimitiveElement.valueSet(a,false); +} or { + find mayExist(problem,interpretation,a); + find mayExist(problem,interpretation,b); + RealElement(a); + RealElement(b); + PrimitiveElement.valueSet(b,false); +} or { + find mayExist(problem,interpretation,a); + find mayExist(problem,interpretation,b); + RealElement(a); + IntegerElement(b); + PrimitiveElement.valueSet(a,false); +} or { + find mayExist(problem,interpretation,a); + find mayExist(problem,interpretation,b); + RealElement(a); + IntegerElement(b); + PrimitiveElement.valueSet(b,false); +} or { + find mayExist(problem,interpretation,a); + find mayExist(problem,interpretation,b); + IntegerElement(a); + RealElement(b); + PrimitiveElement.valueSet(a,false); +} or { + find mayExist(problem,interpretation,a); + find mayExist(problem,interpretation,b); + IntegerElement(a); + RealElement(b); + PrimitiveElement.valueSet(b,false); +} or { + find mayExist(problem,interpretation,a); + find mayExist(problem,interpretation,b); + StringElement(a); + StringElement(b); + PrimitiveElement.valueSet(a,false); +} or { + find mayExist(problem,interpretation,a); + find mayExist(problem,interpretation,b); + StringElement(a); + StringElement(b); + PrimitiveElement.valueSet(b,false); +} + +pattern mustEquivalent(problem:LogicProblem, interpretation:PartialInterpretation, a: DefinedElement, b: DefinedElement) { +// For non-primitive and Boolean primitive type + find mustExist(problem,interpretation,a); + find mustExist(problem,interpretation,b); + a == b; +} or { + find mustExist(problem,interpretation,a); + find mustExist(problem,interpretation,b); + PrimitiveElement.valueSet(a,true); + PrimitiveElement.valueSet(b,true); + IntegerElement.value(a,value); + IntegerElement.value(b,value); +} or { + find mustExist(problem,interpretation,a); + find mustExist(problem,interpretation,b); + PrimitiveElement.valueSet(a,true); + PrimitiveElement.valueSet(b,true); + RealElement.value(a,value); + RealElement.value(b,value); +} or { + find mustExist(problem,interpretation,a); + find mustExist(problem,interpretation,b); + PrimitiveElement.valueSet(a,true); + PrimitiveElement.valueSet(b,true); + RealElement.value(a,value); + IntegerElement.value(b,value); +} or { + find mustExist(problem,interpretation,a); + find mustExist(problem,interpretation,b); + PrimitiveElement.valueSet(a,true); + PrimitiveElement.valueSet(b,true); + IntegerElement.value(a,value); + RealElement.value(b,value); +} or { + find mustExist(problem,interpretation,a); + find mustExist(problem,interpretation,b); + PrimitiveElement.valueSet(a,true); + PrimitiveElement.valueSet(b,true); + StringElement.value(a,value); + StringElement.value(b,value); +} + +////////// +// 1. Problem-Specific Base Indexers +////////// +// 1.1 Type Indexers +////////// +// 1.1.1 Required Patterns by TypeIndexer +////////// +private pattern typeInterpretation(problem:LogicProblem, interpretation:PartialInterpretation, type:TypeDeclaration, typeInterpretation:PartialComplexTypeInterpretation) { + find interpretation(problem,interpretation); + LogicProblem.types(problem,type); + PartialInterpretation.partialtypeinterpratation(interpretation,typeInterpretation); + PartialComplexTypeInterpretation.interpretationOf(typeInterpretation,type); +} + +private pattern directInstanceOf(problem:LogicProblem, interpretation:PartialInterpretation, element:DefinedElement, type:Type) { + find interpretation(problem,interpretation); + LogicProblem.types(problem,type); + TypeDefinition.elements(type,element); +} or { + find interpretation(problem,interpretation); + find typeInterpretation(problem,interpretation,type,typeInterpretation); + PartialComplexTypeInterpretation.elements(typeInterpretation,element); +} + +private pattern isPrimitive(element: PrimitiveElement) { + PrimitiveElement(element); +} +////////// +// 1.1.2 primitive Type Indexers +////////// +// Currently unused. Refer primitive types as: +// > PrimitiveElement(element) +// specific types are referred as: +// > BooleanElement(variableName) +// > IntegerElement(variableName) +// > RealElement(variableName) +// > StringElement(variableName) +// And their value as +// > BooleanElement.value(variableName,value) +// > IntegerElement.value(variableName,value) +// > RealElement.value(variableName,value) +// > StringElement.value(variableName,value) +// Whether a value is set is defined by: +// > PrimitiveElement.valueSet(variableName,isFilled); +////////// +// 1.1.3 domain-specific Type Indexers +////////// +/** + * An element must be an instance of type "FamilyTree class". + */ +private pattern mustInstanceOfFamilyTree_class(problem:LogicProblem, interpretation:PartialInterpretation, element:DefinedElement) { + Type.name(type,"FamilyTree class"); + find directInstanceOf(problem,interpretation,element,type); +} +private pattern scopeDisallowsNewFamilyTree_class(problem:LogicProblem, interpretation:PartialInterpretation) { + find interpretation(problem,interpretation); + PartialInterpretation.scopes(interpretation,scope); + Scope.targetTypeInterpretation(scope,typeInterpretation); + Scope.maxNewElements(scope,0); + PartialComplexTypeInterpretation.interpretationOf(typeInterpretation,type); + Type.name(type,"FamilyTree class"); +} + +/** + * An element may be an instance of type "FamilyTree class". + */ +private pattern mayInstanceOfFamilyTree_class(problem:LogicProblem, interpretation:PartialInterpretation, element:DefinedElement) +{ + find interpretation(problem,interpretation); + PartialInterpretation.newElements(interpretation,element); + neg find mustInstanceOfMember_class(problem,interpretation,element); + neg find scopeDisallowsNewFamilyTree_class(problem, interpretation); + neg find isPrimitive(element); +} or { + find interpretation(problem,interpretation); + PartialInterpretation.openWorldElements(interpretation,element); + neg find mustInstanceOfMember_class(problem,interpretation,element); + neg find scopeDisallowsNewFamilyTree_class(problem, interpretation); + neg find isPrimitive(element); +} or +{ find mustInstanceOfFamilyTree_class(problem,interpretation,element); } +/** + * An element must be an instance of type "Member class". + */ +private pattern mustInstanceOfMember_class(problem:LogicProblem, interpretation:PartialInterpretation, element:DefinedElement) { + Type.name(type,"Member class"); + find directInstanceOf(problem,interpretation,element,type); +} +private pattern scopeDisallowsNewMember_class(problem:LogicProblem, interpretation:PartialInterpretation) { + find interpretation(problem,interpretation); + PartialInterpretation.scopes(interpretation,scope); + Scope.targetTypeInterpretation(scope,typeInterpretation); + Scope.maxNewElements(scope,0); + PartialComplexTypeInterpretation.interpretationOf(typeInterpretation,type); + Type.name(type,"Member class"); +} + +/** + * An element may be an instance of type "Member class". + */ +private pattern mayInstanceOfMember_class(problem:LogicProblem, interpretation:PartialInterpretation, element:DefinedElement) +{ + find interpretation(problem,interpretation); + PartialInterpretation.newElements(interpretation,element); + neg find mustInstanceOfFamilyTree_class(problem,interpretation,element); + neg find scopeDisallowsNewMember_class(problem, interpretation); + neg find isPrimitive(element); +} or { + find interpretation(problem,interpretation); + PartialInterpretation.openWorldElements(interpretation,element); + neg find mustInstanceOfFamilyTree_class(problem,interpretation,element); + neg find scopeDisallowsNewMember_class(problem, interpretation); + neg find isPrimitive(element); +} or +{ find mustInstanceOfMember_class(problem,interpretation,element); } + +////////// +// 1.2 Relation Declaration Indexers +////////// +/** + * Matcher for detecting tuples t where []members reference FamilyTree(source,target) + */ +private pattern mustInRelationmembers_reference_FamilyTree( + problem:LogicProblem, interpretation:PartialInterpretation, + source: DefinedElement, target:DefinedElement) +{ + find interpretation(problem,interpretation); + PartialInterpretation.partialrelationinterpretation(interpretation,relationIterpretation); + PartialRelationInterpretation.interpretationOf.name(relationIterpretation,"members reference FamilyTree"); + PartialRelationInterpretation.relationlinks(relationIterpretation,link); + BinaryElementRelationLink.param1(link,source); + BinaryElementRelationLink.param2(link,target); +} +/** + * Matcher for detecting tuples t where <>members reference FamilyTree(source,target) + */ +private pattern mayInRelationmembers_reference_FamilyTree( + problem:LogicProblem, interpretation:PartialInterpretation, + source: DefinedElement, target:DefinedElement) +{ + find interpretation(problem,interpretation); + // The two endpoint of the link have to exist + find mayExist(problem, interpretation, source); + find mayExist(problem, interpretation, target); + // Type consistency + find mayInstanceOfFamilyTree_class(problem,interpretation,source); + find mayInstanceOfMember_class(problem,interpretation,target); + // The reference is containment, then a new reference cannot be create if: + // 1. Multiple parents + neg find mustContains4(problem,interpretation,_,target); + // 2. Circle in the containment hierarchy + neg find mustTransitiveContains(source,target); +} or { + find mustInRelationmembers_reference_FamilyTree(problem,interpretation,source,target); +} +/** + * Matcher for detecting tuples t where []children reference Member(source,target) + */ +private pattern mustInRelationchildren_reference_Member( + problem:LogicProblem, interpretation:PartialInterpretation, + source: DefinedElement, target:DefinedElement) +{ + find interpretation(problem,interpretation); + PartialInterpretation.partialrelationinterpretation(interpretation,relationIterpretation); + PartialRelationInterpretation.interpretationOf.name(relationIterpretation,"children reference Member"); + PartialRelationInterpretation.relationlinks(relationIterpretation,link); + BinaryElementRelationLink.param1(link,source); + BinaryElementRelationLink.param2(link,target); +} +/** + * Matcher for detecting tuples t where <>children reference Member(source,target) + */ +private pattern mayInRelationchildren_reference_Member( + problem:LogicProblem, interpretation:PartialInterpretation, + source: DefinedElement, target:DefinedElement) +{ + find interpretation(problem,interpretation); + // The two endpoint of the link have to exist + find mayExist(problem, interpretation, source); + find mayExist(problem, interpretation, target); + // Type consistency + find mayInstanceOfMember_class(problem,interpretation,source); + find mayInstanceOfMember_class(problem,interpretation,target); + // There are "numberOfExistingReferences" currently existing instances of the reference to the target, + // the upper bound of the opposite reference multiplicity should be considered. + numberOfExistingOppositeReferences == count find mustInRelationparents_reference_Member(problem,interpretation,target,_); + check(numberOfExistingOppositeReferences < 2); +} or { + find mustInRelationchildren_reference_Member(problem,interpretation,source,target); +} +/** + * Matcher for detecting tuples t where []parents reference Member(source,target) + */ +private pattern mustInRelationparents_reference_Member( + problem:LogicProblem, interpretation:PartialInterpretation, + source: DefinedElement, target:DefinedElement) +{ + find interpretation(problem,interpretation); + PartialInterpretation.partialrelationinterpretation(interpretation,relationIterpretation); + PartialRelationInterpretation.interpretationOf.name(relationIterpretation,"parents reference Member"); + PartialRelationInterpretation.relationlinks(relationIterpretation,link); + BinaryElementRelationLink.param1(link,source); + BinaryElementRelationLink.param2(link,target); +} +/** + * Matcher for detecting tuples t where <>parents reference Member(source,target) + */ +private pattern mayInRelationparents_reference_Member( + problem:LogicProblem, interpretation:PartialInterpretation, + source: DefinedElement, target:DefinedElement) +{ + find interpretation(problem,interpretation); + // The two endpoint of the link have to exist + find mayExist(problem, interpretation, source); + find mayExist(problem, interpretation, target); + // Type consistency + find mayInstanceOfMember_class(problem,interpretation,source); + find mayInstanceOfMember_class(problem,interpretation,target); + // There are "numberOfExistingReferences" currently existing instances of the reference from the source, + // the upper bound of the multiplicity should be considered. + numberOfExistingReferences == count find mustInRelationparents_reference_Member(problem,interpretation,source,_); + check(numberOfExistingReferences < 2); +} or { + find mustInRelationparents_reference_Member(problem,interpretation,source,target); +} +/** + * Matcher for detecting tuples t where []name attribute Member(source,target) + */ +private pattern mustInRelationname_attribute_Member( + problem:LogicProblem, interpretation:PartialInterpretation, + source: DefinedElement, target:DefinedElement) +{ + find interpretation(problem,interpretation); + PartialInterpretation.partialrelationinterpretation(interpretation,relationIterpretation); + PartialRelationInterpretation.interpretationOf.name(relationIterpretation,"name attribute Member"); + PartialRelationInterpretation.relationlinks(relationIterpretation,link); + BinaryElementRelationLink.param1(link,source); + BinaryElementRelationLink.param2(link,target); +} +/** + * Matcher for detecting tuples t where <>name attribute Member(source,target) + */ +private pattern mayInRelationname_attribute_Member( + problem:LogicProblem, interpretation:PartialInterpretation, + source: DefinedElement, target:DefinedElement) +{ + find interpretation(problem,interpretation); + // The two endpoint of the link have to exist + find mayExist(problem, interpretation, source); + find mayExist(problem, interpretation, target); + // Type consistency + find mayInstanceOfMember_class(problem,interpretation,source); + StringElement(target); + // There are "numberOfExistingReferences" currently existing instances of the reference from the source, + // the upper bound of the multiplicity should be considered. + numberOfExistingReferences == count find mustInRelationname_attribute_Member(problem,interpretation,source,_); + check(numberOfExistingReferences < 1); +} or { + find mustInRelationname_attribute_Member(problem,interpretation,source,target); +} +/** + * Matcher for detecting tuples t where []age attribute Member(source,target) + */ +private pattern mustInRelationage_attribute_Member( + problem:LogicProblem, interpretation:PartialInterpretation, + source: DefinedElement, target:DefinedElement) +{ + find interpretation(problem,interpretation); + PartialInterpretation.partialrelationinterpretation(interpretation,relationIterpretation); + PartialRelationInterpretation.interpretationOf.name(relationIterpretation,"age attribute Member"); + PartialRelationInterpretation.relationlinks(relationIterpretation,link); + BinaryElementRelationLink.param1(link,source); + BinaryElementRelationLink.param2(link,target); +} +/** + * Matcher for detecting tuples t where <>age attribute Member(source,target) + */ +private pattern mayInRelationage_attribute_Member( + problem:LogicProblem, interpretation:PartialInterpretation, + source: DefinedElement, target:DefinedElement) +{ + find interpretation(problem,interpretation); + // The two endpoint of the link have to exist + find mayExist(problem, interpretation, source); + find mayExist(problem, interpretation, target); + // Type consistency + find mayInstanceOfMember_class(problem,interpretation,source); + IntegerElement(target); + // There are "numberOfExistingReferences" currently existing instances of the reference from the source, + // the upper bound of the multiplicity should be considered. + numberOfExistingReferences == count find mustInRelationage_attribute_Member(problem,interpretation,source,_); + check(numberOfExistingReferences < 1); +} or { + find mustInRelationage_attribute_Member(problem,interpretation,source,target); +} + +////////// +// 1.3 Relation Definition Indexers +////////// +// Must, May and Current queries for pattern queries memberIsItsOwnParent +private pattern mustInRelation_pattern_queries_memberIsItsOwnParent( + problem:LogicProblem, interpretation:PartialInterpretation, + var_m) +{ + find interpretation(problem,interpretation); + find mustInstanceOfMember_class(problem,interpretation,var_m); + // m is exported + find mustInstanceOfFamilyTree_class(problem,interpretation,var__0); + find mustInRelationmembers_reference_FamilyTree(problem,interpretation,var__0,var_virtual0); + find mustInstanceOfMember_class(problem,interpretation,var_virtual0); + find mustEquivalent(problem, interpretation, var_virtual0, var_m); + find mustInstanceOfMember_class(problem,interpretation,var_m); + find mustInRelationparents_reference_Member(problem,interpretation,var_m,var_virtual1); + find mustInstanceOfMember_class(problem,interpretation,var_virtual1); + find mustEquivalent(problem, interpretation, var_virtual1, var_p); + find mustEquivalent(problem, interpretation, var_m, var_p); +} +private pattern mayInRelation_pattern_queries_memberIsItsOwnParent( + problem:LogicProblem, interpretation:PartialInterpretation, + var_m) +{ + find interpretation(problem,interpretation); + find mayInstanceOfMember_class(problem,interpretation,var_m); + // m is exported + find mayInstanceOfFamilyTree_class(problem,interpretation,var__0); + find mayInRelationmembers_reference_FamilyTree(problem,interpretation,var__0,var_virtual0); + find mayInstanceOfMember_class(problem,interpretation,var_virtual0); + find mayEquivalent(problem, interpretation, var_virtual0, var_m); + find mayInstanceOfMember_class(problem,interpretation,var_m); + find mayInRelationparents_reference_Member(problem,interpretation,var_m,var_virtual1); + find mayInstanceOfMember_class(problem,interpretation,var_virtual1); + find mayEquivalent(problem, interpretation, var_virtual1, var_p); + find mayEquivalent(problem, interpretation, var_m, var_p); +} +private pattern currentInRelation_pattern_queries_memberIsItsOwnParent( + problem:LogicProblem, interpretation:PartialInterpretation, + var_m) +{ + find interpretation(problem,interpretation); + find mustInstanceOfMember_class(problem,interpretation,var_m); + // m is exported + find mustInstanceOfFamilyTree_class(problem,interpretation,var__0); + find mustInRelationmembers_reference_FamilyTree(problem,interpretation,var__0,var_virtual0); + find mustInstanceOfMember_class(problem,interpretation,var_virtual0); + find mustEquivalent(problem, interpretation, var_virtual0, var_m); + find mustInstanceOfMember_class(problem,interpretation,var_m); + find mustInRelationparents_reference_Member(problem,interpretation,var_m,var_virtual1); + find mustInstanceOfMember_class(problem,interpretation,var_virtual1); + find mustEquivalent(problem, interpretation, var_virtual1, var_p); + find mustEquivalent(problem, interpretation, var_m, var_p); +} + +////////// +// 1.4 Containment Indexer +////////// +private pattern mustContains2(source: DefinedElement, target: DefinedElement) { + find mustContains4(_,_,source,target); +} + +private pattern mustContains4(problem:LogicProblem, interpretation:PartialInterpretation, + source: DefinedElement, target: DefinedElement) + { find mustInRelationmembers_reference_FamilyTree(problem,interpretation,source,target); } + +private pattern mustTransitiveContains(source,target) { + find mustContains2+(source,target); +} + +////////// +// 2. Invalidation Indexers +////////// +// 2.1 Invalidated by WF Queries +////////// +pattern invalidatedBy_pattern_queries_memberIsItsOwnParent(problem:LogicProblem, interpretation:PartialInterpretation, + var_m) +{ + find mustInRelation_pattern_queries_memberIsItsOwnParent(problem,interpretation,var_m); +} + +////////// +// 3. Unfinishedness Indexers +////////// +// 3.1 Unfinishedness Measured by Multiplicity +////////// + +////////// +// 3.2 Unfinishedness Measured by WF Queries +////////// +pattern unfinishedBy_pattern_queries_memberIsItsOwnParent(problem:LogicProblem, interpretation:PartialInterpretation, + var_m) +{ + find currentInRelation_pattern_queries_memberIsItsOwnParent(problem,interpretation,var_m); +} + +////////// +// 4. Refinement Indexers +////////// +// 4.1 Object constructors +////////// +private pattern hasElementInContainment(problem:LogicProblem, interpretation:PartialInterpretation) +{ + find interpretation(problem,interpretation); + find mustInstanceOfFamilyTree_class(problem,interpretation,root); + find mustExist(problem, interpretation, root); +}or{ + find interpretation(problem,interpretation); + find mustInstanceOfMember_class(problem,interpretation,root); + find mustExist(problem, interpretation, root); +} +pattern createObject_FamilyTree_class( + problem:LogicProblem, interpretation:PartialInterpretation, + typeInterpretation:PartialComplexTypeInterpretation) +{ + find interpretation(problem,interpretation); + neg find hasElementInContainment(problem,interpretation); + PartialInterpretation.partialtypeinterpratation(interpretation,typeInterpretation); + PartialComplexTypeInterpretation.interpretationOf.name(typeInterpretation,"FamilyTree class"); + find mayInstanceOfFamilyTree_class(problem,interpretation,newObject); + find mayExist(problem, interpretation, newObject); + neg find mustExist(problem, interpretation, newObject); +} +pattern createObject_Member_class_by_members_reference_FamilyTree( + problem:LogicProblem, interpretation:PartialInterpretation, + relationInterpretation:PartialRelationInterpretation, typeInterpretation:PartialComplexTypeInterpretation, + container:DefinedElement) +{ + find interpretation(problem,interpretation); + PartialInterpretation.partialtypeinterpratation(interpretation,typeInterpretation); + PartialComplexTypeInterpretation.interpretationOf.name(typeInterpretation,"Member class"); + PartialInterpretation.partialrelationinterpretation(interpretation,relationInterpretation); + PartialRelationInterpretation.interpretationOf.name(relationInterpretation,"members reference FamilyTree"); + find mustInstanceOfFamilyTree_class(problem,interpretation,container); + find mayInstanceOfMember_class(problem,interpretation,newObject); + find mayInRelationmembers_reference_FamilyTree(problem,interpretation,container,newObject); + find mustExist(problem, interpretation, container); + neg find mustExist(problem, interpretation, newObject); +} +pattern createObject_Member_class( + problem:LogicProblem, interpretation:PartialInterpretation, + typeInterpretation:PartialComplexTypeInterpretation) +{ + find interpretation(problem,interpretation); + neg find hasElementInContainment(problem,interpretation); + PartialInterpretation.partialtypeinterpratation(interpretation,typeInterpretation); + PartialComplexTypeInterpretation.interpretationOf.name(typeInterpretation,"Member class"); + find mayInstanceOfMember_class(problem,interpretation,newObject); + find mayExist(problem, interpretation, newObject); + neg find mustExist(problem, interpretation, newObject); +} + +////////// +// 4.2 Type refinement +////////// +pattern refineTypeTo_FamilyTree_class(problem:LogicProblem, interpretation:PartialInterpretation, element: DefinedElement) { + find interpretation(problem,interpretation); + PartialInterpretation.newElements(interpretation,element); + find mayInstanceOfFamilyTree_class(problem,interpretation,element); + neg find mustInstanceOfFamilyTree_class(problem,interpretation,element); + neg find mustInstanceOfMember_class(problem,interpretation,element); +} +pattern refineTypeTo_Member_class(problem:LogicProblem, interpretation:PartialInterpretation, element: DefinedElement) { + find interpretation(problem,interpretation); + PartialInterpretation.newElements(interpretation,element); + find mayInstanceOfMember_class(problem,interpretation,element); + neg find mustInstanceOfFamilyTree_class(problem,interpretation,element); + neg find mustInstanceOfMember_class(problem,interpretation,element); +} + +////////// +// 4.3 Relation refinement +////////// +pattern refineRelation_children_reference_Member_and_parents_reference_Member( + problem:LogicProblem, interpretation:PartialInterpretation, + relationIterpretation:PartialRelationInterpretation, oppositeInterpretation:PartialRelationInterpretation, + from: DefinedElement, to: DefinedElement) +{ + find interpretation(problem,interpretation); + PartialInterpretation.partialrelationinterpretation(interpretation,relationIterpretation); + PartialRelationInterpretation.interpretationOf.name(relationIterpretation,"children reference Member"); + PartialInterpretation.partialrelationinterpretation(interpretation,oppositeInterpretation); + PartialRelationInterpretation.interpretationOf.name(oppositeInterpretation,"parents reference Member"); + find mustExist(problem, interpretation, from); + find mustExist(problem, interpretation, to); + find mustInstanceOfMember_class(problem,interpretation,from); + find mustInstanceOfMember_class(problem,interpretation,to); + find mayInRelationchildren_reference_Member(problem,interpretation,from,to); + neg find mustInRelationchildren_reference_Member(problem,interpretation,from,to); +} +pattern refineRelation_name_attribute_Member( + problem:LogicProblem, interpretation:PartialInterpretation, + relationIterpretation:PartialRelationInterpretation, + from: DefinedElement, to: DefinedElement) +{ + find interpretation(problem,interpretation); + PartialInterpretation.partialrelationinterpretation(interpretation,relationIterpretation); + PartialRelationInterpretation.interpretationOf.name(relationIterpretation,"name attribute Member"); + find mustExist(problem, interpretation, from); + find mustExist(problem, interpretation, to); + find mustInstanceOfMember_class(problem,interpretation,from); + StringElement(to); + find mayInRelationname_attribute_Member(problem,interpretation,from,to); + neg find mustInRelationname_attribute_Member(problem,interpretation,from,to); +} +pattern refineRelation_age_attribute_Member( + problem:LogicProblem, interpretation:PartialInterpretation, + relationIterpretation:PartialRelationInterpretation, + from: DefinedElement, to: DefinedElement) +{ + find interpretation(problem,interpretation); + PartialInterpretation.partialrelationinterpretation(interpretation,relationIterpretation); + PartialRelationInterpretation.interpretationOf.name(relationIterpretation,"age attribute Member"); + find mustExist(problem, interpretation, from); + find mustExist(problem, interpretation, to); + find mustInstanceOfMember_class(problem,interpretation,from); + IntegerElement(to); + find mayInRelationage_attribute_Member(problem,interpretation,from,to); + neg find mustInRelationage_attribute_Member(problem,interpretation,from,to); +} + diff --git a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/debug/generation.logicproblem b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/debug/generation.logicproblem new file mode 100644 index 00000000..dd3b15b1 --- /dev/null +++ b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/debug/generation.logicproblem @@ -0,0 +1,190 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/debug/init.partialmodel b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/debug/init.partialmodel new file mode 100644 index 00000000..949d6b64 --- /dev/null +++ b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/debug/init.partialmodel @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/log.txt b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/log.txt new file mode 100644 index 00000000..6186ec60 --- /dev/null +++ b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/log.txt @@ -0,0 +1 @@ +Model generation finished diff --git a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/models/1.gml b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/models/1.gml new file mode 100644 index 00000000..0182add9 --- /dev/null +++ b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/models/1.gml @@ -0,0 +1,1011 @@ +graph +[ + node + [ + id 0 + graphics + [ + w 41.800000000000004 + h 26 + type "rectangle" + fill "#FFFFFF" + fill2 "#FFFFFF" + outline "#000000" + ] + LabelGraphics + [ + text "true" + outline "#000000" + fill "#FFFFFF" + fontSize 16 + fontName "Monospace" + autoSizePolicy "node_width" + anchor "t" + borderDistance 0.0 + ] + LabelGraphics + [ + text " + " + fontSize 14 + fontName "Consolas" + alignment "left" + anchor "tl" + borderDistance 6 + ] + ] + + node + [ + id 1 + graphics + [ + w 50.6 + h 26 + type "rectangle" + fill "#FFFFFF" + fill2 "#FFFFFF" + outline "#000000" + ] + LabelGraphics + [ + text "false" + outline "#000000" + fill "#FFFFFF" + fontSize 16 + fontName "Monospace" + autoSizePolicy "node_width" + anchor "t" + borderDistance 0.0 + ] + LabelGraphics + [ + text " + " + fontSize 14 + fontName "Consolas" + alignment "left" + anchor "tl" + borderDistance 6 + ] + ] + + node + [ + id 2 + graphics + [ + w 15.400000000000002 + h 26 + type "rectangle" + fill "#FFFFFF" + fill2 "#FFFFFF" + outline "#000000" + ] + LabelGraphics + [ + text "1" + outline "#000000" + fill "#FFFFFF" + fontSize 16 + fontName "Monospace" + autoSizePolicy "node_width" + anchor "t" + borderDistance 0.0 + ] + LabelGraphics + [ + text " + " + fontSize 14 + fontName "Consolas" + alignment "left" + anchor "tl" + borderDistance 6 + ] + ] + + node + [ + id 3 + graphics + [ + w 15.400000000000002 + h 26 + type "rectangle" + fill "#FFFFFF" + fill2 "#FFFFFF" + outline "#000000" + ] + LabelGraphics + [ + text "2" + outline "#000000" + fill "#FFFFFF" + fontSize 16 + fontName "Monospace" + autoSizePolicy "node_width" + anchor "t" + borderDistance 0.0 + ] + LabelGraphics + [ + text " + " + fontSize 14 + fontName "Consolas" + alignment "left" + anchor "tl" + borderDistance 6 + ] + ] + + node + [ + id 4 + graphics + [ + w 15.400000000000002 + h 26 + type "rectangle" + fill "#FFFFFF" + fill2 "#FFFFFF" + outline "#000000" + ] + LabelGraphics + [ + text "3" + outline "#000000" + fill "#FFFFFF" + fontSize 16 + fontName "Monospace" + autoSizePolicy "node_width" + anchor "t" + borderDistance 0.0 + ] + LabelGraphics + [ + text " + " + fontSize 14 + fontName "Consolas" + alignment "left" + anchor "tl" + borderDistance 6 + ] + ] + + node + [ + id 5 + graphics + [ + w 15.400000000000002 + h 26 + type "rectangle" + fill "#FFFFFF" + fill2 "#FFFFFF" + outline "#000000" + ] + LabelGraphics + [ + text "4" + outline "#000000" + fill "#FFFFFF" + fontSize 16 + fontName "Monospace" + autoSizePolicy "node_width" + anchor "t" + borderDistance 0.0 + ] + LabelGraphics + [ + text " + " + fontSize 14 + fontName "Consolas" + alignment "left" + anchor "tl" + borderDistance 6 + ] + ] + + node + [ + id 6 + graphics + [ + w 15.400000000000002 + h 26 + type "rectangle" + fill "#FFFFFF" + fill2 "#FFFFFF" + outline "#000000" + ] + LabelGraphics + [ + text "5" + outline "#000000" + fill "#FFFFFF" + fontSize 16 + fontName "Monospace" + autoSizePolicy "node_width" + anchor "t" + borderDistance 0.0 + ] + LabelGraphics + [ + text " + " + fontSize 14 + fontName "Consolas" + alignment "left" + anchor "tl" + borderDistance 6 + ] + ] + + node + [ + id 7 + graphics + [ + w 138.60000000000002 + h 40 + type "rectangle" + fill "#FFFFFF" + fill2 "#FFFFFF" + outline "#000000" + ] + LabelGraphics + [ + text "null" + outline "#000000" + fill "#FFFFFF" + fontSize 16 + fontName "Monospace" + autoSizePolicy "node_width" + anchor "t" + borderDistance 0.0 + ] + LabelGraphics + [ + text " + FamilyTree class + " + fontSize 14 + fontName "Consolas" + alignment "left" + anchor "tl" + borderDistance 6 + ] + ] + + node + [ + id 8 + graphics + [ + w 107.80000000000001 + h 40 + type "rectangle" + fill "#FFFFFF" + fill2 "#FFFFFF" + outline "#000000" + ] + LabelGraphics + [ + text "null" + outline "#000000" + fill "#FFFFFF" + fontSize 16 + fontName "Monospace" + autoSizePolicy "node_width" + anchor "t" + borderDistance 0.0 + ] + LabelGraphics + [ + text " + Member class + " + fontSize 14 + fontName "Consolas" + alignment "left" + anchor "tl" + borderDistance 6 + ] + ] + + node + [ + id 9 + graphics + [ + w 107.80000000000001 + h 40 + type "rectangle" + fill "#FFFFFF" + fill2 "#FFFFFF" + outline "#000000" + ] + LabelGraphics + [ + text "null" + outline "#000000" + fill "#FFFFFF" + fontSize 16 + fontName "Monospace" + autoSizePolicy "node_width" + anchor "t" + borderDistance 0.0 + ] + LabelGraphics + [ + text " + Member class + " + fontSize 14 + fontName "Consolas" + alignment "left" + anchor "tl" + borderDistance 6 + ] + ] + + node + [ + id 10 + graphics + [ + w 107.80000000000001 + h 40 + type "rectangle" + fill "#FFFFFF" + fill2 "#FFFFFF" + outline "#000000" + ] + LabelGraphics + [ + text "null" + outline "#000000" + fill "#FFFFFF" + fontSize 16 + fontName "Monospace" + autoSizePolicy "node_width" + anchor "t" + borderDistance 0.0 + ] + LabelGraphics + [ + text " + Member class + " + fontSize 14 + fontName "Consolas" + alignment "left" + anchor "tl" + borderDistance 6 + ] + ] + + node + [ + id 11 + graphics + [ + w 107.80000000000001 + h 40 + type "rectangle" + fill "#FFFFFF" + fill2 "#FFFFFF" + outline "#000000" + ] + LabelGraphics + [ + text "null" + outline "#000000" + fill "#FFFFFF" + fontSize 16 + fontName "Monospace" + autoSizePolicy "node_width" + anchor "t" + borderDistance 0.0 + ] + LabelGraphics + [ + text " + Member class + " + fontSize 14 + fontName "Consolas" + alignment "left" + anchor "tl" + borderDistance 6 + ] + ] + + node + [ + id 12 + graphics + [ + w 107.80000000000001 + h 40 + type "rectangle" + fill "#FFFFFF" + fill2 "#FFFFFF" + outline "#000000" + ] + LabelGraphics + [ + text "null" + outline "#000000" + fill "#FFFFFF" + fontSize 16 + fontName "Monospace" + autoSizePolicy "node_width" + anchor "t" + borderDistance 0.0 + ] + LabelGraphics + [ + text " + Member class + " + fontSize 14 + fontName "Consolas" + alignment "left" + anchor "tl" + borderDistance 6 + ] + ] + + node + [ + id 13 + graphics + [ + w 85.80000000000001 + h 26 + type "rectangle" + fill "#FFFFFF" + fill2 "#FFFFFF" + outline "#000000" + ] + LabelGraphics + [ + text "New Reals" + outline "#000000" + fill "#FFFFFF" + fontSize 16 + fontName "Monospace" + autoSizePolicy "node_width" + anchor "t" + borderDistance 0.0 + ] + LabelGraphics + [ + text " + " + fontSize 14 + fontName "Consolas" + alignment "left" + anchor "tl" + borderDistance 6 + ] + ] + + node + [ + id 14 + graphics + [ + w 103.4 + h 26 + type "rectangle" + fill "#FFFFFF" + fill2 "#FFFFFF" + outline "#000000" + ] + LabelGraphics + [ + text "New Strings" + outline "#000000" + fill "#FFFFFF" + fontSize 16 + fontName "Monospace" + autoSizePolicy "node_width" + anchor "t" + borderDistance 0.0 + ] + LabelGraphics + [ + text " + " + fontSize 14 + fontName "Consolas" + alignment "left" + anchor "tl" + borderDistance 6 + ] + ] + + node + [ + id 15 + graphics + [ + w 103.4 + h 26 + type "rectangle" + fill "#FFFFFF" + fill2 "#FFFFFF" + outline "#000000" + ] + LabelGraphics + [ + text "New Objects" + outline "#000000" + fill "#FFFFFF" + fontSize 16 + fontName "Monospace" + autoSizePolicy "node_width" + anchor "t" + borderDistance 0.0 + ] + LabelGraphics + [ + text " + " + fontSize 14 + fontName "Consolas" + alignment "left" + anchor "tl" + borderDistance 6 + ] + ] + edge + [ + source 7 + target 8 + graphics + [ + fill "#000000" + width 3 + targetArrow "standard" + ] + LabelGraphics + [ + text "members reference FamilyTree" + fontSize 14 + fontName "Consolas" + configuration "AutoFlippingLabel" + model "six_pos" + position "thead" + ] + ] + edge + [ + source 7 + target 9 + graphics + [ + fill "#000000" + width 3 + targetArrow "standard" + ] + LabelGraphics + [ + text "members reference FamilyTree" + fontSize 14 + fontName "Consolas" + configuration "AutoFlippingLabel" + model "six_pos" + position "thead" + ] + ] + edge + [ + source 7 + target 10 + graphics + [ + fill "#000000" + width 3 + targetArrow "standard" + ] + LabelGraphics + [ + text "members reference FamilyTree" + fontSize 14 + fontName "Consolas" + configuration "AutoFlippingLabel" + model "six_pos" + position "thead" + ] + ] + edge + [ + source 7 + target 11 + graphics + [ + fill "#000000" + width 3 + targetArrow "standard" + ] + LabelGraphics + [ + text "members reference FamilyTree" + fontSize 14 + fontName "Consolas" + configuration "AutoFlippingLabel" + model "six_pos" + position "thead" + ] + ] + edge + [ + source 7 + target 12 + graphics + [ + fill "#000000" + width 3 + targetArrow "standard" + ] + LabelGraphics + [ + text "members reference FamilyTree" + fontSize 14 + fontName "Consolas" + configuration "AutoFlippingLabel" + model "six_pos" + position "thead" + ] + ] + edge + [ + source 9 + target 8 + graphics + [ + fill "#000000" + targetArrow "standard" + ] + LabelGraphics + [ + text "children reference Member" + fontSize 14 + fontName "Consolas" + configuration "AutoFlippingLabel" + model "six_pos" + position "thead" + ] + ] + edge + [ + source 8 + target 9 + graphics + [ + fill "#000000" + targetArrow "standard" + ] + LabelGraphics + [ + text "children reference Member" + fontSize 14 + fontName "Consolas" + configuration "AutoFlippingLabel" + model "six_pos" + position "thead" + ] + ] + edge + [ + source 10 + target 11 + graphics + [ + fill "#000000" + targetArrow "standard" + ] + LabelGraphics + [ + text "children reference Member" + fontSize 14 + fontName "Consolas" + configuration "AutoFlippingLabel" + model "six_pos" + position "thead" + ] + ] + edge + [ + source 8 + target 10 + graphics + [ + fill "#000000" + targetArrow "standard" + ] + LabelGraphics + [ + text "children reference Member" + fontSize 14 + fontName "Consolas" + configuration "AutoFlippingLabel" + model "six_pos" + position "thead" + ] + ] + edge + [ + source 11 + target 9 + graphics + [ + fill "#000000" + targetArrow "standard" + ] + LabelGraphics + [ + text "children reference Member" + fontSize 14 + fontName "Consolas" + configuration "AutoFlippingLabel" + model "six_pos" + position "thead" + ] + ] + edge + [ + source 11 + target 10 + graphics + [ + fill "#000000" + targetArrow "standard" + ] + LabelGraphics + [ + text "children reference Member" + fontSize 14 + fontName "Consolas" + configuration "AutoFlippingLabel" + model "six_pos" + position "thead" + ] + ] + edge + [ + source 10 + target 8 + graphics + [ + fill "#000000" + targetArrow "standard" + ] + LabelGraphics + [ + text "children reference Member" + fontSize 14 + fontName "Consolas" + configuration "AutoFlippingLabel" + model "six_pos" + position "thead" + ] + ] + edge + [ + source 8 + target 9 + graphics + [ + fill "#000000" + targetArrow "standard" + ] + LabelGraphics + [ + text "parents reference Member" + fontSize 14 + fontName "Consolas" + configuration "AutoFlippingLabel" + model "six_pos" + position "thead" + ] + ] + edge + [ + source 9 + target 8 + graphics + [ + fill "#000000" + targetArrow "standard" + ] + LabelGraphics + [ + text "parents reference Member" + fontSize 14 + fontName "Consolas" + configuration "AutoFlippingLabel" + model "six_pos" + position "thead" + ] + ] + edge + [ + source 11 + target 10 + graphics + [ + fill "#000000" + targetArrow "standard" + ] + LabelGraphics + [ + text "parents reference Member" + fontSize 14 + fontName "Consolas" + configuration "AutoFlippingLabel" + model "six_pos" + position "thead" + ] + ] + edge + [ + source 10 + target 8 + graphics + [ + fill "#000000" + targetArrow "standard" + ] + LabelGraphics + [ + text "parents reference Member" + fontSize 14 + fontName "Consolas" + configuration "AutoFlippingLabel" + model "six_pos" + position "thead" + ] + ] + edge + [ + source 9 + target 11 + graphics + [ + fill "#000000" + targetArrow "standard" + ] + LabelGraphics + [ + text "parents reference Member" + fontSize 14 + fontName "Consolas" + configuration "AutoFlippingLabel" + model "six_pos" + position "thead" + ] + ] + edge + [ + source 10 + target 11 + graphics + [ + fill "#000000" + targetArrow "standard" + ] + LabelGraphics + [ + text "parents reference Member" + fontSize 14 + fontName "Consolas" + configuration "AutoFlippingLabel" + model "six_pos" + position "thead" + ] + ] + edge + [ + source 8 + target 10 + graphics + [ + fill "#000000" + targetArrow "standard" + ] + LabelGraphics + [ + text "parents reference Member" + fontSize 14 + fontName "Consolas" + configuration "AutoFlippingLabel" + model "six_pos" + position "thead" + ] + ] + edge + [ + source 8 + target 6 + graphics + [ + fill "#000000" + targetArrow "standard" + ] + LabelGraphics + [ + text "age attribute Member" + fontSize 14 + fontName "Consolas" + configuration "AutoFlippingLabel" + model "six_pos" + position "thead" + ] + ] + edge + [ + source 9 + target 5 + graphics + [ + fill "#000000" + targetArrow "standard" + ] + LabelGraphics + [ + text "age attribute Member" + fontSize 14 + fontName "Consolas" + configuration "AutoFlippingLabel" + model "six_pos" + position "thead" + ] + ] + edge + [ + source 10 + target 2 + graphics + [ + fill "#000000" + targetArrow "standard" + ] + LabelGraphics + [ + text "age attribute Member" + fontSize 14 + fontName "Consolas" + configuration "AutoFlippingLabel" + model "six_pos" + position "thead" + ] + ] + edge + [ + source 11 + target 4 + graphics + [ + fill "#000000" + targetArrow "standard" + ] + LabelGraphics + [ + text "age attribute Member" + fontSize 14 + fontName "Consolas" + configuration "AutoFlippingLabel" + model "six_pos" + position "thead" + ] + ] +] + diff --git a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/models/1.png b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/models/1.png new file mode 100644 index 00000000..391d902b Binary files /dev/null and b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/models/1.png differ diff --git a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/models/1.xmi b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/models/1.xmi new file mode 100644 index 00000000..11e0e7c3 --- /dev/null +++ b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/models/1.xmi @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/plugin.xml b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/plugin.xml new file mode 100644 index 00000000..b32b0215 --- /dev/null +++ b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/plugin.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src-gen/queries/.FamilyTreeConstraints.java._trace b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src-gen/queries/.FamilyTreeConstraints.java._trace new file mode 100644 index 00000000..80158bd8 Binary files /dev/null and b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src-gen/queries/.FamilyTreeConstraints.java._trace differ diff --git a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src-gen/queries/.MemberIsItsOwnParent.java._trace b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src-gen/queries/.MemberIsItsOwnParent.java._trace new file mode 100644 index 00000000..1b0dca98 Binary files /dev/null and b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src-gen/queries/.MemberIsItsOwnParent.java._trace differ diff --git a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src-gen/queries/FamilyTreeConstraints.java b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src-gen/queries/FamilyTreeConstraints.java new file mode 100644 index 00000000..a5c375c6 --- /dev/null +++ b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src-gen/queries/FamilyTreeConstraints.java @@ -0,0 +1,53 @@ +/** + * Generated from platform:/resource/case.study.familyTree.run/src/queries/familyTreeConstraints.vql + */ +package queries; + +import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedPatternGroup; +import queries.MemberIsItsOwnParent; + +/** + * A pattern group formed of all public patterns defined in familyTreeConstraints.vql. + * + *

Use the static instance as any {@link interface org.eclipse.viatra.query.runtime.api.IQueryGroup}, to conveniently prepare + * a VIATRA Query engine for matching all patterns originally defined in file familyTreeConstraints.vql, + * in order to achieve better performance than one-by-one on-demand matcher initialization. + * + *

From package queries, the group contains the definition of the following patterns:

+ * + * @see IQueryGroup + * + */ +@SuppressWarnings("all") +public final class FamilyTreeConstraints extends BaseGeneratedPatternGroup { + /** + * Access the pattern group. + * + * @return the singleton instance of the group + * @throws ViatraQueryRuntimeException if there was an error loading the generated code of pattern specifications + * + */ + public static FamilyTreeConstraints instance() { + if (INSTANCE == null) { + INSTANCE = new FamilyTreeConstraints(); + } + return INSTANCE; + } + + private static FamilyTreeConstraints INSTANCE; + + private FamilyTreeConstraints() { + querySpecifications.add(MemberIsItsOwnParent.instance()); + } + + public MemberIsItsOwnParent getMemberIsItsOwnParent() { + return MemberIsItsOwnParent.instance(); + } + + public MemberIsItsOwnParent.Matcher getMemberIsItsOwnParent(final ViatraQueryEngine engine) { + return MemberIsItsOwnParent.Matcher.on(engine); + } +} diff --git a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src-gen/queries/MemberIsItsOwnParent.java b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src-gen/queries/MemberIsItsOwnParent.java new file mode 100644 index 00000000..67cdafb5 --- /dev/null +++ b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src-gen/queries/MemberIsItsOwnParent.java @@ -0,0 +1,577 @@ +/** + * Generated from platform:/resource/case.study.familyTree.run/src/queries/familyTreeConstraints.vql + */ +package queries; + +import familytree.Member; +import java.util.Arrays; +import java.util.Collection; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.function.Consumer; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.apache.log4j.Logger; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.viatra.query.runtime.api.IPatternMatch; +import org.eclipse.viatra.query.runtime.api.IQuerySpecification; +import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; +import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; +import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; +import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; +import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; +import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; +import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; +import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; +import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; +import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; +import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; +import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; +import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; + +/** + * A pattern-specific query specification that can instantiate Matcher in a type-safe way. + * + *

Original source: + *

+ *         {@literal @}Constraint(message="memberIsItsOwnParent", severity="error", key={m})
+ *         pattern memberIsItsOwnParent(m: Member) = {
+ *         	FamilyTree.members(_, m);
+ *         	Member.parents(m, p);
+ *         	m == p;
+ *         }
+ * 
+ * + * @see Matcher + * @see Match + * + */ +@SuppressWarnings("all") +public final class MemberIsItsOwnParent extends BaseGeneratedEMFQuerySpecification { + /** + * Pattern-specific match representation of the queries.memberIsItsOwnParent pattern, + * to be used in conjunction with {@link Matcher}. + * + *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. + * Each instance is a (possibly partial) substitution of pattern parameters, + * usable to represent a match of the pattern in the result of a query, + * or to specify the bound (fixed) input parameters when issuing a query. + * + * @see Matcher + * + */ + public static abstract class Match extends BasePatternMatch { + private Member fM; + + private static List parameterNames = makeImmutableList("m"); + + private Match(final Member pM) { + this.fM = pM; + } + + @Override + public Object get(final String parameterName) { + switch(parameterName) { + case "m": return this.fM; + default: return null; + } + } + + @Override + public Object get(final int index) { + switch(index) { + case 0: return this.fM; + default: return null; + } + } + + public Member getM() { + return this.fM; + } + + @Override + public boolean set(final String parameterName, final Object newValue) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + if ("m".equals(parameterName) ) { + this.fM = (Member) newValue; + return true; + } + return false; + } + + public void setM(final Member pM) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + this.fM = pM; + } + + @Override + public String patternName() { + return "queries.memberIsItsOwnParent"; + } + + @Override + public List parameterNames() { + return MemberIsItsOwnParent.Match.parameterNames; + } + + @Override + public Object[] toArray() { + return new Object[]{fM}; + } + + @Override + public MemberIsItsOwnParent.Match toImmutable() { + return isMutable() ? newMatch(fM) : this; + } + + @Override + public String prettyPrint() { + StringBuilder result = new StringBuilder(); + result.append("\"m\"=" + prettyPrintValue(fM)); + return result.toString(); + } + + @Override + public int hashCode() { + return Objects.hash(fM); + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null) { + return false; + } + if ((obj instanceof MemberIsItsOwnParent.Match)) { + MemberIsItsOwnParent.Match other = (MemberIsItsOwnParent.Match) obj; + return Objects.equals(fM, other.fM); + } else { + // this should be infrequent + if (!(obj instanceof IPatternMatch)) { + return false; + } + IPatternMatch otherSig = (IPatternMatch) obj; + return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); + } + } + + @Override + public MemberIsItsOwnParent specification() { + return MemberIsItsOwnParent.instance(); + } + + /** + * Returns an empty, mutable match. + * Fields of the mutable match can be filled to create a partial match, usable as matcher input. + * + * @return the empty match. + * + */ + public static MemberIsItsOwnParent.Match newEmptyMatch() { + return new Mutable(null); + } + + /** + * Returns a mutable (partial) match. + * Fields of the mutable match can be filled to create a partial match, usable as matcher input. + * + * @param pM the fixed value of pattern parameter m, or null if not bound. + * @return the new, mutable (partial) match object. + * + */ + public static MemberIsItsOwnParent.Match newMutableMatch(final Member pM) { + return new Mutable(pM); + } + + /** + * Returns a new (partial) match. + * This can be used e.g. to call the matcher with a partial match. + *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. + * @param pM the fixed value of pattern parameter m, or null if not bound. + * @return the (partial) match object. + * + */ + public static MemberIsItsOwnParent.Match newMatch(final Member pM) { + return new Immutable(pM); + } + + private static final class Mutable extends MemberIsItsOwnParent.Match { + Mutable(final Member pM) { + super(pM); + } + + @Override + public boolean isMutable() { + return true; + } + } + + private static final class Immutable extends MemberIsItsOwnParent.Match { + Immutable(final Member pM) { + super(pM); + } + + @Override + public boolean isMutable() { + return false; + } + } + } + + /** + * Generated pattern matcher API of the queries.memberIsItsOwnParent pattern, + * providing pattern-specific query methods. + * + *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, + * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. + * + *

Matches of the pattern will be represented as {@link Match}. + * + *

Original source: + *

+   * {@literal @}Constraint(message="memberIsItsOwnParent", severity="error", key={m})
+   * pattern memberIsItsOwnParent(m: Member) = {
+   * 	FamilyTree.members(_, m);
+   * 	Member.parents(m, p);
+   * 	m == p;
+   * }
+   * 
+ * + * @see Match + * @see MemberIsItsOwnParent + * + */ + public static class Matcher extends BaseMatcher { + /** + * Initializes the pattern matcher within an existing VIATRA Query engine. + * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. + * + * @param engine the existing VIATRA Query engine in which this matcher will be created. + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * + */ + public static MemberIsItsOwnParent.Matcher on(final ViatraQueryEngine engine) { + // check if matcher already exists + Matcher matcher = engine.getExistingMatcher(querySpecification()); + if (matcher == null) { + matcher = (Matcher)engine.getMatcher(querySpecification()); + } + return matcher; + } + + /** + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * @return an initialized matcher + * @noreference This method is for internal matcher initialization by the framework, do not call it manually. + * + */ + public static MemberIsItsOwnParent.Matcher create() { + return new Matcher(); + } + + private static final int POSITION_M = 0; + + private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(MemberIsItsOwnParent.Matcher.class); + + /** + * Initializes the pattern matcher within an existing VIATRA Query engine. + * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. + * + * @param engine the existing VIATRA Query engine in which this matcher will be created. + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * + */ + private Matcher() { + super(querySpecification()); + } + + /** + * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. + * @param pM the fixed value of pattern parameter m, or null if not bound. + * @return matches represented as a Match object. + * + */ + public Collection getAllMatches(final Member pM) { + return rawStreamAllMatches(new Object[]{pM}).collect(Collectors.toSet()); + } + + /** + * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * @param pM the fixed value of pattern parameter m, or null if not bound. + * @return a stream of matches represented as a Match object. + * + */ + public Stream streamAllMatches(final Member pM) { + return rawStreamAllMatches(new Object[]{pM}); + } + + /** + * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. + * Neither determinism nor randomness of selection is guaranteed. + * @param pM the fixed value of pattern parameter m, or null if not bound. + * @return a match represented as a Match object, or null if no match is found. + * + */ + public Optional getOneArbitraryMatch(final Member pM) { + return rawGetOneArbitraryMatch(new Object[]{pM}); + } + + /** + * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, + * under any possible substitution of the unspecified parameters (if any). + * @param pM the fixed value of pattern parameter m, or null if not bound. + * @return true if the input is a valid (partial) match of the pattern. + * + */ + public boolean hasMatch(final Member pM) { + return rawHasMatch(new Object[]{pM}); + } + + /** + * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. + * @param pM the fixed value of pattern parameter m, or null if not bound. + * @return the number of pattern matches found. + * + */ + public int countMatches(final Member pM) { + return rawCountMatches(new Object[]{pM}); + } + + /** + * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. + * Neither determinism nor randomness of selection is guaranteed. + * @param pM the fixed value of pattern parameter m, or null if not bound. + * @param processor the action that will process the selected match. + * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked + * + */ + public boolean forOneArbitraryMatch(final Member pM, final Consumer processor) { + return rawForOneArbitraryMatch(new Object[]{pM}, processor); + } + + /** + * Returns a new (partial) match. + * This can be used e.g. to call the matcher with a partial match. + *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. + * @param pM the fixed value of pattern parameter m, or null if not bound. + * @return the (partial) match object. + * + */ + public MemberIsItsOwnParent.Match newMatch(final Member pM) { + return MemberIsItsOwnParent.Match.newMatch(pM); + } + + /** + * Retrieve the set of values that occur in matches for m. + * @return the Set of all values or empty set if there are no matches + * + */ + protected Stream rawStreamAllValuesOfm(final Object[] parameters) { + return rawStreamAllValues(POSITION_M, parameters).map(Member.class::cast); + } + + /** + * Retrieve the set of values that occur in matches for m. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfm() { + return rawStreamAllValuesOfm(emptyArray()).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for m. + * @return the Set of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfm() { + return rawStreamAllValuesOfm(emptyArray()); + } + + @Override + protected MemberIsItsOwnParent.Match tupleToMatch(final Tuple t) { + try { + return MemberIsItsOwnParent.Match.newMatch((Member) t.get(POSITION_M)); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in tuple not properly typed!",e); + return null; + } + } + + @Override + protected MemberIsItsOwnParent.Match arrayToMatch(final Object[] match) { + try { + return MemberIsItsOwnParent.Match.newMatch((Member) match[POSITION_M]); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in array not properly typed!",e); + return null; + } + } + + @Override + protected MemberIsItsOwnParent.Match arrayToMatchMutable(final Object[] match) { + try { + return MemberIsItsOwnParent.Match.newMutableMatch((Member) match[POSITION_M]); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in array not properly typed!",e); + return null; + } + } + + /** + * @return the singleton instance of the query specification of this pattern + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static IQuerySpecification querySpecification() { + return MemberIsItsOwnParent.instance(); + } + } + + private MemberIsItsOwnParent() { + super(GeneratedPQuery.INSTANCE); + } + + /** + * @return the singleton instance of the query specification + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static MemberIsItsOwnParent instance() { + try{ + return LazyHolder.INSTANCE; + } catch (ExceptionInInitializerError err) { + throw processInitializerError(err); + } + } + + @Override + protected MemberIsItsOwnParent.Matcher instantiate(final ViatraQueryEngine engine) { + return MemberIsItsOwnParent.Matcher.on(engine); + } + + @Override + public MemberIsItsOwnParent.Matcher instantiate() { + return MemberIsItsOwnParent.Matcher.create(); + } + + @Override + public MemberIsItsOwnParent.Match newEmptyMatch() { + return MemberIsItsOwnParent.Match.newEmptyMatch(); + } + + @Override + public MemberIsItsOwnParent.Match newMatch(final Object... parameters) { + return MemberIsItsOwnParent.Match.newMatch((familytree.Member) parameters[0]); + } + + /** + * Inner class allowing the singleton instance of {@link MemberIsItsOwnParent} to be created + * not at the class load time of the outer class, + * but rather at the first call to {@link MemberIsItsOwnParent#instance()}. + * + *

This workaround is required e.g. to support recursion. + * + */ + private static class LazyHolder { + private static final MemberIsItsOwnParent INSTANCE = new MemberIsItsOwnParent(); + + /** + * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. + * This initialization order is required to support indirect recursion. + * + *

The static initializer is defined using a helper field to work around limitations of the code generator. + * + */ + private static final Object STATIC_INITIALIZER = ensureInitialized(); + + public static Object ensureInitialized() { + INSTANCE.ensureInitializedInternal(); + return null; + } + } + + private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { + private static final MemberIsItsOwnParent.GeneratedPQuery INSTANCE = new GeneratedPQuery(); + + private final PParameter parameter_m = new PParameter("m", "familytree.Member", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/familytree", "Member")), PParameterDirection.INOUT); + + private final List parameters = Arrays.asList(parameter_m); + + private GeneratedPQuery() { + super(PVisibility.PUBLIC); + } + + @Override + public String getFullyQualifiedName() { + return "queries.memberIsItsOwnParent"; + } + + @Override + public List getParameterNames() { + return Arrays.asList("m"); + } + + @Override + public List getParameters() { + return parameters; + } + + @Override + public Set doGetContainedBodies() { + setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); + Set bodies = new LinkedHashSet<>(); + { + PBody body = new PBody(this); + PVariable var_m = body.getOrCreateVariableByName("m"); + PVariable var___0_ = body.getOrCreateVariableByName("_<0>"); + PVariable var_p = body.getOrCreateVariableByName("p"); + new TypeConstraint(body, Tuples.flatTupleOf(var_m), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/familytree", "Member"))); + body.setSymbolicParameters(Arrays.asList( + new ExportedParameter(body, var_m, parameter_m) + )); + // FamilyTree.members(_, m) + new TypeConstraint(body, Tuples.flatTupleOf(var___0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/familytree", "FamilyTree"))); + PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); + new TypeConstraint(body, Tuples.flatTupleOf(var___0_, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/familytree", "FamilyTree", "members"))); + new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/familytree", "Member"))); + new Equality(body, var__virtual_0_, var_m); + // Member.parents(m, p) + new TypeConstraint(body, Tuples.flatTupleOf(var_m), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/familytree", "Member"))); + PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); + new TypeConstraint(body, Tuples.flatTupleOf(var_m, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/familytree", "Member", "parents"))); + new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/familytree", "Member"))); + new Equality(body, var__virtual_1_, var_p); + // m == p + new Equality(body, var_m, var_p); + bodies.add(body); + } + { + PAnnotation annotation = new PAnnotation("Constraint"); + annotation.addAttribute("message", "memberIsItsOwnParent"); + annotation.addAttribute("severity", "error"); + annotation.addAttribute("key", Arrays.asList(new Object[] { + new ParameterReference("m") + })); + addAnnotation(annotation); + } + return bodies; + } + } +} diff --git a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src/queries/familyTreeConstraints.vql b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src/queries/familyTreeConstraints.vql new file mode 100644 index 00000000..1b9b6659 --- /dev/null +++ b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src/queries/familyTreeConstraints.vql @@ -0,0 +1,24 @@ +package queries + +import "http://www.example.org/familytree" + +@Constraint(message="memberIsItsOwnParent", severity="error", key={m}) +pattern memberIsItsOwnParent(m: Member) = { + FamilyTree.members(_, m); + Member.parents(m, p); + m == p; +} + +//@Constraint(message="parentTooYoung", severity="error", key={m, p}) +//pattern parentTooYoung(m: Member, p: Member) = { +// FamilyTree.members(_, m); +// Member.parents(m, p); +// Member.age(m, mAge); +// Member.age(p, pAge); +// check (mAge <= (pAge + 12)); +//} + + + + + diff --git a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src/run/FamilyTreeGen.java b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src/run/FamilyTreeGen.java new file mode 100644 index 00000000..4dcd77a5 --- /dev/null +++ b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src/run/FamilyTreeGen.java @@ -0,0 +1,13 @@ +package run; + +import hu.bme.mit.inf.dslreasoner.application.execution.StandaloneScriptExecutor; + +public class FamilyTreeGen { + public static void main(String[] args) { + String errorMessages = StandaloneScriptExecutor.executeScript("inputs/familytreeGen.vsconfig"); + if(errorMessages!=null) { + System.out.println(errorMessages); + } + } + +} -- cgit v1.2.3-54-g00ecf