Search in sources :

Example 36 with Solver

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

the class CeilingsAndFloors method main.

/**
 * Usage: java examples.CeilingsAndFloors [# men] [# platforms]
 */
public static void main(String[] args) {
    if (args.length < 2)
        usage();
    final CeilingsAndFloors model = new CeilingsAndFloors();
    final Solver solver = new Solver();
    solver.options().setSolver(SATFactory.MiniSat);
    try {
        final int m = Integer.parseInt(args[0]);
        final int p = Integer.parseInt(args[1]);
        final Formula show = model.checkBelowTooDoublePrime();
        final Solution sol = solver.solve(show, model.bounds(m, p));
        System.out.println(show);
        System.out.println(sol);
    } catch (NumberFormatException nfe) {
        usage();
    }
}
Also used : Formula(kodkod.ast.Formula) Solver(kodkod.engine.Solver) Solution(kodkod.engine.Solution)

Example 37 with Solver

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

the class DiffEg method main.

/**
 * Usage: java examples.DiffEq [scope]
 */
public static void main(String[] args) {
    if (args.length < 1)
        usage();
    try {
        final int n = Integer.parseInt(args[0]);
        if (n < 1)
            usage();
        final DiffEg model = new DiffEg();
        final Solver solver = new Solver();
        final Formula f = model.runPol();
        final Bounds b = model.bounds(n);
        System.out.println(f);
        final Solution sol = solver.solve(f, b);
        System.out.println(sol);
    } catch (NumberFormatException nfe) {
        usage();
    }
}
Also used : Formula(kodkod.ast.Formula) Solver(kodkod.engine.Solver) Bounds(kodkod.instance.Bounds) Solution(kodkod.engine.Solution)

Example 38 with Solver

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

the class Hotel method main.

/**
 * Usage: java examples.Hotel [scope]
 */
public static void main(String[] args) {
    if (args.length < 1)
        usage();
    try {
        final int n = Integer.parseInt(args[0]);
        if (n < 1)
            usage();
        final Hotel model = new Hotel();
        final Solver solver = new Solver();
        solver.options().setSolver(SATFactory.MiniSatProver);
        solver.options().setLogTranslation(1);
        final Formula f = model.checkNoBadEntry();
        final Bounds b = model.bounds(n);
        // System.out.println(PrettyPrinter.print(f, 2, 100));
        final Solution sol = solver.solve(f, b);
        System.out.println(sol);
        if (sol.instance() == null) {
            final Proof proof = sol.proof();
            System.out.println("top-level formulas: " + proof.log().roots().size());
            System.out.println("initial core: " + proof.highLevelCore().size());
            System.out.print("\nminimizing core ... ");
            final long start = System.currentTimeMillis();
            proof.minimize(new RCEStrategy(proof.log()));
            final Set<Formula> core = Nodes.minRoots(f, proof.highLevelCore().values());
            final long end = System.currentTimeMillis();
            System.out.println("done (" + (end - start) + " ms).");
            System.out.println("minimal core: " + core.size());
            for (Formula u : core) {
                System.out.println(PrettyPrinter.print(u, 2, 100));
            }
            checkMinimal(core, b);
        } else {
            System.out.println(sol);
        }
    } catch (NumberFormatException nfe) {
        usage();
    }
}
Also used : Formula(kodkod.ast.Formula) Solver(kodkod.engine.Solver) RCEStrategy(kodkod.engine.ucore.RCEStrategy) Bounds(kodkod.instance.Bounds) Proof(kodkod.engine.Proof) Solution(kodkod.engine.Solution)

Example 39 with Solver

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

the class Hotel method checkMinimal.

private static void 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 = new 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).");
    } 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);
        }
    // Solution sol = problem.solver.solve(Formula.and(minCore),
    // problem.bounds);
    // System.out.println(sol);
    // sol.proof().highLevelCore();
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Formula(kodkod.ast.Formula) Solver(kodkod.engine.Solver)

Example 40 with Solver

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

the class Pigeonhole method main.

/**
 * Usage: java tests.Pigeonhole [# pigeons] [# holes]
 */
public static void main(String[] args) {
    if (args.length < 2)
        usage();
    final Pigeonhole model = new Pigeonhole();
    final Solver solver = new Solver();
    try {
        final int p = Integer.parseInt(args[0]);
        final int h = Integer.parseInt(args[1]);
        solver.options().setSolver(SATFactory.MiniSat);
        solver.options().setSymmetryBreaking(p);
        final Formula show = model.declarations().and(model.pigeonPerHole());
        final Solution sol = solver.solve(show, model.bounds(p, h));
        // System.out.println(show);
        System.out.println(sol);
    } catch (NumberFormatException nfe) {
        usage();
    }
}
Also used : Formula(kodkod.ast.Formula) Solver(kodkod.engine.Solver) Solution(kodkod.engine.Solution)

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