diff options
author | Aren Babikian <aren.babikian@mail.mcgill.ca> | 2021-02-16 01:11:15 +0100 |
---|---|---|
committer | Aren Babikian <aren.babikian@mail.mcgill.ca> | 2021-02-16 01:11:15 +0100 |
commit | acb8dedc9d03e1d17f570e07c9f75a571bd66cf8 (patch) | |
tree | 56d4f9899af7c70fa006395ffb0b93ff339fac7b | |
parent | Minor adjsutments to CrossScen ad FamTree local case studies (diff) | |
download | VIATRA-Generator-acb8dedc9d03e1d17f570e07c9f75a571bd66cf8.tar.gz VIATRA-Generator-acb8dedc9d03e1d17f570e07c9f75a571bd66cf8.tar.zst VIATRA-Generator-acb8dedc9d03e1d17f570e07c9f75a571bd66cf8.zip |
Ready for strategies case study
5 files changed, 40 insertions, 6 deletions
diff --git a/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/NumericDrealProblemSolver.java b/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/NumericDrealProblemSolver.java index 70aa933a..f098d575 100644 --- a/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/NumericDrealProblemSolver.java +++ b/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/NumericDrealProblemSolver.java | |||
@@ -43,7 +43,7 @@ public class NumericDrealProblemSolver extends NumericProblemSolver{ | |||
43 | private Map<String, String> curVar2Decl; | 43 | private Map<String, String> curVar2Decl; |
44 | 44 | ||
45 | private final int TIMEOUT_DOCKER = 5000; | 45 | private final int TIMEOUT_DOCKER = 5000; |
46 | private final int TIMEOUT_LOCAL = 100000; | 46 | private final int TIMEOUT_LOCAL = -1; |
47 | private final int DEBUG_PRINT = 3; | 47 | private final int DEBUG_PRINT = 3; |
48 | 48 | ||
49 | public NumericDrealProblemSolver(boolean useDocker, String drealLocalPath) throws IOException, InterruptedException { | 49 | public NumericDrealProblemSolver(boolean useDocker, String drealLocalPath) throws IOException, InterruptedException { |
@@ -75,7 +75,9 @@ public class NumericDrealProblemSolver extends NumericProblemSolver{ | |||
75 | // p.waitFor(); | 75 | // p.waitFor(); |
76 | //TODO timeout if needed | 76 | //TODO timeout if needed |
77 | long startTime = System.nanoTime(); | 77 | long startTime = System.nanoTime(); |
78 | if (!p.waitFor(timeout, TimeUnit.MILLISECONDS)) { | 78 | if (timeout == -1) { |
79 | p.waitFor(); | ||
80 | } else if (!p.waitFor(timeout, TimeUnit.MILLISECONDS)) { | ||
79 | p.destroy(); | 81 | p.destroy(); |
80 | if (p.isAlive()) { | 82 | if (p.isAlive()) { |
81 | p.destroyForcibly(); | 83 | p.destroyForcibly(); |
@@ -406,6 +408,7 @@ public class NumericDrealProblemSolver extends NumericProblemSolver{ | |||
406 | //CREATE DREAL STM2 FILE CONTENTS | 408 | //CREATE DREAL STM2 FILE CONTENTS |
407 | long startformingProblem = System.nanoTime(); | 409 | long startformingProblem = System.nanoTime(); |
408 | List<String> numProbContent = formNumericProblemInstance(matches); | 410 | List<String> numProbContent = formNumericProblemInstance(matches); |
411 | if (DEBUG_PRINT > 2) printOutput(numProbContent); | ||
409 | endformingProblem = System.nanoTime()-startformingProblem; | 412 | endformingProblem = System.nanoTime()-startformingProblem; |
410 | 413 | ||
411 | if (numProbContent == null) { | 414 | if (numProbContent == null) { |
@@ -446,7 +449,6 @@ public class NumericDrealProblemSolver extends NumericProblemSolver{ | |||
446 | System.out.println(result); | 449 | System.out.println(result); |
447 | } | 450 | } |
448 | if (DEBUG_PRINT > 2) { | 451 | if (DEBUG_PRINT > 2) { |
449 | printOutput(numProbContent); | ||
450 | if (outputs != null) printOutput(outputs.get(0)); | 452 | if (outputs != null) printOutput(outputs.get(0)); |
451 | } | 453 | } |
452 | 454 | ||
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/PExpressionGenerator.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/PExpressionGenerator.xtend index 62ff92b2..9835356e 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/PExpressionGenerator.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/PExpressionGenerator.xtend | |||
@@ -10,6 +10,8 @@ import org.eclipse.xtext.xbase.XNumberLiteral | |||
10 | import org.eclipse.xtext.xbase.XUnaryOperation | 10 | import org.eclipse.xtext.xbase.XUnaryOperation |
11 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.PrimitiveTypeReference | 11 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.PrimitiveTypeReference |
12 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RealTypeReference | 12 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RealTypeReference |
13 | import org.eclipse.xtext.xbase.XIfExpression | ||
14 | import org.eclipse.xtext.xbase.XBlockExpression | ||
13 | 15 | ||
14 | class PExpressionGenerator { | 16 | class PExpressionGenerator { |
15 | static val N_Base = "org.eclipse.xtext.xbase.lib." | 17 | static val N_Base = "org.eclipse.xtext.xbase.lib." |
@@ -113,4 +115,17 @@ class PExpressionGenerator { | |||
113 | def dispatch CharSequence translateExpression(XExpression expression, Map<PVariable,String> valueName, Map<PVariable, PrimitiveTypeReference> variable2Type) { | 115 | def dispatch CharSequence translateExpression(XExpression expression, Map<PVariable,String> valueName, Map<PVariable, PrimitiveTypeReference> variable2Type) { |
114 | throw new UnsupportedOperationException('''Unsupported expression in check or eval: «expression.class.name», «expression»"''') | 116 | throw new UnsupportedOperationException('''Unsupported expression in check or eval: «expression.class.name», «expression»"''') |
115 | } | 117 | } |
118 | |||
119 | def dispatch CharSequence translateExpression(XIfExpression e, Map<PVariable,String> valueName, Map<PVariable, PrimitiveTypeReference> variable2Type) { | ||
120 | val i = e.^if.translateExpression(valueName,variable2Type) | ||
121 | val t = e.then.translateExpression(valueName,variable2Type) | ||
122 | val el = e.^else.translateExpression(valueName,variable2Type) | ||
123 | |||
124 | return '''(if(«i»){«t»}else{«el»})''' | ||
125 | } | ||
126 | |||
127 | def dispatch CharSequence translateExpression(XBlockExpression e, Map<PVariable,String> valueName, Map<PVariable, PrimitiveTypeReference> variable2Type) { | ||
128 | //Assuming 1-item blocks only | ||
129 | return (e as XBlockExpression).expressions.get(0).translateExpression(valueName,variable2Type) | ||
130 | } | ||
116 | } \ No newline at end of file | 131 | } \ No newline at end of file |
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/ViatraReasoner.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/ViatraReasoner.xtend index 5ad78506..a692e1e5 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/ViatraReasoner.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/ViatraReasoner.xtend | |||
@@ -110,7 +110,7 @@ class ViatraReasoner extends LogicReasoner { | |||
110 | new SolutionStore(numberOfRequiredSolutions) | 110 | new SolutionStore(numberOfRequiredSolutions) |
111 | } | 111 | } |
112 | solutionStore.registerSolutionFoundHandler(new LoggerSolutionFoundHandler(viatraConfig)) | 112 | solutionStore.registerSolutionFoundHandler(new LoggerSolutionFoundHandler(viatraConfig)) |
113 | val numericSolver = new NumericSolver(method, viatraConfig, true)//was formerly hard-coded to false for caching | 113 | val numericSolver = new NumericSolver(method, viatraConfig, false)//was formerly hard-coded to false for caching |
114 | val solutionSaver = method.solutionSaver | 114 | val solutionSaver = method.solutionSaver |
115 | solutionSaver.numericSolver = numericSolver | 115 | solutionSaver.numericSolver = numericSolver |
116 | val solutionCopier = solutionSaver.solutionCopier | 116 | val solutionCopier = solutionSaver.solutionCopier |
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/NumericSolver.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/NumericSolver.xtend index 44964079..28edff41 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/NumericSolver.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/NumericSolver.xtend | |||
@@ -24,10 +24,12 @@ import java.util.List | |||
24 | import java.util.Map | 24 | import java.util.Map |
25 | import org.eclipse.emf.ecore.EObject | 25 | import org.eclipse.emf.ecore.EObject |
26 | import org.eclipse.viatra.dse.base.ThreadContext | 26 | import org.eclipse.viatra.dse.base.ThreadContext |
27 | import org.eclipse.viatra.dse.objectives.Fitness | ||
27 | import org.eclipse.viatra.query.runtime.api.IPatternMatch | 28 | import org.eclipse.viatra.query.runtime.api.IPatternMatch |
28 | import org.eclipse.viatra.query.runtime.api.ViatraQueryMatcher | 29 | import org.eclipse.viatra.query.runtime.api.ViatraQueryMatcher |
29 | import org.eclipse.viatra.query.runtime.matchers.psystem.PConstraint | 30 | import org.eclipse.viatra.query.runtime.matchers.psystem.PConstraint |
30 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation | 31 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation |
32 | import org.eclipse.viatra.dse.objectives.IObjective | ||
31 | 33 | ||
32 | class NumericSolver { | 34 | class NumericSolver { |
33 | val ModelGenerationMethod method | 35 | val ModelGenerationMethod method |
@@ -206,7 +208,6 @@ class NumericSolver { | |||
206 | } | 208 | } |
207 | } else { | 209 | } else { |
208 | if (needsFilling){ | 210 | if (needsFilling){ |
209 | //TODO ASSUME Always True | ||
210 | //GET LIST OF VARS TO FILL | 211 | //GET LIST OF VARS TO FILL |
211 | val fillMap = t.delegateGetSolution(dataObjects, propagatedConstraints, selectSolver(phase)) | 212 | val fillMap = t.delegateGetSolution(dataObjects, propagatedConstraints, selectSolver(phase)) |
212 | if (fillMap === null) finalResult = false | 213 | if (fillMap === null) finalResult = false |
@@ -225,7 +226,9 @@ class NumericSolver { | |||
225 | //STRATEGY | 226 | //STRATEGY |
226 | if (phase == 2) { | 227 | if (phase == 2) { |
227 | if (!finalResult) return finalResult | 228 | if (!finalResult) return finalResult |
228 | else finalResult = isSatisfiable(matches, 3) | 229 | else { |
230 | finalResult = isSatisfiable(matches, 3) | ||
231 | } | ||
229 | } | 232 | } |
230 | return finalResult | 233 | return finalResult |
231 | } | 234 | } |
@@ -243,6 +246,14 @@ class NumericSolver { | |||
243 | // -1 : take all numeric constraints | 246 | // -1 : take all numeric constraints |
244 | // -2 : SKIP (take no numeric constraints) | 247 | // -2 : SKIP (take no numeric constraints) |
245 | if (strategy == ExplorationStrategy.CrossingScenario) { | 248 | if (strategy == ExplorationStrategy.CrossingScenario) { |
249 | // //if has structural (non-WF) fitness issues, skip numeric handling | ||
250 | // val IObjective ob = threadContext.objectives.filter[it instanceof ModelGenerationCompositeObjective].get(0) | ||
251 | // val compo = ob as ModelGenerationCompositeObjective | ||
252 | // if (compo.getNonWFFitness(threadContext) > 0) { | ||
253 | // println("bootleg numeric-skip") | ||
254 | // return -2; | ||
255 | // } | ||
256 | |||
246 | //assumikng standard input, w/ visinBlocked and CollisionExists between pre-included actors | 257 | //assumikng standard input, w/ visinBlocked and CollisionExists between pre-included actors |
247 | val PartialInterpretation head = threadContext.getModel() as PartialInterpretation; | 258 | val PartialInterpretation head = threadContext.getModel() as PartialInterpretation; |
248 | val List<PartialRelationInterpretation> relations = head.getPartialrelationinterpretation(); | 259 | val List<PartialRelationInterpretation> relations = head.getPartialrelationinterpretation(); |
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/UnfinishedWFObjective.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/UnfinishedWFObjective.xtend index 1b61ffa5..b5b44254 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/UnfinishedWFObjective.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/UnfinishedWFObjective.xtend | |||
@@ -37,6 +37,12 @@ class UnfinishedWFObjective implements IObjective { | |||
37 | override getComparator() { Comparators.LOWER_IS_BETTER } | 37 | override getComparator() { Comparators.LOWER_IS_BETTER } |
38 | 38 | ||
39 | override getFitness(ThreadContext context) { | 39 | override getFitness(ThreadContext context) { |
40 | // //MEGA ASSUMPTION Below TODO | ||
41 | // //if has no unfilled variables, return 0 | ||
42 | // val model = context.getModel as PartialInterpretation | ||
43 | // val unfilledDataObjects = model.newElements.filter(PrimitiveElement).filter[!model.openWorldElements.contains(it)].filter[!it.isValueSet].toList | ||
44 | // if (unfilledDataObjects.isEmpty) return 0.0 | ||
45 | |||
40 | var sumOfMatches = 0 | 46 | var sumOfMatches = 0 |
41 | for (matcher : matchers) { | 47 | for (matcher : matchers) { |
42 | val number = matcher.countMatches | 48 | val number = matcher.countMatches |