Search in sources :

Example 1 with ProcessRunner

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

the class BenchmarkStatsDriver method main.

/**
 * Usage: java tests.benchmarks.BenchmarksStatsDriver <sharing depth>
 */
public static void main(String[] args) {
    if (args.length != 1)
        usage();
    System.out.print("name\t");
    System.out.print("method\t");
    System.out.print("universe\t");
    System.out.print("outcome\t");
    System.out.print("translation (ms)\t");
    System.out.print("gates\t");
    System.out.print("primary vars\t");
    System.out.print("vars\t");
    System.out.print("clauses\t");
    System.out.println("solving time (ms)");
    for (Problem problem : problems) {
        final String cmd = "java -Xmx2G -cp bin tests.benchmarks.BenchmarkStats " + problem.problem + " " + problem.spec + " -scope=" + problem.bounds + " -sharing=" + args[0];
        // System.out.println(cmd);
        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();
                System.out.print(problem.problem + "\t");
                System.out.print(problem.spec + "\t");
                System.out.println("na\tna\tna\tna\tna\tna\tna\tna");
                continue;
            }
            final BufferedReader out = new BufferedReader(new InputStreamReader(runner.processOutput(), "ISO-8859-1"));
            System.out.println(out.readLine());
        } 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)

Example 2 with ProcessRunner

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

the class BenchmarkSymmStats method printSymmInfo.

private static void printSymmInfo(Formula formula, Bounds bounds) {
    final SymmReporter reporter = SymmReporter.report(formula, bounds);
    // <partial model bits> <gbp (ms)> <gbp (symms)>
    System.out.print(pmBits(bounds) + "\t");
    System.out.print(reporter.gbpTime + "\t");
    System.out.print(symms(reporter.symms) + "\t");
    // <gad (ms)> <gad (symms)>
    try {
        final long startGen = bean.getCurrentThreadUserTime();
        final File tmp = File.createTempFile("symmgraph", ".txt");
        final PrintStream stream = new PrintStream(new FileOutputStream(tmp));
        toNauty(reporter.bounds, stream);
        stream.close();
        final long endGen = bean.getCurrentThreadUserTime();
        final String cmd = "/Users/emina/Desktop/tools/nauty22/run_dreadnaut " + tmp.getAbsoluteFile();
        final ProcessRunner runner = new ProcessRunner(cmd.split("\\s"));
        runner.start();
        try {
            runner.join(BenchmarkDriver.FIVE_MIN);
            if (runner.getState() != Thread.State.TERMINATED) {
                System.out.print("t\\o\t");
                System.out.print("t\\o\t");
                runner.destroyProcess();
                destroy("dreadnaut");
                return;
            }
            final BufferedReader out = new BufferedReader(new InputStreamReader(runner.processOutput(), "ISO-8859-1"));
            String line;
            String allSymms = null;
            long gadTime = -1;
            final Pattern spattern = Pattern.compile(".+grpsize=(.+?);.*");
            final Matcher smatcher = spattern.matcher("");
            final Pattern tpattern = Pattern.compile(".+cpu time = (.+?)\\s.*");
            final Matcher tmatcher = tpattern.matcher("");
            while ((line = out.readLine()) != null) {
                smatcher.reset(line);
                if (smatcher.matches()) {
                    allSymms = smatcher.group(1);
                } else {
                    tmatcher.reset(line);
                    if (tmatcher.matches()) {
                        gadTime = (long) (Double.parseDouble(tmatcher.group(1)) * 1000);
                        if (gadTime == 0)
                            gadTime++;
                    }
                }
            // System.out.println(line);
            }
            out.close();
            System.out.print(gadTime < 0 ? "err\t" : (gadTime + (endGen - startGen) / 1000000) + "\t");
            System.out.print(allSymms == null ? "err\t" : allSymms + "\t");
        } catch (InterruptedException e) {
            System.out.println("INTERRUPTED");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            System.exit(1);
        } finally {
            runner.destroyProcess();
            destroy("dreadnaut");
            tmp.delete();
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : PrintStream(java.io.PrintStream) Pattern(java.util.regex.Pattern) InputStreamReader(java.io.InputStreamReader) Matcher(java.util.regex.Matcher) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) FileOutputStream(java.io.FileOutputStream) BufferedReader(java.io.BufferedReader) ProcessRunner(tests.util.ProcessRunner) File(java.io.File)

Example 3 with ProcessRunner

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

the class BenchmarkSymmStatsDriver method runSolveNoSymms.

/**
 * <solve no symms (ms)> \n
 */
private static void runSolveNoSymms(Problem problem) {
    final String cmd = "java -Xmx2G -cp bin tests.benchmarks.BenchmarkStats " + problem.problem + " " + problem.spec + " -scope=" + problem.bounds + " -symm=" + 0;
    final ProcessRunner runner = new ProcessRunner(cmd.split("\\s"));
    runner.start();
    try {
        runner.join(FIVE_MIN);
        if (runner.getState() != Thread.State.TERMINATED) {
            runner.interrupt();
            System.out.println("t\\o");
            runner.destroyProcess();
        } else {
            final BufferedReader out = new BufferedReader(new InputStreamReader(runner.processOutput(), "ISO-8859-1"));
            final String line = out.readLine();
            final String[] data = line.split("\\s");
            System.out.println(data.length == 10 ? data[9] : "t\\o");
            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 4 with ProcessRunner

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

the class UCoreStatsDriver method trainMax.

/**
 * Trains the given strategy at 75% of the test scope.
 */
private static void trainMax(String strategy) {
    if (strategy.toLowerCase().indexOf("rce") < 0)
        return;
    trainHeaders(strategy);
    final long timeout = FIVE_MIN;
    final int[] depths = { Integer.MAX_VALUE, 6, 5, 4, 3, 2, 1 };
    for (MaxSpec spec : MAX_SPECS) {
        final int scope = (int) Math.round(0.75 * spec.scope);
        for (int depth : depths) {
            final String opt = " -m " + spec.check + " -s " + strategy + " -d " + depth + " -o stats";
            final String cmd = "java -cp bin -Xmx2G tests.benchmarks.UCoreStats " + spec.problem + " " + 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(scope);
                    for (int i = 1; i < parsed.length; i++) {
                        System.out.print("\t" + parsed[i]);
                    }
                    System.out.println("\t" + depth);
                }
            } 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)

Example 5 with ProcessRunner

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

the class BenchmarkSymmStats2 method allSymms.

private static SymmInfo allSymms(Bounds bounds) {
    try {
        final long startGen = bean.getCurrentThreadUserTime();
        final File tmp = File.createTempFile("symmgraph", ".txt");
        final PrintStream stream = new PrintStream(new FileOutputStream(tmp));
        toNauty(bounds, stream);
        stream.close();
        final long endGen = bean.getCurrentThreadUserTime();
        final String cmd = "/Users/emina/Desktop/tools/nauty22/run_dreadnaut " + tmp.getAbsoluteFile();
        final ProcessRunner runner = new ProcessRunner(cmd.split("\\s"));
        runner.start();
        try {
            runner.join(BenchmarkDriver.FIVE_MIN);
            if (runner.getState() != Thread.State.TERMINATED) {
                System.out.print("t\\o\t");
                System.out.print("t\\o\t");
                runner.destroyProcess();
                destroy("dreadnaut");
                tmp.delete();
                return new SymmInfo(bounds.universe().size());
            }
            final BufferedReader out = new BufferedReader(new InputStreamReader(runner.processOutput(), "ISO-8859-1"));
            String line;
            String allSymms = null;
            long time = -1;
            final Set<IntSet> parts = new LinkedHashSet<IntSet>();
            final Matcher smatcher = Pattern.compile(".+grpsize=(.+?);.*").matcher("");
            final Matcher tmatcher = Pattern.compile(".+cpu time = (.+?)\\s.*").matcher("");
            final Matcher omatcher = Pattern.compile("invarproc \"adjacencies\"").matcher("");
            while ((line = out.readLine()) != null) {
                smatcher.reset(line);
                if (smatcher.matches()) {
                    allSymms = smatcher.group(1);
                } else {
                    tmatcher.reset(line);
                    if (tmatcher.matches()) {
                        time = (long) (Double.parseDouble(tmatcher.group(1)) * 1000);
                        if (time == 0)
                            time++;
                    } else {
                        omatcher.reset(line);
                        if (omatcher.find()) {
                            break;
                        }
                    }
                }
            }
            if (line != null) {
                final StringBuilder builder = new StringBuilder();
                while ((line = out.readLine()) != null) {
                    builder.append(line);
                }
                line = builder.toString();
                // System.out.println(line);
                final String[] orbits = line.split(";");
                final Matcher dmatcher = Pattern.compile("\\s*(\\d+)\\s*").matcher("");
                for (String n : orbits) {
                    String[] range = n.split(":");
                    if (range.length == 2) {
                        dmatcher.reset(range[0]);
                        dmatcher.matches();
                        final int min = Integer.parseInt(dmatcher.group(1));
                        if (min >= bounds.universe().size())
                            break;
                        dmatcher.reset(range[1]);
                        dmatcher.matches();
                        parts.add(Ints.rangeSet(Ints.range(min, Integer.parseInt(dmatcher.group(1)))));
                    } else {
                        range = n.split("\\s+");
                        final IntSet part = new IntTreeSet();
                        for (int i = 0; i < range.length; i++) {
                            dmatcher.reset(range[i]);
                            if (dmatcher.matches()) {
                                final int match = Integer.parseInt(dmatcher.group(1));
                                if (match < bounds.universe().size())
                                    part.add(match);
                                else
                                    break;
                            }
                        }
                        if (part.isEmpty())
                            break;
                        else
                            parts.add(part);
                    }
                }
            }
            out.close();
            tmp.delete();
            runner.destroyProcess();
            if (time < 0 || allSymms == null || parts.isEmpty())
                throw new IllegalStateException();
            return new SymmInfo(parts, String.valueOf(time + (endGen - startGen) / 1000000), allSymms);
        } catch (IOException e) {
            tmp.delete();
            runner.destroyProcess();
            destroy("dreadnaut");
            throw new IllegalStateException(e);
        } catch (InterruptedException e) {
            tmp.delete();
            runner.destroyProcess();
            destroy("dreadnaut");
            e.printStackTrace();
            throw new IllegalStateException(e);
        }
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) PrintStream(java.io.PrintStream) InputStreamReader(java.io.InputStreamReader) Matcher(java.util.regex.Matcher) IntSet(kodkod.util.ints.IntSet) IntTreeSet(kodkod.util.ints.IntTreeSet) IOException(java.io.IOException) FileOutputStream(java.io.FileOutputStream) BufferedReader(java.io.BufferedReader) ProcessRunner(tests.util.ProcessRunner) File(java.io.File)

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