aboutsummaryrefslogtreecommitdiffstats
path: root/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application
diff options
context:
space:
mode:
authorLibravatar OszkarSemerath <oszkar.semerath@gmail.com>2018-07-16 18:25:34 +0200
committerLibravatar OszkarSemerath <oszkar.semerath@gmail.com>2018-07-16 18:25:34 +0200
commit59a53fc819355fb2809b23544a5ca19ffff802fb (patch)
treee67cba5ca12cfbba7d2dc68e6c07fe36c996e3f2 /Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application
parentSupport for building float, double and BigDecimal literals (diff)
downloadVIATRA-Generator-59a53fc819355fb2809b23544a5ca19ffff802fb.tar.gz
VIATRA-Generator-59a53fc819355fb2809b23544a5ca19ffff802fb.tar.zst
VIATRA-Generator-59a53fc819355fb2809b23544a5ca19ffff802fb.zip
Scope support for attributes
Diffstat (limited to 'Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application')
-rw-r--r--Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/ApplicationConfiguration.xtext8
-rw-r--r--Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/GenerationTaskExecutor.xtend153
-rw-r--r--Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScopeLoader.xtend171
3 files changed, 239 insertions, 93 deletions
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/ApplicationConfiguration.xtext b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/ApplicationConfiguration.xtext
index 1f9495cf..6af31723 100644
--- a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/ApplicationConfiguration.xtext
+++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/ApplicationConfiguration.xtext
@@ -15,8 +15,8 @@ Command :
15 15
16QualifiedName returns ecore::EString: 16QualifiedName returns ecore::EString:
17 ID ('.' ID)*; 17 ID ('.' ID)*;
18//terminal REAL returns ecore::EBigDecimal: '-'? INT '.' INT; 18REALLiteral returns ecore::EBigDecimal: '-'? INT '.' INT;
19//terminal INTEGER returns ecore::EInt: '-'? INT; 19INTLiteral returns ecore::EInt: '-'? INT;
20 20
21/////////////////////////////////////////////////// 21///////////////////////////////////////////////////
22// Imports 22// Imports
@@ -144,8 +144,8 @@ StringReference: {StringScope} 'string';
144NumberSpecification: ExactNumber | IntervallNumber | IntEnumberation | RealEnumeration | StringEnumeration; 144NumberSpecification: ExactNumber | IntervallNumber | IntEnumberation | RealEnumeration | StringEnumeration;
145ExactNumber: exactNumber = INT | exactUnlimited ?= '*'; 145ExactNumber: exactNumber = INT | exactUnlimited ?= '*';
146IntervallNumber: min = INT '..' (maxNumber = INT | maxUnlimited ?= '*'); 146IntervallNumber: min = INT '..' (maxNumber = INT | maxUnlimited ?= '*');
147IntEnumberation: {IntEnumberation} '{' (entry += INT (',' entry += INT)*)?'}'; 147IntEnumberation: {IntEnumberation} '{' (entry += INTLiteral (',' entry += INTLiteral)*)?'}';
148RealEnumeration: {RealEnumeration} '{' (entry += INT (',' entry += INT)*)?'}'; 148RealEnumeration: {RealEnumeration} '{' (entry += REALLiteral (',' entry += REALLiteral)*)?'}';
149StringEnumeration: {StringEnumeration} '{' (entry += STRING (',' entry += STRING)*)?'}'; 149StringEnumeration: {StringEnumeration} '{' (entry += STRING (',' entry += STRING)*)?'}';
150 150
151ScopeDeclaration: 'scope' name = ID specification = ScopeSpecification; 151ScopeDeclaration: 'scope' name = ID specification = ScopeSpecification;
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/GenerationTaskExecutor.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/GenerationTaskExecutor.xtend
index 40ffaf28..9a8ac8a3 100644
--- a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/GenerationTaskExecutor.xtend
+++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/GenerationTaskExecutor.xtend
@@ -143,89 +143,114 @@ class GenerationTaskExecutor {
143 1 143 1
144 } 144 }
145 ] 145 ]
146 solverConfig.typeScopes = scopeLoader.loadScope( 146
147 val typeScopes = scopeLoader.loadScope(
147 scopeSpecification, 148 scopeSpecification,
148 problem, 149 problem,
149 ecore2Logic, 150 ecore2Logic,
150 modelGeneration.trace 151 modelGeneration.trace
151 ) 152 )
152 153 // If the type scope contains errors, then the problem is inconsistent
153 // 5.3 set resource limits 154 if(!typeScopes.value.empty) {
154 documentationLevel.ifPresent[solverConfig.documentationLevel = it] 155 monitor.worked(50)
155 runtieLimit.ifPresent[solverConfig.runtimeLimit = it] 156 console.writeMessage("Model generation started")
156 memoryLimit.ifPresent[solverConfig.memoryLimit = it] 157 typeScopes.value.forEach[console.writeMessage(it)]
157
158 // 6. execute the solver on the problem with the configuration
159 // 6.1 calculating the runs
160 val runs = if(task.runSpecified) { task.runs } else { 1 }
161 monitor.worked(50)
162
163 console.writeMessage("Model generation started")
164 for(run : 1..runs) {
165 monitor.subTask('''Solving problem«IF runs>0» «run»/«runs»«ENDIF»''')
166 158
167 // 6.2 For each run, the configuration and the workspace is adjusted 159 val runs = if(task.runSpecified) { task.runs } else { 1 }
168 solverLoader.setRunIndex(solverConfig,configurationMap,run,console) 160 for(run : 1..runs) {
169 solverConfig.progressMonitor = new EclipseBasedProgressMonitor(monitor) 161 console.writeMessage('''Problem is inconsistent, no model is created!''')
170 val reasonerWorkspaceForRun = if(runs > 1) { 162 val statistics = new LinkedHashMap
171 reasonerWorkspace.subWorkspace('''run«run»''',"") => [initAndClear] 163 statistics.put("Task",(task.eContainer as ConfigurationScript).commands.indexOf(task)+1)
172 } else { 164 statistics.put("Run",run)
173 reasonerWorkspace 165 statistics.put("Result","InconsistencyResult")
166 statistics.put("Domain to logic transformation time",domain2LogicTransformationTime/1000000)
167 statistics.put("Logic to solver transformation time",0)
168 statistics.put("Solver time",0)
169 statistics.put("Postprocessing time",0)
170 console.addStatistics(statistics)
174 } 171 }
175 172
176 // 7. Solver call 173 } else {
177 val solution = solver.solve(problem,solverConfig,reasonerWorkspaceForRun) 174 solverConfig.typeScopes = typeScopes.key
178 console.writeMessage(solution.soutionDescription.toString) 175
176 // 5.3 set resource limits
177 documentationLevel.ifPresent[solverConfig.documentationLevel = it]
178 runtieLimit.ifPresent[solverConfig.runtimeLimit = it]
179 memoryLimit.ifPresent[solverConfig.memoryLimit = it]
179 180
180 // 8. Solution processing 181 // 6. execute the solver on the problem with the configuration
182 // 6.1 calculating the runs
183 val runs = if(task.runSpecified) { task.runs } else { 1 }
184 monitor.worked(50)
181 185
182 // 8.1 Visualisation 186 console.writeMessage("Model generation started")
183 var solutionVisualisationTime = System.nanoTime 187 for(run : 1..runs) {
184 if(solution instanceof ModelResult) { 188 monitor.subTask('''Solving problem«IF runs>0» «run»/«runs»«ENDIF»''')
185 val interpretations = solver.getInterpretations(solution) 189
186 val outputWorkspaceForRun = if(runs > 1) { 190 // 6.2 For each run, the configuration and the workspace is adjusted
187 outputWorkspace.subWorkspace('''run«run»''',"") => [initAndClear] 191 solverLoader.setRunIndex(solverConfig,configurationMap,run,console)
192 solverConfig.progressMonitor = new EclipseBasedProgressMonitor(monitor)
193 val reasonerWorkspaceForRun = if(runs > 1) {
194 reasonerWorkspace.subWorkspace('''run«run»''',"") => [initAndClear]
188 } else { 195 } else {
189 outputWorkspace 196 reasonerWorkspace
190 } 197 }
191 198
192 for(interpretationIndex : 0..<interpretations.size) { 199 // 7. Solver call
193 monitor.subTask('''Solving problem«IF runs>0» «run»/«runs»«ENDIF»: Visualising solution «interpretationIndex+1»/«interpretations.size»''') 200 val solution = solver.solve(problem,solverConfig,reasonerWorkspaceForRun)
194 val interpretation = interpretations.get(interpretationIndex) 201 console.writeMessage(solution.soutionDescription.toString)
195 val model = logic2Ecore.transformInterpretation(interpretation,modelGeneration.trace) 202
196 outputWorkspaceForRun.writeModel(model,'''model«IF runs>1»_«run»«ENDIF»_«interpretationIndex+1».xmi''') 203 // 8. Solution processing
204
205 // 8.1 Visualisation
206 var solutionVisualisationTime = System.nanoTime
207 if(solution instanceof ModelResult) {
208 val interpretations = solver.getInterpretations(solution)
209 val outputWorkspaceForRun = if(runs > 1) {
210 outputWorkspace.subWorkspace('''run«run»''',"") => [initAndClear]
211 } else {
212 outputWorkspace
213 }
197 214
198 val representation = solution.representation.get(interpretationIndex) 215 for(interpretationIndex : 0..<interpretations.size) {
199 if(representation instanceof PartialInterpretation) { 216 monitor.subTask('''Solving problem«IF runs>0» «run»/«runs»«ENDIF»: Visualising solution «interpretationIndex+1»/«interpretations.size»''')
200 val vis1 = new PartialInterpretation2Gml 217 val interpretation = interpretations.get(interpretationIndex)
201 val gml = vis1.transform(representation) 218 val model = logic2Ecore.transformInterpretation(interpretation,modelGeneration.trace)
202 outputWorkspaceForRun.writeText('''model«IF runs>1»_«run»«ENDIF»_«interpretationIndex+1».gml''',gml) 219 outputWorkspaceForRun.writeModel(model,'''model«IF runs>1»_«run»«ENDIF»_«interpretationIndex+1».xmi''')
203 if(representation.newElements.size + representation.problem.elements.size < 150) { 220
204 val vis2 = new GraphvizVisualiser 221 val representation = solution.representation.get(interpretationIndex)
205 val dot = vis2.visualiseConcretization(representation) 222 if(representation instanceof PartialInterpretation) {
206 dot.writeToFile(outputWorkspaceForRun,'''model«IF runs>1»_«run»«ENDIF»_«interpretationIndex+1».png''') 223 val vis1 = new PartialInterpretation2Gml
224 val gml = vis1.transform(representation)
225 outputWorkspaceForRun.writeText('''model«IF runs>1»_«run»«ENDIF»_«interpretationIndex+1».gml''',gml)
226 if(representation.newElements.size + representation.problem.elements.size < 150) {
227 val vis2 = new GraphvizVisualiser
228 val dot = vis2.visualiseConcretization(representation)
229 dot.writeToFile(outputWorkspaceForRun,'''model«IF runs>1»_«run»«ENDIF»_«interpretationIndex+1».png''')
230 }
207 } 231 }
232 monitor.worked(100)
208 } 233 }
209 monitor.worked(100) 234 } else {
235 monitor.worked(solverConfig.solutionScope.numberOfRequiredSolution*100)
210 } 236 }
211 } else { 237 solutionVisualisationTime = System.nanoTime - solutionVisualisationTime
212 monitor.worked(solverConfig.solutionScope.numberOfRequiredSolution*100) 238
239 // 8.2 Statistics
240 val statistics = new LinkedHashMap
241 statistics.put("Task",(task.eContainer as ConfigurationScript).commands.indexOf(task)+1)
242 statistics.put("Run",run)
243 statistics.put("Result",solution.class.simpleName)
244 statistics.put("Domain to logic transformation time",domain2LogicTransformationTime/1000000)
245 statistics.put("Logic to solver transformation time",solution.statistics.transformationTime)
246 statistics.put("Solver time",solution.statistics.solverTime)
247 statistics.put("Postprocessing time",solutionVisualisationTime)
248 for(entry: solution.statistics.entries) {
249 statistics.put(entry.name,statisticsUtil.readValue(entry))
250 }
251 console.addStatistics(statistics)
213 } 252 }
214 solutionVisualisationTime = System.nanoTime - solutionVisualisationTime
215 253
216 // 8.2 Statistics
217 val statistics = new LinkedHashMap
218 statistics.put("Task",(task.eContainer as ConfigurationScript).commands.indexOf(task)+1)
219 statistics.put("Run",run)
220 statistics.put("Result",solution.class.simpleName)
221 statistics.put("Domain to logic transformation time",domain2LogicTransformationTime/1000000)
222 statistics.put("Logic to solver transformation time",solution.statistics.transformationTime)
223 statistics.put("Solver time",solution.statistics.solverTime)
224 statistics.put("Postprocessing time",solutionVisualisationTime)
225 for(entry: solution.statistics.entries) {
226 statistics.put(entry.name,statisticsUtil.readValue(entry))
227 }
228 console.addStatistics(statistics)
229 } 254 }
230 console.flushStatistics 255 console.flushStatistics
231 console.writeMessage("Model generation finished") 256 console.writeMessage("Model generation finished")
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 ee1a92f0..9b2b4a3e 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
@@ -14,49 +14,172 @@ import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.StringTyp
14import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic 14import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic
15import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace 15import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace
16import hu.bme.mit.inf.dslreasoner.logic.model.builder.TypeScopes 16import hu.bme.mit.inf.dslreasoner.logic.model.builder.TypeScopes
17import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.DefinedElement
18import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type
19import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeDefinition
17import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem 20import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem
21import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partial2logicannotations.PartialModelRelation2Assertion
22import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.BinaryElementRelationLink
23import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.IntegerElement
24import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.NaryRelationLink
25import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PrimitiveElement
26import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.RealElement
27import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.StringElement
28import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.UnaryElementRelationLink
29import java.math.BigDecimal
30import java.util.HashMap
31import java.util.LinkedList
32import java.util.List
33import java.util.Map
34import java.util.Set
18import org.eclipse.emf.ecore.EClass 35import org.eclipse.emf.ecore.EClass
36import org.eclipse.xtend.lib.annotations.Data
37
38import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.*
39import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.IntLiteral
40import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RealLiteral
41import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.StringLiteral
42
43@Data class KnownElements {
44 val Map<Type,Set<DefinedElement>> knownElementsByType
45 val Set<Integer> knownIntegers
46 val Set<BigDecimal> knownReals
47 val Set<String> knownStrings
48}
19 49
20class ScopeLoader { 50class ScopeLoader {
21 def TypeScopes loadScope(ScopeSpecification specification, LogicProblem problem, Ecore2Logic ecore2Logic, Ecore2Logic_Trace trace) { 51 def loadScope(ScopeSpecification specification, LogicProblem problem, Ecore2Logic ecore2Logic, Ecore2Logic_Trace trace) {
22 val res = new TypeScopes 52 val res = new TypeScopes
53 val knownElements = initialiseknownElements(problem,res)
54 val inconsistencies = new LinkedList<String>()
55
23 for(scopeSpecification : specification.scopes) { 56 for(scopeSpecification : specification.scopes) {
24 setSpecification(scopeSpecification,res,ecore2Logic,trace) 57 setSpecification(scopeSpecification,res,knownElements,ecore2Logic,trace,inconsistencies)
25 } 58 }
26 return res 59
60 return res -> inconsistencies
61 }
62
63 def protected initialiseknownElements(LogicProblem p, TypeScopes s) {
64 val Map<Type,Set<DefinedElement>> res = new HashMap
65 for(definedType : p.types.filter(TypeDefinition)) {
66 val supertypes = definedType.<Type>transitiveClosureStar[x|x.supertypes]
67 for(supertype : supertypes) {
68 for(element : definedType.elements) {
69 res.putOrAddToSet(supertype,element)
70 }
71 }
72 }
73 val partailModelContents = p.annotations.filter(PartialModelRelation2Assertion).map[target].toList.map[eAllContents.toIterable].flatten.toList
74 s.knownIntegers += partailModelContents.filter(IntLiteral).map[it.value]
75 s.knownReals += partailModelContents.filter(RealLiteral).map[it.value]
76 s.knownStrings += partailModelContents.filter(StringLiteral).map[it.value]
77
78 res
79 }
80
81 def dispatch getElements(UnaryElementRelationLink link) {
82 #[link.param1]
83 }
84 def dispatch getElements(BinaryElementRelationLink link) {
85 #[link.param1,link.param2]
86 }
87 def dispatch getElements(NaryRelationLink link) {
88 link.elements
27 } 89 }
28 90
29 def dispatch setSpecification(ObjectTypeScope scope, TypeScopes aggregated, Ecore2Logic ecore2Logic, Ecore2Logic_Trace trace) { 91 def dispatch setSpecification(ObjectTypeScope scope, TypeScopes aggregated, Map<Type, Set<DefinedElement>> knownElements, Ecore2Logic ecore2Logic, Ecore2Logic_Trace trace, List<String> inconsistencies) {
30 //val existingObjects = 92 val numberOfKnownElements = knownElements.values.flatten.toSet.size
31 aggregated.minNewElements = getLowerLimit(scope.number) 93
32 aggregated.maxNewElements = getUpperLimit(scope.number) 94 aggregated.minNewElements = updateLowerLimit(scope.isSetsNew,numberOfKnownElements,aggregated.minNewElements,getLowerLimit(scope.number))
95 aggregated.maxNewElements = updateUpperLimit(scope.isSetsNew,numberOfKnownElements,aggregated.maxNewElements,getUpperLimit(scope.number))
33 } 96 }
34 def dispatch setSpecification(ClassTypeScope scope, TypeScopes aggregated, Ecore2Logic ecore2Logic, Ecore2Logic_Trace trace) { 97 def dispatch setSpecification(ClassTypeScope scope, TypeScopes aggregated, Map<Type, Set<DefinedElement>> knownElements, Ecore2Logic ecore2Logic, Ecore2Logic_Trace trace, List<String> inconsistencies) {
35 val target = scope.type.element 98 val target = scope.type.element
36 if(target.feature != null) { 99 if(target.feature !== null) {
37 throw new IllegalArgumentException('''Feature scopes are not supported: "«target.feature.name»"!''') 100 throw new IllegalArgumentException('''Feature scopes are not supported: "«target.feature.name»"!''')
38 } else { 101 } else {
39 val targetClassifier = target.classifier 102 val targetClassifier = target.classifier
40 if(targetClassifier instanceof EClass) { 103 if(targetClassifier instanceof EClass) {
41 val type = ecore2Logic.TypeofEClass(trace,targetClassifier) 104 val type = ecore2Logic.TypeofEClass(trace,targetClassifier)
42 aggregated.minNewElementsByType.put(type,getLowerLimit(scope.number)) 105 val known = type.lookup(knownElements).size
43 aggregated.maxNewElementsByType.put(type,getUpperLimit(scope.number)) 106 aggregated.minNewElementsByType.put(type,
107 updateLowerLimit(
108 scope.setsNew,
109 known,
110 type.lookup(aggregated.minNewElementsByType),
111 getLowerLimit(scope.number)
112 )
113 )
114 aggregated.maxNewElementsByType.put(type,
115 updateUpperLimit(
116 scope.setsNew,
117 known,
118 type.lookup(aggregated.minNewElementsByType),
119 getUpperLimit(scope.number)
120 )
121 )
44 } else { 122 } else {
45 throw new IllegalArgumentException('''Non-EClass scopes are not supported: "«targetClassifier.name»"!''') 123 throw new IllegalArgumentException('''Non-EClass scopes are not supported: "«targetClassifier.name»"!''')
46 } 124 }
47 } 125 }
48 } 126 }
49 def dispatch setSpecification(IntegerTypeScope scope, TypeScopes aggregated, Ecore2Logic ecore2Logic, Ecore2Logic_Trace trace) { 127 def dispatch setSpecification(IntegerTypeScope scope, TypeScopes aggregated, Map<Type, Set<DefinedElement>> knownElements, Ecore2Logic ecore2Logic, Ecore2Logic_Trace trace, List<String> inconsistencies) {
50 aggregated.minNewIntegers = scope.number.lowerLimit 128 val number = scope.number
51 aggregated.maxNewIntegers = scope.number.upperLimit 129 if(number instanceof IntEnumberation) {
130 addToKnownCollection(aggregated.knownIntegers,number.entry,scope.isSetsNew,inconsistencies)
131 } else {
132 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)
134 }
135 }
136
137 def dispatch setSpecification(RealTypeScope scope, TypeScopes aggregated, Map<Type, Set<DefinedElement>> knownElements, Ecore2Logic ecore2Logic, Ecore2Logic_Trace trace, List<String> inconsistencies) {
138 val number = scope.number
139 if(number instanceof RealEnumeration) {
140 val x = number.entry;
141 <BigDecimal>addToKnownCollection(aggregated.knownReals,x,scope.isSetsNew,inconsistencies)
142 } else {
143 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)
145 }
146 }
147 def dispatch setSpecification(StringTypeScope scope, TypeScopes aggregated, Map<Type, Set<DefinedElement>> knownElements, Ecore2Logic ecore2Logic, Ecore2Logic_Trace trace, List<String> inconsistencies) {
148 val number = scope.number
149 if(number instanceof StringEnumeration) {
150 <String>addToKnownCollection(aggregated.knownStrings,number.entry,scope.isSetsNew,inconsistencies)
151 } else {
152 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)
154 }
155 }
156 def <Type> addToKnownCollection(Set<Type> known, List<Type> definedInScope, boolean isSetNew, List<String> inconsistencies) {
157 if(isSetNew) {
158 known += definedInScope
159 } else {
160 if(!definedInScope.containsAll(known)) {
161 val notDefinedInScope = known.filter[!definedInScope.contains(it)]
162 inconsistencies += '''Inconsistent scope: problem already contains literal«IF notDefinedInScope.size > 0»s«ENDIF» that excluded by a scope: «FOR e: notDefinedInScope SEPARATOR ", "»«e»«ENDFOR».'''
163 }
164 known.clear
165 known += definedInScope
166 }
52 } 167 }
53 def dispatch setSpecification(RealTypeScope scope, TypeScopes aggregated, Ecore2Logic ecore2Logic, Ecore2Logic_Trace trace) { 168
54 aggregated.minNewReals = scope.number.lowerLimit 169 def updateLowerLimit(boolean isAdditional, int known, int original, int value) {
55 aggregated.maxNewReals = scope.number.upperLimit 170 if(isAdditional) {
171 return Math.max(original,value)
172 } else {
173 return Math.max(original,value-known)
174 }
56 } 175 }
57 def dispatch setSpecification(StringTypeScope scope, TypeScopes aggregated, Ecore2Logic ecore2Logic, Ecore2Logic_Trace trace) { 176 def updateUpperLimit(boolean isAdditional, int known, int original, int value) {
58 aggregated.minNewStrings = scope.number.lowerLimit 177 if(isAdditional) {
59 aggregated.maxNewStrings = scope.number.upperLimit 178 return Math.min(original,value)
179 } else {
180 val target = if(value == Integer.MAX_VALUE) { Integer.MAX_VALUE } else {value-known}
181 return Math.min(original,target)
182 }
60 } 183 }
61 184
62 def dispatch getLowerLimit(IntervallNumber specification) { 185 def dispatch getLowerLimit(IntervallNumber specification) {
@@ -70,14 +193,12 @@ class ScopeLoader {
70 def dispatch getLowerLimit(RealEnumeration specification) { 0 } 193 def dispatch getLowerLimit(RealEnumeration specification) { 0 }
71 def dispatch getLowerLimit(StringEnumeration specification) { 0 } 194 def dispatch getLowerLimit(StringEnumeration specification) { 0 }
72 def dispatch getUpperLimit(IntervallNumber specification) { 195 def dispatch getUpperLimit(IntervallNumber specification) {
73 if(specification.isMaxUnlimited) return -1 196 if(specification.isMaxUnlimited) return Integer.MAX_VALUE
74 else return specification.maxNumber 197 else return specification.maxNumber
75 } 198 }
76 def dispatch getUpperLimit(ExactNumber specification) { 199 def dispatch getUpperLimit(ExactNumber specification) {
77 if(specification.isExactUnlimited) return -1 200 if(specification.isExactUnlimited) return Integer.MAX_VALUE
78 else return specification.exactNumber 201 else return specification.exactNumber
79 } 202 }
80 def dispatch getUpperLimit(IntEnumberation specification) { 0 } 203
81 def dispatch getUpperLimit(RealEnumeration specification) { 0 }
82 def dispatch getUpperLimit(StringEnumeration specification) { 0 }
83} \ No newline at end of file 204} \ No newline at end of file