Search in sources :

Example 6 with ProcessRunner

use of tests.util.ProcessRunner in project org.alloytools.alloy by AlloyTools.

the class BenchmarkSymmStatsDriver method runSolveWithSymms.

/**
 * <state space (bits)> <SAT|UNSAT> <solve with symms (ms)> \t
 */
private static void runSolveWithSymms(Problem problem) {
    final String cmd = "java -Xmx2G -cp bin tests.benchmarks.BenchmarkStats " + problem.problem + " " + problem.spec + " -scope=" + problem.bounds;
    final ProcessRunner runner = new ProcessRunner(cmd.split("\\s"));
    runner.start();
    try {
        runner.join();
        final BufferedReader out = new BufferedReader(new InputStreamReader(runner.processOutput(), "ISO-8859-1"));
        final String line = out.readLine();
        final String[] data = line.split("\\s");
        if (data.length != 10)
            throw new RuntimeException("badly formatted output: " + line);
        // <class name> <method name> <universe size> <S|U> <translation
        // time (ms)> <# of gates> <# of primary vars> <# of vars> <# of
        // clauses> <solving time (ms)>
        System.out.print(data[6] + "\t");
        System.out.print(data[3].startsWith("S") ? "SAT\t" : "UNSAT\t");
        System.out.print(data[9] + "\t");
        out.close();
    } catch (InterruptedException e) {
        e.printStackTrace();
        System.exit(1);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
        System.exit(1);
    } catch (IOException e) {
        e.printStackTrace();
        System.exit(1);
    } finally {
        runner.destroyProcess();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) ProcessRunner(tests.util.ProcessRunner)

Example 7 with ProcessRunner

use of tests.util.ProcessRunner in project org.alloytools.alloy by AlloyTools.

the class BenchmarkSymmStatsDriver method runSymms.

/**
 * <class name> <method name> <partial model (bits)> <gbp (ms)> <gbp (symms)>
 * <gad (ms)> <gad (symms)> \t
 */
private static void runSymms(Problem problem) {
    final String cmd = "java -Xmx2G -cp bin tests.benchmarks.BenchmarkSymmStats " + problem.problem + " " + problem.spec + " " + problem.bounds;
    final ProcessRunner runner = new ProcessRunner(cmd.split("\\s"));
    runner.start();
    try {
        runner.join();
        final BufferedReader out;
        out = new BufferedReader(new InputStreamReader(runner.processOutput(), "ISO-8859-1"));
        System.out.print(out.readLine());
        out.close();
    } catch (InterruptedException e) {
        e.printStackTrace();
        System.exit(1);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
        System.exit(1);
    } catch (IOException e) {
        e.printStackTrace();
        System.exit(1);
    } finally {
        runner.destroyProcess();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) ProcessRunner(tests.util.ProcessRunner)

Example 8 with ProcessRunner

use of tests.util.ProcessRunner in project org.alloytools.alloy by AlloyTools.

the class UCoreStatsDriver method runAllInScopes.

/**
 * Runs all problems with the given strategy for the given scope range.
 *
 * @requires 1 < min <= max
 * @requires strategy is the name of a reduction strategy supported by
 *           {@linkplain UCoreStats#main(String[])}
 */
private static void runAllInScopes(String strategy, int min, int max) {
    testHeaders(strategy);
    final Set<Method> timedOut = new LinkedHashSet<Method>();
    final Set<Method> sat = new LinkedHashSet<Method>();
    for (int scope = min; scope <= max; scope++) {
        for (String problem : RANGE_PROBLEMS) {
            for (Method m : checks(findClass(problem))) {
                if (timedOut.contains(m)) {
                    skip(problem, m.getName(), scope, "G");
                    continue;
                }
                if (sat.contains(m)) {
                    skip(problem, m.getName(), scope, "S");
                    continue;
                }
                final String cmd = "java -cp bin -Xmx2G tests.UCoreStats " + problem + " " + String.valueOf(scope) + " -o stats -m " + m.getName() + " -s " + strategy;
                final ProcessRunner runner = new ProcessRunner(cmd.split("\\s"));
                runner.start();
                try {
                    runner.join(FIVE_MIN);
                    if (runner.getState() != Thread.State.TERMINATED) {
                        runner.interrupt();
                        runner.destroyProcess();
                        skip(problem, m.getName(), scope, "G");
                        timedOut.add(m);
                        continue;
                    }
                    final BufferedReader out = new BufferedReader(new InputStreamReader(runner.processOutput(), "ISO-8859-1"));
                    String line = null;
                    while ((line = out.readLine()) != null) {
                        final String[] parsed = line.split("\\s");
                        System.out.print(problem.substring(problem.lastIndexOf(".") + 1) + "\t");
                        System.out.print(parsed[0] + "\t");
                        System.out.print(scope);
                        for (int i = 1; i < parsed.length; i++) {
                            System.out.print("\t" + parsed[i]);
                        }
                        System.out.println();
                        if ("S".equals(parsed[1]) || "T".equals(parsed[1])) {
                            sat.add(m);
                        }
                    }
                } catch (InterruptedException e) {
                    System.out.println("INTERRUPTED");
                    runner.destroyProcess();
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                    System.exit(1);
                } catch (IOException e) {
                    e.printStackTrace();
                    System.exit(1);
                }
            }
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Method(java.lang.reflect.Method) IOException(java.io.IOException) ProcessRunner(tests.util.ProcessRunner)

Example 9 with ProcessRunner

use of tests.util.ProcessRunner in project org.alloytools.alloy by AlloyTools.

the class UCoreStatsDriver method testMax.

/**
 * Runs all problems with the given strategy for the predetermined maximum
 * scopes.
 *
 * @requires strategy is the name of a reduction strategy supported by
 *           {@linkplain UCoreStats#main(String[])}
 */
private static void testMax(String strategy) {
    testHeaders(strategy);
    final long timeout = ONE_HOUR;
    for (MaxSpec spec : TRAIN_SPECS) {
        final String opt = " -m " + spec.check + " -s " + strategy + " -d " + Integer.MAX_VALUE + " -o stats";
        // final String opt = " -m " + spec.check + " -s " +strategy + " -d
        // " + spec.depth + " -o stats";
        final String cmd = "java -cp bin -Xmx2G tests.benchmarks.UCoreStats " + spec.problem + " " + spec.scope + " " + opt;
        final ProcessRunner runner = new ProcessRunner(cmd.split("\\s"));
        runner.start();
        try {
            runner.join(timeout);
            if (runner.getState() != Thread.State.TERMINATED) {
                runner.interrupt();
                runner.destroyProcess();
                skip(spec.problem, spec.check, spec.scope, "G");
                continue;
            }
            final BufferedReader out = new BufferedReader(new InputStreamReader(runner.processOutput(), "ISO-8859-1"));
            String line = null;
            while ((line = out.readLine()) != null) {
                final String[] parsed = line.split("\\s");
                System.out.print(spec.problem.substring(spec.problem.lastIndexOf(".") + 1) + "\t");
                System.out.print(parsed[0] + "\t");
                System.out.print(spec.scope);
                for (int i = 1; i < parsed.length; i++) {
                    System.out.print("\t" + parsed[i]);
                }
                System.out.println();
            }
        } catch (InterruptedException e) {
            System.out.println("INTERRUPTED");
            runner.destroyProcess();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            System.exit(1);
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) ProcessRunner(tests.util.ProcessRunner)

Aggregations

BufferedReader (java.io.BufferedReader)9 IOException (java.io.IOException)9 InputStreamReader (java.io.InputStreamReader)9 ProcessRunner (tests.util.ProcessRunner)9 UnsupportedEncodingException (java.io.UnsupportedEncodingException)8 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 PrintStream (java.io.PrintStream)2 LinkedHashSet (java.util.LinkedHashSet)2 Matcher (java.util.regex.Matcher)2 Method (java.lang.reflect.Method)1 Pattern (java.util.regex.Pattern)1 IntSet (kodkod.util.ints.IntSet)1 IntTreeSet (kodkod.util.ints.IntTreeSet)1