diff options
author | 2020-04-30 20:15:24 +0200 | |
---|---|---|
committer | 2020-04-30 20:15:24 +0200 | |
commit | 363e62749b7415d67906ba8df46d6da8655b1869 (patch) | |
tree | 5a33fc88039c28b7ae6869e112b0fb1e2aa31bee /Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf | |
parent | UP rule precondition provider (diff) | |
download | VIATRA-Generator-363e62749b7415d67906ba8df46d6da8655b1869.tar.gz VIATRA-Generator-363e62749b7415d67906ba8df46d6da8655b1869.tar.zst VIATRA-Generator-363e62749b7415d67906ba8df46d6da8655b1869.zip |
UnitPropagationProvider added to the generated patterns
Diffstat (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf')
2 files changed, 32 insertions, 6 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 379e334a..56138ee8 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 | |||
@@ -36,6 +36,7 @@ class PatternGenerator { | |||
36 | @Accessors(PUBLIC_GETTER) val UnfinishedIndexer unfinishedIndexer = new UnfinishedIndexer(this) | 36 | @Accessors(PUBLIC_GETTER) val UnfinishedIndexer unfinishedIndexer = new UnfinishedIndexer(this) |
37 | @Accessors(PUBLIC_GETTER) val TypeRefinementGenerator typeRefinementGenerator //= new RefinementGenerator(this) | 37 | @Accessors(PUBLIC_GETTER) val TypeRefinementGenerator typeRefinementGenerator //= new RefinementGenerator(this) |
38 | @Accessors(PUBLIC_GETTER) val RelationRefinementGenerator relationRefinementGenerator = new RelationRefinementGenerator(this) | 38 | @Accessors(PUBLIC_GETTER) val RelationRefinementGenerator relationRefinementGenerator = new RelationRefinementGenerator(this) |
39 | @Accessors(PUBLIC_GETTER) val UnitPropagationPreconditionGenerator unitPropagationPreconditionGenerator = new UnitPropagationPreconditionGenerator(this) | ||
39 | 40 | ||
40 | public new(TypeInferenceMethod typeInferenceMethod) { | 41 | public new(TypeInferenceMethod typeInferenceMethod) { |
41 | if(typeInferenceMethod == TypeInferenceMethod.Generic) { | 42 | if(typeInferenceMethod == TypeInferenceMethod.Generic) { |
@@ -390,6 +391,11 @@ class PatternGenerator { | |||
390 | // 4.3 Relation refinement | 391 | // 4.3 Relation refinement |
391 | ////////// | 392 | ////////// |
392 | «relationRefinementGenerator.generateRefineReference(problem)» | 393 | «relationRefinementGenerator.generateRefineReference(problem)» |
394 | |||
395 | ////////// | ||
396 | // 5 Unit Propagations | ||
397 | ////////// | ||
398 | «unitPropagationPreconditionGenerator.generateUnitPropagationRules(problem,problem.relations.filter(RelationDefinition),fqn2PQuery)» | ||
393 | ''' | 399 | ''' |
394 | } | 400 | } |
395 | } | 401 | } |
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/UnitPropagationPreconditionGenerator.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/UnitPropagationPreconditionGenerator.xtend index 25354af4..6cd94657 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/UnitPropagationPreconditionGenerator.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/UnitPropagationPreconditionGenerator.xtend | |||
@@ -32,6 +32,7 @@ import java.util.ArrayList | |||
32 | class UnitPropagationPreconditionGenerationResult { | 32 | class UnitPropagationPreconditionGenerationResult { |
33 | List<CharSequence> definitions= new LinkedList | 33 | List<CharSequence> definitions= new LinkedList |
34 | Map<UnitPropagation,String> unitPropagation2PatternName = new HashMap | 34 | Map<UnitPropagation,String> unitPropagation2PatternName = new HashMap |
35 | Map<PConstraint,String> constraintOccurence2Name = new HashMap | ||
35 | 36 | ||
36 | def registerQuery(PQuery q, PConstraint c, PropagationModality pm, Modality m3, String patternName, CharSequence definition) { | 37 | def registerQuery(PQuery q, PConstraint c, PropagationModality pm, Modality m3, String patternName, CharSequence definition) { |
37 | val key = new UnitPropagation(q,c,pm,m3) | 38 | val key = new UnitPropagation(q,c,pm,m3) |
@@ -72,17 +73,27 @@ class UnitPropagationPreconditionGenerator { | |||
72 | { | 73 | { |
73 | // Create an empty result | 74 | // Create an empty result |
74 | val res = new UnitPropagationPreconditionGenerationResult | 75 | val res = new UnitPropagationPreconditionGenerationResult |
75 | |||
76 | val wfs = base.wfQueries(problem)//.map[it.patternPQuery] | 76 | val wfs = base.wfQueries(problem)//.map[it.patternPQuery] |
77 | val mainPropagationNames = new LinkedList | ||
77 | for(wf : wfs) { | 78 | for(wf : wfs) { |
78 | val query = wf.patternPQuery as PQuery | 79 | val query = wf.patternPQuery as PQuery |
79 | val relation = wf.target | 80 | val relation = wf.target |
80 | val allReferredChecks = query.allReferredConstraints.filter(ExpressionEvaluation) | 81 | val allReferredChecks = query.allReferredConstraints.filter(ExpressionEvaluation) |
81 | 82 | ||
82 | for(referredCheck : allReferredChecks) { | 83 | for(referredCheck : allReferredChecks) { |
83 | generatePropagationRule(res,relation,query,referredCheck,PropagationModality::UP, Modality::MUST) | 84 | mainPropagationNames+= getOrGeneratePropagationRule(res,relation,query,referredCheck,PropagationModality::UP, Modality::MUST) |
84 | } | 85 | } |
85 | } | 86 | } |
87 | return ''' | ||
88 | «FOR def : res.definitions» | ||
89 | «def» | ||
90 | «ENDFOR» | ||
91 | |||
92 | // Main propagations: | ||
93 | «FOR name : mainPropagationNames» | ||
94 | «name» | ||
95 | «ENDFOR» | ||
96 | ''' | ||
86 | } | 97 | } |
87 | def allReferredConstraints(PQuery query) { | 98 | def allReferredConstraints(PQuery query) { |
88 | val allReferredQueries = query.allReferredQueries | 99 | val allReferredQueries = query.allReferredQueries |
@@ -97,9 +108,18 @@ class UnitPropagationPreconditionGenerator { | |||
97 | return res.getName(q,c,pm,m3) | 108 | return res.getName(q,c,pm,m3) |
98 | } | 109 | } |
99 | } | 110 | } |
111 | def getOrGenerateConstraintName(UnitPropagationPreconditionGenerationResult res, PConstraint c){ | ||
112 | if(res.constraintOccurence2Name.containsKey(c)) { | ||
113 | return res.constraintOccurence2Name.get(c) | ||
114 | } else { | ||
115 | val constraintName = '''Constraint«res.constraintOccurence2Name.size»''' | ||
116 | res.constraintOccurence2Name.put(c,constraintName) | ||
117 | return constraintName | ||
118 | } | ||
119 | } | ||
100 | 120 | ||
101 | def void generatePropagationRule(UnitPropagationPreconditionGenerationResult res, Relation relation, PQuery q, PConstraint c, PropagationModality pm, Modality m3) { | 121 | def void generatePropagationRule(UnitPropagationPreconditionGenerationResult res, Relation relation, PQuery q, PConstraint c, PropagationModality pm, Modality m3) { |
102 | val name = relationDefinitionName(relation,q,c,pm,m3) | 122 | val name = relationDefinitionName(res,relation,q,c,pm,m3) |
103 | val constraintArity = c.arity | 123 | val constraintArity = c.arity |
104 | val generatedBodies = new LinkedList | 124 | val generatedBodies = new LinkedList |
105 | for(body : q.disjunctBodies.bodies) { | 125 | for(body : q.disjunctBodies.bodies) { |
@@ -180,7 +200,7 @@ class UnitPropagationPreconditionGenerator { | |||
180 | problem:LogicProblem, interpretation:PartialInterpretation, | 200 | problem:LogicProblem, interpretation:PartialInterpretation, |
181 | «FOR param : q.parameters SEPARATOR ', '»var_«param.name»«ENDFOR», | 201 | «FOR param : q.parameters SEPARATOR ', '»var_«param.name»«ENDFOR», |
182 | «FOR arity : 1..constraintArity SEPARATOR ', '»«canonizeName(arity,pm)»«ENDFOR») | 202 | «FOR arity : 1..constraintArity SEPARATOR ', '»«canonizeName(arity,pm)»«ENDFOR») |
183 | «FOR generatedBody: generatedBodies SEPARATOR "or"»{ | 203 | «FOR generatedBody: generatedBodies SEPARATOR " or "»{ |
184 | «generatedBody» | 204 | «generatedBody» |
185 | }«ENDFOR» | 205 | }«ENDFOR» |
186 | ''' | 206 | ''' |
@@ -188,8 +208,8 @@ class UnitPropagationPreconditionGenerator { | |||
188 | } | 208 | } |
189 | } | 209 | } |
190 | 210 | ||
191 | private def String relationDefinitionName(Relation relation, PQuery q, PConstraint c, PropagationModality pm, Modality m3) | 211 | private def String relationDefinitionName(UnitPropagationPreconditionGenerationResult res, Relation relation, PQuery q, PConstraint c, PropagationModality pm, Modality m3) |
192 | '''«pm.name»«m3.name»Propagate_«base.canonizeName(relation.name)»''' | 212 | '''«pm.name»«m3.name»Propagate«res.getOrGenerateConstraintName(c)»_«base.canonizeName(relation.name)»''' |
193 | 213 | ||
194 | def canonizeName(PVariable v) { | 214 | def canonizeName(PVariable v) { |
195 | return '''«IF v.referringConstraints.size == 1»_«ENDIF»var_«v.name.replaceAll("\\W","")»''' | 215 | return '''«IF v.referringConstraints.size == 1»_«ENDIF»var_«v.name.replaceAll("\\W","")»''' |