aboutsummaryrefslogtreecommitdiffstats
path: root/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <marussy@mit.bme.hu>2020-08-28 18:58:37 +0200
committerLibravatar Kristóf Marussy <marussy@mit.bme.hu>2020-08-28 18:58:37 +0200
commit4fe7fce97aedbd516109ef81afc33e00112b7b68 (patch)
tree7eaa7c4e9b31b2a1488e49de48721b4dbad31fae /Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns
parentMoDeS3 unit propagation WIP (diff)
downloadVIATRA-Generator-4fe7fce97aedbd516109ef81afc33e00112b7b68.tar.gz
VIATRA-Generator-4fe7fce97aedbd516109ef81afc33e00112b7b68.tar.zst
VIATRA-Generator-4fe7fce97aedbd516109ef81afc33e00112b7b68.zip
Must unit propagation
Diffstat (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns')
-rw-r--r--Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/PatternGenerator.xtend4
-rw-r--r--Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/PatternProvider.xtend11
-rw-r--r--Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/RelationDeclarationIndexer.xtend2
-rw-r--r--Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/RelationRefinementGenerator.xtend137
4 files changed, 112 insertions, 42 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 a3efcf76..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
@@ -369,13 +369,13 @@ class PatternGenerator {
369 ////////// 369 //////////
370 // 4.3 Relation refinement 370 // 4.3 Relation refinement
371 ////////// 371 //////////
372 «relationRefinementGenerator.generateRefineReference(problem)» 372 «relationRefinementGenerator.generateRefineReference(problem, unitPropagationPatternGenerators
373 373
374 ////////// 374 //////////
375 // 5 Hints 375 // 5 Hints
376 ////////// 376 //////////
377 «FOR hint : hints» 377 «FOR hint : hints»
378 «hint.getAdditionalPatterns(this)» 378 «hint.getAdditionalPatterns(this, fqn2PQuery
379 «ENDFOR» 379 «ENDFOR»
380 «FOR generator : unitPropagationPatternGenerators» 380 «FOR generator : unitPropagationPatternGenerators»
381 «generator.getAdditionalPatterns(this, fqn2PQuery)» 381 «generator.getAdditionalPatterns(this, fqn2PQuery)»
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/PatternProvider.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/PatternProvider.xtend
index 21fd1989..2e786286 100644
--- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/PatternProvider.xtend
+++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/PatternProvider.xtend
@@ -38,7 +38,8 @@ import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.*
38 public IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> hasElementInContainmentQuery 38 public IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> hasElementInContainmentQuery
39 public Map<ObjectCreationPrecondition, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> refineObjectQueries 39 public Map<ObjectCreationPrecondition, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> refineObjectQueries
40 public Map<? extends Type, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> refineTypeQueries 40 public Map<? extends Type, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> refineTypeQueries
41 public Map<Pair<RelationDeclaration, Relation>, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> refinerelationQueries 41 public Map<Pair<RelationDeclaration, Relation>, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> refineRelationQueries
42 public Map<Pair<RelationDeclaration, Relation>, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> mustRelationPropagationQueries
42 public Map<PConstraint, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> mustUnitPropagationPreconditionPatterns 43 public Map<PConstraint, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> mustUnitPropagationPreconditionPatterns
43 public Map<PConstraint, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> currentUnitPropagationPreconditionPatterns 44 public Map<PConstraint, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> currentUnitPropagationPreconditionPatterns
44 public Map<RelationDefinition, ModalPatternQueries> modalRelationQueries 45 public Map<RelationDefinition, ModalPatternQueries> modalRelationQueries
@@ -70,7 +71,6 @@ class UnifinishedMultiplicityQueries {
70} 71}
71 72
72class PatternProvider { 73class PatternProvider {
73
74 val TypeAnalysis typeAnalysis = new TypeAnalysis 74 val TypeAnalysis typeAnalysis = new TypeAnalysis
75 75
76 def generateQueries(LogicProblem problem, PartialInterpretation emptySolution, ModelGenerationStatistics statistics, 76 def generateQueries(LogicProblem problem, PartialInterpretation emptySolution, ModelGenerationStatistics statistics,
@@ -98,7 +98,8 @@ class PatternProvider {
98 val generatedQueries = parseUtil.parse(patternGeneratorResult.patternText) 98 val generatedQueries = parseUtil.parse(patternGeneratorResult.patternText)
99 val runtimeQueries = calclulateRuntimeQueries(patternGenerator, problem, emptySolution, typeAnalysisResult, 99 val runtimeQueries = calclulateRuntimeQueries(patternGenerator, problem, emptySolution, typeAnalysisResult,
100 patternGeneratorResult.constraint2MustPreconditionName, 100 patternGeneratorResult.constraint2MustPreconditionName,
101 patternGeneratorResult.constraint2CurrentPreconditionName, relationConstraints, generatedQueries) 101 patternGeneratorResult.constraint2CurrentPreconditionName, relationConstraints,
102 unitPropagationPatternGenerators, generatedQueries)
102 return runtimeQueries 103 return runtimeQueries
103 } 104 }
104 105
@@ -110,6 +111,7 @@ class PatternProvider {
110 HashMap<PConstraint, String> mustUnitPropagationTrace, 111 HashMap<PConstraint, String> mustUnitPropagationTrace,
111 HashMap<PConstraint, String> currentUnitPropagationTrace, 112 HashMap<PConstraint, String> currentUnitPropagationTrace,
112 RelationConstraints relationConstraints, 113 RelationConstraints relationConstraints,
114 Collection<UnitPropagationPatternGenerator> unitPropagationPatternGenerators,
113 Map<String, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> queries 115 Map<String, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> queries
114 ) { 116 ) {
115 val Map<Relation, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> invalidWFQueries = patternGenerator. 117 val Map<Relation, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> invalidWFQueries = patternGenerator.
@@ -136,6 +138,8 @@ class PatternProvider {
136 ] 138 ]
137 val Map<Pair<RelationDeclaration, Relation>, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> refineRelationQueries = patternGenerator. 139 val Map<Pair<RelationDeclaration, Relation>, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> refineRelationQueries = patternGenerator.
138 relationRefinementGenerator.getRefineRelationQueries(problem).mapValues[it.lookup(queries)] 140 relationRefinementGenerator.getRefineRelationQueries(problem).mapValues[it.lookup(queries)]
141 val Map<Pair<RelationDeclaration, Relation>, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> mustRelationPropagationQueries = patternGenerator.
142 relationRefinementGenerator.getMustPropagationQueries(problem, unitPropagationPatternGenerators).mapValues[it.lookup(queries)]
139 val Map<PConstraint, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> mustUnitPropagationPreconditionPatterns = mustUnitPropagationTrace. 143 val Map<PConstraint, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> mustUnitPropagationPreconditionPatterns = mustUnitPropagationTrace.
140 mapValues[it.lookup(queries)] 144 mapValues[it.lookup(queries)]
141 val Map<PConstraint, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> currentUnitPropagationPreconditionPatterns = currentUnitPropagationTrace. 145 val Map<PConstraint, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> currentUnitPropagationPreconditionPatterns = currentUnitPropagationTrace.
@@ -158,6 +162,7 @@ class PatternProvider {
158 refineObjectsQueries, 162 refineObjectsQueries,
159 refineTypeQueries, 163 refineTypeQueries,
160 refineRelationQueries, 164 refineRelationQueries,
165 mustRelationPropagationQueries,
161 mustUnitPropagationPreconditionPatterns, 166 mustUnitPropagationPreconditionPatterns,
162 currentUnitPropagationPreconditionPatterns, 167 currentUnitPropagationPreconditionPatterns,
163 modalRelationQueries, 168 modalRelationQueries,
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/RelationDeclarationIndexer.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/RelationDeclarationIndexer.xtend
index 29d3eb61..23ba3cad 100644
--- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/RelationDeclarationIndexer.xtend
+++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/RelationDeclarationIndexer.xtend
@@ -113,7 +113,7 @@ class RelationDeclarationIndexer {
113 // 2. Circle in the containment hierarchy 113 // 2. Circle in the containment hierarchy
114 neg «base.containmentIndexer.referTransitiveMustContains("source","target")» 114 neg «base.containmentIndexer.referTransitiveMustContains("source","target")»
115 «ENDIF» 115 «ENDIF»
116 «IF mustNotRelations.empty» 116 «IF !mustNotRelations.empty»
117 // ![] unit propagation relations 117 // ![] unit propagation relations
118 «FOR mustNotRelation : mustNotRelations» 118 «FOR mustNotRelation : mustNotRelations»
119 neg find «mustNotRelation»(problem, interpretation, source, target); 119 neg find «mustNotRelation»(problem, interpretation, source, target);
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/RelationRefinementGenerator.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/RelationRefinementGenerator.xtend
index 783cd36b..6f5f2402 100644
--- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/RelationRefinementGenerator.xtend
+++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/RelationRefinementGenerator.xtend
@@ -1,10 +1,17 @@
1package hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.patterns 1package hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.patterns
2 2
3import com.google.common.collect.ImmutableList
4import com.google.common.collect.ImmutableMap
5import com.google.common.collect.ImmutableSet
3import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Relation 6import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Relation
4import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RelationDeclaration 7import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RelationDeclaration
5import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem 8import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem
6import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.Modality 9import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.Modality
10import java.util.Collection
7import java.util.LinkedList 11import java.util.LinkedList
12import java.util.Map
13import java.util.Set
14import org.eclipse.xtend2.lib.StringConcatenationClient
8 15
9class RelationRefinementGenerator { 16class RelationRefinementGenerator {
10 PatternGenerator base; 17 PatternGenerator base;
@@ -13,53 +20,61 @@ class RelationRefinementGenerator {
13 this.base = base 20 this.base = base
14 } 21 }
15 22
16 def CharSequence generateRefineReference(LogicProblem p) ''' 23 def CharSequence generateRefineReference(LogicProblem p,
17 «FOR relationRefinement : this.getRelationRefinements(p)» 24 Collection<UnitPropagationPatternGenerator> unitPropagationPatternGenerators) {
18 pattern «relationRefinementQueryName(relationRefinement.key,relationRefinement.value)»( 25 val mustRelations = getMustRelations(unitPropagationPatternGenerators)
19 problem:LogicProblem, interpretation:PartialInterpretation, 26
20 relationIterpretation:PartialRelationInterpretation«IF relationRefinement.value !== null», oppositeInterpretation:PartialRelationInterpretation«ENDIF», 27 '''
21 from: DefinedElement, to: DefinedElement) 28 «FOR relationRefinement : this.getRelationRefinements(p)»
22 { 29 pattern «relationRefinementQueryName(relationRefinement.key,relationRefinement.value)»(
23 find interpretation(problem,interpretation); 30 problem:LogicProblem, interpretation:PartialInterpretation,
24 PartialInterpretation.partialrelationinterpretation(interpretation,relationIterpretation); 31 relationIterpretation:PartialRelationInterpretation«IF relationRefinement.value !== null», oppositeInterpretation:PartialRelationInterpretation«ENDIF»,
25 PartialRelationInterpretation.interpretationOf.name(relationIterpretation,"«relationRefinement.key.name»"); 32 from: DefinedElement, to: DefinedElement)
26 «IF relationRefinement.value !== null» 33 {
27 PartialInterpretation.partialrelationinterpretation(interpretation,oppositeInterpretation); 34 find interpretation(problem,interpretation);
28 PartialRelationInterpretation.interpretationOf.name(oppositeInterpretation,"«relationRefinement.value.name»"); 35 PartialInterpretation.partialrelationinterpretation(interpretation,relationIterpretation);
36 PartialRelationInterpretation.interpretationOf.name(relationIterpretation,"«relationRefinement.key.name»");
37 «IF relationRefinement.value !== null»
38 PartialInterpretation.partialrelationinterpretation(interpretation,oppositeInterpretation);
39 PartialRelationInterpretation.interpretationOf.name(oppositeInterpretation,"«relationRefinement.value.name»");
40 «ENDIF»
41 find mustExist(problem, interpretation, from);
42 find mustExist(problem, interpretation, to);
43 «base.typeIndexer.referInstanceOfByReference(relationRefinement.key.parameters.get(0), Modality::MUST,"from")»
44 «base.typeIndexer.referInstanceOfByReference(relationRefinement.key.parameters.get(1), Modality::MUST,"to")»
45 «base.relationDeclarationIndexer.referRelation(relationRefinement.key,"from","to",Modality.MAY)»
46 neg «base.relationDeclarationIndexer.referRelation(relationRefinement.key,"from","to",Modality.MUST)»
47 }
48
49 «IF isMustPropagationQueryNeeded(relationRefinement.key, relationRefinement.value, mustRelations)»
50 pattern «mustPropagationQueryName(relationRefinement.key)»(
51 problem:LogicProblem, interpretation:PartialInterpretation,
52 relationIterpretation:PartialRelationInterpretation«IF relationRefinement.value !== null», oppositeInterpretation:PartialRelationInterpretation«ENDIF»,
53 from: DefinedElement, to: DefinedElement)
54 «FOR body : getMustPropagationBodies(relationRefinement.key, relationRefinement.value, mustRelations) SEPARATOR " or "»
55 {
56 «referRefinementQuery(relationRefinement.key, relationRefinement.value, "relationIterpretation", "oppositeInterpretation", "from", "to")»
57 «body»
58 }
59 «ENDFOR»
29 «ENDIF» 60 «ENDIF»
30 find mustExist(problem, interpretation, from); 61 «ENDFOR»
31 find mustExist(problem, interpretation, to); 62 '''
32 «base.typeIndexer.referInstanceOfByReference(relationRefinement.key.parameters.get(0), Modality::MUST,"from")» 63 }
33 «base.typeIndexer.referInstanceOfByReference(relationRefinement.key.parameters.get(1), Modality::MUST,"to")»
34 «base.relationDeclarationIndexer.referRelation(relationRefinement.key,"from","to",Modality.MAY)»
35 neg «base.relationDeclarationIndexer.referRelation(relationRefinement.key,"from","to",Modality.MUST)»
36 }
37 «ENDFOR»
38 '''
39 64
40 def String relationRefinementQueryName(RelationDeclaration relation, Relation inverseRelation) { 65 def String relationRefinementQueryName(RelationDeclaration relation, Relation inverseRelation) {
41 '''«IF inverseRelation !== null»refineRelation_«base.canonizeName(relation.name)»_and_«base.canonizeName(inverseRelation.name)»«ELSE»refineRelation_«base.canonizeName(relation.name)»«ENDIF»''' 66 '''«IF inverseRelation !== null»refineRelation_«base.canonizeName(relation.name)»_and_«base.canonizeName(inverseRelation.name)»«ELSE»refineRelation_«base.canonizeName(relation.name)»«ENDIF»'''
42 } 67 }
43 68
69 def String mustPropagationQueryName(RelationDeclaration relation) {
70 '''mustPropagation_«base.canonizeName(relation.name)»'''
71 }
72
44 def referRefinementQuery(RelationDeclaration relation, Relation inverseRelation, String relInterpretationName, 73 def referRefinementQuery(RelationDeclaration relation, Relation inverseRelation, String relInterpretationName,
45 String inverseInterpretationName, String sourceName, 74 String inverseInterpretationName, String sourceName,
46 String targetName) '''find «this.relationRefinementQueryName(relation,inverseRelation)»(problem, interpretation, «relInterpretationName», «IF inverseRelation !== null»«inverseInterpretationName», «ENDIF»«sourceName», «targetName»);''' 75 String targetName) '''find «this.relationRefinementQueryName(relation,inverseRelation)»(problem, interpretation, «relInterpretationName», «IF inverseRelation !== null»«inverseInterpretationName», «ENDIF»«sourceName», «targetName»);'''
47 76
48 def getRefineRelationQueries(LogicProblem p) { 77 def getRefineRelationQueries(LogicProblem p) {
49// val containmentRelations = p.containmentHierarchies.map[containmentRelations].flatten.toSet
50// p.relations.filter(RelationDeclaration).filter[!containmentRelations.contains(it)].toInvertedMap['''refineRelation_«base.canonizeName(it.name)»''']
51 /*
52 * val res = new LinkedHashMap
53 * for(relation: getRelationRefinements(p)) {
54 * if(inverseRelations.containsKey(relation)) {
55 * val name = '''refineRelation_«base.canonizeName(relation.name)»_and_«base.canonizeName(inverseRelations.get(relation).name)»'''
56 * res.put(relation -> inverseRelations.get(relation),name)
57 * } else {
58 * val name = '''refineRelation_«base.canonizeName(relation.name)»'''
59 * res.put(relation -> null,name)
60 * }
61 * }
62 return res*/
63 getRelationRefinements(p).toInvertedMap[relationRefinementQueryName(it.key, it.value)] 78 getRelationRefinements(p).toInvertedMap[relationRefinementQueryName(it.key, it.value)]
64 } 79 }
65 80
@@ -83,4 +98,54 @@ class RelationRefinementGenerator {
83 } 98 }
84 return list 99 return list
85 } 100 }
101
102 def getMustPropagationQueries(LogicProblem p,
103 Collection<UnitPropagationPatternGenerator> unitPropagationPatternGenerators) {
104 val refinements = getRelationRefinements(p)
105 val mustRelations = getMustRelations(unitPropagationPatternGenerators)
106 refinements.filter[isMustPropagationQueryNeeded(key, value, mustRelations)].toInvertedMap [
107 mustPropagationQueryName(key)
108 ]
109 }
110
111 private def getMustRelations(Collection<UnitPropagationPatternGenerator> unitPropagationPatternGenerators) {
112 ImmutableMap.copyOf(unitPropagationPatternGenerators.flatMap[mustPatterns.entrySet].groupBy[key].mapValues [
113 ImmutableSet.copyOf(map[value])
114 ])
115 }
116
117 private def isMustPropagationQueryNeeded(Relation relation, Relation inverseRelation,
118 Map<Relation, ? extends Set<String>> mustRelations) {
119 val mustSet = mustRelations.get(relation)
120 if (mustSet !== null && !mustSet.empty) {
121 return true
122 }
123 if (inverseRelation !== null) {
124 val inverseMustSet = mustRelations.get(inverseRelation)
125 if (inverseMustSet !== null && !inverseMustSet.empty) {
126 return true
127 }
128 }
129 false
130 }
131
132 private def getMustPropagationBodies(Relation relation, Relation inverseRelation,
133 Map<Relation, ? extends Set<String>> mustRelations) {
134 val builder = ImmutableList.<StringConcatenationClient>builder()
135 val mustSet = mustRelations.get(relation)
136 if (mustSet !== null) {
137 for (refinementQuery : mustSet) {
138 builder.add('''find «refinementQuery»(problem, interpretation, from, to);''')
139 }
140 }
141 if (inverseRelation !== null && inverseRelation != relation) {
142 val inverseMustSet = mustRelations.get(inverseRelation)
143 if (inverseMustSet !== null) {
144 for (refinementQuery : inverseMustSet) {
145 builder.add('''find «refinementQuery»(problem, interpretation, to, from);''')
146 }
147 }
148 }
149 builder.build
150 }
86} 151}