aboutsummaryrefslogtreecommitdiffstats
path: root/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/cardinality/PolyhedronScopePropagator.xtend
diff options
context:
space:
mode:
Diffstat (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/cardinality/PolyhedronScopePropagator.xtend')
-rw-r--r--Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/cardinality/PolyhedronScopePropagator.xtend54
1 files changed, 16 insertions, 38 deletions
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/cardinality/PolyhedronScopePropagator.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/cardinality/PolyhedronScopePropagator.xtend
index c28d4caa..ad8f94ab 100644
--- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/cardinality/PolyhedronScopePropagator.xtend
+++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/cardinality/PolyhedronScopePropagator.xtend
@@ -1,7 +1,5 @@
1package hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality 1package hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality
2 2
3import com.google.common.cache.Cache
4import com.google.common.cache.CacheBuilder
5import com.google.common.collect.ImmutableList 3import com.google.common.collect.ImmutableList
6import com.google.common.collect.ImmutableMap 4import com.google.common.collect.ImmutableMap
7import com.google.common.collect.ImmutableSet 5import com.google.common.collect.ImmutableSet
@@ -23,7 +21,6 @@ import java.util.HashSet
23import java.util.List 21import java.util.List
24import java.util.Map 22import java.util.Map
25import java.util.Set 23import java.util.Set
26import javax.naming.OperationNotSupportedException
27import org.eclipse.viatra.query.runtime.api.IPatternMatch 24import org.eclipse.viatra.query.runtime.api.IPatternMatch
28import org.eclipse.viatra.query.runtime.api.IQuerySpecification 25import org.eclipse.viatra.query.runtime.api.IQuerySpecification
29import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine 26import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine
@@ -32,31 +29,29 @@ import org.eclipse.viatra.query.runtime.emf.EMFScope
32import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor 29import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor
33 30
34class PolyhedronScopePropagator extends TypeHierarchyScopePropagator { 31class PolyhedronScopePropagator extends TypeHierarchyScopePropagator {
35 static val CACHE_SIZE = 10000
36
37 val boolean updateHeuristic 32 val boolean updateHeuristic
38 val Map<Scope, LinearBoundedExpression> scopeBounds 33 val Map<Scope, LinearBoundedExpression> scopeBounds
39 val LinearBoundedExpression topLevelBounds 34 val LinearBoundedExpression topLevelBounds
40 val Polyhedron polyhedron 35 val Polyhedron polyhedron
41 val PolyhedronSaturationOperator operator 36 val PolyhedronScopePropagatorStrategy strategy
42 val Set<Relation> relevantRelations 37 val Set<Relation> relevantRelations
43 val Cache<PolyhedronSignature, PolyhedronSignature> cache = CacheBuilder.newBuilder.maximumSize(CACHE_SIZE).build
44 List<RelationConstraintUpdater> updaters = emptyList 38 List<RelationConstraintUpdater> updaters = emptyList
45 39
46 new(PartialInterpretation p, ModelGenerationStatistics statistics, Set<? extends Type> possibleNewDynamicTypes, 40 new(PartialInterpretation p, ModelGenerationStatistics statistics, Set<? extends Type> possibleNewDynamicTypes,
47 Map<RelationMultiplicityConstraint, UnifinishedMultiplicityQueries> unfinishedMultiplicityQueries, 41 Map<RelationMultiplicityConstraint, UnifinishedMultiplicityQueries> unfinishedMultiplicityQueries,
48 IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> hasElementInContainmentQuery, 42 IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> hasElementInContainmentQuery,
49 Map<String, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> allPatternsByName, 43 Map<String, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> allPatternsByName,
50 Collection<LinearTypeConstraintHint> hints, PolyhedronSolver solver, boolean propagateRelations, 44 Collection<LinearTypeConstraintHint> hints, PolyhedronScopePropagatorStrategy strategy,
51 boolean updateHeuristic) { 45 boolean propagateRelations, boolean updateHeuristic) {
52 super(p, statistics) 46 super(p, statistics)
53 this.updateHeuristic = updateHeuristic 47 this.updateHeuristic = updateHeuristic
48 this.strategy = strategy
54 val builder = new PolyhedronBuilder(p) 49 val builder = new PolyhedronBuilder(p)
55 builder.buildPolyhedron(possibleNewDynamicTypes) 50 builder.buildPolyhedron(possibleNewDynamicTypes)
56 scopeBounds = builder.scopeBounds 51 scopeBounds = builder.scopeBounds
57 topLevelBounds = builder.topLevelBounds 52 topLevelBounds = builder.topLevelBounds
58 polyhedron = builder.polyhedron 53 polyhedron = builder.polyhedron
59 operator = solver.createSaturationOperator(polyhedron) 54 strategy.setPolyhedron(polyhedron, builder.typeBounds, builder.expressionsCache)
60 propagateAllScopeConstraints() 55 propagateAllScopeConstraints()
61 if (propagateRelations) { 56 if (propagateRelations) {
62 val maximumNumberOfNewNodes = topLevelBounds.upperBound 57 val maximumNumberOfNewNodes = topLevelBounds.upperBound
@@ -80,30 +75,10 @@ class PolyhedronScopePropagator extends TypeHierarchyScopePropagator {
80 resetBounds() 75 resetBounds()
81 populatePolyhedronFromScope() 76 populatePolyhedronFromScope()
82// println(polyhedron) 77// println(polyhedron)
83 val signature = polyhedron.createSignature 78 if (strategy.saturate) {
84 val cachedSignature = cache.getIfPresent(signature) 79 populateScopesFromPolyhedron()
85 switch (cachedSignature) { 80 } else {
86 case null: { 81 setScopesInvalid()
87 statistics.incrementScopePropagationSolverCount
88 val result = operator.saturate()
89 if (result == PolyhedronSaturationResult.EMPTY) {
90 cache.put(signature, PolyhedronSignature.EMPTY)
91// println("INVALID")
92 setScopesInvalid()
93 } else {
94 val resultSignature = polyhedron.createSignature
95 cache.put(signature, resultSignature)
96 populateScopesFromPolyhedron()
97 }
98 }
99 case PolyhedronSignature.EMPTY:
100 setScopesInvalid()
101 PolyhedronSignature.Bounds: {
102 polyhedron.applySignature(signature)
103 populateScopesFromPolyhedron()
104 }
105 default:
106 throw new IllegalStateException("Unknown polyhedron signature: " + signature)
107 } 82 }
108// println(polyhedron) 83// println(polyhedron)
109 if (updateHeuristic) { 84 if (updateHeuristic) {
@@ -112,9 +87,9 @@ class PolyhedronScopePropagator extends TypeHierarchyScopePropagator {
112 } 87 }
113 88
114 override isPropagationNeededAfterAdditionToRelation(Relation r) { 89 override isPropagationNeededAfterAdditionToRelation(Relation r) {
115 relevantRelations.contains(r) || super.isPropagationNeededAfterAdditionToRelation(r) 90 relevantRelations.contains(r) || strategy.isRelevantRelation(r) || super.isPropagationNeededAfterAdditionToRelation(r)
116 } 91 }
117 92
118 override isQueryEngineFlushRequiredBeforePropagation() { 93 override isQueryEngineFlushRequiredBeforePropagation() {
119 true 94 true
120 } 95 }
@@ -253,7 +228,10 @@ class PolyhedronScopePropagator extends TypeHierarchyScopePropagator {
253 } 228 }
254 buildRelevantRelations(constraints.keySet) 229 buildRelevantRelations(constraints.keySet)
255 for (hint : hints) { 230 for (hint : hints) {
256 updatersBuilder.add(hint.createConstraintUpdater(this)) 231 val updater = hint.createConstraintUpdater(this)
232 if (updater !== null) {
233 updatersBuilder.add(updater)
234 }
257 } 235 }
258 updaters = updatersBuilder.build 236 updaters = updatersBuilder.build
259 addCachedConstraintsToPolyhedron() 237 addCachedConstraintsToPolyhedron()
@@ -410,7 +388,7 @@ class PolyhedronScopePropagator extends TypeHierarchyScopePropagator {
410 for (scope : p.scopes) { 388 for (scope : p.scopes) {
411 switch (targetTypeInterpretation : scope.targetTypeInterpretation) { 389 switch (targetTypeInterpretation : scope.targetTypeInterpretation) {
412 PartialPrimitiveInterpretation: 390 PartialPrimitiveInterpretation:
413 throw new OperationNotSupportedException("Primitive type scopes are not yet implemented") 391 throw new IllegalStateException("Primitive type scopes are not yet implemented")
414 PartialComplexTypeInterpretation: { 392 PartialComplexTypeInterpretation: {
415 val complexType = targetTypeInterpretation.interpretationOf 393 val complexType = targetTypeInterpretation.interpretationOf
416 val typeBound = typeBounds.get(complexType) 394 val typeBound = typeBounds.get(complexType)