diff options
Diffstat (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/cardinality')
3 files changed, 40 insertions, 22 deletions
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/cardinality/MultiplicityGoalConstraintCalculator.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/cardinality/MultiplicityGoalConstraintCalculator.xtend index 86a59aa1..034420d6 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/cardinality/MultiplicityGoalConstraintCalculator.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/cardinality/MultiplicityGoalConstraintCalculator.xtend | |||
@@ -7,26 +7,39 @@ import org.eclipse.viatra.query.runtime.api.ViatraQueryMatcher | |||
7 | import org.eclipse.viatra.query.runtime.emf.EMFScope | 7 | import org.eclipse.viatra.query.runtime.emf.EMFScope |
8 | 8 | ||
9 | class MultiplicityGoalConstraintCalculator { | 9 | class MultiplicityGoalConstraintCalculator { |
10 | val String targetRelationName; | 10 | val String targetRelationName |
11 | val IQuerySpecification<?> querySpecification; | 11 | val IQuerySpecification<?> querySpecification |
12 | var ViatraQueryMatcher<?> matcher; | 12 | var ViatraQueryMatcher<?> matcher |
13 | val int minValue | ||
14 | val boolean containment | ||
15 | val int cost | ||
13 | 16 | ||
14 | new(String targetRelationName, IQuerySpecification<?> querySpecification) { | 17 | public new(String targetRelationName, IQuerySpecification<?> querySpecification, int minValue, boolean containment, int cost) { |
15 | this.targetRelationName = targetRelationName | 18 | this.targetRelationName = targetRelationName |
16 | this.querySpecification = querySpecification | 19 | this.querySpecification = querySpecification |
17 | this.matcher = null | 20 | this.matcher = null |
21 | this.minValue = minValue | ||
22 | this.containment = containment | ||
23 | this.cost = cost | ||
18 | } | 24 | } |
19 | 25 | ||
20 | new(MultiplicityGoalConstraintCalculator other) { | 26 | new(MultiplicityGoalConstraintCalculator other) { |
21 | this.targetRelationName = other.targetRelationName | 27 | this.targetRelationName = other.targetRelationName |
22 | this.querySpecification = other.querySpecification | 28 | this.querySpecification = other.querySpecification |
23 | this.matcher = null | 29 | this.matcher = null |
30 | this.minValue = other.minValue | ||
31 | this.containment = other.containment | ||
32 | this.cost = other.cost | ||
24 | } | 33 | } |
25 | 34 | ||
26 | def getName() { | 35 | def getName() { |
27 | targetRelationName | 36 | targetRelationName |
28 | } | 37 | } |
29 | 38 | ||
39 | def isContainment() { | ||
40 | return containment | ||
41 | } | ||
42 | |||
30 | def init(Notifier notifier) { | 43 | def init(Notifier notifier) { |
31 | val engine = ViatraQueryEngine.on(new EMFScope(notifier)) | 44 | val engine = ViatraQueryEngine.on(new EMFScope(notifier)) |
32 | matcher = querySpecification.getMatcher(engine) | 45 | matcher = querySpecification.getMatcher(engine) |
@@ -36,11 +49,17 @@ class MultiplicityGoalConstraintCalculator { | |||
36 | var res = 0 | 49 | var res = 0 |
37 | val allMatches = this.matcher.allMatches | 50 | val allMatches = this.matcher.allMatches |
38 | for(match : allMatches) { | 51 | for(match : allMatches) { |
39 | //println(targetRelationName+ " missing multiplicity: "+match.get(3)) | 52 | val existingMultiplicity = match.get(4) as Integer |
40 | val missingMultiplicity = match.get(2) as Integer | 53 | if(existingMultiplicity < this.minValue) { |
41 | res += missingMultiplicity | 54 | val missingMultiplicity = this.minValue-existingMultiplicity |
55 | res += missingMultiplicity | ||
56 | } | ||
57 | // if(missingMultiplicity!=0) { | ||
58 | // println(targetRelationName+ " missing multiplicity: "+missingMultiplicity) | ||
59 | // } | ||
42 | } | 60 | } |
43 | //println(targetRelationName+ " all missing multiplicities: "+res) | 61 | // if(res>0) |
44 | return res | 62 | // println(targetRelationName+ " all missing multiplicities: "+res + "*"+cost+"="+res*cost) |
63 | return res*cost | ||
45 | } | 64 | } |
46 | } | 65 | } |
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 51dba244..120fb18a 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 | |||
@@ -187,16 +187,7 @@ class PolyhedronScopePropagator extends TypeHierarchyScopePropagator { | |||
187 | if (bounds.upperBound !== null && bounds.upperBound < 0) { | 187 | if (bounds.upperBound !== null && bounds.upperBound < 0) { |
188 | throw new IllegalArgumentException("Negative upper bound: " + bounds) | 188 | throw new IllegalArgumentException("Negative upper bound: " + bounds) |
189 | } | 189 | } |
190 | } | 190 | } |
191 | |||
192 | private def setScopesInvalid() { | ||
193 | partialInterpretation.minNewElements = Integer.MAX_VALUE | ||
194 | partialInterpretation.maxNewElements = 0 | ||
195 | for (scope : partialInterpretation.scopes) { | ||
196 | scope.minNewElements = Integer.MAX_VALUE | ||
197 | scope.maxNewElements = 0 | ||
198 | } | ||
199 | } | ||
200 | 191 | ||
201 | private static def <T extends IPatternMatch> getCalculatedMultiplicity(ViatraQueryMatcher<T> matcher, | 192 | private static def <T extends IPatternMatch> getCalculatedMultiplicity(ViatraQueryMatcher<T> matcher, |
202 | PartialInterpretation p) { | 193 | PartialInterpretation p) { |
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/cardinality/ScopePropagator.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/cardinality/ScopePropagator.xtend index 2376fb38..8f3a5bb0 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/cardinality/ScopePropagator.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/cardinality/ScopePropagator.xtend | |||
@@ -79,7 +79,7 @@ class ScopePropagator { | |||
79 | // Nothing to propagate. | 79 | // Nothing to propagate. |
80 | } | 80 | } |
81 | 81 | ||
82 | def propagateAdditionToType(PartialTypeInterpratation t) { | 82 | def decrementTypeScope(PartialTypeInterpratation t) { |
83 | // println('''Adding to «(t as PartialComplexTypeInterpretation).interpretationOf.name»''') | 83 | // println('''Adding to «(t as PartialComplexTypeInterpretation).interpretationOf.name»''') |
84 | val targetScope = type2Scope.get(t) | 84 | val targetScope = type2Scope.get(t) |
85 | if (targetScope !== null) { | 85 | if (targetScope !== null) { |
@@ -96,15 +96,23 @@ class ScopePropagator { | |||
96 | if (this.partialInterpretation.maxNewElements > 0) { | 96 | if (this.partialInterpretation.maxNewElements > 0) { |
97 | this.partialInterpretation.maxNewElements = this.partialInterpretation.maxNewElements - 1 | 97 | this.partialInterpretation.maxNewElements = this.partialInterpretation.maxNewElements - 1 |
98 | } else if (this.partialInterpretation.maxNewElements === 0) { | 98 | } else if (this.partialInterpretation.maxNewElements === 0) { |
99 | throw new IllegalArgumentException('''Inconsistent object creation: lower node limit is 0!''') | 99 | setScopesInvalid() |
100 | } | 100 | } |
101 | propagateAllScopeConstraints | ||
102 | 101 | ||
103 | // println('''Target Scope: «targetScope.minNewElements» - «targetScope.maxNewElements»''') | 102 | // println('''Target Scope: «targetScope.minNewElements» - «targetScope.maxNewElements»''') |
104 | // println(''' «this.partialInterpretation.minNewElements» - «this.partialInterpretation.maxNewElements»''') | 103 | // println(''' «this.partialInterpretation.minNewElements» - «this.partialInterpretation.maxNewElements»''') |
105 | // this.partialInterpretation.scopes.forEach[println(''' «(it.targetTypeInterpretation as PartialComplexTypeInterpretation).interpretationOf.name»: «it.minNewElements»-«it.maxNewElements»''')] | 104 | // this.partialInterpretation.scopes.forEach[println(''' «(it.targetTypeInterpretation as PartialComplexTypeInterpretation).interpretationOf.name»: «it.minNewElements»-«it.maxNewElements»''')] |
106 | // println('''All constraints are propagated upon increasing «(t as PartialComplexTypeInterpretation).interpretationOf.name»''') | 105 | // println('''All constraints are propagated upon increasing «(t as PartialComplexTypeInterpretation).interpretationOf.name»''') |
107 | } | 106 | } |
107 | |||
108 | protected def setScopesInvalid() { | ||
109 | partialInterpretation.minNewElements = Integer.MAX_VALUE | ||
110 | partialInterpretation.maxNewElements = 0 | ||
111 | for (scope : partialInterpretation.scopes) { | ||
112 | scope.minNewElements = Integer.MAX_VALUE | ||
113 | scope.maxNewElements = 0 | ||
114 | } | ||
115 | } | ||
108 | 116 | ||
109 | def void propagateAdditionToRelation(Relation r) { | 117 | def void propagateAdditionToRelation(Relation r) { |
110 | // Nothing to propagate. | 118 | // Nothing to propagate. |