diff options
author | Kristóf Marussy <marussy@mit.bme.hu> | 2020-05-19 21:22:01 +0200 |
---|---|---|
committer | Kristóf Marussy <marussy@mit.bme.hu> | 2020-05-19 22:11:37 +0200 |
commit | 167e0470bc4562f77d46d8af8c0ef6794dfee693 (patch) | |
tree | 8f647b4a6d6b412b9e912a4e0841a2898e830b13 /Framework | |
parent | Config language WIP (diff) | |
parent | Merge branch 'master' of https://github.com/viatra/VIATRA-Generator (diff) | |
download | VIATRA-Generator-167e0470bc4562f77d46d8af8c0ef6794dfee693.tar.gz VIATRA-Generator-167e0470bc4562f77d46d8af8c0ef6794dfee693.tar.zst VIATRA-Generator-167e0470bc4562f77d46d8af8c0ef6794dfee693.zip |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'Framework')
5 files changed, 136 insertions, 63 deletions
diff --git a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic/model/statistics/StatisticSections2CSV.xtend b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic/model/statistics/StatisticSections2CSV.xtend index d673cb17..a78ceb19 100644 --- a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic/model/statistics/StatisticSections2CSV.xtend +++ b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic/model/statistics/StatisticSections2CSV.xtend | |||
@@ -17,7 +17,7 @@ class StatisticsData { | |||
17 | } | 17 | } |
18 | 18 | ||
19 | class StatisticSections2CSV { | 19 | class StatisticSections2CSV { |
20 | static val separator = ';' | 20 | static val separator = ',' |
21 | static val empty = "" | 21 | static val empty = "" |
22 | 22 | ||
23 | private def getValue(Map<String, String> map,String key) { | 23 | private def getValue(Map<String, String> map,String key) { |
diff --git a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic/model/statistics/StatisticSections2Print.xtend b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic/model/statistics/StatisticSections2Print.xtend index 39370d75..c5e81f94 100644 --- a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic/model/statistics/StatisticSections2Print.xtend +++ b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic/model/statistics/StatisticSections2Print.xtend | |||
@@ -12,7 +12,7 @@ class StatisticSections2Print { | |||
12 | { | 12 | { |
13 | var result = ""; | 13 | var result = ""; |
14 | for(statistic : statistics) { | 14 | for(statistic : statistics) { |
15 | result+= '''«statistic.readValue»;''' | 15 | result+= '''«statistic.readValue»,''' |
16 | } | 16 | } |
17 | return result | 17 | return result |
18 | } | 18 | } |
diff --git a/Framework/hu.bme.mit.inf.dslreasoner.logic2ecore/src/hu/bme/mit/inf/dslreasoner/logic2ecore/Logic2Ecore.xtend b/Framework/hu.bme.mit.inf.dslreasoner.logic2ecore/src/hu/bme/mit/inf/dslreasoner/logic2ecore/Logic2Ecore.xtend index 92deeae6..08c6b7b7 100644 --- a/Framework/hu.bme.mit.inf.dslreasoner.logic2ecore/src/hu/bme/mit/inf/dslreasoner/logic2ecore/Logic2Ecore.xtend +++ b/Framework/hu.bme.mit.inf.dslreasoner.logic2ecore/src/hu/bme/mit/inf/dslreasoner/logic2ecore/Logic2Ecore.xtend | |||
@@ -20,6 +20,8 @@ import org.eclipse.emf.ecore.EcorePackage | |||
20 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TermDescription | 20 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TermDescription |
21 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicProblemBuilder | 21 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicProblemBuilder |
22 | import java.util.Map | 22 | import java.util.Map |
23 | import org.eclipse.emf.ecore.EAttribute | ||
24 | import java.math.BigDecimal | ||
23 | 25 | ||
24 | class Logic2Ecore { | 26 | class Logic2Ecore { |
25 | val extension LogicStructureBuilder structureBuilder = new LogicStructureBuilder | 27 | val extension LogicStructureBuilder structureBuilder = new LogicStructureBuilder |
@@ -92,7 +94,7 @@ class Logic2Ecore { | |||
92 | list += l.key | 94 | list += l.key |
93 | } else { | 95 | } else { |
94 | try { | 96 | try { |
95 | sourceObject.eSet(attributeType,l.key) | 97 | sourceObject.eSet(attributeType,translateType(attributeType.EAttributeType,l.key)) |
96 | } catch(Exception e) { | 98 | } catch(Exception e) { |
97 | e.printStackTrace | 99 | e.printStackTrace |
98 | } | 100 | } |
@@ -107,6 +109,16 @@ class Logic2Ecore { | |||
107 | return element2Object.values.root | 109 | return element2Object.values.root |
108 | } | 110 | } |
109 | 111 | ||
112 | def translateType(EDataType type, Object value) { | ||
113 | if(type == EcorePackage.eINSTANCE.EFloat) { | ||
114 | val bd = value as BigDecimal | ||
115 | return bd.floatValue | ||
116 | } else if( type == EcorePackage.eINSTANCE.EDouble ) { | ||
117 | val bd = value as BigDecimal | ||
118 | return bd.doubleValue | ||
119 | } else return value | ||
120 | } | ||
121 | |||
110 | 122 | ||
111 | // if(attributeType.EAttributeType.isSuperTypeOf(targetObject.eClass)) { | 123 | // if(attributeType.EAttributeType.isSuperTypeOf(targetObject.eClass)) { |
112 | // val expression = ecore2Logic.IsAttributeValue(forwardTrace,sourceElement,targetElement,attributeType) | 124 | // val expression = ecore2Logic.IsAttributeValue(forwardTrace,sourceElement,targetElement,attributeType) |
diff --git a/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/NumericProblemSolver.java b/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/NumericProblemSolver.java index 8749a5a8..0b249962 100644 --- a/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/NumericProblemSolver.java +++ b/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/NumericProblemSolver.java | |||
@@ -1,5 +1,6 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.viatra2logic; | 1 | package hu.bme.mit.inf.dslreasoner.viatra2logic; |
2 | 2 | ||
3 | import java.math.BigDecimal; | ||
3 | import java.util.ArrayList; | 4 | import java.util.ArrayList; |
4 | import java.util.HashMap; | 5 | import java.util.HashMap; |
5 | import java.util.HashSet; | 6 | import java.util.HashSet; |
@@ -23,12 +24,14 @@ import com.microsoft.z3.Context; | |||
23 | import com.microsoft.z3.Expr; | 24 | import com.microsoft.z3.Expr; |
24 | import com.microsoft.z3.IntExpr; | 25 | import com.microsoft.z3.IntExpr; |
25 | import com.microsoft.z3.Model; | 26 | import com.microsoft.z3.Model; |
27 | import com.microsoft.z3.RealExpr; | ||
26 | import com.microsoft.z3.Solver; | 28 | import com.microsoft.z3.Solver; |
27 | import com.microsoft.z3.Status; | 29 | import com.microsoft.z3.Status; |
28 | import com.microsoft.z3.enumerations.Z3_ast_print_mode; | 30 | import com.microsoft.z3.enumerations.Z3_ast_print_mode; |
29 | 31 | ||
30 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Term; | 32 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Term; |
31 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.IntegerElement; | 33 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.IntegerElement; |
34 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.RealElement; | ||
32 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PrimitiveElement; | 35 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PrimitiveElement; |
33 | 36 | ||
34 | 37 | ||
@@ -49,11 +52,15 @@ public class NumericProblemSolver { | |||
49 | private static final String N_EQUALS3 = "operator_tripleEquals"; | 52 | private static final String N_EQUALS3 = "operator_tripleEquals"; |
50 | private static final String N_NOTEQUALS3 = "operator_tripleNotEquals"; | 53 | private static final String N_NOTEQUALS3 = "operator_tripleNotEquals"; |
51 | 54 | ||
52 | 55 | ||
53 | private Context ctx; | 56 | private Context ctx; |
54 | private Solver s; | 57 | private Solver s; |
55 | private Map<Object, Expr> varMap; | 58 | private Map<Object, Expr> varMap; |
56 | 59 | ||
60 | long endformingProblem=0; | ||
61 | long endSolvingProblem=0; | ||
62 | long endFormingSolution=0; | ||
63 | |||
57 | public NumericProblemSolver() { | 64 | public NumericProblemSolver() { |
58 | HashMap<String, String> cfg = new HashMap<String, String>(); | 65 | HashMap<String, String> cfg = new HashMap<String, String>(); |
59 | cfg.put("model", "true"); | 66 | cfg.put("model", "true"); |
@@ -66,18 +73,29 @@ public class NumericProblemSolver { | |||
66 | public Context getNumericProblemContext() { | 73 | public Context getNumericProblemContext() { |
67 | return ctx; | 74 | return ctx; |
68 | } | 75 | } |
69 | 76 | ||
70 | 77 | public long getEndformingProblem() { | |
78 | return endformingProblem; | ||
79 | } | ||
80 | |||
81 | public long getEndSolvingProblem() { | ||
82 | return endSolvingProblem; | ||
83 | } | ||
84 | |||
85 | public long getEndFormingSolution() { | ||
86 | return endFormingSolution; | ||
87 | } | ||
88 | |||
71 | private ArrayList<JvmIdentifiableElement> getJvmIdentifiableElements(XExpression expression) { | 89 | private ArrayList<JvmIdentifiableElement> getJvmIdentifiableElements(XExpression expression) { |
72 | ArrayList<JvmIdentifiableElement> allElem = new ArrayList<JvmIdentifiableElement>(); | 90 | ArrayList<JvmIdentifiableElement> allElem = new ArrayList<JvmIdentifiableElement>(); |
73 | XExpression left = ((XBinaryOperation) expression).getLeftOperand(); | 91 | XExpression left = ((XBinaryOperation) expression).getLeftOperand(); |
74 | XExpression right = ((XBinaryOperation) expression).getRightOperand(); | 92 | XExpression right = ((XBinaryOperation) expression).getRightOperand(); |
75 | 93 | ||
76 | getJvmIdentifiableElementsHelper(left, allElem); | 94 | getJvmIdentifiableElementsHelper(left, allElem); |
77 | getJvmIdentifiableElementsHelper(right, allElem); | 95 | getJvmIdentifiableElementsHelper(right, allElem); |
78 | return allElem; | 96 | return allElem; |
79 | } | 97 | } |
80 | 98 | ||
81 | private void getJvmIdentifiableElementsHelper(XExpression e, List<JvmIdentifiableElement> allElem) { | 99 | private void getJvmIdentifiableElementsHelper(XExpression e, List<JvmIdentifiableElement> allElem) { |
82 | if (e instanceof XFeatureCall) { | 100 | if (e instanceof XFeatureCall) { |
83 | allElem.add(((XFeatureCall) e).getFeature()); | 101 | allElem.add(((XFeatureCall) e).getFeature()); |
@@ -86,42 +104,53 @@ public class NumericProblemSolver { | |||
86 | getJvmIdentifiableElementsHelper(((XBinaryOperation) e).getRightOperand(), allElem); | 104 | getJvmIdentifiableElementsHelper(((XBinaryOperation) e).getRightOperand(), allElem); |
87 | } | 105 | } |
88 | } | 106 | } |
89 | 107 | ||
90 | public boolean isSatisfiable(Map<XExpression, Iterable<Map<JvmIdentifiableElement,PrimitiveElement>>> matches) throws Exception { | 108 | public boolean isSatisfiable(Map<XExpression, Iterable<Map<JvmIdentifiableElement,PrimitiveElement>>> matches) throws Exception { |
109 | long startformingProblem = System.nanoTime(); | ||
91 | BoolExpr problemInstance = formNumericProblemInstance(matches); | 110 | BoolExpr problemInstance = formNumericProblemInstance(matches); |
92 | s.add(problemInstance); | 111 | s.add(problemInstance); |
112 | endformingProblem = System.nanoTime()-startformingProblem; | ||
113 | long startSolvingProblem = System.nanoTime(); | ||
93 | boolean result = (s.check() == Status.SATISFIABLE); | 114 | boolean result = (s.check() == Status.SATISFIABLE); |
115 | endSolvingProblem = System.nanoTime()-startSolvingProblem; | ||
94 | this.ctx.close(); | 116 | this.ctx.close(); |
95 | return result; | 117 | return result; |
96 | } | 118 | } |
97 | 119 | ||
98 | public Map<PrimitiveElement,Integer> getOneSolution(List<PrimitiveElement> objs, Map<XExpression, Iterable<Map<JvmIdentifiableElement,PrimitiveElement>>> matches) throws Exception { | 120 | public Map<PrimitiveElement,Number> getOneSolution(List<PrimitiveElement> objs, Map<XExpression, Iterable<Map<JvmIdentifiableElement,PrimitiveElement>>> matches) throws Exception { |
99 | Map<PrimitiveElement,Integer> sol = new HashMap<PrimitiveElement, Integer>(); | 121 | Map<PrimitiveElement,Number> sol = new HashMap<PrimitiveElement, Number>(); |
100 | long startformingProblem = System.currentTimeMillis(); | 122 | long startformingProblem = System.nanoTime(); |
101 | BoolExpr problemInstance = formNumericProblemInstance(matches); | 123 | BoolExpr problemInstance = formNumericProblemInstance(matches); |
102 | long endformingProblem = System.currentTimeMillis(); | 124 | endformingProblem = System.nanoTime()-startformingProblem; |
103 | System.out.println("Forming problem: " + (endformingProblem - startformingProblem)); | 125 | //System.out.println("Forming problem: " + (endformingProblem - startformingProblem)); |
104 | s.add(problemInstance); | 126 | s.add(problemInstance); |
105 | long startSolvingProblem = System.currentTimeMillis(); | 127 | long startSolvingProblem = System.nanoTime(); |
106 | if (s.check() == Status.SATISFIABLE) { | 128 | if (s.check() == Status.SATISFIABLE) { |
107 | Model m = s.getModel(); | 129 | Model m = s.getModel(); |
108 | long endSolvingProblem = System.currentTimeMillis(); | 130 | endSolvingProblem = System.nanoTime()-startSolvingProblem; |
109 | System.out.println("Solving problem: " + (endSolvingProblem - startSolvingProblem)); | 131 | //System.out.println("Solving problem: " + (endSolvingProblem - startSolvingProblem)); |
110 | long startFormingSolution = System.currentTimeMillis(); | 132 | long startFormingSolution = System.nanoTime(); |
111 | for (PrimitiveElement o: objs) { | 133 | for (PrimitiveElement o: objs) { |
112 | if(varMap.containsKey(o)) { | 134 | if(varMap.containsKey(o)) { |
113 | IntExpr val =(IntExpr) m.evaluate(varMap.get(o), false); | 135 | if (o instanceof IntegerElement) { |
114 | Integer oSol = Integer.parseInt(val.toString()); | 136 | IntExpr val =(IntExpr) m.evaluate(varMap.get(o), false); |
137 | Integer oSol = Integer.parseInt(val.toString()); | ||
138 | sol.put(o, oSol); | ||
139 | } else { | ||
140 | RealExpr val = (RealExpr) m.evaluate(varMap.get(o), false); | ||
141 | Double oSol = Double.parseDouble(val.toString()); | ||
142 | sol.put(o, oSol); | ||
143 | } | ||
115 | //System.out.println("Solution:" + o + "->" + oSol); | 144 | //System.out.println("Solution:" + o + "->" + oSol); |
116 | sol.put(o, oSol); | 145 | |
117 | } else { | 146 | } else { |
118 | //System.out.println("not used var:" + o); | 147 | //System.out.println("not used var:" + o); |
119 | } | 148 | } |
120 | } | 149 | } |
121 | long endFormingSolution = System.currentTimeMillis(); | 150 | endFormingSolution = System.nanoTime()-startFormingSolution; |
122 | System.out.println("Forming solution: " + (endFormingSolution - startFormingSolution)); | 151 | //System.out.println("Forming solution: " + (endFormingSolution - startFormingSolution)); |
123 | } else { | 152 | } else { |
124 | System.out.println("Unsatisfiable"); | 153 | System.out.println("Unsatisfiable numerical problem"); |
125 | } | 154 | } |
126 | this.ctx.close(); | 155 | this.ctx.close(); |
127 | return sol; | 156 | return sol; |
@@ -135,7 +164,7 @@ public class NumericProblemSolver { | |||
135 | String name = ((XBinaryOperation) e).getFeature().getQualifiedName(); | 164 | String name = ((XBinaryOperation) e).getFeature().getQualifiedName(); |
136 | 165 | ||
137 | BoolExpr constraint = null; | 166 | BoolExpr constraint = null; |
138 | 167 | ||
139 | ArithExpr left_operand = formNumericConstraintHelper(((XBinaryOperation) e).getLeftOperand(), aMatch); | 168 | ArithExpr left_operand = formNumericConstraintHelper(((XBinaryOperation) e).getLeftOperand(), aMatch); |
140 | ArithExpr right_operand = formNumericConstraintHelper(((XBinaryOperation) e).getRightOperand(), aMatch); | 169 | ArithExpr right_operand = formNumericConstraintHelper(((XBinaryOperation) e).getRightOperand(), aMatch); |
141 | 170 | ||
@@ -158,34 +187,50 @@ public class NumericProblemSolver { | |||
158 | } else { | 187 | } else { |
159 | throw new Exception ("Unsupported binary operation " + name); | 188 | throw new Exception ("Unsupported binary operation " + name); |
160 | } | 189 | } |
161 | 190 | ||
162 | return constraint; | 191 | return constraint; |
163 | } | 192 | } |
164 | 193 | ||
165 | // TODO: add variable: state of the solver | ||
166 | private ArithExpr formNumericConstraintHelper(XExpression e, Map<JvmIdentifiableElement, PrimitiveElement> aMatch) throws Exception { | 194 | private ArithExpr formNumericConstraintHelper(XExpression e, Map<JvmIdentifiableElement, PrimitiveElement> aMatch) throws Exception { |
167 | ArithExpr expr = null; | 195 | ArithExpr expr = null; |
168 | // Variables | 196 | // Variables |
169 | if (e instanceof XFeatureCall) { | 197 | if (e instanceof XFeatureCall) { |
170 | PrimitiveElement matchedObj = aMatch.get(((XFeatureCall) e).getFeature()); | 198 | PrimitiveElement matchedObj = aMatch.get(((XFeatureCall) e).getFeature()); |
199 | boolean isInt = matchedObj instanceof IntegerElement; | ||
171 | if (!matchedObj.isValueSet()) { | 200 | if (!matchedObj.isValueSet()) { |
172 | if (varMap.get(matchedObj) == null) { | 201 | if (varMap.get(matchedObj) == null) { |
173 | String var_name = ((XFeatureCall) e).getFeature().getQualifiedName() + matchedObj.toString(); | 202 | String var_name = ((XFeatureCall) e).getFeature().getQualifiedName() + matchedObj.toString(); |
174 | expr = (ArithExpr) ctx.mkConst(ctx.mkSymbol(var_name), ctx.getIntSort()); | 203 | if (isInt) { |
204 | expr = (ArithExpr) ctx.mkConst(ctx.mkSymbol(var_name), ctx.getIntSort()); | ||
205 | } else { | ||
206 | expr = (ArithExpr) ctx.mkConst(ctx.mkSymbol(var_name), ctx.getRealSort()); | ||
207 | } | ||
175 | varMap.put(matchedObj, expr); | 208 | varMap.put(matchedObj, expr); |
176 | } else { | 209 | } else { |
177 | expr = (ArithExpr) varMap.get(matchedObj); | 210 | expr = (ArithExpr) varMap.get(matchedObj); |
178 | } | 211 | } |
179 | } else { | 212 | } else { |
180 | int value = ((IntegerElement) matchedObj).getValue(); | 213 | if (isInt) { |
181 | expr = (ArithExpr) ctx.mkInt(value); | 214 | int value = ((IntegerElement) matchedObj).getValue(); |
215 | expr = (ArithExpr) ctx.mkInt(value); | ||
216 | } else { | ||
217 | double value = ((RealElement) matchedObj).getValue().doubleValue(); | ||
218 | expr = (ArithExpr) ctx.mkReal(String.valueOf(value)); | ||
219 | } | ||
182 | varMap.put(matchedObj, expr); | 220 | varMap.put(matchedObj, expr); |
183 | } | 221 | } |
184 | } | 222 | } |
185 | // Constants | 223 | // Constants |
186 | else if (e instanceof XNumberLiteral) { | 224 | else if (e instanceof XNumberLiteral) { |
187 | String value = ((XNumberLiteral) e).getValue(); | 225 | String value = ((XNumberLiteral) e).getValue(); |
188 | try{ int val = Integer.parseInt(value); expr = (ArithExpr) ctx.mkInt(val);} catch(NumberFormatException err){} | 226 | try{ |
227 | int val = Integer.parseInt(value); | ||
228 | expr = (ArithExpr) ctx.mkInt(val); | ||
229 | } catch(NumberFormatException err){ | ||
230 | try{ | ||
231 | expr = (ArithExpr) ctx.mkReal(value); | ||
232 | } catch(NumberFormatException err2){} | ||
233 | } | ||
189 | } | 234 | } |
190 | // Expressions with operators | 235 | // Expressions with operators |
191 | else if (e instanceof XBinaryOperation) { | 236 | else if (e instanceof XBinaryOperation) { |
@@ -218,7 +263,7 @@ public class NumericProblemSolver { | |||
218 | private boolean nameEndsWith(String name, String end) { | 263 | private boolean nameEndsWith(String name, String end) { |
219 | return name.startsWith(N_Base) && name.endsWith(end); | 264 | return name.startsWith(N_Base) && name.endsWith(end); |
220 | } | 265 | } |
221 | 266 | ||
222 | private BoolExpr formNumericProblemInstance(Map<XExpression, Iterable<Map<JvmIdentifiableElement,PrimitiveElement>>> matches) throws Exception { | 267 | private BoolExpr formNumericProblemInstance(Map<XExpression, Iterable<Map<JvmIdentifiableElement,PrimitiveElement>>> matches) throws Exception { |
223 | BoolExpr constraintInstances = ctx.mkTrue(); | 268 | BoolExpr constraintInstances = ctx.mkTrue(); |
224 | for (XExpression e: matches.keySet()) { | 269 | for (XExpression e: matches.keySet()) { |
@@ -230,15 +275,15 @@ public class NumericProblemSolver { | |||
230 | } | 275 | } |
231 | return constraintInstances; | 276 | return constraintInstances; |
232 | } | 277 | } |
233 | 278 | ||
234 | 279 | ||
235 | /* | 280 | /* |
236 | public void testIsSat(XExpression expression, Term t) throws Exception { | 281 | public void testIsSat(XExpression expression, Term t) throws Exception { |
237 | int count = 10000; | 282 | int count = 10000; |
238 | Map<XExpression, Set<Map<JvmIdentifiableElement,PrimitiveElement>>> matches = new HashMap<XExpression, Set<Map<JvmIdentifiableElement,PrimitiveElement>>>(); | 283 | Map<XExpression, Set<Map<JvmIdentifiableElement,PrimitiveElement>>> matches = new HashMap<XExpression, Set<Map<JvmIdentifiableElement,PrimitiveElement>>>(); |
239 | Set<Map<JvmIdentifiableElement,PrimitiveElement>> matchSet = new HashSet<Map<JvmIdentifiableElement,PrimitiveElement>>(); | 284 | Set<Map<JvmIdentifiableElement,PrimitiveElement>> matchSet = new HashSet<Map<JvmIdentifiableElement,PrimitiveElement>>(); |
240 | ArrayList<JvmIdentifiableElement> allElem = getJvmIdentifiableElements(expression); | 285 | ArrayList<JvmIdentifiableElement> allElem = getJvmIdentifiableElements(expression); |
241 | 286 | ||
242 | for (int i = 0; i < count; i++) { | 287 | for (int i = 0; i < count; i++) { |
243 | Map<JvmIdentifiableElement,PrimitiveElement> match = new HashMap<JvmIdentifiableElement,PrimitiveElement>(); | 288 | Map<JvmIdentifiableElement,PrimitiveElement> match = new HashMap<JvmIdentifiableElement,PrimitiveElement>(); |
244 | for (JvmIdentifiableElement e: allElem) { | 289 | for (JvmIdentifiableElement e: allElem) { |
@@ -247,7 +292,7 @@ public class NumericProblemSolver { | |||
247 | } | 292 | } |
248 | matchSet.add(match); | 293 | matchSet.add(match); |
249 | } | 294 | } |
250 | 295 | ||
251 | matches.put(expression, matchSet); | 296 | matches.put(expression, matchSet); |
252 | long start = System.currentTimeMillis(); | 297 | long start = System.currentTimeMillis(); |
253 | boolean sat = isSatisfiable(matches); | 298 | boolean sat = isSatisfiable(matches); |
@@ -256,7 +301,7 @@ public class NumericProblemSolver { | |||
256 | System.out.println("Number of matches: " + count); | 301 | System.out.println("Number of matches: " + count); |
257 | System.out.println("Running time:" + (end - start)); | 302 | System.out.println("Running time:" + (end - start)); |
258 | } | 303 | } |
259 | 304 | ||
260 | public void testIsNotSat(XExpression expression, Term t) throws Exception { | 305 | public void testIsNotSat(XExpression expression, Term t) throws Exception { |
261 | Map<XExpression, Set<Map<JvmIdentifiableElement,PrimitiveElement>>> matches = new HashMap<XExpression, Set<Map<JvmIdentifiableElement,PrimitiveElement>>>(); | 306 | Map<XExpression, Set<Map<JvmIdentifiableElement,PrimitiveElement>>> matches = new HashMap<XExpression, Set<Map<JvmIdentifiableElement,PrimitiveElement>>>(); |
262 | Set<Map<JvmIdentifiableElement,PrimitiveElement>> matchSet = new HashSet<Map<JvmIdentifiableElement,PrimitiveElement>>(); | 307 | Set<Map<JvmIdentifiableElement,PrimitiveElement>> matchSet = new HashSet<Map<JvmIdentifiableElement,PrimitiveElement>>(); |
@@ -273,11 +318,11 @@ public class NumericProblemSolver { | |||
273 | } else { | 318 | } else { |
274 | int2 = intE; | 319 | int2 = intE; |
275 | } | 320 | } |
276 | 321 | ||
277 | match.put(e, intE); | 322 | match.put(e, intE); |
278 | } | 323 | } |
279 | matchSet.add(match); | 324 | matchSet.add(match); |
280 | 325 | ||
281 | Map<JvmIdentifiableElement,PrimitiveElement> match2 = new HashMap<JvmIdentifiableElement,PrimitiveElement>(); | 326 | Map<JvmIdentifiableElement,PrimitiveElement> match2 = new HashMap<JvmIdentifiableElement,PrimitiveElement>(); |
282 | boolean first2 = true; | 327 | boolean first2 = true; |
283 | for (JvmIdentifiableElement e: allElem) { | 328 | for (JvmIdentifiableElement e: allElem) { |
@@ -289,7 +334,7 @@ public class NumericProblemSolver { | |||
289 | } | 334 | } |
290 | } | 335 | } |
291 | matchSet.add(match2); | 336 | matchSet.add(match2); |
292 | 337 | ||
293 | matches.put(expression, matchSet); | 338 | matches.put(expression, matchSet); |
294 | long start = System.currentTimeMillis(); | 339 | long start = System.currentTimeMillis(); |
295 | boolean sat = isSatisfiable(matches); | 340 | boolean sat = isSatisfiable(matches); |
@@ -298,16 +343,16 @@ public class NumericProblemSolver { | |||
298 | System.out.println("Number of matches: "); | 343 | System.out.println("Number of matches: "); |
299 | System.out.println("Running time:" + (end - start)); | 344 | System.out.println("Running time:" + (end - start)); |
300 | } | 345 | } |
301 | */ | 346 | */ |
302 | 347 | ||
303 | /*public void testGetOneSol(XExpression expression, Term t) throws Exception { | 348 | /* public void testGetOneSol(XExpression expression, Term t) throws Exception { |
304 | int count = 10; | 349 | int count = 10; |
305 | Map<XExpression, Set<Map<JvmIdentifiableElement,PrimitiveElement>>> matches = new HashMap<XExpression, Set<Map<JvmIdentifiableElement,PrimitiveElement>>>(); | 350 | Map<XExpression, Iterable<Map<JvmIdentifiableElement,PrimitiveElement>>> matches = new HashMap<XExpression, Iterable<Map<JvmIdentifiableElement,PrimitiveElement>>>(); |
306 | Set<Map<JvmIdentifiableElement,PrimitiveElement>> matchSet = new HashSet<Map<JvmIdentifiableElement,PrimitiveElement>>(); | 351 | Iterable<Map<JvmIdentifiableElement,PrimitiveElement>> matchSet = new ArrayList<Map<JvmIdentifiableElement,PrimitiveElement>>(); |
307 | 352 | ||
308 | ArrayList<JvmIdentifiableElement> allElem = getJvmIdentifiableElements(expression); | 353 | ArrayList<JvmIdentifiableElement> allElem = getJvmIdentifiableElements(expression); |
309 | List<Object> obj = new ArrayList<Object>(); | 354 | List<PrimitiveElement> obj = new ArrayList<PrimitiveElement>(); |
310 | 355 | ||
311 | for (int i = 0; i < count; i++) { | 356 | for (int i = 0; i < count; i++) { |
312 | Map<JvmIdentifiableElement,PrimitiveElement> match = new HashMap<JvmIdentifiableElement,PrimitiveElement>(); | 357 | Map<JvmIdentifiableElement,PrimitiveElement> match = new HashMap<JvmIdentifiableElement,PrimitiveElement>(); |
313 | for (JvmIdentifiableElement e: allElem) { | 358 | for (JvmIdentifiableElement e: allElem) { |
@@ -315,21 +360,21 @@ public class NumericProblemSolver { | |||
315 | obj.add(intE); | 360 | obj.add(intE); |
316 | match.put(e, intE); | 361 | match.put(e, intE); |
317 | } | 362 | } |
318 | matchSet.add(match); | 363 | ((ArrayList) matchSet).add(match); |
319 | matches.put(expression, matchSet); | 364 | matches.put(expression, matchSet); |
320 | } | 365 | } |
321 | 366 | ||
322 | long start = System.currentTimeMillis(); | 367 | long start = System.currentTimeMillis(); |
323 | Map<Object,Integer> sol = getOneSolution(obj, matches); | 368 | Map<PrimitiveElement,Integer> sol = getOneSolution(obj, matches); |
324 | long end = System.currentTimeMillis(); | 369 | long end = System.currentTimeMillis(); |
325 | 370 | ||
326 | 371 | ||
327 | // Print sol | 372 | // Print sol |
328 | for (Object o: sol.keySet()) { | 373 | for (Object o: sol.keySet()) { |
329 | System.out.println(o + " :" + sol.get(o)); | 374 | System.out.println(o + " :" + sol.get(o)); |
330 | } | 375 | } |
331 | 376 | ||
332 | 377 | ||
333 | System.out.println("Number of matches: " + count); | 378 | System.out.println("Number of matches: " + count); |
334 | System.out.println("Running time:" + (end - start)); | 379 | System.out.println("Running time:" + (end - start)); |
335 | }*/ | 380 | }*/ |
@@ -354,7 +399,7 @@ public class NumericProblemSolver { | |||
354 | obj.add(intE); | 399 | obj.add(intE); |
355 | match.put(e, intE); | 400 | match.put(e, intE); |
356 | } | 401 | } |
357 | 402 | ||
358 | Map<JvmIdentifiableElement,PrimitiveElement> match2 = new HashMap<JvmIdentifiableElement,PrimitiveElement>(); | 403 | Map<JvmIdentifiableElement,PrimitiveElement> match2 = new HashMap<JvmIdentifiableElement,PrimitiveElement>(); |
359 | boolean first2 = true; | 404 | boolean first2 = true; |
360 | for (JvmIdentifiableElement e: allElem) { | 405 | for (JvmIdentifiableElement e: allElem) { |
@@ -368,13 +413,13 @@ public class NumericProblemSolver { | |||
368 | obj.add(intE); | 413 | obj.add(intE); |
369 | match2.put(e, intE); | 414 | match2.put(e, intE); |
370 | } | 415 | } |
371 | 416 | ||
372 | 417 | ||
373 | matchSet.add(match); | 418 | matchSet.add(match); |
374 | matchSet.add(match2); | 419 | matchSet.add(match2); |
375 | } | 420 | } |
376 | matches.put(expression, matchSet); | 421 | matches.put(expression, matchSet); |
377 | 422 | ||
378 | System.out.println("Number of matches: " + matchSet.size()); | 423 | System.out.println("Number of matches: " + matchSet.size()); |
379 | for (int i = 0; i < 10; i++) { | 424 | for (int i = 0; i < 10; i++) { |
380 | Map<Object,Integer> sol = getOneSolution(obj, matches); | 425 | Map<Object,Integer> sol = getOneSolution(obj, matches); |
@@ -382,7 +427,7 @@ public class NumericProblemSolver { | |||
382 | Thread.sleep(3000); | 427 | Thread.sleep(3000); |
383 | } | 428 | } |
384 | } | 429 | } |
385 | 430 | ||
386 | public void testGetOneSol3(XExpression expression, Term t) throws Exception { | 431 | public void testGetOneSol3(XExpression expression, Term t) throws Exception { |
387 | int count = 15000; | 432 | int count = 15000; |
388 | Random rand = new Random(); | 433 | Random rand = new Random(); |
@@ -416,7 +461,7 @@ public class NumericProblemSolver { | |||
416 | matchSet.add(match); | 461 | matchSet.add(match); |
417 | } | 462 | } |
418 | matches.put(expression, matchSet); | 463 | matches.put(expression, matchSet); |
419 | 464 | ||
420 | System.out.println("Number of matches: " + matchSet.size()); | 465 | System.out.println("Number of matches: " + matchSet.size()); |
421 | for (int i = 0; i < 10; i++) { | 466 | for (int i = 0; i < 10; i++) { |
422 | Map<Object,Integer> sol = getOneSolution(obj, matches); | 467 | Map<Object,Integer> sol = getOneSolution(obj, matches); |
@@ -424,5 +469,5 @@ public class NumericProblemSolver { | |||
424 | Thread.sleep(3000); | 469 | Thread.sleep(3000); |
425 | } | 470 | } |
426 | } | 471 | } |
427 | */ | 472 | */ |
428 | } | 473 | } |
diff --git a/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/NumericTranslator.xtend b/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/NumericTranslator.xtend index 89719b91..81bc1796 100644 --- a/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/NumericTranslator.xtend +++ b/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/NumericTranslator.xtend | |||
@@ -19,6 +19,10 @@ class NumericTranslator { | |||
19 | 19 | ||
20 | private XExpressionExtractor extractor = new XExpressionExtractor(); | 20 | private XExpressionExtractor extractor = new XExpressionExtractor(); |
21 | 21 | ||
22 | long formingProblemTime=0; | ||
23 | long solvingProblemTime=0; | ||
24 | long formingSolutionTime=0; | ||
25 | |||
22 | val comparator = new Comparator<JvmIdentifiableElement>(){ | 26 | val comparator = new Comparator<JvmIdentifiableElement>(){ |
23 | override compare(JvmIdentifiableElement o1, JvmIdentifiableElement o2) { | 27 | override compare(JvmIdentifiableElement o1, JvmIdentifiableElement o2) { |
24 | //println('''«o1.simpleName» - «o2.simpleName»''') | 28 | //println('''«o1.simpleName» - «o2.simpleName»''') |
@@ -52,6 +56,7 @@ class NumericTranslator { | |||
52 | val input = formNumericProblemInstance(matches) | 56 | val input = formNumericProblemInstance(matches) |
53 | val solver = new NumericProblemSolver | 57 | val solver = new NumericProblemSolver |
54 | val satisfiability = solver.isSatisfiable(input) | 58 | val satisfiability = solver.isSatisfiable(input) |
59 | solver.updateTimes | ||
55 | return satisfiability | 60 | return satisfiability |
56 | } | 61 | } |
57 | 62 | ||
@@ -59,6 +64,17 @@ class NumericTranslator { | |||
59 | val input = formNumericProblemInstance(matches) | 64 | val input = formNumericProblemInstance(matches) |
60 | val solver = new NumericProblemSolver | 65 | val solver = new NumericProblemSolver |
61 | val solution = solver.getOneSolution(primitiveElements,input) | 66 | val solution = solver.getOneSolution(primitiveElements,input) |
67 | solver.updateTimes | ||
62 | return solution | 68 | return solution |
63 | } | 69 | } |
70 | |||
71 | private def updateTimes(NumericProblemSolver s) { | ||
72 | this.formingProblemTime += s.getEndformingProblem | ||
73 | this.solvingProblemTime += s.getEndSolvingProblem | ||
74 | this.formingSolutionTime += s.getEndFormingSolution | ||
75 | } | ||
76 | |||
77 | def getFormingProblemTime() {formingProblemTime} | ||
78 | def getSolvingProblemTime() {solvingProblemTime} | ||
79 | def getFormingSolutionTime() {formingSolutionTime} | ||
64 | } \ No newline at end of file | 80 | } \ No newline at end of file |