diff options
Diffstat (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage')
1 files changed, 75 insertions, 11 deletions
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/PartialInterpretationInitialiser.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/PartialInterpretationInitialiser.xtend index 2a350d53..cc76ce3f 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/PartialInterpretationInitialiser.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/PartialInterpretationInitialiser.xtend | |||
@@ -2,6 +2,7 @@ package hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage | |||
2 | 2 | ||
3 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.TracedOutput | 3 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.TracedOutput |
4 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.TypeScopes | 4 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.TypeScopes |
5 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.DefinedElement | ||
5 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.LogiclanguageFactory | 6 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.LogiclanguageFactory |
6 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RelationDeclaration | 7 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RelationDeclaration |
7 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type | 8 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type |
@@ -10,8 +11,10 @@ import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeDefinition | |||
10 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem | 11 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem |
11 | import hu.bme.mit.inf.dslreasoner.logic.model.patterns.SupertypeStar | 12 | import hu.bme.mit.inf.dslreasoner.logic.model.patterns.SupertypeStar |
12 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partial2logicannotations.PartialModelRelation2Assertion | 13 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partial2logicannotations.PartialModelRelation2Assertion |
14 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.BinaryElementRelationLink | ||
13 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.BooleanElement | 15 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.BooleanElement |
14 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.IntegerElement | 16 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.IntegerElement |
17 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.NaryRelationLink | ||
15 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialBooleanInterpretation | 18 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialBooleanInterpretation |
16 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialComplexTypeInterpretation | 19 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialComplexTypeInterpretation |
17 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialIntegerInterpretation | 20 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialIntegerInterpretation |
@@ -22,16 +25,22 @@ import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.par | |||
22 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialinterpretationFactory | 25 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialinterpretationFactory |
23 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.RealElement | 26 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.RealElement |
24 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.StringElement | 27 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.StringElement |
28 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.UnaryElementRelationLink | ||
25 | import java.math.BigDecimal | 29 | import java.math.BigDecimal |
26 | import java.util.HashMap | 30 | import java.util.HashMap |
27 | import java.util.Map | 31 | import java.util.Map |
28 | import java.util.SortedSet | 32 | import java.util.SortedSet |
29 | import org.eclipse.emf.ecore.util.EcoreUtil | ||
30 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine | 33 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine |
31 | import org.eclipse.viatra.query.runtime.emf.EMFScope | 34 | import org.eclipse.viatra.query.runtime.emf.EMFScope |
32 | import org.eclipse.xtend.lib.annotations.Data | 35 | import org.eclipse.xtend.lib.annotations.Data |
33 | 36 | ||
34 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* | 37 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* |
38 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.SymbolicValue | ||
39 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.And | ||
40 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.BoolLiteral | ||
41 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.IntLiteral | ||
42 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RealLiteral | ||
43 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.StringLiteral | ||
35 | 44 | ||
36 | @Data class Problem2PartialInterpretationTrace { | 45 | @Data class Problem2PartialInterpretationTrace { |
37 | Map<TypeDeclaration, PartialComplexTypeInterpretation> type2Interpretation | 46 | Map<TypeDeclaration, PartialComplexTypeInterpretation> type2Interpretation |
@@ -81,7 +90,7 @@ class PartialInterpretationInitialiser { | |||
81 | typeScopes.maxNewElements) | 90 | typeScopes.maxNewElements) |
82 | 91 | ||
83 | // Initialise relations | 92 | // Initialise relations |
84 | val relation2Interpretation = initRelations(res) | 93 | val relation2Interpretation = initRelations(res,primitiveTrace) |
85 | 94 | ||
86 | val trace = new Problem2PartialInterpretationTrace(type2Interpretation,primitiveTrace,relation2Interpretation) | 95 | val trace = new Problem2PartialInterpretationTrace(type2Interpretation,primitiveTrace,relation2Interpretation) |
87 | return new TracedOutput(res,trace) | 96 | return new TracedOutput(res,trace) |
@@ -95,13 +104,13 @@ class PartialInterpretationInitialiser { | |||
95 | { | 104 | { |
96 | return new PrimitiveValueTrace( | 105 | return new PrimitiveValueTrace( |
97 | booleanType, | 106 | booleanType, |
98 | booleanType.elements.filter(BooleanElement).toMap[value], | 107 | booleanType.elements.filter(BooleanElement).filter[it.isValueSet].toMap[value], |
99 | integerType, | 108 | integerType, |
100 | integerType.elements.filter(IntegerElement).toMap[value], | 109 | integerType.elements.filter(IntegerElement).filter[it.isValueSet].toMap[value], |
101 | realType, | 110 | realType, |
102 | realType.elements.filter(RealElement).toMap[value], | 111 | realType.elements.filter(RealElement).filter[it.isValueSet].toMap[value], |
103 | stringType, | 112 | stringType, |
104 | stringType.elements.filter(StringElement).toMap[value] | 113 | stringType.elements.filter(StringElement).filter[it.isValueSet].toMap[value] |
105 | ) | 114 | ) |
106 | } | 115 | } |
107 | 116 | ||
@@ -130,7 +139,9 @@ class PartialInterpretationInitialiser { | |||
130 | partialInterpretation.newElements += integerElement | 139 | partialInterpretation.newElements += integerElement |
131 | } | 140 | } |
132 | if(maxNewIntegers>0) { | 141 | if(maxNewIntegers>0) { |
133 | throw new UnsupportedOperationException('''Unspecified Integers are currently not supported!''') | 142 | val newElements = createIntegerElement => [it.name = "New Integers" it.valueSet = false] |
143 | partialInterpretation.openWorldElements += newElements | ||
144 | integerInterpretation.elements += newElements | ||
134 | } | 145 | } |
135 | 146 | ||
136 | return integerInterpretation | 147 | return integerInterpretation |
@@ -146,7 +157,9 @@ class PartialInterpretationInitialiser { | |||
146 | partialInterpretation.newElements += realElement | 157 | partialInterpretation.newElements += realElement |
147 | } | 158 | } |
148 | if(maxNewReals>0) { | 159 | if(maxNewReals>0) { |
149 | throw new UnsupportedOperationException('''Unspecified Real values are currently not supported!''') | 160 | val newElements = createRealElement => [it.name = "New Reals" it.valueSet = false] |
161 | partialInterpretation.openWorldElements += newElements | ||
162 | realInterpretation.elements += newElements | ||
150 | } | 163 | } |
151 | return realInterpretation | 164 | return realInterpretation |
152 | } | 165 | } |
@@ -161,7 +174,9 @@ class PartialInterpretationInitialiser { | |||
161 | partialInterpretation.newElements += stringElement | 174 | partialInterpretation.newElements += stringElement |
162 | } | 175 | } |
163 | if(maxNewStrings>0) { | 176 | if(maxNewStrings>0) { |
164 | throw new UnsupportedOperationException('''Unspecified String values are currently not supported!''') | 177 | val newElements = createStringElement => [it.name = "New Strings" it.valueSet = false] |
178 | partialInterpretation.openWorldElements += newElements | ||
179 | stringInterpretation.elements += newElements | ||
165 | } | 180 | } |
166 | 181 | ||
167 | return stringInterpretation | 182 | return stringInterpretation |
@@ -201,7 +216,7 @@ class PartialInterpretationInitialiser { | |||
201 | } | 216 | } |
202 | } | 217 | } |
203 | 218 | ||
204 | def private initRelations(PartialInterpretation interpretation) { | 219 | def private Map<RelationDeclaration, PartialRelationInterpretation> initRelations(PartialInterpretation interpretation, PrimitiveValueTrace trace) { |
205 | val Map<RelationDeclaration, PartialRelationInterpretation> relation2Interpretation = new HashMap | 220 | val Map<RelationDeclaration, PartialRelationInterpretation> relation2Interpretation = new HashMap |
206 | for(relation : interpretation.problem.relations.filter(RelationDeclaration)) { | 221 | for(relation : interpretation.problem.relations.filter(RelationDeclaration)) { |
207 | val partialInterpretation = relation.initialisePartialRelationInterpretation | 222 | val partialInterpretation = relation.initialisePartialRelationInterpretation |
@@ -211,8 +226,24 @@ class PartialInterpretationInitialiser { | |||
211 | for(pMR2A : interpretation.problem.annotations.filter(PartialModelRelation2Assertion)) { | 226 | for(pMR2A : interpretation.problem.annotations.filter(PartialModelRelation2Assertion)) { |
212 | val relation = pMR2A.targetRelation | 227 | val relation = pMR2A.targetRelation |
213 | val r = relation.lookup(relation2Interpretation) | 228 | val r = relation.lookup(relation2Interpretation) |
214 | r.relationlinks+=pMR2A.links.map[EcoreUtil.copy(it)] | 229 | val assertion = pMR2A.target.value |
230 | val links = if(assertion instanceof SymbolicValue) { | ||
231 | #[assertion] | ||
232 | } else if(assertion instanceof And){ | ||
233 | val res = assertion.operands.filter(SymbolicValue) | ||
234 | if(res.size != assertion.operands) { | ||
235 | throw new UnsupportedOperationException('''Assertion describing partial model of "«r.interpretationOf.name»" contains unsupported constructs''') | ||
236 | } else { | ||
237 | res | ||
238 | } | ||
239 | } else { | ||
240 | throw new UnsupportedOperationException('''Assertion describing partial model of "«r.interpretationOf.name»" contains unsupported constructs''') | ||
241 | } | ||
242 | for(link:links) { | ||
243 | r.relationlinks += createLink(link,trace) | ||
244 | } | ||
215 | } | 245 | } |
246 | |||
216 | // interpretation.partialfunctioninterpretation += interpretation.problem.functions.filter(FunctionDeclaration) | 247 | // interpretation.partialfunctioninterpretation += interpretation.problem.functions.filter(FunctionDeclaration) |
217 | // .map[initialisePartialFunctionInterpretation(trace)] | 248 | // .map[initialisePartialFunctionInterpretation(trace)] |
218 | // interpretation.partialconstantinterpretation += interpretation.problem.constants.filter(ConstantDeclaration) | 249 | // interpretation.partialconstantinterpretation += interpretation.problem.constants.filter(ConstantDeclaration) |
@@ -220,6 +251,39 @@ class PartialInterpretationInitialiser { | |||
220 | 251 | ||
221 | return relation2Interpretation | 252 | return relation2Interpretation |
222 | } | 253 | } |
254 | def private createLink(SymbolicValue v, PrimitiveValueTrace trace) { | ||
255 | val translatedValues = v.parameterSubstitutions.map[getElement(trace)].toList | ||
256 | if(translatedValues.size == 1) { | ||
257 | return createUnaryElementRelationLink => [it.param1 = translatedValues.get(0)] | ||
258 | } else if(translatedValues.size == 2) { | ||
259 | return createBinaryElementRelationLink => [it.param1 = translatedValues.get(0) it.param2 = translatedValues.get(1)] | ||
260 | } else { | ||
261 | val res = createNaryRelationLink | ||
262 | for(i : 0..<translatedValues.size) { | ||
263 | res.elements += createNaryRelationLinkElement => [ | ||
264 | it.index = i | ||
265 | it.param = translatedValues.get(i) | ||
266 | ] | ||
267 | } | ||
268 | return res | ||
269 | } | ||
270 | } | ||
271 | |||
272 | def private dispatch getElement(SymbolicValue element, PrimitiveValueTrace trace) { | ||
273 | return element.symbolicReference as DefinedElement | ||
274 | } | ||
275 | def private dispatch getElement(BoolLiteral element, PrimitiveValueTrace trace) { | ||
276 | element.value.lookup(trace.booleanMap) | ||
277 | } | ||
278 | def private dispatch getElement(IntLiteral element, PrimitiveValueTrace trace) { | ||
279 | element.value.lookup(trace.integerMap) | ||
280 | } | ||
281 | def private dispatch getElement(RealLiteral element, PrimitiveValueTrace trace) { | ||
282 | element.value.lookup(trace.realMap) | ||
283 | } | ||
284 | def private dispatch getElement(StringLiteral element, PrimitiveValueTrace trace) { | ||
285 | element.value.lookup(trace.stringMap) | ||
286 | } | ||
223 | 287 | ||
224 | def private initialisePartialTypeInterpretation(TypeDeclaration t, ViatraQueryEngine engine) { | 288 | def private initialisePartialTypeInterpretation(TypeDeclaration t, ViatraQueryEngine engine) { |
225 | val supertypeMatcher = SupertypeStar.Matcher.on(engine) | 289 | val supertypeMatcher = SupertypeStar.Matcher.on(engine) |