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