diff options
Diffstat (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/PatternGenerator.xtend')
-rw-r--r-- | Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/PatternGenerator.xtend | 150 |
1 files changed, 71 insertions, 79 deletions
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/PatternGenerator.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/PatternGenerator.xtend index d4c76bb4..1b0db90e 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/PatternGenerator.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/PatternGenerator.xtend | |||
@@ -1,7 +1,6 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.patterns | 1 | package hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.patterns |
2 | 2 | ||
3 | import hu.bme.mit.inf.dslreasoner.ecore2logic.ecore2logicannotations.InverseRelationAssertion | 3 | import hu.bme.mit.inf.dslreasoner.ecore2logic.ecore2logicannotations.InverseRelationAssertion |
4 | import hu.bme.mit.inf.dslreasoner.ecore2logic.ecore2logicannotations.LowerMultiplicityAssertion | ||
5 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.BoolTypeReference | 4 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.BoolTypeReference |
6 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.IntTypeReference | 5 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.IntTypeReference |
7 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RealTypeReference | 6 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RealTypeReference |
@@ -17,6 +16,7 @@ import hu.bme.mit.inf.dslreasoner.viatra2logic.viatra2logicannotations.Transform | |||
17 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.Modality | 16 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.Modality |
18 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.TypeAnalysisResult | 17 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.TypeAnalysisResult |
19 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.TypeInferenceMethod | 18 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.TypeInferenceMethod |
19 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.RelationConstraints | ||
20 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation | 20 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation |
21 | import java.util.HashMap | 21 | import java.util.HashMap |
22 | import java.util.Map | 22 | import java.util.Map |
@@ -26,22 +26,26 @@ import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PQuery | |||
26 | import org.eclipse.xtend.lib.annotations.Accessors | 26 | import org.eclipse.xtend.lib.annotations.Accessors |
27 | 27 | ||
28 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* | 28 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* |
29 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.ScopePropagatorStrategy | ||
29 | 30 | ||
30 | class PatternGenerator { | 31 | class PatternGenerator { |
31 | @Accessors(PUBLIC_GETTER) val TypeIndexer typeIndexer //= new TypeIndexer(this) | 32 | @Accessors(PUBLIC_GETTER) val TypeIndexer typeIndexer // = new TypeIndexer(this) |
32 | @Accessors(PUBLIC_GETTER) val RelationDeclarationIndexer relationDeclarationIndexer = new RelationDeclarationIndexer(this) | 33 | @Accessors(PUBLIC_GETTER) val RelationDeclarationIndexer relationDeclarationIndexer = new RelationDeclarationIndexer( |
33 | @Accessors(PUBLIC_GETTER) val RelationDefinitionIndexer relationDefinitionIndexer = new RelationDefinitionIndexer(this) | 34 | this) |
35 | @Accessors(PUBLIC_GETTER) val RelationDefinitionIndexer relationDefinitionIndexer = new RelationDefinitionIndexer( | ||
36 | this) | ||
34 | @Accessors(PUBLIC_GETTER) val ContainmentIndexer containmentIndexer = new ContainmentIndexer(this) | 37 | @Accessors(PUBLIC_GETTER) val ContainmentIndexer containmentIndexer = new ContainmentIndexer(this) |
35 | @Accessors(PUBLIC_GETTER) val InvalidIndexer invalidIndexer = new InvalidIndexer(this) | 38 | @Accessors(PUBLIC_GETTER) val InvalidIndexer invalidIndexer = new InvalidIndexer(this) |
36 | @Accessors(PUBLIC_GETTER) val UnfinishedIndexer unfinishedIndexer = new UnfinishedIndexer(this) | 39 | @Accessors(PUBLIC_GETTER) val UnfinishedIndexer unfinishedIndexer |
37 | @Accessors(PUBLIC_GETTER) val TypeRefinementGenerator typeRefinementGenerator //= new RefinementGenerator(this) | 40 | @Accessors(PUBLIC_GETTER) val TypeRefinementGenerator typeRefinementGenerator // = new RefinementGenerator(this) |
38 | @Accessors(PUBLIC_GETTER) val RelationRefinementGenerator relationRefinementGenerator = new RelationRefinementGenerator(this) | 41 | @Accessors(PUBLIC_GETTER) val RelationRefinementGenerator relationRefinementGenerator = new RelationRefinementGenerator( |
39 | 42 | this) | |
40 | public new(TypeInferenceMethod typeInferenceMethod) { | 43 | |
41 | if(typeInferenceMethod == TypeInferenceMethod.Generic) { | 44 | new(TypeInferenceMethod typeInferenceMethod, ScopePropagatorStrategy scopePropagatorStrategy) { |
45 | if (typeInferenceMethod == TypeInferenceMethod.Generic) { | ||
42 | this.typeIndexer = new GenericTypeIndexer(this) | 46 | this.typeIndexer = new GenericTypeIndexer(this) |
43 | this.typeRefinementGenerator = new GenericTypeRefinementGenerator(this) | 47 | this.typeRefinementGenerator = new GenericTypeRefinementGenerator(this) |
44 | } else if(typeInferenceMethod == TypeInferenceMethod.PreliminaryAnalysis) { | 48 | } else if (typeInferenceMethod == TypeInferenceMethod.PreliminaryAnalysis) { |
45 | this.typeIndexer = new TypeIndexerWithPreliminaryTypeAnalysis(this) | 49 | this.typeIndexer = new TypeIndexerWithPreliminaryTypeAnalysis(this) |
46 | this.typeRefinementGenerator = new TypeRefinementWithPreliminaryTypeAnalysis(this) | 50 | this.typeRefinementGenerator = new TypeRefinementWithPreliminaryTypeAnalysis(this) |
47 | } else { | 51 | } else { |
@@ -49,112 +53,100 @@ class PatternGenerator { | |||
49 | this.typeRefinementGenerator = null | 53 | this.typeRefinementGenerator = null |
50 | throw new IllegalArgumentException('''Unknown type indexing technique : «typeInferenceMethod.name»''') | 54 | throw new IllegalArgumentException('''Unknown type indexing technique : «typeInferenceMethod.name»''') |
51 | } | 55 | } |
56 | this.unfinishedIndexer = new UnfinishedIndexer(this, scopePropagatorStrategy.requiresUpperBoundIndexing) | ||
52 | } | 57 | } |
53 | 58 | ||
54 | public def requiresTypeAnalysis() { | 59 | def requiresTypeAnalysis() { |
55 | typeIndexer.requiresTypeAnalysis || typeRefinementGenerator.requiresTypeAnalysis | 60 | typeIndexer.requiresTypeAnalysis || typeRefinementGenerator.requiresTypeAnalysis |
56 | } | 61 | } |
57 | 62 | ||
58 | public dispatch def referRelation( | 63 | dispatch def CharSequence referRelation(RelationDeclaration referred, String sourceVariable, String targetVariable, |
59 | RelationDeclaration referred, | 64 | Modality modality, Map<String, PQuery> fqn2PQuery) { |
60 | String sourceVariable, | 65 | return this.relationDeclarationIndexer.referRelation(referred, sourceVariable, targetVariable, modality) |
61 | String targetVariable, | ||
62 | Modality modality, | ||
63 | Map<String,PQuery> fqn2PQuery) | ||
64 | { | ||
65 | return this.relationDeclarationIndexer.referRelation(referred,sourceVariable,targetVariable,modality) | ||
66 | } | 66 | } |
67 | public dispatch def referRelation( | 67 | |
68 | RelationDefinition referred, | 68 | dispatch def CharSequence referRelation(RelationDefinition referred, String sourceVariable, String targetVariable, |
69 | String sourceVariable, | 69 | Modality modality, Map<String, PQuery> fqn2PQuery) { |
70 | String targetVariable, | 70 | val pattern = referred.annotations.filter(TransfomedViatraQuery).head.patternFullyQualifiedName.lookup( |
71 | Modality modality, | 71 | fqn2PQuery) |
72 | Map<String,PQuery> fqn2PQuery) | 72 | return this.relationDefinitionIndexer.referPattern(pattern, #[sourceVariable, targetVariable], modality, true, |
73 | { | 73 | false) |
74 | val pattern = referred.annotations.filter(TransfomedViatraQuery).head.patternFullyQualifiedName.lookup(fqn2PQuery) | ||
75 | return this.relationDefinitionIndexer.referPattern(pattern,#[sourceVariable,targetVariable],modality,true,false) | ||
76 | } | 74 | } |
77 | 75 | ||
78 | def public referRelationByName(EReference reference, | 76 | def referRelationByName(EReference reference, String sourceVariable, String targetVariable, Modality modality) { |
79 | String sourceVariable, | 77 | '''find «modality.name.toLowerCase»InRelation«canonizeName('''«reference.name» reference «reference.EContainingClass.name»''')»(problem,interpretation,«sourceVariable»,«targetVariable»);''' |
80 | String targetVariable, | ||
81 | Modality modality) | ||
82 | { | ||
83 | '''find «modality.name.toLowerCase»InRelation«canonizeName('''«reference.name» reference «reference.EContainingClass.name»''') | ||
84 | »(problem,interpretation,«sourceVariable»,«targetVariable»);''' | ||
85 | } | 78 | } |
86 | 79 | ||
87 | def public CharSequence referAttributeByName(EAttribute attribute, | 80 | def CharSequence referAttributeByName(EAttribute attribute, String sourceVariable, String targetVariable, |
88 | String sourceVariable, | 81 | Modality modality) { |
89 | String targetVariable, | 82 | '''find «modality.name.toLowerCase»InRelation«canonizeName('''«attribute.name» attribute «attribute.EContainingClass.name»''')»(problem,interpretation,«sourceVariable»,«targetVariable»);''' |
90 | Modality modality) | ||
91 | { | ||
92 | '''find «modality.name.toLowerCase»InRelation«canonizeName('''«attribute.name» attribute «attribute.EContainingClass.name»''') | ||
93 | »(problem,interpretation,«sourceVariable»,«targetVariable»);''' | ||
94 | } | 83 | } |
95 | 84 | ||
96 | public def canonizeName(String name) { | 85 | def canonizeName(String name) { |
97 | name.split(' ').join('_') | 86 | name.split(' ').join('_') |
98 | } | 87 | } |
99 | 88 | ||
100 | public def lowerMultiplicities(LogicProblem problem) { | 89 | def wfQueries(LogicProblem problem) { |
101 | problem.assertions.map[annotations].flatten.filter(LowerMultiplicityAssertion).filter[!it.relation.isDerived] | 90 | problem.assertions.map[it.annotations].flatten.filter(TransformedViatraWellformednessConstraint).map[it.query] |
102 | } | ||
103 | public def wfQueries(LogicProblem problem) { | ||
104 | problem.assertions.map[it.annotations] | ||
105 | .flatten | ||
106 | .filter(TransformedViatraWellformednessConstraint) | ||
107 | .map[it.query] | ||
108 | } | 91 | } |
109 | public def getContainments(LogicProblem p) { | 92 | |
93 | def getContainments(LogicProblem p) { | ||
110 | return p.containmentHierarchies.head.containmentRelations | 94 | return p.containmentHierarchies.head.containmentRelations |
111 | } | 95 | } |
112 | public def getInverseRelations(LogicProblem p) { | 96 | |
97 | def getInverseRelations(LogicProblem p) { | ||
113 | val inverseRelations = new HashMap | 98 | val inverseRelations = new HashMap |
114 | p.annotations.filter(InverseRelationAssertion).forEach[ | 99 | p.annotations.filter(InverseRelationAssertion).forEach [ |
115 | inverseRelations.put(it.inverseA,it.inverseB) | 100 | inverseRelations.put(it.inverseA, it.inverseB) |
116 | inverseRelations.put(it.inverseB,it.inverseA) | 101 | inverseRelations.put(it.inverseB, it.inverseA) |
117 | ] | 102 | ] |
118 | return inverseRelations | 103 | return inverseRelations |
119 | } | 104 | } |
120 | public def isRepresentative(Relation relation, Relation inverse) { | 105 | |
121 | if(inverse == null) { | 106 | def isRepresentative(Relation relation, Relation inverse) { |
107 | if (inverse === null) { | ||
122 | return true | 108 | return true |
123 | } else { | 109 | } else { |
124 | relation.name.compareTo(inverse.name)<1 | 110 | relation.name.compareTo(inverse.name) < 1 |
125 | } | 111 | } |
126 | } | 112 | } |
127 | 113 | ||
128 | public def isDerived(Relation relation) { | 114 | def isDerived(Relation relation) { |
129 | relation.annotations.exists[it instanceof DefinedByDerivedFeature] | 115 | relation.annotations.exists[it instanceof DefinedByDerivedFeature] |
130 | } | 116 | } |
131 | public def getDerivedDefinition(RelationDeclaration relation) { | 117 | |
118 | def getDerivedDefinition(RelationDeclaration relation) { | ||
132 | relation.annotations.filter(DefinedByDerivedFeature).head.query | 119 | relation.annotations.filter(DefinedByDerivedFeature).head.query |
133 | } | 120 | } |
134 | 121 | ||
135 | private def allTypeReferences(LogicProblem problem) { | 122 | private def allTypeReferences(LogicProblem problem) { |
136 | problem.eAllContents.filter(TypeReference).toIterable | 123 | problem.eAllContents.filter(TypeReference).toIterable |
137 | } | 124 | } |
125 | |||
138 | protected def hasBoolean(LogicProblem problem) { | 126 | protected def hasBoolean(LogicProblem problem) { |
139 | problem.allTypeReferences.exists[it instanceof BoolTypeReference] | 127 | problem.allTypeReferences.exists[it instanceof BoolTypeReference] |
140 | } | 128 | } |
129 | |||
141 | protected def hasInteger(LogicProblem problem) { | 130 | protected def hasInteger(LogicProblem problem) { |
142 | problem.allTypeReferences.exists[it instanceof IntTypeReference] | 131 | problem.allTypeReferences.exists[it instanceof IntTypeReference] |
143 | } | 132 | } |
133 | |||
144 | protected def hasReal(LogicProblem problem) { | 134 | protected def hasReal(LogicProblem problem) { |
145 | problem.allTypeReferences.exists[it instanceof RealTypeReference] | 135 | problem.allTypeReferences.exists[it instanceof RealTypeReference] |
146 | } | 136 | } |
137 | |||
147 | protected def hasString(LogicProblem problem) { | 138 | protected def hasString(LogicProblem problem) { |
148 | problem.allTypeReferences.exists[it instanceof StringTypeReference] | 139 | problem.allTypeReferences.exists[it instanceof StringTypeReference] |
149 | } | 140 | } |
150 | 141 | ||
151 | public def transformBaseProperties( | 142 | def transformBaseProperties( |
152 | LogicProblem problem, | 143 | LogicProblem problem, |
153 | PartialInterpretation emptySolution, | 144 | PartialInterpretation emptySolution, |
154 | Map<String,PQuery> fqn2PQuery, | 145 | Map<String, PQuery> fqn2PQuery, |
155 | TypeAnalysisResult typeAnalysisResult | 146 | TypeAnalysisResult typeAnalysisResult, |
147 | RelationConstraints constraints | ||
156 | ) { | 148 | ) { |
157 | 149 | ||
158 | return ''' | 150 | return ''' |
159 | import epackage "http://www.bme.hu/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage" | 151 | import epackage "http://www.bme.hu/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage" |
160 | import epackage "http://www.bme.hu/mit/inf/dslreasoner/logic/model/problem" | 152 | import epackage "http://www.bme.hu/mit/inf/dslreasoner/logic/model/problem" |
@@ -188,7 +180,7 @@ class PatternGenerator { | |||
188 | 180 | ||
189 | private pattern elementCloseWorld(element:DefinedElement) { | 181 | private pattern elementCloseWorld(element:DefinedElement) { |
190 | PartialInterpretation.openWorldElements(i,element); | 182 | PartialInterpretation.openWorldElements(i,element); |
191 | PartialInterpretation.maxNewElements(i,0); | 183 | PartialInterpretation.maxNewElements(i,0); |
192 | } or { | 184 | } or { |
193 | Scope.targetTypeInterpretation(scope,interpretation); | 185 | Scope.targetTypeInterpretation(scope,interpretation); |
194 | PartialTypeInterpratation.elements(interpretation,element); | 186 | PartialTypeInterpratation.elements(interpretation,element); |
@@ -221,7 +213,7 @@ class PatternGenerator { | |||
221 | ////////// | 213 | ////////// |
222 | // 1.1.1 primitive Type Indexers | 214 | // 1.1.1 primitive Type Indexers |
223 | ////////// | 215 | ////////// |
224 | ««« pattern instanceofBoolean(problem:LogicProblem, interpretation:PartialInterpretation, element:DefinedElement) { | 216 | ««« pattern instanceofBoolean(problem:LogicProblem, interpretation:PartialInterpretation, element:DefinedElement) { |
225 | ««« find interpretation(problem,interpretation); | 217 | ««« find interpretation(problem,interpretation); |
226 | ««« PartialInterpretation.booleanelements(interpretation,element); | 218 | ««« PartialInterpretation.booleanelements(interpretation,element); |
227 | ««« } | 219 | ««« } |
@@ -279,7 +271,7 @@ class PatternGenerator { | |||
279 | ////////// | 271 | ////////// |
280 | // 3.1 Unfinishedness Measured by Multiplicity | 272 | // 3.1 Unfinishedness Measured by Multiplicity |
281 | ////////// | 273 | ////////// |
282 | «unfinishedIndexer.generateUnfinishedMultiplicityQueries(problem,fqn2PQuery)» | 274 | «unfinishedIndexer.generateUnfinishedMultiplicityQueries(constraints.multiplicityConstraints,fqn2PQuery)» |
283 | 275 | ||
284 | ////////// | 276 | ////////// |
285 | // 3.2 Unfinishedness Measured by WF Queries | 277 | // 3.2 Unfinishedness Measured by WF Queries |
@@ -302,6 +294,6 @@ class PatternGenerator { | |||
302 | // 4.3 Relation refinement | 294 | // 4.3 Relation refinement |
303 | ////////// | 295 | ////////// |
304 | «relationRefinementGenerator.generateRefineReference(problem)» | 296 | «relationRefinementGenerator.generateRefineReference(problem)» |
305 | ''' | 297 | ''' |
306 | } | 298 | } |
307 | } | 299 | } |