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 | 303 |
1 files changed, 194 insertions, 109 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..edf92343 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,31 +16,55 @@ 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 |
24 | import org.eclipse.emf.ecore.EReference | 27 | import org.eclipse.emf.ecore.EReference |
28 | import org.eclipse.viatra.query.runtime.matchers.psystem.PConstraint | ||
25 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PQuery | 29 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PQuery |
26 | import org.eclipse.xtend.lib.annotations.Accessors | 30 | import org.eclipse.xtend.lib.annotations.Accessors |
31 | import org.eclipse.xtend.lib.annotations.Data | ||
32 | import org.eclipse.xtend2.lib.StringConcatenationClient | ||
27 | 33 | ||
28 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* | 34 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* |
29 | 35 | ||
36 | @Data class PatternGeneratorResult { | ||
37 | CharSequence patternText | ||
38 | HashMap<PConstraint,String> constraint2MustPreconditionName | ||
39 | HashMap<PConstraint,String> constraint2CurrentPreconditionName | ||
40 | } | ||
41 | |||
42 | interface UnitPropagationPatternGenerator { | ||
43 | def Map<Relation, String> getMustPatterns() | ||
44 | |||
45 | def Map<Relation, String> getMustNotPatterns() | ||
46 | |||
47 | def StringConcatenationClient getAdditionalPatterns(PatternGenerator generator, Map<String, PQuery> fqn2PQuery) | ||
48 | } | ||
49 | |||
30 | class PatternGenerator { | 50 | class PatternGenerator { |
31 | @Accessors(PUBLIC_GETTER) val TypeIndexer typeIndexer //= new TypeIndexer(this) | 51 | @Accessors(PUBLIC_GETTER) val TypeIndexer typeIndexer // = new TypeIndexer(this) |
32 | @Accessors(PUBLIC_GETTER) val RelationDeclarationIndexer relationDeclarationIndexer = new RelationDeclarationIndexer(this) | 52 | @Accessors(PUBLIC_GETTER) val RelationDeclarationIndexer relationDeclarationIndexer = new RelationDeclarationIndexer( |
33 | @Accessors(PUBLIC_GETTER) val RelationDefinitionIndexer relationDefinitionIndexer = new RelationDefinitionIndexer(this) | 53 | this) |
54 | @Accessors(PUBLIC_GETTER) val RelationDefinitionIndexer relationDefinitionIndexer = new RelationDefinitionIndexer( | ||
55 | this) | ||
34 | @Accessors(PUBLIC_GETTER) val ContainmentIndexer containmentIndexer = new ContainmentIndexer(this) | 56 | @Accessors(PUBLIC_GETTER) val ContainmentIndexer containmentIndexer = new ContainmentIndexer(this) |
35 | @Accessors(PUBLIC_GETTER) val InvalidIndexer invalidIndexer = new InvalidIndexer(this) | 57 | @Accessors(PUBLIC_GETTER) val InvalidIndexer invalidIndexer = new InvalidIndexer(this) |
36 | @Accessors(PUBLIC_GETTER) val UnfinishedIndexer unfinishedIndexer = new UnfinishedIndexer(this) | 58 | @Accessors(PUBLIC_GETTER) val UnfinishedIndexer unfinishedIndexer |
37 | @Accessors(PUBLIC_GETTER) val TypeRefinementGenerator typeRefinementGenerator //= new RefinementGenerator(this) | 59 | @Accessors(PUBLIC_GETTER) val TypeRefinementGenerator typeRefinementGenerator //= new RefinementGenerator(this) |
38 | @Accessors(PUBLIC_GETTER) val RelationRefinementGenerator relationRefinementGenerator = new RelationRefinementGenerator(this) | 60 | @Accessors(PUBLIC_GETTER) val RelationRefinementGenerator relationRefinementGenerator = new RelationRefinementGenerator(this) |
61 | @Accessors(PUBLIC_GETTER) val UnitPropagationPreconditionGenerator unitPropagationPreconditionGenerator = new UnitPropagationPreconditionGenerator(this) | ||
39 | 62 | ||
40 | public new(TypeInferenceMethod typeInferenceMethod) { | 63 | new(TypeInferenceMethod typeInferenceMethod, ScopePropagatorStrategy scopePropagatorStrategy) { |
41 | if(typeInferenceMethod == TypeInferenceMethod.Generic) { | 64 | if(typeInferenceMethod == TypeInferenceMethod.Generic) { |
42 | this.typeIndexer = new GenericTypeIndexer(this) | 65 | this.typeIndexer = new GenericTypeIndexer(this) |
43 | this.typeRefinementGenerator = new GenericTypeRefinementGenerator(this) | 66 | this.typeRefinementGenerator = new GenericTypeRefinementGenerator(this) |
44 | } else if(typeInferenceMethod == TypeInferenceMethod.PreliminaryAnalysis) { | 67 | } else if (typeInferenceMethod == TypeInferenceMethod.PreliminaryAnalysis) { |
45 | this.typeIndexer = new TypeIndexerWithPreliminaryTypeAnalysis(this) | 68 | this.typeIndexer = new TypeIndexerWithPreliminaryTypeAnalysis(this) |
46 | this.typeRefinementGenerator = new TypeRefinementWithPreliminaryTypeAnalysis(this) | 69 | this.typeRefinementGenerator = new TypeRefinementWithPreliminaryTypeAnalysis(this) |
47 | } else { | 70 | } else { |
@@ -49,113 +72,105 @@ class PatternGenerator { | |||
49 | this.typeRefinementGenerator = null | 72 | this.typeRefinementGenerator = null |
50 | throw new IllegalArgumentException('''Unknown type indexing technique : «typeInferenceMethod.name»''') | 73 | throw new IllegalArgumentException('''Unknown type indexing technique : «typeInferenceMethod.name»''') |
51 | } | 74 | } |
75 | this.unfinishedIndexer = new UnfinishedIndexer(this, scopePropagatorStrategy.requiresUpperBoundIndexing) | ||
52 | } | 76 | } |
53 | 77 | ||
54 | public def requiresTypeAnalysis() { | 78 | def requiresTypeAnalysis() { |
55 | typeIndexer.requiresTypeAnalysis || typeRefinementGenerator.requiresTypeAnalysis | 79 | typeIndexer.requiresTypeAnalysis || typeRefinementGenerator.requiresTypeAnalysis |
56 | } | 80 | } |
57 | 81 | ||
58 | public dispatch def referRelation( | 82 | dispatch def CharSequence referRelation(RelationDeclaration referred, String sourceVariable, String targetVariable, |
59 | RelationDeclaration referred, | 83 | Modality modality, Map<String, PQuery> fqn2PQuery) { |
60 | String sourceVariable, | 84 | 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 | } | 85 | } |
67 | public dispatch def referRelation( | 86 | |
68 | RelationDefinition referred, | 87 | dispatch def CharSequence referRelation(RelationDefinition referred, String sourceVariable, String targetVariable, |
69 | String sourceVariable, | 88 | Modality modality, Map<String, PQuery> fqn2PQuery) { |
70 | String targetVariable, | 89 | val pattern = referred.annotations.filter(TransfomedViatraQuery).head.patternFullyQualifiedName.lookup( |
71 | Modality modality, | 90 | fqn2PQuery) |
72 | Map<String,PQuery> fqn2PQuery) | 91 | return this.relationDefinitionIndexer.referPattern(pattern, #[sourceVariable, targetVariable], modality, true, |
73 | { | 92 | false) |
74 | val pattern = referred.annotations.filter(TransfomedViatraQuery).head.patternFullyQualifiedName.lookup(fqn2PQuery) | ||
75 | return this.relationDefinitionIndexer.referPattern(pattern,#[sourceVariable,targetVariable],modality,true,false) | ||
76 | } | 93 | } |
77 | 94 | ||
78 | def public referRelationByName(EReference reference, | 95 | def referRelationByName(EReference reference, String sourceVariable, String targetVariable, Modality modality) { |
79 | String sourceVariable, | 96 | '''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 | } | 97 | } |
86 | 98 | ||
87 | def public CharSequence referAttributeByName(EAttribute attribute, | 99 | def CharSequence referAttributeByName(EAttribute attribute, String sourceVariable, String targetVariable, |
88 | String sourceVariable, | 100 | Modality modality) { |
89 | String targetVariable, | 101 | '''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 | } | 102 | } |
95 | 103 | ||
96 | public def canonizeName(String name) { | 104 | def canonizeName(String name) { |
97 | name.split(' ').join('_') | 105 | name.split(' ').join('_') |
98 | } | 106 | } |
99 | 107 | ||
100 | public def lowerMultiplicities(LogicProblem problem) { | 108 | def wfQueries(LogicProblem problem) { |
101 | problem.assertions.map[annotations].flatten.filter(LowerMultiplicityAssertion).filter[!it.relation.isDerived] | 109 | 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 | } | 110 | } |
109 | public def getContainments(LogicProblem p) { | 111 | |
112 | def getContainments(LogicProblem p) { | ||
110 | return p.containmentHierarchies.head.containmentRelations | 113 | return p.containmentHierarchies.head.containmentRelations |
111 | } | 114 | } |
112 | public def getInverseRelations(LogicProblem p) { | 115 | |
116 | def getInverseRelations(LogicProblem p) { | ||
113 | val inverseRelations = new HashMap | 117 | val inverseRelations = new HashMap |
114 | p.annotations.filter(InverseRelationAssertion).forEach[ | 118 | p.annotations.filter(InverseRelationAssertion).forEach [ |
115 | inverseRelations.put(it.inverseA,it.inverseB) | 119 | inverseRelations.put(it.inverseA, it.inverseB) |
116 | inverseRelations.put(it.inverseB,it.inverseA) | 120 | inverseRelations.put(it.inverseB, it.inverseA) |
117 | ] | 121 | ] |
118 | return inverseRelations | 122 | return inverseRelations |
119 | } | 123 | } |
120 | public def isRepresentative(Relation relation, Relation inverse) { | 124 | |
121 | if(inverse == null) { | 125 | def isRepresentative(Relation relation, Relation inverse) { |
126 | if (relation === null) { | ||
127 | return false | ||
128 | } else if (inverse === null) { | ||
122 | return true | 129 | return true |
123 | } else { | 130 | } else { |
124 | relation.name.compareTo(inverse.name)<1 | 131 | relation.name.compareTo(inverse.name) < 1 |
125 | } | 132 | } |
126 | } | 133 | } |
127 | 134 | ||
128 | public def isDerived(Relation relation) { | 135 | def isDerived(Relation relation) { |
129 | relation.annotations.exists[it instanceof DefinedByDerivedFeature] | 136 | relation.annotations.exists[it instanceof DefinedByDerivedFeature] |
130 | } | 137 | } |
131 | public def getDerivedDefinition(RelationDeclaration relation) { | 138 | |
139 | def getDerivedDefinition(RelationDeclaration relation) { | ||
132 | relation.annotations.filter(DefinedByDerivedFeature).head.query | 140 | relation.annotations.filter(DefinedByDerivedFeature).head.query |
133 | } | 141 | } |
134 | 142 | ||
135 | private def allTypeReferences(LogicProblem problem) { | 143 | private def allTypeReferences(LogicProblem problem) { |
136 | problem.eAllContents.filter(TypeReference).toIterable | 144 | problem.eAllContents.filter(TypeReference).toIterable |
137 | } | 145 | } |
146 | |||
138 | protected def hasBoolean(LogicProblem problem) { | 147 | protected def hasBoolean(LogicProblem problem) { |
139 | problem.allTypeReferences.exists[it instanceof BoolTypeReference] | 148 | problem.allTypeReferences.exists[it instanceof BoolTypeReference] |
140 | } | 149 | } |
150 | |||
141 | protected def hasInteger(LogicProblem problem) { | 151 | protected def hasInteger(LogicProblem problem) { |
142 | problem.allTypeReferences.exists[it instanceof IntTypeReference] | 152 | problem.allTypeReferences.exists[it instanceof IntTypeReference] |
143 | } | 153 | } |
154 | |||
144 | protected def hasReal(LogicProblem problem) { | 155 | protected def hasReal(LogicProblem problem) { |
145 | problem.allTypeReferences.exists[it instanceof RealTypeReference] | 156 | problem.allTypeReferences.exists[it instanceof RealTypeReference] |
146 | } | 157 | } |
158 | |||
147 | protected def hasString(LogicProblem problem) { | 159 | protected def hasString(LogicProblem problem) { |
148 | problem.allTypeReferences.exists[it instanceof StringTypeReference] | 160 | problem.allTypeReferences.exists[it instanceof StringTypeReference] |
149 | } | 161 | } |
150 | 162 | ||
151 | public def transformBaseProperties( | 163 | def transformBaseProperties( |
152 | LogicProblem problem, | 164 | LogicProblem problem, |
153 | PartialInterpretation emptySolution, | 165 | PartialInterpretation emptySolution, |
154 | Map<String,PQuery> fqn2PQuery, | 166 | Map<String, PQuery> fqn2PQuery, |
155 | TypeAnalysisResult typeAnalysisResult | 167 | TypeAnalysisResult typeAnalysisResult, |
168 | RelationConstraints constraints, | ||
169 | Collection<LinearTypeConstraintHint> hints, | ||
170 | Collection<UnitPropagationPatternGenerator> unitPropagationPatternGenerators | ||
156 | ) { | 171 | ) { |
157 | 172 | val first = | |
158 | return ''' | 173 | ''' |
159 | import epackage "http://www.bme.hu/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage" | 174 | import epackage "http://www.bme.hu/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage" |
160 | import epackage "http://www.bme.hu/mit/inf/dslreasoner/logic/model/problem" | 175 | import epackage "http://www.bme.hu/mit/inf/dslreasoner/logic/model/problem" |
161 | import epackage "http://www.bme.hu/mit/inf/dslreasoner/logic/model/language" | 176 | import epackage "http://www.bme.hu/mit/inf/dslreasoner/logic/model/language" |
@@ -170,6 +185,7 @@ class PatternGenerator { | |||
170 | ///////////////////////// | 185 | ///////////////////////// |
171 | // 0.1 Existence | 186 | // 0.1 Existence |
172 | ///////////////////////// | 187 | ///////////////////////// |
188 | /** [[exist(element)]]=1 */ | ||
173 | private pattern mustExist(problem:LogicProblem, interpretation:PartialInterpretation, element:DefinedElement) { | 189 | private pattern mustExist(problem:LogicProblem, interpretation:PartialInterpretation, element:DefinedElement) { |
174 | find interpretation(problem,interpretation); | 190 | find interpretation(problem,interpretation); |
175 | LogicProblem.elements(problem,element); | 191 | LogicProblem.elements(problem,element); |
@@ -178,6 +194,7 @@ class PatternGenerator { | |||
178 | PartialInterpretation.newElements(interpretation,element); | 194 | PartialInterpretation.newElements(interpretation,element); |
179 | } | 195 | } |
180 | 196 | ||
197 | /** [[exist(element)]]>=1/2 */ | ||
181 | private pattern mayExist(problem:LogicProblem, interpretation:PartialInterpretation, element:DefinedElement) { | 198 | private pattern mayExist(problem:LogicProblem, interpretation:PartialInterpretation, element:DefinedElement) { |
182 | find mustExist(problem,interpretation,element); | 199 | find mustExist(problem,interpretation,element); |
183 | } or { | 200 | } or { |
@@ -188,7 +205,7 @@ class PatternGenerator { | |||
188 | 205 | ||
189 | private pattern elementCloseWorld(element:DefinedElement) { | 206 | private pattern elementCloseWorld(element:DefinedElement) { |
190 | PartialInterpretation.openWorldElements(i,element); | 207 | PartialInterpretation.openWorldElements(i,element); |
191 | PartialInterpretation.maxNewElements(i,0); | 208 | PartialInterpretation.maxNewElements(i,0); |
192 | } or { | 209 | } or { |
193 | Scope.targetTypeInterpretation(scope,interpretation); | 210 | Scope.targetTypeInterpretation(scope,interpretation); |
194 | PartialTypeInterpratation.elements(interpretation,element); | 211 | PartialTypeInterpratation.elements(interpretation,element); |
@@ -198,64 +215,115 @@ class PatternGenerator { | |||
198 | //////////////////////// | 215 | //////////////////////// |
199 | // 0.2 Equivalence | 216 | // 0.2 Equivalence |
200 | //////////////////////// | 217 | //////////////////////// |
201 | pattern mayEquivalent(problem:LogicProblem, interpretation:PartialInterpretation, a: DefinedElement, b: DefinedElement) { | 218 | pattern mayEquivalent(problem:LogicProblem, interpretation:PartialInterpretation, a: DefinedElement, b: DefinedElement) |
219 | // For non-primitive type. Boolean types always must equivalent or cannot equivalent | ||
220 | { | ||
202 | find mayExist(problem,interpretation,a); | 221 | find mayExist(problem,interpretation,a); |
203 | find mayExist(problem,interpretation,b); | 222 | find mayExist(problem,interpretation,b); |
204 | a == b; | 223 | a == b; |
224 | ««« } or { | ||
225 | ««« find mayExist(problem,interpretation,a); | ||
226 | ««« find mayExist(problem,interpretation,b); | ||
227 | ««« IntegerElement(a); | ||
228 | ««« IntegerElement(b); | ||
229 | ««« PrimitiveElement.valueSet(a,false); | ||
230 | ««« } or { | ||
231 | ««« find mayExist(problem,interpretation,a); | ||
232 | ««« find mayExist(problem,interpretation,b); | ||
233 | ««« IntegerElement(a); | ||
234 | ««« IntegerElement(b); | ||
235 | ««« PrimitiveElement.valueSet(b,false); | ||
236 | ««« } or { | ||
237 | ««« find mayExist(problem,interpretation,a); | ||
238 | ««« find mayExist(problem,interpretation,b); | ||
239 | ««« RealElement(a); | ||
240 | ««« RealElement(b); | ||
241 | ««« PrimitiveElement.valueSet(a,false); | ||
242 | ««« } or { | ||
243 | ««« find mayExist(problem,interpretation,a); | ||
244 | ««« find mayExist(problem,interpretation,b); | ||
245 | ««« RealElement(a); | ||
246 | ««« RealElement(b); | ||
247 | ««« PrimitiveElement.valueSet(b,false); | ||
248 | ««« } or { | ||
249 | ««« find mayExist(problem,interpretation,a); | ||
250 | ««« find mayExist(problem,interpretation,b); | ||
251 | ««« StringElement(a); | ||
252 | ««« StringElement(b); | ||
253 | ««« PrimitiveElement.valueSet(a,false); | ||
254 | ««« } or { | ||
255 | ««« find mayExist(problem,interpretation,a); | ||
256 | ««« find mayExist(problem,interpretation,b); | ||
257 | ««« StringElement(a); | ||
258 | ««« StringElement(b); | ||
259 | ««« PrimitiveElement.valueSet(b,false); | ||
205 | } | 260 | } |
261 | |||
206 | pattern mustEquivalent(problem:LogicProblem, interpretation:PartialInterpretation, a: DefinedElement, b: DefinedElement) { | 262 | pattern mustEquivalent(problem:LogicProblem, interpretation:PartialInterpretation, a: DefinedElement, b: DefinedElement) { |
263 | // For non-primitive and Boolean primitive type | ||
207 | find mustExist(problem,interpretation,a); | 264 | find mustExist(problem,interpretation,a); |
208 | find mustExist(problem,interpretation,b); | 265 | find mustExist(problem,interpretation,b); |
209 | a == b; | 266 | a == b; |
267 | ««« } or { | ||
268 | ««« find mustExist(problem,interpretation,a); | ||
269 | ««« find mustExist(problem,interpretation,b); | ||
270 | ««« PrimitiveElement.valueSet(a,true); | ||
271 | ««« PrimitiveElement.valueSet(b,true); | ||
272 | ««« IntegerElement.value(a,value); | ||
273 | ««« IntegerElement.value(b,value); | ||
274 | ««« } or { | ||
275 | ««« find mustExist(problem,interpretation,a); | ||
276 | ««« find mustExist(problem,interpretation,b); | ||
277 | ««« PrimitiveElement.valueSet(a,true); | ||
278 | ««« PrimitiveElement.valueSet(b,true); | ||
279 | ««« RealElement.value(a,value); | ||
280 | ««« RealElement.value(b,value); | ||
281 | ««« } or { | ||
282 | ««« find mustExist(problem,interpretation,a); | ||
283 | ««« find mustExist(problem,interpretation,b); | ||
284 | ««« PrimitiveElement.valueSet(a,true); | ||
285 | ««« PrimitiveElement.valueSet(b,true); | ||
286 | ««« StringElement.value(a,value); | ||
287 | ««« StringElement.value(b,value); | ||
210 | } | 288 | } |
211 | 289 | ||
212 | //////////////////////// | ||
213 | // 0.3 Required Patterns by TypeIndexer | ||
214 | //////////////////////// | ||
215 | «typeIndexer.requiredQueries» | ||
216 | |||
217 | ////////// | 290 | ////////// |
218 | // 1. Problem-Specific Base Indexers | 291 | // 1. Problem-Specific Base Indexers |
219 | ////////// | 292 | ////////// |
220 | // 1.1 Type Indexers | 293 | // 1.1 Type Indexers |
221 | ////////// | 294 | ////////// |
222 | // 1.1.1 primitive Type Indexers | 295 | // 1.1.1 Required Patterns by TypeIndexer |
223 | ////////// | 296 | ////////// |
224 | ««« pattern instanceofBoolean(problem:LogicProblem, interpretation:PartialInterpretation, element:DefinedElement) { | 297 | |
225 | ««« find interpretation(problem,interpretation); | 298 | «typeIndexer.requiredQueries» |
226 | ««« PartialInterpretation.booleanelements(interpretation,element); | ||
227 | ««« } | ||
228 | ««« pattern instanceofInteger(problem:LogicProblem, interpretation:PartialInterpretation, element:DefinedElement) { | ||
229 | ««« find interpretation(problem,interpretation); | ||
230 | ««« PartialInterpretation.integerelements(interpretation,element); | ||
231 | ««« } or { | ||
232 | ««« find interpretation(problem,interpretation); | ||
233 | ««« PartialInterpretation.newIntegers(interpetation,element); | ||
234 | ««« } | ||
235 | ««« pattern instanceofReal(problem:LogicProblem, interpretation:PartialInterpretation, element:DefinedElement) { | ||
236 | ««« find interpretation(problem,interpretation); | ||
237 | ««« PartialInterpretation.realelements(interpretation,element); | ||
238 | ««« } or { | ||
239 | ««« find interpretation(problem,interpretation); | ||
240 | ««« PartialInterpretation.newReals(interpetation,element); | ||
241 | ««« } | ||
242 | ««« pattern instanceofString(problem:LogicProblem, interpretation:PartialInterpretation, element:DefinedElement) { | ||
243 | ««« find interpretation(problem,interpretation); | ||
244 | ««« PartialInterpretation.stringelements(interpretation,element); | ||
245 | ««« } or { | ||
246 | ««« find interpretation(problem,interpretation); | ||
247 | ««« PartialInterpretation.newStrings(interpetation,element); | ||
248 | ««« } | ||
249 | 299 | ||
250 | ////////// | 300 | ////////// |
251 | // 1.1.2 domain-specific Type Indexers | 301 | // 1.1.2 primitive Type Indexers |
302 | ////////// | ||
303 | // Currently unused. Refer primitive types as: | ||
304 | // > PrimitiveElement(element) | ||
305 | // specific types are referred as: | ||
306 | // > BooleanElement(variableName) | ||
307 | // > IntegerElement(variableName) | ||
308 | // > RealElement(variableName) | ||
309 | // > StringElement(variableName) | ||
310 | // And their value as | ||
311 | // > BooleanElement.value(variableName,value) | ||
312 | // > IntegerElement.value(variableName,value) | ||
313 | // > RealElement.value(variableName,value) | ||
314 | // > StringElement.value(variableName,value) | ||
315 | // Whether a value is set is defined by: | ||
316 | // > PrimitiveElement.valueSet(variableName,isFilled); | ||
317 | |||
318 | ////////// | ||
319 | // 1.1.3 domain-specific Type Indexers | ||
252 | ////////// | 320 | ////////// |
253 | «typeIndexer.generateInstanceOfQueries(problem,emptySolution,typeAnalysisResult)» | 321 | «typeIndexer.generateInstanceOfQueries(problem,emptySolution,typeAnalysisResult)» |
254 | 322 | ||
255 | ////////// | 323 | ////////// |
256 | // 1.2 Relation Declaration Indexers | 324 | // 1.2 Relation Declaration Indexers |
257 | ////////// | 325 | ////////// |
258 | «relationDeclarationIndexer.generateRelationIndexers(problem,problem.relations.filter(RelationDeclaration),fqn2PQuery)» | 326 | «relationDeclarationIndexer.generateRelationIndexers(problem,problem.relations.filter(RelationDeclaration),unitPropagationPatternGenerators,fqn2PQuery)» |
259 | 327 | ||
260 | ////////// | 328 | ////////// |
261 | // 1.3 Relation Definition Indexers | 329 | // 1.3 Relation Definition Indexers |
@@ -279,7 +347,7 @@ class PatternGenerator { | |||
279 | ////////// | 347 | ////////// |
280 | // 3.1 Unfinishedness Measured by Multiplicity | 348 | // 3.1 Unfinishedness Measured by Multiplicity |
281 | ////////// | 349 | ////////// |
282 | «unfinishedIndexer.generateUnfinishedMultiplicityQueries(problem,fqn2PQuery)» | 350 | «unfinishedIndexer.generateUnfinishedMultiplicityQueries(constraints.multiplicityConstraints,fqn2PQuery)» |
283 | 351 | ||
284 | ////////// | 352 | ////////// |
285 | // 3.2 Unfinishedness Measured by WF Queries | 353 | // 3.2 Unfinishedness Measured by WF Queries |
@@ -301,7 +369,24 @@ class PatternGenerator { | |||
301 | ////////// | 369 | ////////// |
302 | // 4.3 Relation refinement | 370 | // 4.3 Relation refinement |
303 | ////////// | 371 | ////////// |
304 | «relationRefinementGenerator.generateRefineReference(problem)» | 372 | «relationRefinementGenerator.generateRefineReference(problem, unitPropagationPatternGenerators)» |
373 | |||
374 | ////////// | ||
375 | // 5 Hints | ||
376 | ////////// | ||
377 | «FOR hint : hints» | ||
378 | «hint.getAdditionalPatterns(this, fqn2PQuery)» | ||
379 | «ENDFOR» | ||
380 | «FOR generator : unitPropagationPatternGenerators» | ||
381 | «generator.getAdditionalPatterns(this, fqn2PQuery)» | ||
382 | «ENDFOR» | ||
383 | |||
384 | ////////// | ||
385 | // 6 Unit Propagations | ||
386 | ////////// | ||
305 | ''' | 387 | ''' |
388 | val up = unitPropagationPreconditionGenerator.generateUnitPropagationRules(problem,problem.relations.filter(RelationDefinition),fqn2PQuery) | ||
389 | val second = up.definitions | ||
390 | return new PatternGeneratorResult(first+second,up.constraint2MustPreconditionName,up.constraint2CurrentPreconditionName) | ||
306 | } | 391 | } |
307 | } | 392 | } |