diff options
author | 2018-09-14 16:42:18 +0200 | |
---|---|---|
committer | 2018-09-14 16:42:18 +0200 | |
commit | b942d8a221180119e56f1d9bfd3d818b68f7298b (patch) | |
tree | 420f40698a801a75c6fe6973c3aa5a00574d4b88 /Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme | |
parent | Diversity support for Solver config (diff) | |
download | VIATRA-Generator-b942d8a221180119e56f1d9bfd3d818b68f7298b.tar.gz VIATRA-Generator-b942d8a221180119e56f1d9bfd3d818b68f7298b.tar.zst VIATRA-Generator-b942d8a221180119e56f1d9bfd3d818b68f7298b.zip |
Scope in partial model initialised by the given model scope
Diffstat (limited to 'Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme')
-rw-r--r-- | Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScopeLoader.xtend | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScopeLoader.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScopeLoader.xtend index 4f1a8f38..dcaf74cd 100644 --- a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScopeLoader.xtend +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScopeLoader.xtend | |||
@@ -35,6 +35,7 @@ import org.eclipse.emf.ecore.EClass | |||
35 | import org.eclipse.xtend.lib.annotations.Data | 35 | import org.eclipse.xtend.lib.annotations.Data |
36 | 36 | ||
37 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* | 37 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* |
38 | import java.util.HashSet | ||
38 | 39 | ||
39 | @Data class KnownElements { | 40 | @Data class KnownElements { |
40 | val Map<Type,Set<DefinedElement>> knownElementsByType | 41 | val Map<Type,Set<DefinedElement>> knownElementsByType |
@@ -58,11 +59,18 @@ class ScopeLoader { | |||
58 | 59 | ||
59 | def protected initialiseknownElements(LogicProblem p, TypeScopes s) { | 60 | def protected initialiseknownElements(LogicProblem p, TypeScopes s) { |
60 | val Map<Type,Set<DefinedElement>> res = new HashMap | 61 | val Map<Type,Set<DefinedElement>> res = new HashMap |
62 | |||
63 | // 1. fill map with every types | ||
64 | for(t : p.types) { | ||
65 | res.put(t,new HashSet) | ||
66 | } | ||
67 | |||
68 | // 2. fill map with every objects | ||
61 | for(definedType : p.types.filter(TypeDefinition)) { | 69 | for(definedType : p.types.filter(TypeDefinition)) { |
62 | val supertypes = definedType.<Type>transitiveClosureStar[x|x.supertypes] | 70 | val supertypes = definedType.<Type>transitiveClosureStar[x|x.supertypes] |
63 | for(supertype : supertypes) { | 71 | for(supertype : supertypes) { |
64 | for(element : definedType.elements) { | 72 | for(element : definedType.elements) { |
65 | res.putOrAddToSet(supertype,element) | 73 | res.get(supertype).add(element) |
66 | } | 74 | } |
67 | } | 75 | } |
68 | } | 76 | } |
@@ -107,7 +115,7 @@ class ScopeLoader { | |||
107 | updateLowerLimit( | 115 | updateLowerLimit( |
108 | scope.setsNew, | 116 | scope.setsNew, |
109 | known, | 117 | known, |
110 | type.lookup(aggregated.minNewElementsByType), | 118 | aggregated.minNewElementsByType.get(type), |
111 | getLowerLimit(scope.number) | 119 | getLowerLimit(scope.number) |
112 | ) | 120 | ) |
113 | ) | 121 | ) |
@@ -115,7 +123,7 @@ class ScopeLoader { | |||
115 | updateUpperLimit( | 123 | updateUpperLimit( |
116 | scope.setsNew, | 124 | scope.setsNew, |
117 | known, | 125 | known, |
118 | type.lookup(aggregated.minNewElementsByType), | 126 | aggregated.maxNewElementsByType.get(type), |
119 | getUpperLimit(scope.number) | 127 | getUpperLimit(scope.number) |
120 | ) | 128 | ) |
121 | ) | 129 | ) |
@@ -128,6 +136,9 @@ class ScopeLoader { | |||
128 | val number = scope.number | 136 | val number = scope.number |
129 | if(number instanceof IntEnumberation) { | 137 | if(number instanceof IntEnumberation) { |
130 | addToKnownCollection(aggregated.knownIntegers,number.entry,scope.isSetsNew,inconsistencies) | 138 | addToKnownCollection(aggregated.knownIntegers,number.entry,scope.isSetsNew,inconsistencies) |
139 | if(!scope.isSetsNew) { | ||
140 | aggregated.maxNewIntegers = 0 | ||
141 | } | ||
131 | } else { | 142 | } else { |
132 | aggregated.minNewIntegers = updateLowerLimit(scope.isSetsNew,aggregated.knownIntegers.size,aggregated.minNewIntegers,number.lowerLimit) | 143 | aggregated.minNewIntegers = updateLowerLimit(scope.isSetsNew,aggregated.knownIntegers.size,aggregated.minNewIntegers,number.lowerLimit) |
133 | aggregated.maxNewIntegers = updateLowerLimit(scope.isSetsNew,aggregated.knownIntegers.size,aggregated.maxNewIntegers,number.upperLimit) | 144 | aggregated.maxNewIntegers = updateLowerLimit(scope.isSetsNew,aggregated.knownIntegers.size,aggregated.maxNewIntegers,number.upperLimit) |
@@ -139,6 +150,9 @@ class ScopeLoader { | |||
139 | if(number instanceof RealEnumeration) { | 150 | if(number instanceof RealEnumeration) { |
140 | val x = number.entry; | 151 | val x = number.entry; |
141 | <BigDecimal>addToKnownCollection(aggregated.knownReals,x,scope.isSetsNew,inconsistencies) | 152 | <BigDecimal>addToKnownCollection(aggregated.knownReals,x,scope.isSetsNew,inconsistencies) |
153 | if(!scope.isSetsNew) { | ||
154 | aggregated.maxNewReals = 0 | ||
155 | } | ||
142 | } else { | 156 | } else { |
143 | aggregated.minNewReals = updateLowerLimit(scope.isSetsNew,aggregated.knownReals.size,aggregated.minNewReals,number.lowerLimit) | 157 | aggregated.minNewReals = updateLowerLimit(scope.isSetsNew,aggregated.knownReals.size,aggregated.minNewReals,number.lowerLimit) |
144 | aggregated.maxNewReals = updateLowerLimit(scope.isSetsNew,aggregated.knownReals.size,aggregated.maxNewReals,number.upperLimit) | 158 | aggregated.maxNewReals = updateLowerLimit(scope.isSetsNew,aggregated.knownReals.size,aggregated.maxNewReals,number.upperLimit) |
@@ -148,6 +162,9 @@ class ScopeLoader { | |||
148 | val number = scope.number | 162 | val number = scope.number |
149 | if(number instanceof StringEnumeration) { | 163 | if(number instanceof StringEnumeration) { |
150 | <String>addToKnownCollection(aggregated.knownStrings,number.entry,scope.isSetsNew,inconsistencies) | 164 | <String>addToKnownCollection(aggregated.knownStrings,number.entry,scope.isSetsNew,inconsistencies) |
165 | if(!scope.isSetsNew) { | ||
166 | aggregated.maxNewStrings = 0 | ||
167 | } | ||
151 | } else { | 168 | } else { |
152 | aggregated.minNewStrings = updateLowerLimit(scope.isSetsNew,aggregated.knownStrings.size,aggregated.minNewStrings,number.lowerLimit) | 169 | aggregated.minNewStrings = updateLowerLimit(scope.isSetsNew,aggregated.knownStrings.size,aggregated.minNewStrings,number.lowerLimit) |
153 | aggregated.maxNewStrings = updateLowerLimit(scope.isSetsNew,aggregated.knownStrings.size,aggregated.maxNewStrings,number.upperLimit) | 170 | aggregated.maxNewStrings = updateLowerLimit(scope.isSetsNew,aggregated.knownStrings.size,aggregated.maxNewStrings,number.upperLimit) |
@@ -166,19 +183,21 @@ class ScopeLoader { | |||
166 | } | 183 | } |
167 | } | 184 | } |
168 | 185 | ||
169 | def updateLowerLimit(boolean isAdditional, int known, int original, int value) { | 186 | def updateLowerLimit(boolean isAdditional, int known, Integer original, int value) { |
187 | val o = if(original === null) {0} else {original} | ||
170 | if(isAdditional) { | 188 | if(isAdditional) { |
171 | return Math.max(original,value) | 189 | return Math.max(o,value) |
172 | } else { | 190 | } else { |
173 | return Math.max(original,value-known) | 191 | return Math.max(o,value-known) |
174 | } | 192 | } |
175 | } | 193 | } |
176 | def updateUpperLimit(boolean isAdditional, int known, int original, int value) { | 194 | def updateUpperLimit(boolean isAdditional, int known, Integer original, int value) { |
195 | val o = if(original === null) {Integer.MAX_VALUE} else {original} | ||
177 | if(isAdditional) { | 196 | if(isAdditional) { |
178 | return Math.min(original,value) | 197 | return Math.min(o,value) |
179 | } else { | 198 | } else { |
180 | val target = if(value == Integer.MAX_VALUE) { Integer.MAX_VALUE } else {value-known} | 199 | val target = if(value == Integer.MAX_VALUE) { Integer.MAX_VALUE } else {value-known} |
181 | return Math.min(original,target) | 200 | return Math.min(o,target) |
182 | } | 201 | } |
183 | } | 202 | } |
184 | 203 | ||