diff options
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.xtend | 33 |
1 files changed, 30 insertions, 3 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 f6b101b6..e7e40ab0 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 | |||
@@ -2,9 +2,12 @@ package hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality | |||
2 | 2 | ||
3 | import com.google.common.collect.ImmutableList | 3 | import com.google.common.collect.ImmutableList |
4 | import com.google.common.collect.ImmutableMap | 4 | import com.google.common.collect.ImmutableMap |
5 | import com.google.common.collect.ImmutableSet | ||
5 | import com.google.common.collect.Maps | 6 | import com.google.common.collect.Maps |
6 | import com.google.common.collect.Sets | 7 | import com.google.common.collect.Sets |
8 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Relation | ||
7 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type | 9 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type |
10 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.ModelGenerationStatistics | ||
8 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.patterns.UnifinishedMultiplicityQueries | 11 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.patterns.UnifinishedMultiplicityQueries |
9 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialComplexTypeInterpretation | 12 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialComplexTypeInterpretation |
10 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation | 13 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation |
@@ -30,13 +33,14 @@ class PolyhedronScopePropagator extends ScopePropagator { | |||
30 | val LinearBoundedExpression topLevelBounds | 33 | val LinearBoundedExpression topLevelBounds |
31 | val Polyhedron polyhedron | 34 | val Polyhedron polyhedron |
32 | val PolyhedronSaturationOperator operator | 35 | val PolyhedronSaturationOperator operator |
36 | val Set<Relation> relevantRelations | ||
33 | List<RelationConstraintUpdater> updaters = emptyList | 37 | List<RelationConstraintUpdater> updaters = emptyList |
34 | 38 | ||
35 | new(PartialInterpretation p, Set<? extends Type> possibleNewDynamicTypes, | 39 | new(PartialInterpretation p, ModelGenerationStatistics statistics, Set<? extends Type> possibleNewDynamicTypes, |
36 | Map<RelationMultiplicityConstraint, UnifinishedMultiplicityQueries> unfinishedMultiplicityQueries, | 40 | Map<RelationMultiplicityConstraint, UnifinishedMultiplicityQueries> unfinishedMultiplicityQueries, |
37 | IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> hasElementInContainmentQuery, | 41 | IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> hasElementInContainmentQuery, |
38 | PolyhedronSolver solver, boolean propagateRelations) { | 42 | PolyhedronSolver solver, boolean propagateRelations) { |
39 | super(p) | 43 | super(p, statistics) |
40 | val builder = new PolyhedronBuilder(p) | 44 | val builder = new PolyhedronBuilder(p) |
41 | builder.buildPolyhedron(possibleNewDynamicTypes) | 45 | builder.buildPolyhedron(possibleNewDynamicTypes) |
42 | scopeBounds = builder.scopeBounds | 46 | scopeBounds = builder.scopeBounds |
@@ -54,11 +58,14 @@ class PolyhedronScopePropagator extends ScopePropagator { | |||
54 | } | 58 | } |
55 | builder.buildMultiplicityConstraints(unfinishedMultiplicityQueries, hasElementInContainmentQuery, | 59 | builder.buildMultiplicityConstraints(unfinishedMultiplicityQueries, hasElementInContainmentQuery, |
56 | maximumNumberOfNewNodes) | 60 | maximumNumberOfNewNodes) |
61 | relevantRelations = builder.relevantRelations | ||
57 | updaters = builder.updaters | 62 | updaters = builder.updaters |
63 | } else { | ||
64 | relevantRelations = emptySet | ||
58 | } | 65 | } |
59 | } | 66 | } |
60 | 67 | ||
61 | override void propagateAllScopeConstraints() { | 68 | override void doPropagateAllScopeConstraints() { |
62 | resetBounds() | 69 | resetBounds() |
63 | populatePolyhedronFromScope() | 70 | populatePolyhedronFromScope() |
64 | // println(polyhedron) | 71 | // println(polyhedron) |
@@ -73,6 +80,13 @@ class PolyhedronScopePropagator extends ScopePropagator { | |||
73 | } | 80 | } |
74 | } | 81 | } |
75 | } | 82 | } |
83 | |||
84 | override propagateAdditionToRelation(Relation r) { | ||
85 | super.propagateAdditionToRelation(r) | ||
86 | if (relevantRelations.contains(r)) { | ||
87 | propagateAllScopeConstraints() | ||
88 | } | ||
89 | } | ||
76 | 90 | ||
77 | def resetBounds() { | 91 | def resetBounds() { |
78 | for (dimension : polyhedron.dimensions) { | 92 | for (dimension : polyhedron.dimensions) { |
@@ -188,6 +202,7 @@ class PolyhedronScopePropagator extends ScopePropagator { | |||
188 | Map<Scope, LinearBoundedExpression> scopeBounds | 202 | Map<Scope, LinearBoundedExpression> scopeBounds |
189 | LinearBoundedExpression topLevelBounds | 203 | LinearBoundedExpression topLevelBounds |
190 | Polyhedron polyhedron | 204 | Polyhedron polyhedron |
205 | Set<Relation> relevantRelations | ||
191 | List<RelationConstraintUpdater> updaters | 206 | List<RelationConstraintUpdater> updaters |
192 | 207 | ||
193 | def buildPolyhedron(Set<? extends Type> possibleNewDynamicTypes) { | 208 | def buildPolyhedron(Set<? extends Type> possibleNewDynamicTypes) { |
@@ -222,9 +237,21 @@ class PolyhedronScopePropagator extends ScopePropagator { | |||
222 | buildNonContainmentConstraints(constraint, pair.value) | 237 | buildNonContainmentConstraints(constraint, pair.value) |
223 | } | 238 | } |
224 | } | 239 | } |
240 | buildRelevantRelations(constraints.keySet) | ||
225 | updaters = updatersBuilder.build | 241 | updaters = updatersBuilder.build |
226 | addCachedConstraintsToPolyhedron() | 242 | addCachedConstraintsToPolyhedron() |
227 | } | 243 | } |
244 | |||
245 | private def buildRelevantRelations(Set<RelationMultiplicityConstraint> constraints) { | ||
246 | val builder = ImmutableSet.builder | ||
247 | for (constraint : constraints) { | ||
248 | builder.add(constraint.relation) | ||
249 | if (constraint.inverseRelation !== null) { | ||
250 | builder.add(constraint.inverseRelation) | ||
251 | } | ||
252 | } | ||
253 | relevantRelations = builder.build | ||
254 | } | ||
228 | 255 | ||
229 | private def addCachedConstraintsToPolyhedron() { | 256 | private def addCachedConstraintsToPolyhedron() { |
230 | val constraints = new HashSet | 257 | val constraints = new HashSet |