aboutsummaryrefslogtreecommitdiffstats
path: root/Solvers/Vampire-Solver/ca.mcgill.ecse.dslreasoner.vampire.reasoner/src/ca/mcgill/ecse/dslreasoner/vampire/reasoner/builder/VampireModelInterpretation.xtend
diff options
context:
space:
mode:
Diffstat (limited to 'Solvers/Vampire-Solver/ca.mcgill.ecse.dslreasoner.vampire.reasoner/src/ca/mcgill/ecse/dslreasoner/vampire/reasoner/builder/VampireModelInterpretation.xtend')
-rw-r--r--Solvers/Vampire-Solver/ca.mcgill.ecse.dslreasoner.vampire.reasoner/src/ca/mcgill/ecse/dslreasoner/vampire/reasoner/builder/VampireModelInterpretation.xtend150
1 files changed, 88 insertions, 62 deletions
diff --git a/Solvers/Vampire-Solver/ca.mcgill.ecse.dslreasoner.vampire.reasoner/src/ca/mcgill/ecse/dslreasoner/vampire/reasoner/builder/VampireModelInterpretation.xtend b/Solvers/Vampire-Solver/ca.mcgill.ecse.dslreasoner.vampire.reasoner/src/ca/mcgill/ecse/dslreasoner/vampire/reasoner/builder/VampireModelInterpretation.xtend
index 5df47bbc..ef77b6ca 100644
--- a/Solvers/Vampire-Solver/ca.mcgill.ecse.dslreasoner.vampire.reasoner/src/ca/mcgill/ecse/dslreasoner/vampire/reasoner/builder/VampireModelInterpretation.xtend
+++ b/Solvers/Vampire-Solver/ca.mcgill.ecse.dslreasoner.vampire.reasoner/src/ca/mcgill/ecse/dslreasoner/vampire/reasoner/builder/VampireModelInterpretation.xtend
@@ -24,26 +24,28 @@ import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeDeclaration
24import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeDefinition 24import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeDefinition
25import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.impl.RelationDeclarationImpl 25import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.impl.RelationDeclarationImpl
26import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.impl.TypeDeclarationImpl 26import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.impl.TypeDeclarationImpl
27import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.impl.TypeDefinitionImpl
27import java.util.Arrays 28import java.util.Arrays
28import java.util.HashMap 29import java.util.HashMap
29import java.util.List 30import java.util.List
30import java.util.Map 31import java.util.Map
31import java.util.Set
32 32
33import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* 33import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.*
34import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.impl.TypeDefinitionImpl 34import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RelationDefinition
35import java.util.concurrent.TimeUnit
35 36
36class VampireModelInterpretation implements LogicModelInterpretation { 37class VampireModelInterpretation implements LogicModelInterpretation {
37 protected val extension LogiclanguageFactory factory = LogiclanguageFactory.eINSTANCE 38 protected val extension LogiclanguageFactory factory = LogiclanguageFactory.eINSTANCE
38 39
39 protected val Logic2VampireLanguageMapperTrace forwardTrace; 40 protected val Logic2VampireLanguageMapperTrace forwardTrace;
40 41
41 //These three maps capture all the information found in the Vampire output 42 // These three maps capture all the information found in the Vampire output
42 private val Map<String, DefinedElement> name2DefinedElement = new HashMap 43 private val Map<String, DefinedElement> name2DefinedElement = new HashMap
43 private val Map<TypeDeclaration, List<DefinedElement>> type2DefinedElement = new HashMap 44 private val Map<TypeDeclaration, List<DefinedElement>> type2DefinedElement = new HashMap
44 private val Map<RelationDeclaration, List<String[]>> rel2Inst = new HashMap 45 private val Map<RelationDeclaration, List<String[]>> relDec2Inst = new HashMap
45 //end 46 private val Map<RelationDefinition, List<String[]>> relDef2Inst = new HashMap
46 47
48 // end
47 public new(VampireModel model, Logic2VampireLanguageMapperTrace trace) { 49 public new(VampireModel model, Logic2VampireLanguageMapperTrace trace) {
48 this.forwardTrace = trace 50 this.forwardTrace = trace
49 51
@@ -77,6 +79,7 @@ class VampireModelInterpretation implements LogicModelInterpretation {
77// println() 79// println()
78// println(trace.type2Predicate) 80// println(trace.type2Predicate)
79 // Fill keys of map 81 // Fill keys of map
82 println(trace.type2Predicate.keySet)
80 val allTypeDecls = trace.type2Predicate.keySet.filter[class == TypeDeclarationImpl] 83 val allTypeDecls = trace.type2Predicate.keySet.filter[class == TypeDeclarationImpl]
81 val allTypeFunctions = trace.predicate2Type 84 val allTypeFunctions = trace.predicate2Type
82 println(trace.type2Predicate.keySet.filter[class == TypeDefinitionImpl]) 85 println(trace.type2Predicate.keySet.filter[class == TypeDefinitionImpl])
@@ -86,52 +89,64 @@ class VampireModelInterpretation implements LogicModelInterpretation {
86 } 89 }
87 90
88 // USE THE DECLARE_<TYPE_NAME> FORMULAS TO SEE WHAT THE TYPES ARE 91 // USE THE DECLARE_<TYPE_NAME> FORMULAS TO SEE WHAT THE TYPES ARE
89 val typeFormulas = model.tfformulas.filter[name.length > 12 && name.substring(0, 12) == "predicate_t_"] 92 val typeFormulas = model.tfformulas.filter [
93 name.length > 12 && (name.substring(0, 12) == "predicate_t_" || name.substring(0, 12) == "predicate_e_")
94 ]
90 // ^this way, we ignore the "object" type 95 // ^this way, we ignore the "object" type
91 //TODO potentially need to handle the enums in this case as well 96 // TODO potentially need to handle the enums in this case as well
92 for (formula : typeFormulas) { 97 for (formula : typeFormulas) {
93 // get associated type 98 // get associated type
94 val associatedTypeName = (formula as VLSTffFormula).name.substring(10) 99 val associatedTypeName = (formula as VLSTffFormula).name.substring(10)
95 val associatedFunction = allTypeFunctions.keySet.filter[constant == associatedTypeName]. 100 print(associatedTypeName)
96 get(0) as VLSFunction 101 val associatedFunctions = allTypeFunctions.keySet.filter[constant == associatedTypeName]
97 val associatedTypeAll = associatedFunction.lookup(allTypeFunctions) 102 if (associatedFunctions.length > 0) {
103 val associatedFunction = associatedFunctions.get(0) as VLSFunction
104 val associatedTypeAll = associatedFunction.lookup(allTypeFunctions)
98// val associatedTypeDeclFormula = model.tfformulas.filter[name == ("declare_t_" + associatedTypeName)].get(0) as VLSTffFormula 105// val associatedTypeDeclFormula = model.tfformulas.filter[name == ("declare_t_" + associatedTypeName)].get(0) as VLSTffFormula
99// val associatedTypeDefn = associatedTypeDeclFormula.fofFormula as VLSOtherDeclaration 106// val associatedTypeDefn = associatedTypeDeclFormula.fofFormula as VLSOtherDeclaration
100// val associatedTypeFct = associatedTypeDefn.name as VLSConstant 107// val associatedTypeFct = associatedTypeDefn.name as VLSConstant
101 if (associatedTypeAll.class == TypeDeclarationImpl) { 108 if (associatedTypeAll.class == TypeDeclarationImpl) {
102 val associatedType = associatedTypeAll as TypeDeclaration 109 val associatedType = associatedTypeAll as TypeDeclaration
110
111 // get definedElements
112 var andFormulaTerm = formula.fofFormula
113 end = false
114 val List<DefinedElement> instances = newArrayList
115 while (!end) {
116 if (andFormulaTerm.class == VLSAndImpl) {
117 val andFormula = andFormulaTerm as VLSAnd
118 val andRight = andFormula.right
119 addIfNotNeg(andRight, instances)
120 andFormulaTerm = andFormula.left
121 } else {
122 addIfNotNeg(andFormulaTerm as VLSTerm, instances)
123 end = true
124 }
103 125
104 // get definedElements
105 var andFormulaTerm = formula.fofFormula
106 end = false
107 val List<DefinedElement> instances = newArrayList
108 while (!end) {
109 if (andFormulaTerm.class == VLSAndImpl) {
110 val andFormula = andFormulaTerm as VLSAnd
111 val andRight = andFormula.right
112 addIfNotNeg(andRight, instances)
113 andFormulaTerm = andFormula.left
114 } else {
115 addIfNotNeg(andFormulaTerm as VLSTerm, instances)
116 end = true
117 } 126 }
118 127 for (elem : instances) {
119 } 128 associatedType.lookup(type2DefinedElement).add(elem)
120 for (elem : instances) { 129 }
121 associatedType.lookup(type2DefinedElement).add(elem)
122 } 130 }
123 } 131 }
132
124 } 133 }
125 134
126 printMap() 135 printMap()
127 136
128 // 3. get relations 137 // 3. get relations
129 // Fill keys of map 138 // Fill keys of map
130 val allRelDecls = trace.rel2Predicate.keySet.filter[class == RelationDeclarationImpl] 139 val allRelDecls = trace.rel2Predicate.keySet
131 val allRelFunctions = trace.predicate2Relation 140 val allRelDefns = trace.relDef2Predicate.keySet
141 val allRelDeclFunctions = trace.predicate2Relation
142 val allRelDefnFunctions = trace.predicate2RelDef
132 143
133 for (rel : allRelDecls) { 144 for (rel : allRelDecls) {
134 rel2Inst.put(rel as RelationDeclaration, newArrayList) 145 relDec2Inst.put(rel as RelationDeclaration, newArrayList)
146 }
147
148 for (rel : allRelDefns) {
149 relDef2Inst.put(rel as RelationDefinition, newArrayList)
135 } 150 }
136 151
137 // USE THE DECLARE_<RELATION_NAME> FORMULAS TO SEE WHAT THE RELATIONS ARE 152 // USE THE DECLARE_<RELATION_NAME> FORMULAS TO SEE WHAT THE RELATIONS ARE
@@ -140,34 +155,40 @@ class VampireModelInterpretation implements LogicModelInterpretation {
140 for (formula : relFormulas) { 155 for (formula : relFormulas) {
141 // get associated type 156 // get associated type
142 val associatedRelName = (formula as VLSTffFormula).name.substring(10) 157 val associatedRelName = (formula as VLSTffFormula).name.substring(10)
143 val associatedRelFunction = allRelFunctions.keySet.filter[constant == associatedRelName]. 158
144 get(0) as VLSFunction 159 // TRY FOR DECLARATION
145 val associatedRel = associatedRelFunction.lookup(allRelFunctions) as RelationDeclaration 160 val associatedRelFunctionList = allRelDeclFunctions.keySet.filter[constant == associatedRelName]
146 161 if (associatedRelFunctionList.isEmpty) {
147 // get definedElements 162 // THEN IT IS NOT A DECLARATION
148 var andFormulaTerm = formula.fofFormula 163 } else {
149 end = false 164 val associatedRelFunction = associatedRelFunctionList.get(0) as VLSFunction // ASSUMING ONLY 1 SATISFIES QUERY
150 val List<String[]> instances = newArrayList 165 val associatedRel = associatedRelFunction.lookup(allRelDeclFunctions) as RelationDeclaration
151 while (!end) { 166
152 if (andFormulaTerm.class == VLSAndImpl) { 167 // get definedElements
153 val andFormula = andFormulaTerm as VLSAnd 168 var andFormulaTerm = formula.fofFormula
154 val andRight = andFormula.right 169 end = false
155 addRelIfNotNeg(andRight, instances) 170 val List<String[]> instances = newArrayList
156 andFormulaTerm = andFormula.left 171 while (!end) {
157 } else { 172 if (andFormulaTerm.class == VLSAndImpl) {
158 addRelIfNotNeg(andFormulaTerm as VLSTerm, instances) 173 val andFormula = andFormulaTerm as VLSAnd
159 end = true 174 val andRight = andFormula.right
175 addRelIfNotNeg(andRight, instances)
176 andFormulaTerm = andFormula.left
177 } else {
178 addRelIfNotNeg(andFormulaTerm as VLSTerm, instances)
179 end = true
180 }
181
182 }
183 for (elem : instances) {
184 associatedRel.lookup(relDec2Inst).add(elem)
160 } 185 }
161 186
162 } 187 }
163 for (elem : instances) {
164 associatedRel.lookup(rel2Inst).add(elem)
165 }
166 188
167 } 189 }
168 190
169// printMap2() 191// printMap2()
170
171 } 192 }
172 193
173 def printMap() { 194 def printMap() {
@@ -182,12 +203,12 @@ class VampireModelInterpretation implements LogicModelInterpretation {
182 } 203 }
183 println() 204 println()
184 } 205 }
185 206
186 def printMap2() { 207 def printMap2() {
187 println("------------------") 208 println("------------------")
188 for (key : rel2Inst.keySet) { 209 for (key : relDec2Inst.keySet) {
189 println(key.name + "==>") 210 println(key.name + "==>")
190 for (elem : key.lookup(rel2Inst)) { 211 for (elem : key.lookup(relDec2Inst)) {
191 print("[" + elem.get(0) + "-" + elem.get(1) + "], ") 212 print("[" + elem.get(0) + "-" + elem.get(1) + "], ")
192 } 213 }
193 println() 214 println()
@@ -203,7 +224,7 @@ class VampireModelInterpretation implements LogicModelInterpretation {
203 list.add(defnElem) 224 list.add(defnElem)
204 } 225 }
205 } 226 }
206 227
207 def private addRelIfNotNeg(VLSTerm term, List<String[]> list) { 228 def private addRelIfNotNeg(VLSTerm term, List<String[]> list) {
208 if (term.class != VLSUnaryNegationImpl) { 229 if (term.class != VLSUnaryNegationImpl) {
209 val nodeName1 = ((term as VLSFunction).terms.get(0) as VLSFunctionAsTerm).functor 230 val nodeName1 = ((term as VLSFunction).terms.get(0) as VLSFunctionAsTerm).functor
@@ -232,14 +253,19 @@ class VampireModelInterpretation implements LogicModelInterpretation {
232 } 253 }
233 254
234 override getInterpretation(RelationDeclaration relation, Object[] parameterSubstitution) { 255 override getInterpretation(RelationDeclaration relation, Object[] parameterSubstitution) {
256 print("-- " + relation.name)
235 val node1 = (parameterSubstitution.get(0) as DefinedElement).name 257 val node1 = (parameterSubstitution.get(0) as DefinedElement).name
236 val node2 = (parameterSubstitution.get(1) as DefinedElement).name 258 val node2 = (parameterSubstitution.get(1) as DefinedElement).name
237 val realRelations = relation.lookup(rel2Inst) 259 val realRelations = relation.lookup(relDec2Inst)
238 for (real : realRelations){ 260 for (real : realRelations) {
239 if(real.contains(node1) && real.contains(node2)){ 261 if (real.contains(node1) && real.contains(node2)) {
262 println(" true")
263 TimeUnit.SECONDS.sleep(1)
240 return true 264 return true
241 } 265 }
242 } 266 }
267 println(" false")
268 TimeUnit.SECONDS.sleep(1)
243 return false 269 return false
244 } 270 }
245 271