aboutsummaryrefslogtreecommitdiffstats
path: root/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/cardinality/ScopePropagator.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/ScopePropagator.xtend')
-rw-r--r--Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/cardinality/ScopePropagator.xtend73
1 files changed, 6 insertions, 67 deletions
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 7be6635c..0bdb202e 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
@@ -16,8 +16,8 @@ class ScopePropagator {
16 @Accessors(PROTECTED_GETTER) val PartialInterpretation partialInterpretation 16 @Accessors(PROTECTED_GETTER) val PartialInterpretation partialInterpretation
17 val ModelGenerationStatistics statistics 17 val ModelGenerationStatistics statistics
18 val Map<PartialTypeInterpratation, Scope> type2Scope 18 val Map<PartialTypeInterpratation, Scope> type2Scope
19 val Map<Scope, Set<Scope>> superScopes 19 @Accessors(PROTECTED_GETTER) val Map<Scope, Set<Scope>> superScopes
20 val Map<Scope, Set<Scope>> subScopes 20 @Accessors(PROTECTED_GETTER) val Map<Scope, Set<Scope>> subScopes
21 21
22 new(PartialInterpretation p, ModelGenerationStatistics statistics) { 22 new(PartialInterpretation p, ModelGenerationStatistics statistics) {
23 partialInterpretation = p 23 partialInterpretation = p
@@ -60,26 +60,14 @@ class ScopePropagator {
60 } 60 }
61 } while (changed) 61 } while (changed)
62 } 62 }
63 63
64 def propagateAllScopeConstraints() { 64 def propagateAllScopeConstraints() {
65 statistics.incrementScopePropagationCount() 65 statistics.incrementScopePropagationCount()
66 doPropagateAllScopeConstraints() 66 doPropagateAllScopeConstraints()
67 } 67 }
68 68
69 protected def doPropagateAllScopeConstraints() { 69 protected def void doPropagateAllScopeConstraints() {
70 var boolean hadChanged 70 // Nothing to propagate.
71 do {
72 hadChanged = false
73 for (superScopeEntry : superScopes.entrySet) {
74 val sub = superScopeEntry.key
75 hadChanged = propagateLowerLimitUp(sub, partialInterpretation) || hadChanged
76 hadChanged = propagateUpperLimitDown(sub, partialInterpretation) || hadChanged
77 for (sup : superScopeEntry.value) {
78 hadChanged = propagateLowerLimitUp(sub, sup) || hadChanged
79 hadChanged = propagateUpperLimitDown(sub, sup) || hadChanged
80 }
81 }
82 } while (hadChanged)
83 } 71 }
84 72
85 def propagateAdditionToType(PartialTypeInterpratation t) { 73 def propagateAdditionToType(PartialTypeInterpratation t) {
@@ -103,60 +91,11 @@ class ScopePropagator {
103// this.partialInterpretation.scopes.forEach[println(''' «(it.targetTypeInterpretation as PartialComplexTypeInterpretation).interpretationOf.name»: «it.minNewElements»-«it.maxNewElements»''')] 91// this.partialInterpretation.scopes.forEach[println(''' «(it.targetTypeInterpretation as PartialComplexTypeInterpretation).interpretationOf.name»: «it.minNewElements»-«it.maxNewElements»''')]
104// println('''All constraints are propagated upon increasing «(t as PartialComplexTypeInterpretation).interpretationOf.name»''') 92// println('''All constraints are propagated upon increasing «(t as PartialComplexTypeInterpretation).interpretationOf.name»''')
105 } 93 }
106 94
107 def void propagateAdditionToRelation(Relation r) { 95 def void propagateAdditionToRelation(Relation r) {
108 // Nothing to propagate. 96 // Nothing to propagate.
109 } 97 }
110 98
111 private def propagateLowerLimitUp(Scope subScope, Scope superScope) {
112 if (subScope.minNewElements > superScope.minNewElements) {
113 superScope.minNewElements = subScope.minNewElements
114 return true
115 } else {
116 return false
117 }
118 }
119
120 private def propagateUpperLimitDown(Scope subScope, Scope superScope) {
121 if (superScope.maxNewElements >= 0 &&
122 (superScope.maxNewElements < subScope.maxNewElements || subScope.maxNewElements < 0)) {
123// println('''
124// «(subScope.targetTypeInterpretation as PartialComplexTypeInterpretation).interpretationOf.name» -> «(superScope.targetTypeInterpretation as PartialComplexTypeInterpretation).interpretationOf.name»
125// subScope.maxNewElements «subScope.maxNewElements» = superScope.maxNewElements «superScope.maxNewElements»
126// ''')
127 subScope.maxNewElements = superScope.maxNewElements
128 return true
129 } else {
130 return false
131 }
132 }
133
134 private def propagateLowerLimitUp(Scope subScope, PartialInterpretation p) {
135 if (subScope.minNewElements > p.minNewElements) {
136// println('''
137// «(subScope.targetTypeInterpretation as PartialComplexTypeInterpretation).interpretationOf.name» -> nodes
138// p.minNewElements «p.minNewElements» = subScope.minNewElements «subScope.minNewElements»
139// ''')
140 p.minNewElements = subScope.minNewElements
141 return true
142 } else {
143 return false
144 }
145 }
146
147 private def propagateUpperLimitDown(Scope subScope, PartialInterpretation p) {
148 if (p.maxNewElements >= 0 && (p.maxNewElements < subScope.maxNewElements || subScope.maxNewElements < 0)) {
149// println('''
150// «(subScope.targetTypeInterpretation as PartialComplexTypeInterpretation).interpretationOf.name» -> nodes
151// subScope.maxNewElements «subScope.maxNewElements» = p.maxNewElements «p.maxNewElements»
152// ''')
153 subScope.maxNewElements = p.maxNewElements
154 return true
155 } else {
156 return false
157 }
158 }
159
160 private def removeOne(Scope scope) { 99 private def removeOne(Scope scope) {
161 if (scope.maxNewElements === 0) { 100 if (scope.maxNewElements === 0) {
162 throw new IllegalArgumentException('''Inconsistent object creation: «scope.targetTypeInterpretation»''') 101 throw new IllegalArgumentException('''Inconsistent object creation: «scope.targetTypeInterpretation»''')