aboutsummaryrefslogtreecommitdiffstats
path: root/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf
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 /Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf
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 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf')
-rw-r--r--Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/InstanceModel2PartialInterpretation.xtend81
-rw-r--r--Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/PartialInterpretation2Logic.xtend22
-rw-r--r--Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/PartialInterpretationInitialiser.xtend86
3 files changed, 169 insertions, 20 deletions
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/InstanceModel2PartialInterpretation.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/InstanceModel2PartialInterpretation.xtend
index f4fc1fce..bd0f4ca4 100644
--- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/InstanceModel2PartialInterpretation.xtend
+++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/InstanceModel2PartialInterpretation.xtend
@@ -20,6 +20,10 @@ import org.eclipse.emf.ecore.EObject
20import org.eclipse.emf.ecore.resource.Resource 20import org.eclipse.emf.ecore.resource.Resource
21 21
22import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* 22import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.*
23import java.util.HashSet
24import java.util.Set
25import java.math.BigDecimal
26import org.eclipse.emf.ecore.EAttribute
23 27
24class InstanceModel2PartialInterpretation { 28class InstanceModel2PartialInterpretation {
25 val extension LogiclanguageFactory factory = LogiclanguageFactory.eINSTANCE 29 val extension LogiclanguageFactory factory = LogiclanguageFactory.eINSTANCE
@@ -43,7 +47,12 @@ class InstanceModel2PartialInterpretation {
43 { 47 {
44 val problem = metamodelTranslationResult.output 48 val problem = metamodelTranslationResult.output
45 val ecore2LogicTrace = metamodelTranslationResult.trace 49 val ecore2LogicTrace = metamodelTranslationResult.trace
46 val tracedOutput = partialInterpretationInitialiser.initialisePartialInterpretation(problem, new TypeScopes) 50
51 val referencesUsed = ecore2Logic.allReferencesInScope(ecore2LogicTrace).toSet
52 val attributesUsed = ecore2Logic.allAttributesInScope(ecore2LogicTrace).toSet
53
54 val typeScope = createTypeScopesFromKnownAttributeValues(objects,attributesUsed)
55 val tracedOutput = partialInterpretationInitialiser.initialisePartialInterpretation(problem, typeScope)
47 val partialInterpretation = tracedOutput.output 56 val partialInterpretation = tracedOutput.output
48 val partialInterpretationTrace = tracedOutput.trace 57 val partialInterpretationTrace = tracedOutput.trace
49 58
@@ -54,7 +63,7 @@ class InstanceModel2PartialInterpretation {
54 val object = objects.get(objectIndex) 63 val object = objects.get(objectIndex)
55 val element = createDefinedElement => [ 64 val element = createDefinedElement => [
56 it.name = if(withID) 65 it.name = if(withID)
57 { '''o «objectIndex»''' } else 66 { '''o «objectIndex+1»''' } else
58 { null } 67 { null }
59 ] 68 ]
60 69
@@ -71,8 +80,6 @@ class InstanceModel2PartialInterpretation {
71 object2DefinedElement.put(object, element) 80 object2DefinedElement.put(object, element)
72 } 81 }
73 82
74 val referencesUsed = ecore2Logic.allReferencesInScope(ecore2LogicTrace).toSet
75 val attributesUsed = ecore2Logic.allAttributesInScope(ecore2LogicTrace).toSet
76 for(source : objects) { 83 for(source : objects) {
77 // Translating the references 84 // Translating the references
78 for(reference : source.eClass.EAllReferences.filter[ 85 for(reference : source.eClass.EAllReferences.filter[
@@ -126,6 +133,52 @@ class InstanceModel2PartialInterpretation {
126 return partialInterpretation 133 return partialInterpretation
127 } 134 }
128 135
136 private def createTypeScopesFromKnownAttributeValues(List<EObject> objects, Set<EAttribute> attributesUsed) {
137 val Set<Integer> integers = new HashSet
138 val Set<BigDecimal> reals = new HashSet
139 val Set<String> strings = new HashSet
140 for(object: objects) {
141 for(attribute : object.eClass.EAllAttributes.filter[attributesUsed.contains(it)]) {
142 val value = object.eGet(attribute)
143 if(value !== null) {
144 if(value instanceof List<?>) {
145 for(v : value) {
146 shortValue(v,integers,reals,strings)
147 }
148 } else {
149 shortValue(value,integers,reals,strings)
150 }
151 }
152 }
153 }
154 return new TypeScopes => [
155 it.knownIntegers += integers
156 it.knownReals += reals
157 it.knownStrings += strings
158 ]
159 }
160 private def dispatch shortValue(Boolean value, Set<Integer> integers, Set<BigDecimal> reals, Set<String> strings) {
161 // Do nothing
162 }
163 private def dispatch shortValue(Integer value, Set<Integer> integers, Set<BigDecimal> reals, Set<String> strings) {
164 integers += value
165 }
166 private def dispatch shortValue(Float value, Set<Integer> integers, Set<BigDecimal> reals, Set<String> strings) {
167 reals += BigDecimal.valueOf(value)
168 }
169 private def dispatch shortValue(Double value, Set<Integer> integers, Set<BigDecimal> reals, Set<String> strings) {
170 reals += BigDecimal.valueOf(value)
171 }
172 private def dispatch shortValue(String value, Set<Integer> integers, Set<BigDecimal> reals, Set<String> strings) {
173 strings += value
174 }
175 private def dispatch shortValue(Void value, Set<Integer> integers, Set<BigDecimal> reals, Set<String> strings) {
176 // Do nothing
177 }
178 private def dispatch shortValue(Object value, Set<Integer> integers, Set<BigDecimal> reals, Set<String> strings) {
179 // Do nothing
180 }
181
129 protected def translateLink(PartialRelationInterpretation interpretation, DefinedElement source, DefinedElement target) { 182 protected def translateLink(PartialRelationInterpretation interpretation, DefinedElement source, DefinedElement target) {
130 interpretation.relationlinks += createBinaryElementRelationLink => [it.param1 = source it.param2 = target] 183 interpretation.relationlinks += createBinaryElementRelationLink => [it.param1 = source it.param2 = target]
131 } 184 }
@@ -138,7 +191,23 @@ class InstanceModel2PartialInterpretation {
138 else throw new AssertionError('''term should be a defined element?''') 191 else throw new AssertionError('''term should be a defined element?''')
139 } 192 }
140 193
141 dispatch protected def translateValue(Object value, Ecore2Logic_Trace ecore2LogicTrace, Problem2PartialInterpretationTrace partialInterpretationTrace) { 194 dispatch protected def translateValue(Boolean value, Ecore2Logic_Trace ecore2LogicTrace, Problem2PartialInterpretationTrace partialInterpretationTrace) {
142 //throw new UnsupportedOperationException('''Mapping of «value.class.simpleName» in partial models is currently not supported!''') 195 value.lookup(partialInterpretationTrace.primitiveValues.booleanMap)
196 }
197
198 dispatch protected def translateValue(Integer value, Ecore2Logic_Trace ecore2LogicTrace, Problem2PartialInterpretationTrace partialInterpretationTrace) {
199 value.lookup(partialInterpretationTrace.primitiveValues.integerMap)
200 }
201
202 dispatch protected def translateValue(Double value, Ecore2Logic_Trace ecore2LogicTrace, Problem2PartialInterpretationTrace partialInterpretationTrace) {
203 BigDecimal.valueOf(value).lookup(partialInterpretationTrace.primitiveValues.realMap)
204 }
205
206 dispatch protected def translateValue(Float value, Ecore2Logic_Trace ecore2LogicTrace, Problem2PartialInterpretationTrace partialInterpretationTrace) {
207 BigDecimal.valueOf(value).lookup(partialInterpretationTrace.primitiveValues.realMap)
208 }
209
210 dispatch protected def translateValue(String value, Ecore2Logic_Trace ecore2LogicTrace, Problem2PartialInterpretationTrace partialInterpretationTrace) {
211 value.lookup(partialInterpretationTrace.primitiveValues.stringMap)
143 } 212 }
144} \ No newline at end of file 213} \ No newline at end of file
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/PartialInterpretation2Logic.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/PartialInterpretation2Logic.xtend
index 5d8d9313..bba4ae92 100644
--- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/PartialInterpretation2Logic.xtend
+++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/PartialInterpretation2Logic.xtend
@@ -24,6 +24,9 @@ import org.eclipse.xtend.lib.annotations.Data
24 24
25import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* 25import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.*
26import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PrimitiveElement 26import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PrimitiveElement
27import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.BooleanElement
28import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.IntegerElement
29import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.RealElement
27 30
28@Data class PartialInterpretation2Logic_Trace { 31@Data class PartialInterpretation2Logic_Trace {
29 Map<DefinedElement,DefinedElement> new2Old = new HashMap 32 Map<DefinedElement,DefinedElement> new2Old = new HashMap
@@ -148,7 +151,7 @@ class PartialInterpretation2Logic {
148 val ^annotation= Partial2logicannotationsFactory.eINSTANCE.createPartialModelRelation2Assertion 151 val ^annotation= Partial2logicannotationsFactory.eINSTANCE.createPartialModelRelation2Assertion
149 ^annotation.target = assertion 152 ^annotation.target = assertion
150 ^annotation.targetRelation = relation 153 ^annotation.targetRelation = relation
151 ^annotation.links += links.map[EcoreUtil.copy(it)] 154 //^annotation.links += links.map[EcoreUtil.copy(it)]
152 //val error= assertion.eAllContents.toIterable.filter(SymbolicValue).filter[it.symbolicReference === null] 155 //val error= assertion.eAllContents.toIterable.filter(SymbolicValue).filter[it.symbolicReference === null]
153 //error.forEach[println("error")] 156 //error.forEach[println("error")]
154 p.add(assertion) 157 p.add(assertion)
@@ -162,12 +165,25 @@ class PartialInterpretation2Logic {
162 if((link.param1 !== null) && (link.param2 !== null)) { 165 if((link.param1 !== null) && (link.param2 !== null)) {
163 return createSymbolicValue=>[ 166 return createSymbolicValue=>[
164 it.symbolicReference=relationDeclaration 167 it.symbolicReference=relationDeclaration
165 it.parameterSubstitutions += createSymbolicValue => [it.symbolicReference = link.param1] 168 it.parameterSubstitutions += createValueInLink(link.param1)
166 it.parameterSubstitutions += createSymbolicValue => [it.symbolicReference = link.param2] 169 it.parameterSubstitutions += createValueInLink(link.param2)
167 ] 170 ]
168 } else { 171 } else {
169 throw new IllegalArgumentException 172 throw new IllegalArgumentException
170 } 173 }
171 } else throw new UnsupportedOperationException 174 } else throw new UnsupportedOperationException
172 } 175 }
176
177 def private dispatch createValueInLink(BooleanElement element) {
178 return element.value.asTerm
179 }
180 def private dispatch createValueInLink(IntegerElement element) {
181 return element.value.asTerm
182 }
183 def private dispatch createValueInLink(RealElement element) {
184 return element.value.asTerm
185 }
186 def private dispatch createValueInLink(DefinedElement element) {
187 return createSymbolicValue => [it.symbolicReference = element]
188 }
173} \ No newline at end of file 189} \ No newline at end of file
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
3import hu.bme.mit.inf.dslreasoner.logic.model.builder.TracedOutput 3import hu.bme.mit.inf.dslreasoner.logic.model.builder.TracedOutput
4import hu.bme.mit.inf.dslreasoner.logic.model.builder.TypeScopes 4import hu.bme.mit.inf.dslreasoner.logic.model.builder.TypeScopes
5import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.DefinedElement
5import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.LogiclanguageFactory 6import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.LogiclanguageFactory
6import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RelationDeclaration 7import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RelationDeclaration
7import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type 8import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type
@@ -10,8 +11,10 @@ import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeDefinition
10import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem 11import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem
11import hu.bme.mit.inf.dslreasoner.logic.model.patterns.SupertypeStar 12import hu.bme.mit.inf.dslreasoner.logic.model.patterns.SupertypeStar
12import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partial2logicannotations.PartialModelRelation2Assertion 13import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partial2logicannotations.PartialModelRelation2Assertion
14import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.BinaryElementRelationLink
13import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.BooleanElement 15import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.BooleanElement
14import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.IntegerElement 16import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.IntegerElement
17import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.NaryRelationLink
15import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialBooleanInterpretation 18import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialBooleanInterpretation
16import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialComplexTypeInterpretation 19import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialComplexTypeInterpretation
17import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialIntegerInterpretation 20import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialIntegerInterpretation
@@ -22,16 +25,22 @@ import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.par
22import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialinterpretationFactory 25import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialinterpretationFactory
23import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.RealElement 26import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.RealElement
24import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.StringElement 27import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.StringElement
28import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.UnaryElementRelationLink
25import java.math.BigDecimal 29import java.math.BigDecimal
26import java.util.HashMap 30import java.util.HashMap
27import java.util.Map 31import java.util.Map
28import java.util.SortedSet 32import java.util.SortedSet
29import org.eclipse.emf.ecore.util.EcoreUtil
30import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine 33import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine
31import org.eclipse.viatra.query.runtime.emf.EMFScope 34import org.eclipse.viatra.query.runtime.emf.EMFScope
32import org.eclipse.xtend.lib.annotations.Data 35import org.eclipse.xtend.lib.annotations.Data
33 36
34import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* 37import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.*
38import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.SymbolicValue
39import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.And
40import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.BoolLiteral
41import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.IntLiteral
42import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RealLiteral
43import 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)