Search in sources :

Example 1 with Solver

use of kodkod.engine.Solver in project org.alloytools.alloy by AlloyTools.

the class OverflowTheoremTest method solve.

protected Solution[] solve(Formula formula) {
    Solution s1 = new Solver(options).solve(formula, bounds);
    Options opt2 = options.clone();
    opt2.setSkolemDepth(2);
    // Solution s2 = new Solver(opt2).solve(formula, bounds);
    return new Solution[] { s1 };
}
Also used : Options(kodkod.engine.config.Options) Solver(kodkod.engine.Solver) Solution(kodkod.engine.Solution)

Example 2 with Solver

use of kodkod.engine.Solver in project org.alloytools.alloy by AlloyTools.

the class BenchmarkSymmStats2 method printGBP.

// <symm time (ms)> <# of symms> <state bits> <SAT|UNSAT> <SAT time (ms)>
private static void printGBP(Formula formula, Bounds bounds) {
    final class SymmReporter extends AbstractReporter {

        long gbpTime;

        BigInteger symms;

        @Override
        public void detectingSymmetries(Bounds bounds) {
            gbpTime = bean.getCurrentThreadUserTime();
        }

        @Override
        public void detectedSymmetries(Set<IntSet> parts) {
            final long end = bean.getCurrentThreadUserTime();
            gbpTime = (end - gbpTime) / 1000000;
            symms = new BigInteger("1");
            for (IntSet s : parts) {
                symms = symms.multiply(fact(s.size()));
            }
        // System.out.println(parts);
        }
    }
    ;
    final SymmReporter reporter = new SymmReporter();
    final Solver solver = new Solver();
    solver.options().setBitwidth(8);
    solver.options().setSolver(SATFactory.MiniSat);
    solver.options().setReporter(reporter);
    final Solution sol = solver.solve(formula, bounds);
    // <gbp (ms)> <gbp (symms)>
    System.out.print(reporter.gbpTime + "\t");
    System.out.print(reporter.symms + "\t");
    // <state bits> <SAT|UNSAT> <SAT time (ms)>
    System.out.print(sol.stats().primaryVariables() + "\t");
    System.out.print(sol.instance() == null ? "UNSAT\t" : "SAT\t");
    System.out.print(sol.stats().solvingTime() + "\t");
}
Also used : Solver(kodkod.engine.Solver) LinkedHashSet(java.util.LinkedHashSet) TupleSet(kodkod.instance.TupleSet) IntTreeSet(kodkod.util.ints.IntTreeSet) IntSet(kodkod.util.ints.IntSet) Set(java.util.Set) IntSet(kodkod.util.ints.IntSet) Bounds(kodkod.instance.Bounds) AbstractReporter(kodkod.engine.config.AbstractReporter) BigInteger(java.math.BigInteger) Solution(kodkod.engine.Solution)

Example 3 with Solver

use of kodkod.engine.Solver in project org.alloytools.alloy by AlloyTools.

the class BenchmarkSymmStats2 method printGAD.

// <symm time (ms)> <# of symms> <state bits> <SAT|UNSAT> <SAT time (ms)>
private static void printGAD(Formula formula, Bounds bounds) {
    final class SymmReporter extends AbstractReporter {

        String symms, time;

        Bounds bounds;

        @Override
        public void detectingSymmetries(Bounds bounds) {
            this.bounds = bounds.clone();
        }

        @Override
        public void detectedSymmetries(Set<IntSet> parts) {
            parts.clear();
            final SymmInfo allSymms = allSymms(bounds);
            parts.addAll(allSymms.parts);
            symms = allSymms.symms;
            time = allSymms.time;
        // System.out.println(parts);
        }
    }
    ;
    final SymmReporter reporter = new SymmReporter();
    final Solver solver = new Solver();
    solver.options().setBitwidth(8);
    solver.options().setSolver(SATFactory.MiniSat);
    solver.options().setReporter(reporter);
    final Solution sol = solver.solve(formula, bounds);
    // <gbp (ms)> <gbp (symms)>
    System.out.print(reporter.time + "\t");
    System.out.print(reporter.symms + "\t");
    // <state bits> <SAT|UNSAT> <SAT time (ms)>
    System.out.print(sol.stats().primaryVariables() + "\t");
    System.out.print(sol.instance() == null ? "UNSAT\t" : "SAT\t");
    System.out.print(sol.stats().solvingTime() + "\t");
}
Also used : Solver(kodkod.engine.Solver) LinkedHashSet(java.util.LinkedHashSet) TupleSet(kodkod.instance.TupleSet) IntTreeSet(kodkod.util.ints.IntTreeSet) IntSet(kodkod.util.ints.IntSet) Set(java.util.Set) Bounds(kodkod.instance.Bounds) AbstractReporter(kodkod.engine.config.AbstractReporter) Solution(kodkod.engine.Solution)

Example 4 with Solver

use of kodkod.engine.Solver in project org.alloytools.alloy by AlloyTools.

the class UCoreStats method solver.

private static Solver solver() {
    final Solver solver = new Solver();
    solver.options().setBitwidth(8);
    solver.options().setSolver(SATFactory.MiniSatProver);
    solver.options().setLogTranslation(1);
    return solver;
}
Also used : Solver(kodkod.engine.Solver)

Example 5 with Solver

use of kodkod.engine.Solver in project org.alloytools.alloy by AlloyTools.

the class UCoreStats method checkMinimal.

/**
 * Checks that the given proof of unsatisfiablity for the given problem is
 * miminal. This method assumes that the given proof is correct.
 *
 * @return true if the core is minimal; false otherwise.
 */
static boolean checkMinimal(Set<Formula> core, Bounds bounds) {
    System.out.print("checking minimality ... ");
    final long start = System.currentTimeMillis();
    final Set<Formula> minCore = new LinkedHashSet<Formula>(core);
    Solver solver = solver();
    solver.options().setSolver(SATFactory.MiniSat);
    for (Iterator<Formula> itr = minCore.iterator(); itr.hasNext(); ) {
        Formula f = itr.next();
        Formula noF = Formula.TRUE;
        for (Formula f1 : minCore) {
            if (f != f1)
                noF = noF.and(f1);
        }
        if (solver.solve(noF, bounds).instance() == null) {
            itr.remove();
        }
    }
    final long end = System.currentTimeMillis();
    if (minCore.size() == core.size()) {
        System.out.println("minimal (" + (end - start) + " ms).");
        return true;
    } else {
        System.out.println("not minimal (" + (end - start) + " ms). The minimal core has these " + minCore.size() + " formulas:");
        for (Formula f : minCore) {
            System.out.println(" " + f);
        }
        return false;
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Formula(kodkod.ast.Formula) Solver(kodkod.engine.Solver)

Aggregations

Solver (kodkod.engine.Solver)76 Solution (kodkod.engine.Solution)72 Formula (kodkod.ast.Formula)67 Bounds (kodkod.instance.Bounds)67 Universe (kodkod.instance.Universe)26 TupleFactory (kodkod.instance.TupleFactory)25 Relation (kodkod.ast.Relation)24 TupleSet (kodkod.instance.TupleSet)23 Expression (kodkod.ast.Expression)14 IntExpression (kodkod.ast.IntExpression)14 Variable (kodkod.ast.Variable)14 Decls (kodkod.ast.Decls)11 HigherOrderDeclException (kodkod.engine.fol2sat.HigherOrderDeclException)7 UnboundLeafException (kodkod.engine.fol2sat.UnboundLeafException)7 ConsoleReporter (kodkod.engine.config.ConsoleReporter)6 LinkedHashSet (java.util.LinkedHashSet)5 Evaluator (kodkod.engine.Evaluator)3 AbstractReporter (kodkod.engine.config.AbstractReporter)3 Instance (kodkod.instance.Instance)3 Method (java.lang.reflect.Method)2