diff options
author | 2019-07-24 14:17:45 +0200 | |
---|---|---|
committer | 2019-07-24 14:17:45 +0200 | |
commit | e3e8c7810679acebb3418dd355ca6732b9b117d2 (patch) | |
tree | 39574552b4e89d8bd902527f013be48208d18977 | |
parent | Cardinality propagator WIP (diff) | |
download | VIATRA-Generator-e3e8c7810679acebb3418dd355ca6732b9b117d2.tar.gz VIATRA-Generator-e3e8c7810679acebb3418dd355ca6732b9b117d2.tar.zst VIATRA-Generator-e3e8c7810679acebb3418dd355ca6732b9b117d2.zip |
Containment root constraint propagator
6 files changed, 99 insertions, 51 deletions
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/ModelGenerationMethodProvider.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/ModelGenerationMethodProvider.xtend index 3a99d3bf..4b278188 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/ModelGenerationMethodProvider.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/ModelGenerationMethodProvider.xtend | |||
@@ -45,6 +45,7 @@ class ModelGenerationStatistics { | |||
45 | Collection<? extends BatchTransformationRule<?, ?>> relationRefinementRules | 45 | Collection<? extends BatchTransformationRule<?, ?>> relationRefinementRules |
46 | 46 | ||
47 | List<MultiplicityGoalConstraintCalculator> unfinishedMultiplicities | 47 | List<MultiplicityGoalConstraintCalculator> unfinishedMultiplicities |
48 | |||
48 | Collection<? extends IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> unfinishedWF | 49 | Collection<? extends IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> unfinishedWF |
49 | 50 | ||
50 | Collection<? extends IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> invalidWF | 51 | Collection<? extends IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> invalidWF |
@@ -125,8 +126,8 @@ class ModelGenerationMethodProvider { | |||
125 | case PolyhedralRelations: { | 126 | case PolyhedralRelations: { |
126 | val types = queries.refineObjectQueries.keySet.map[newType].toSet | 127 | val types = queries.refineObjectQueries.keySet.map[newType].toSet |
127 | val solver = new CbcPolyhedronSolver | 128 | val solver = new CbcPolyhedronSolver |
128 | new PolyhedronScopePropagator(emptySolution, types, queries.multiplicityConstraintQueries, solver, | 129 | new PolyhedronScopePropagator(emptySolution, types, queries.multiplicityConstraintQueries, |
129 | scopePropagatorStrategy.requiresUpperBoundIndexing) | 130 | queries.hasElementInContainmentQuery, solver, scopePropagatorStrategy.requiresUpperBoundIndexing) |
130 | } | 131 | } |
131 | default: | 132 | default: |
132 | throw new IllegalArgumentException("Unknown scope propagator strategy: " + scopePropagatorStrategy) | 133 | throw new IllegalArgumentException("Unknown scope propagator strategy: " + scopePropagatorStrategy) |
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 4f0c8f20..ce357272 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 | |||
@@ -3,6 +3,7 @@ package hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality | |||
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.Maps | 5 | import com.google.common.collect.Maps |
6 | import com.google.common.collect.Sets | ||
6 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type | 7 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type |
7 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.patterns.UnifinishedMultiplicityQueries | 8 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.patterns.UnifinishedMultiplicityQueries |
8 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialComplexTypeInterpretation | 9 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialComplexTypeInterpretation |
@@ -18,6 +19,7 @@ import java.util.Map | |||
18 | import java.util.Set | 19 | import java.util.Set |
19 | import javax.naming.OperationNotSupportedException | 20 | import javax.naming.OperationNotSupportedException |
20 | import org.eclipse.viatra.query.runtime.api.IPatternMatch | 21 | import org.eclipse.viatra.query.runtime.api.IPatternMatch |
22 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification | ||
21 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine | 23 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine |
22 | import org.eclipse.viatra.query.runtime.api.ViatraQueryMatcher | 24 | import org.eclipse.viatra.query.runtime.api.ViatraQueryMatcher |
23 | import org.eclipse.viatra.query.runtime.emf.EMFScope | 25 | import org.eclipse.viatra.query.runtime.emf.EMFScope |
@@ -32,6 +34,7 @@ class PolyhedronScopePropagator extends ScopePropagator { | |||
32 | 34 | ||
33 | new(PartialInterpretation p, Set<? extends Type> possibleNewDynamicTypes, | 35 | new(PartialInterpretation p, Set<? extends Type> possibleNewDynamicTypes, |
34 | Map<RelationMultiplicityConstraint, UnifinishedMultiplicityQueries> unfinishedMultiplicityQueries, | 36 | Map<RelationMultiplicityConstraint, UnifinishedMultiplicityQueries> unfinishedMultiplicityQueries, |
37 | IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> hasElementInContainmentQuery, | ||
35 | PolyhedronSolver solver, boolean propagateRelations) { | 38 | PolyhedronSolver solver, boolean propagateRelations) { |
36 | super(p) | 39 | super(p) |
37 | val builder = new PolyhedronBuilder(p) | 40 | val builder = new PolyhedronBuilder(p) |
@@ -49,7 +52,8 @@ class PolyhedronScopePropagator extends ScopePropagator { | |||
49 | if (maximumNumberOfNewNodes <= 0) { | 52 | if (maximumNumberOfNewNodes <= 0) { |
50 | throw new IllegalStateException("Maximum number of new nodes is negative") | 53 | throw new IllegalStateException("Maximum number of new nodes is negative") |
51 | } | 54 | } |
52 | builder.buildMultiplicityConstraints(unfinishedMultiplicityQueries, maximumNumberOfNewNodes) | 55 | builder.buildMultiplicityConstraints(unfinishedMultiplicityQueries, hasElementInContainmentQuery, |
56 | maximumNumberOfNewNodes) | ||
53 | updaters = builder.updaters | 57 | updaters = builder.updaters |
54 | } | 58 | } |
55 | } | 59 | } |
@@ -57,6 +61,7 @@ class PolyhedronScopePropagator extends ScopePropagator { | |||
57 | override void propagateAllScopeConstraints() { | 61 | override void propagateAllScopeConstraints() { |
58 | resetBounds() | 62 | resetBounds() |
59 | populatePolyhedronFromScope() | 63 | populatePolyhedronFromScope() |
64 | println(polyhedron) | ||
60 | val result = operator.saturate() | 65 | val result = operator.saturate() |
61 | if (result == PolyhedronSaturationResult.EMPTY) { | 66 | if (result == PolyhedronSaturationResult.EMPTY) { |
62 | throw new IllegalStateException("Scope bounds cannot be satisfied") | 67 | throw new IllegalStateException("Scope bounds cannot be satisfied") |
@@ -66,7 +71,7 @@ class PolyhedronScopePropagator extends ScopePropagator { | |||
66 | super.propagateAllScopeConstraints() | 71 | super.propagateAllScopeConstraints() |
67 | } | 72 | } |
68 | } | 73 | } |
69 | // println(polyhedron) | 74 | println(polyhedron) |
70 | } | 75 | } |
71 | 76 | ||
72 | def resetBounds() { | 77 | def resetBounds() { |
@@ -188,13 +193,16 @@ class PolyhedronScopePropagator extends ScopePropagator { | |||
188 | 193 | ||
189 | def buildMultiplicityConstraints( | 194 | def buildMultiplicityConstraints( |
190 | Map<RelationMultiplicityConstraint, UnifinishedMultiplicityQueries> constraints, | 195 | Map<RelationMultiplicityConstraint, UnifinishedMultiplicityQueries> constraints, |
196 | IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> hasElementInContainmentQuery, | ||
191 | int maximumNuberOfNewNodes) { | 197 | int maximumNuberOfNewNodes) { |
192 | infinity = maximumNuberOfNewNodes * INFINITY_SCALE | 198 | infinity = maximumNuberOfNewNodes * INFINITY_SCALE |
193 | queryEngine = ViatraQueryEngine.on(new EMFScope(p)) | 199 | queryEngine = ViatraQueryEngine.on(new EMFScope(p)) |
194 | updatersBuilder = ImmutableList.builder | 200 | updatersBuilder = ImmutableList.builder |
195 | for (pair : constraints.entrySet.filter[key.containment].groupBy[key.targetType].entrySet) { | 201 | val containmentConstraints = constraints.entrySet.filter[key.containment].groupBy[key.targetType] |
202 | for (pair : containmentConstraints.entrySet) { | ||
196 | buildContainmentConstraints(pair.key, pair.value) | 203 | buildContainmentConstraints(pair.key, pair.value) |
197 | } | 204 | } |
205 | buildConstainmentRootConstraints(containmentConstraints.keySet, hasElementInContainmentQuery) | ||
198 | for (pair : constraints.entrySet) { | 206 | for (pair : constraints.entrySet) { |
199 | val constraint = pair.key | 207 | val constraint = pair.key |
200 | if (!constraint.containment) { | 208 | if (!constraint.containment) { |
@@ -249,6 +257,19 @@ class PolyhedronScopePropagator extends ScopePropagator { | |||
249 | updatersBuilder.add(updater) | 257 | updatersBuilder.add(updater) |
250 | } | 258 | } |
251 | 259 | ||
260 | private def buildConstainmentRootConstraints(Set<Type> containedTypes, | ||
261 | IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> hasElementInContainmentQuery) { | ||
262 | val matcher = hasElementInContainmentQuery.getMatcher(queryEngine) | ||
263 | val rootDimensions = Sets.newHashSet(instanceCounts.values) | ||
264 | for (type : containedTypes) { | ||
265 | val containedDimensions = subtypeDimensions.get(type).keySet | ||
266 | rootDimensions.removeAll(containedDimensions) | ||
267 | } | ||
268 | for (dimension : rootDimensions) { | ||
269 | updatersBuilder.add(new ContainmentRootConstraintUpdater(dimension, matcher)) | ||
270 | } | ||
271 | } | ||
272 | |||
252 | private def buildNonContainmentConstraints(RelationMultiplicityConstraint constraint, | 273 | private def buildNonContainmentConstraints(RelationMultiplicityConstraint constraint, |
253 | UnifinishedMultiplicityQueries queries) { | 274 | UnifinishedMultiplicityQueries queries) { |
254 | } | 275 | } |
@@ -366,12 +387,23 @@ class PolyhedronScopePropagator extends ScopePropagator { | |||
366 | orphansUpperBound.tightenLowerBound(sum) | 387 | orphansUpperBound.tightenLowerBound(sum) |
367 | } | 388 | } |
368 | } | 389 | } |
369 | 390 | ||
370 | @FinalFieldsConstructor | 391 | @FinalFieldsConstructor |
371 | static class ContainmentRootConstraintUpdater implements RelationConstraintUpdater { | 392 | static class ContainmentRootConstraintUpdater implements RelationConstraintUpdater { |
372 | 393 | val LinearBoundedExpression typeCardinality | |
394 | val ViatraQueryMatcher<? extends IPatternMatch> hasElementInContainmentMatcher | ||
395 | |||
373 | override update(PartialInterpretation p) { | 396 | override update(PartialInterpretation p) { |
374 | throw new UnsupportedOperationException("TODO: auto-generated method stub") | 397 | if (hasElementInContainmentMatcher.hasMatch(p)) { |
398 | typeCardinality.tightenUpperBound(0) | ||
399 | } else { | ||
400 | typeCardinality.tightenUpperBound(1) | ||
401 | } | ||
402 | } | ||
403 | |||
404 | private static def <T extends IPatternMatch> hasMatch(ViatraQueryMatcher<T> matcher, PartialInterpretation p) { | ||
405 | val match = matcher.newMatch(p.problem, p) | ||
406 | matcher.countMatches(match) != 0 | ||
375 | } | 407 | } |
376 | } | 408 | } |
377 | } | 409 | } |
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/GenericTypeRefinementGenerator.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/GenericTypeRefinementGenerator.xtend index 2e03d6ed..c9f6abce 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/GenericTypeRefinementGenerator.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/GenericTypeRefinementGenerator.xtend | |||
@@ -11,7 +11,7 @@ import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.par | |||
11 | import java.util.HashMap | 11 | import java.util.HashMap |
12 | 12 | ||
13 | class GenericTypeRefinementGenerator extends TypeRefinementGenerator { | 13 | class GenericTypeRefinementGenerator extends TypeRefinementGenerator { |
14 | public new(PatternGenerator base) { | 14 | new(PatternGenerator base) { |
15 | super(base) | 15 | super(base) |
16 | } | 16 | } |
17 | override requiresTypeAnalysis() { false } | 17 | override requiresTypeAnalysis() { false } |
@@ -25,7 +25,7 @@ class GenericTypeRefinementGenerator extends TypeRefinementGenerator { | |||
25 | inverseRelations.put(it.inverseB,it.inverseA) | 25 | inverseRelations.put(it.inverseB,it.inverseA) |
26 | ] | 26 | ] |
27 | return ''' | 27 | return ''' |
28 | private pattern hasElementInContainment(problem:LogicProblem, interpretation:PartialInterpretation) | 28 | pattern «hasElementInContainmentName»(problem:LogicProblem, interpretation:PartialInterpretation) |
29 | «FOR type :containment.typesOrderedInHierarchy SEPARATOR "or"»{ | 29 | «FOR type :containment.typesOrderedInHierarchy SEPARATOR "or"»{ |
30 | find interpretation(problem,interpretation); | 30 | find interpretation(problem,interpretation); |
31 | «base.typeIndexer.referInstanceOf(type,Modality.MUST,"root")» | 31 | «base.typeIndexer.referInstanceOf(type,Modality.MUST,"root")» |
@@ -77,7 +77,7 @@ class GenericTypeRefinementGenerator extends TypeRefinementGenerator { | |||
77 | typeInterpretation:PartialComplexTypeInterpretation) | 77 | typeInterpretation:PartialComplexTypeInterpretation) |
78 | { | 78 | { |
79 | find interpretation(problem,interpretation); | 79 | find interpretation(problem,interpretation); |
80 | neg find hasElementInContainment(problem,interpretation); | 80 | neg find «hasElementInContainmentName»(problem,interpretation); |
81 | PartialInterpretation.partialtypeinterpratation(interpretation,typeInterpretation); | 81 | PartialInterpretation.partialtypeinterpratation(interpretation,typeInterpretation); |
82 | PartialComplexTypeInterpretation.interpretationOf.name(type,"«type.name»"); | 82 | PartialComplexTypeInterpretation.interpretationOf.name(type,"«type.name»"); |
83 | «base.typeIndexer.referInstanceOf(type,Modality.MAY,"newObject")» | 83 | «base.typeIndexer.referInstanceOf(type,Modality.MAY,"newObject")» |
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 90f79810..b10c8e88 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 | |||
@@ -12,6 +12,7 @@ import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.TypeAnalysisResult | |||
12 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.TypeInferenceMethod | 12 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.TypeInferenceMethod |
13 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.RelationConstraints | 13 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.RelationConstraints |
14 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.RelationMultiplicityConstraint | 14 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.RelationMultiplicityConstraint |
15 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.ScopePropagatorStrategy | ||
15 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.util.ParseUtil | 16 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.util.ParseUtil |
16 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation | 17 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation |
17 | import hu.bme.mit.inf.dslreasoner.workspace.ReasonerWorkspace | 18 | import hu.bme.mit.inf.dslreasoner.workspace.ReasonerWorkspace |
@@ -25,13 +26,13 @@ import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PQuery | |||
25 | import org.eclipse.xtend.lib.annotations.Data | 26 | import org.eclipse.xtend.lib.annotations.Data |
26 | 27 | ||
27 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* | 28 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* |
28 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.ScopePropagatorStrategy | ||
29 | 29 | ||
30 | @Data | 30 | @Data |
31 | class GeneratedPatterns { | 31 | class GeneratedPatterns { |
32 | public Map<Relation, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> invalidWFQueries | 32 | public Map<Relation, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> invalidWFQueries |
33 | public Map<Relation, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> unfinishedWFQueries | 33 | public Map<Relation, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> unfinishedWFQueries |
34 | public Map<RelationMultiplicityConstraint, UnifinishedMultiplicityQueries> multiplicityConstraintQueries | 34 | public Map<RelationMultiplicityConstraint, UnifinishedMultiplicityQueries> multiplicityConstraintQueries |
35 | public IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> hasElementInContainmentQuery | ||
35 | public Map<Relation, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> unfinishedMulticiplicityQueries | 36 | public Map<Relation, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> unfinishedMulticiplicityQueries |
36 | public Map<ObjectCreationPrecondition, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> refineObjectQueries | 37 | public Map<ObjectCreationPrecondition, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> refineObjectQueries |
37 | public Map<? extends Type, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> refineTypeQueries | 38 | public Map<? extends Type, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> refineTypeQueries |
@@ -105,6 +106,8 @@ class PatternProvider { | |||
105 | unrepairableMultiplicityQueryName?.lookup(queries), | 106 | unrepairableMultiplicityQueryName?.lookup(queries), |
106 | remainingInverseMultiplicityQueryName?.lookup(queries), remainingContentsQueryName?.lookup(queries)) | 107 | remainingInverseMultiplicityQueryName?.lookup(queries), remainingContentsQueryName?.lookup(queries)) |
107 | ] | 108 | ] |
109 | val hasElementInContainmentQuery = patternGenerator.typeRefinementGenerator.hasElementInContainmentName.lookup( | ||
110 | queries) | ||
108 | val unfinishedMultiplicityQueries = multiplicityConstraintQueries.entrySet.filter [ | 111 | val unfinishedMultiplicityQueries = multiplicityConstraintQueries.entrySet.filter [ |
109 | value.unfinishedMultiplicityQuery !== null | 112 | value.unfinishedMultiplicityQuery !== null |
110 | ].toMap([key.relation], [value.unfinishedMultiplicityQuery]) | 113 | ].toMap([key.relation], [value.unfinishedMultiplicityQuery]) |
@@ -126,6 +129,7 @@ class PatternProvider { | |||
126 | invalidWFQueries, | 129 | invalidWFQueries, |
127 | unfinishedWFQueries, | 130 | unfinishedWFQueries, |
128 | multiplicityConstraintQueries, | 131 | multiplicityConstraintQueries, |
132 | hasElementInContainmentQuery, | ||
129 | unfinishedMultiplicityQueries, | 133 | unfinishedMultiplicityQueries, |
130 | refineObjectsQueries, | 134 | refineObjectsQueries, |
131 | refineTypeQueries, | 135 | refineTypeQueries, |
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/TypeRefinementGenerator.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/TypeRefinementGenerator.xtend index ee7299cd..4ef336ae 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/TypeRefinementGenerator.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/TypeRefinementGenerator.xtend | |||
@@ -25,69 +25,76 @@ class ObjectCreationPrecondition { | |||
25 | 25 | ||
26 | abstract class TypeRefinementGenerator { | 26 | abstract class TypeRefinementGenerator { |
27 | val protected PatternGenerator base; | 27 | val protected PatternGenerator base; |
28 | public new(PatternGenerator base) { | 28 | |
29 | new(PatternGenerator base) { | ||
29 | this.base = base | 30 | this.base = base |
30 | } | 31 | } |
31 | 32 | ||
32 | public def boolean requiresTypeAnalysis() | 33 | def boolean requiresTypeAnalysis() |
33 | public def CharSequence generateRefineObjectQueries(LogicProblem p, PartialInterpretation emptySolution, TypeAnalysisResult typeAnalysisResult) | 34 | |
34 | public def CharSequence generateRefineTypeQueries(LogicProblem p, PartialInterpretation emptySolution, TypeAnalysisResult typeAnalysisResult) | 35 | def CharSequence generateRefineObjectQueries(LogicProblem p, PartialInterpretation emptySolution, |
35 | public def Map<? extends Type, String> getRefineTypeQueryNames(LogicProblem p, PartialInterpretation emptySolution, TypeAnalysisResult typeAnalysisResult) | 36 | TypeAnalysisResult typeAnalysisResult) |
36 | 37 | ||
37 | public def getRefineObjectQueryNames(LogicProblem p, PartialInterpretation emptySolution, TypeAnalysisResult typeAnalysisResult) { | 38 | def CharSequence generateRefineTypeQueries(LogicProblem p, PartialInterpretation emptySolution, |
38 | val Map<ObjectCreationPrecondition,String> objectCreationQueries = new LinkedHashMap | 39 | TypeAnalysisResult typeAnalysisResult) |
40 | |||
41 | def Map<? extends Type, String> getRefineTypeQueryNames(LogicProblem p, PartialInterpretation emptySolution, | ||
42 | TypeAnalysisResult typeAnalysisResult) | ||
43 | |||
44 | def getRefineObjectQueryNames(LogicProblem p, PartialInterpretation emptySolution, | ||
45 | TypeAnalysisResult typeAnalysisResult) { | ||
46 | val Map<ObjectCreationPrecondition, String> objectCreationQueries = new LinkedHashMap | ||
39 | val containment = p.containmentHierarchies.head | 47 | val containment = p.containmentHierarchies.head |
40 | val inverseRelations = new HashMap | 48 | val inverseRelations = new HashMap |
41 | p.annotations.filter(InverseRelationAssertion).forEach[ | 49 | p.annotations.filter(InverseRelationAssertion).forEach [ |
42 | inverseRelations.put(it.inverseA,it.inverseB) | 50 | inverseRelations.put(it.inverseA, it.inverseB) |
43 | inverseRelations.put(it.inverseB,it.inverseA) | 51 | inverseRelations.put(it.inverseB, it.inverseA) |
44 | ] | 52 | ] |
45 | for(type: p.types.filter(TypeDeclaration).filter[!it.isAbstract]) { | 53 | for (type : p.types.filter(TypeDeclaration).filter[!it.isAbstract]) { |
46 | if(containment.typeInContainment(type)) { | 54 | if (containment.typeInContainment(type)) { |
47 | for(containmentRelation : containment.containmentRelations.filter[canBeContainedByRelation(it,type)]) { | 55 | for (containmentRelation : containment.containmentRelations. |
48 | if(inverseRelations.containsKey(containmentRelation)) { | 56 | filter[canBeContainedByRelation(it, type)]) { |
57 | if (inverseRelations.containsKey(containmentRelation)) { | ||
49 | objectCreationQueries.put( | 58 | objectCreationQueries.put( |
50 | new ObjectCreationPrecondition(containmentRelation,inverseRelations.get(containmentRelation),type), | 59 | new ObjectCreationPrecondition(containmentRelation, |
51 | this.patternName(containmentRelation,inverseRelations.get(containmentRelation),type)) | 60 | inverseRelations.get(containmentRelation), type), |
61 | this.patternName(containmentRelation, inverseRelations.get(containmentRelation), type)) | ||
52 | } else { | 62 | } else { |
53 | objectCreationQueries.put( | 63 | objectCreationQueries.put(new ObjectCreationPrecondition(containmentRelation, null, type), |
54 | new ObjectCreationPrecondition(containmentRelation,null,type), | 64 | patternName(containmentRelation, null, type)) |
55 | patternName(containmentRelation,null,type)) | ||
56 | } | 65 | } |
57 | } | 66 | } |
58 | objectCreationQueries.put( | 67 | objectCreationQueries.put(new ObjectCreationPrecondition(null, null, type), |
59 | new ObjectCreationPrecondition(null,null,type), | 68 | patternName(null, null, type)) |
60 | patternName(null,null,type)) | ||
61 | } else { | 69 | } else { |
62 | objectCreationQueries.put( | 70 | objectCreationQueries.put(new ObjectCreationPrecondition(null, null, type), |
63 | new ObjectCreationPrecondition(null,null,type), | 71 | this.patternName(null, null, type)) |
64 | this.patternName(null,null,type)) | ||
65 | } | 72 | } |
66 | } | 73 | } |
67 | return objectCreationQueries | 74 | return objectCreationQueries |
68 | } | 75 | } |
69 | 76 | ||
70 | protected def canBeContainedByRelation(Relation r, Type t) { | 77 | protected def canBeContainedByRelation(Relation r, Type t) { |
71 | if(r.parameters.size==2) { | 78 | if (r.parameters.size == 2) { |
72 | val param = r.parameters.get(1) | 79 | val param = r.parameters.get(1) |
73 | if(param instanceof ComplexTypeReference) { | 80 | if (param instanceof ComplexTypeReference) { |
74 | val allSuperTypes = t.transitiveClosureStar[it.supertypes] | 81 | val allSuperTypes = t.transitiveClosureStar[it.supertypes] |
75 | for(superType : allSuperTypes) { | 82 | for (superType : allSuperTypes) { |
76 | if(param.referred == superType) return true | 83 | if(param.referred == superType) return true |
77 | } | 84 | } |
78 | } | 85 | } |
79 | } | 86 | } |
80 | return false | 87 | return false |
81 | } | 88 | } |
82 | 89 | ||
83 | private def typeInContainment(ContainmentHierarchy hierarchy, Type type) { | 90 | private def typeInContainment(ContainmentHierarchy hierarchy, Type type) { |
84 | val allSuperTypes = type.transitiveClosureStar[it.supertypes] | 91 | val allSuperTypes = type.transitiveClosureStar[it.supertypes] |
85 | return allSuperTypes.exists[hierarchy.typesOrderedInHierarchy.contains(it)] | 92 | return allSuperTypes.exists[hierarchy.typesOrderedInHierarchy.contains(it)] |
86 | } | 93 | } |
87 | 94 | ||
88 | protected def String patternName(Relation containmentRelation, Relation inverseContainment, Type newType) { | 95 | protected def String patternName(Relation containmentRelation, Relation inverseContainment, Type newType) { |
89 | if(containmentRelation !== null) { | 96 | if (containmentRelation !== null) { |
90 | if(inverseContainment !== null) { | 97 | if (inverseContainment !== null) { |
91 | '''createObject_«base.canonizeName(newType.name)»_by_«base.canonizeName(containmentRelation.name)»_with_«base.canonizeName(inverseContainment.name)»''' | 98 | '''createObject_«base.canonizeName(newType.name)»_by_«base.canonizeName(containmentRelation.name)»_with_«base.canonizeName(inverseContainment.name)»''' |
92 | } else { | 99 | } else { |
93 | '''createObject_«base.canonizeName(newType.name)»_by_«base.canonizeName(containmentRelation.name)»''' | 100 | '''createObject_«base.canonizeName(newType.name)»_by_«base.canonizeName(containmentRelation.name)»''' |
@@ -96,4 +103,8 @@ abstract class TypeRefinementGenerator { | |||
96 | '''createObject_«base.canonizeName(newType.name)»''' | 103 | '''createObject_«base.canonizeName(newType.name)»''' |
97 | } | 104 | } |
98 | } | 105 | } |
99 | } \ No newline at end of file | 106 | |
107 | def hasElementInContainmentName() { | ||
108 | "hasElementInContainment" | ||
109 | } | ||
110 | } | ||
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/TypeRefinementWithPreliminaryTypeAnalysis.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/TypeRefinementWithPreliminaryTypeAnalysis.xtend index cbbbcb08..1a81695e 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/TypeRefinementWithPreliminaryTypeAnalysis.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/TypeRefinementWithPreliminaryTypeAnalysis.xtend | |||
@@ -10,7 +10,7 @@ import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.par | |||
10 | import java.util.HashMap | 10 | import java.util.HashMap |
11 | 11 | ||
12 | class TypeRefinementWithPreliminaryTypeAnalysis extends TypeRefinementGenerator{ | 12 | class TypeRefinementWithPreliminaryTypeAnalysis extends TypeRefinementGenerator{ |
13 | public new(PatternGenerator base) { | 13 | new(PatternGenerator base) { |
14 | super(base) | 14 | super(base) |
15 | } | 15 | } |
16 | override requiresTypeAnalysis() { true } | 16 | override requiresTypeAnalysis() { true } |
@@ -24,7 +24,7 @@ class TypeRefinementWithPreliminaryTypeAnalysis extends TypeRefinementGenerator{ | |||
24 | inverseRelations.put(it.inverseB,it.inverseA) | 24 | inverseRelations.put(it.inverseB,it.inverseA) |
25 | ] | 25 | ] |
26 | return ''' | 26 | return ''' |
27 | private pattern hasElementInContainment(problem:LogicProblem, interpretation:PartialInterpretation) | 27 | pattern «hasElementInContainmentName»(problem:LogicProblem, interpretation:PartialInterpretation) |
28 | «FOR type :containment.typesOrderedInHierarchy SEPARATOR "or"»{ | 28 | «FOR type :containment.typesOrderedInHierarchy SEPARATOR "or"»{ |
29 | find interpretation(problem,interpretation); | 29 | find interpretation(problem,interpretation); |
30 | «base.typeIndexer.referInstanceOf(type,Modality.MUST,"root")» | 30 | «base.typeIndexer.referInstanceOf(type,Modality.MUST,"root")» |
@@ -76,7 +76,7 @@ class TypeRefinementWithPreliminaryTypeAnalysis extends TypeRefinementGenerator{ | |||
76 | typeInterpretation:PartialComplexTypeInterpretation) | 76 | typeInterpretation:PartialComplexTypeInterpretation) |
77 | { | 77 | { |
78 | find interpretation(problem,interpretation); | 78 | find interpretation(problem,interpretation); |
79 | neg find hasElementInContainment(problem,interpretation); | 79 | neg find «hasElementInContainmentName»(problem,interpretation); |
80 | PartialInterpretation.partialtypeinterpratation(interpretation,typeInterpretation); | 80 | PartialInterpretation.partialtypeinterpratation(interpretation,typeInterpretation); |
81 | PartialComplexTypeInterpretation.interpretationOf.name(typeInterpretation,"«type.name»"); | 81 | PartialComplexTypeInterpretation.interpretationOf.name(typeInterpretation,"«type.name»"); |
82 | «base.typeIndexer.referInstanceOf(type,Modality.MAY,"newObject")» | 82 | «base.typeIndexer.referInstanceOf(type,Modality.MAY,"newObject")» |