From 88f90f0f78ab94ab67c8aaa882023d059a31b385 Mon Sep 17 00:00:00 2001 From: Aren Babikian Date: Wed, 3 Feb 2021 02:34:15 +0100 Subject: fix derived feature handling + impove dreal calling --- .../application/execution/QueryLoader.xtend | 21 ++++++++++++- .../viatra2logic/NumericDrealProblemSolver.java | 36 ++++++++++++++++++---- 2 files changed, 50 insertions(+), 7 deletions(-) diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/QueryLoader.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/QueryLoader.xtend index 5a73845d..277a1d5f 100644 --- a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/QueryLoader.xtend +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/QueryLoader.xtend @@ -51,7 +51,8 @@ class QueryLoader { .map[lookup(pattern2Specification)] .toSet val derivedFeatures = calculateDerivedFeatures(patterns.referredEcoreModels,patterns.map[it.lookup(pattern2Specification)]) - +// patternsToTranslate.forEach[println(it.fullyQualifiedName)] +// if (true) throw new Exception return new ViatraQuerySetDescriptor( patternsToTranslate, validationPatterns, @@ -130,6 +131,7 @@ class QueryLoader { val features = packages.map[EClassifiers].flatten.filter(EClass).map[it.EStructuralFeatures].flatten val res = new HashMap for(feature : features) { +/* val QBFAnnotation = feature.EAnnotations.filter[it.source.equals("org.eclipse.viatra.query.querybasedfeature")].head if(QBFAnnotation !== null) { val targetFQN = QBFAnnotation.details.get("patternFQN") @@ -141,7 +143,24 @@ class QueryLoader { res.put(referredPattern, feature) } } +*/ + if (feature.derived){ + //TODO we can check if feature is not from the ECORE MM + //TODO we can check that the found pattern has a "@QueryBasedFeature" annotation + val referredPattern = patterns.filter[ + val fqnSplit = it.fullyQualifiedName.split("\\.") + val patName = fqnSplit.get(fqnSplit.length - 1) + patName.equals(feature.name) + ].head + if(referredPattern!== null) { + res.put(referredPattern, feature) + } + } } +// if (!res.empty) { +// println("Derived Features") +// res.entrySet.forEach[println(it)] +// } return res } } 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 0105d985..4fef6448 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 @@ -42,8 +42,8 @@ public class NumericDrealProblemSolver extends NumericProblemSolver{ private Map varMap; private Map curVar2Decl; - private final int TIMEOUT_DOCKER = 5; - private final int TIMEOUT_LOCAL = 2; + private final int TIMEOUT_DOCKER = 5000; + private final int TIMEOUT_LOCAL = 20000; public NumericDrealProblemSolver(boolean useDocker, String drealLocalPath) throws IOException, InterruptedException { this.useDocker = useDocker; @@ -68,14 +68,26 @@ public class NumericDrealProblemSolver extends NumericProblemSolver{ } private Process runProcess(List cmd, int timeout) throws IOException, InterruptedException { - String s = String.join(" ", cmd); - Process p = Runtime.getRuntime().exec(s); +// String s = String.join(" ", cmd); +// Process p = Runtime.getRuntime().exec(s); + Process p = (new ProcessBuilder(cmd)).start(); // p.waitFor(); //TODO timeout if needed - if (!p.waitFor(timeout, TimeUnit.SECONDS)) { + long startTime = System.nanoTime(); + if (!p.waitFor(timeout, TimeUnit.MILLISECONDS)) { p.destroy(); + if (p.isAlive()) { + p.destroyForcibly(); + if (p.isAlive()) { + //Platform-specific but fine for now + Runtime.getRuntime().exec("killall -9 dreal").waitFor(); + if (p.isAlive()) System.out.println("dreal process not closed"); + } + } return null; } + double duration = (double) (System.nanoTime() - startTime) / 1000000000; + System.out.println("Dur = " + duration + " : "); return p; } @@ -371,18 +383,30 @@ public class NumericDrealProblemSolver extends NumericProblemSolver{ if (outputProcess != null) { outputs = getProcessOutput(outputProcess); result = getDrealResult(outputProcess.exitValue(), outputs); +// } else { +// System.err.print("Timeout, RETRYING..."); +// if (this.useDocker) outputProcess = callDrealDocker(numProbContent, false); +// else outputProcess = callDrealLocal(numProbContent, false); +// if (outputProcess != null) { +// outputs = getProcessOutput(outputProcess); +// result = getDrealResult(outputProcess.exitValue(), outputs); +// System.out.println("pass"); +// } else { +// System.out.println("fail"); +// } } endSolvingProblem = System.nanoTime()-startSolvingProblem; //DEBUG - Print things if (outputProcess == null) { + System.err.println("TIMEOUT"); // printOutput(numProbContent); } // printOutput(numProbContent); // if (outputs != null) printOutput(outputs.get(0)); -// System.out.println(result); + System.out.println(result); // END DEBUG return result; -- cgit v1.2.3-54-g00ecf