Search in sources :

Example 6 with Solver

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

the class Handshake method main.

/**
 * Usage: java examples.Handshake [# persons, must be >= 2]
 */
public static void main(String[] args) {
    if (args.length < 1)
        usage();
    final Handshake model = new Handshake();
    final Solver solver = new Solver();
    try {
        final int persons = Integer.parseInt(args[0]);
        if (persons < 2)
            usage();
        solver.options().setBitwidth(6);
        // solver.options().setSolver(SATFactory.ZChaff);
        solver.options().setSolver(SATFactory.MiniSat);
        solver.options().setSymmetryBreaking(0);
        solver.options().setBitwidth(32 - Integer.numberOfLeadingZeros(persons));
        solver.options().setReporter(new ConsoleReporter());
        final Bounds b = model.bounds(persons);
        // .and(model.Person.count().eq(IntConstant.constant(persons)));
        final Formula f = model.runPuzzle();
        Solution sol = solver.solve(f, b);
        System.out.println(sol);
    } catch (NumberFormatException nfe) {
        usage();
    }
}
Also used : Formula(kodkod.ast.Formula) Solver(kodkod.engine.Solver) ConsoleReporter(kodkod.engine.config.ConsoleReporter) Bounds(kodkod.instance.Bounds) Solution(kodkod.engine.Solution)

Example 7 with Solver

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

the class Lists method main.

/**
 * Usage: java examples.Lists [scope]
 */
public static void main(String[] args) {
    if (args.length < 1)
        usage();
    try {
        final int n = Integer.parseInt(args[0]);
        final Lists model = new Lists();
        final Bounds b = model.bounds(n);
        final Solver solver = new Solver();
        solver.options().setSolver(SATFactory.MiniSat);
        // solver.options().setFlatten(false);
        // solver.options().setSkolemize(false);
        Formula f = model.runShow();
        System.out.println("running show");
        Solution s = solver.solve(f, b);
        System.out.println(s);
        f = model.checkEmpties();
        System.out.println("checking empties");
        s = solver.solve(f, b);
        System.out.println(s);
        f = model.checkReflexive();
        System.out.println("checking reflexive");
        s = solver.solve(f, b);
        System.out.println(s);
        f = model.checkSymmetric();
        System.out.println("checking symmetric");
        s = solver.solve(f, b);
        System.out.println(s);
    } catch (NumberFormatException nfe) {
        usage();
    } catch (HigherOrderDeclException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (UnboundLeafException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : Formula(kodkod.ast.Formula) Solver(kodkod.engine.Solver) UnboundLeafException(kodkod.engine.fol2sat.UnboundLeafException) Bounds(kodkod.instance.Bounds) HigherOrderDeclException(kodkod.engine.fol2sat.HigherOrderDeclException) Solution(kodkod.engine.Solution)

Example 8 with Solver

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

the class RingElection method main.

/**
 * Usage: java examples.RingElection [# processes] [# times]
 */
public static void main(String[] args) {
    if (args.length < 2)
        usage();
    try {
        final RingElection model = new RingElection();
        final Solver solver = new Solver();
        solver.options().setSolver(SATFactory.MiniSat);
        final int p = Integer.parseInt(args[0]);
        final int t = Integer.parseInt(args[1]);
        final Formula checkAtMostOneElected = model.checkAtMostOneElected();
        final Bounds boundspt = model.bounds(p, t);
        System.out.println("*****check AtMostOneElected for " + p + " Process, " + t + " Time*****");
        Solution sol1 = solver.solve(checkAtMostOneElected, boundspt);
        System.out.println(sol1);
    // // run looplessPath for 13 Time, 3 Process
    // final Formula runLooplessPath =
    // model.declsAndFacts();//.and(model.looplessPath());
    // final Bounds bounds313 = model.bounds(p, t);
    // System.out.println("*****run looplessPath for 13 Time, 3
    // Process*****");
    // System.out.println(runLooplessPath);
    // System.out.println(bounds313);
    // Solution sol2 = solver.solve(runLooplessPath, bounds313);
    // System.out.println(sol2);
    } catch (NumberFormatException nfe) {
        usage();
    }
}
Also used : Formula(kodkod.ast.Formula) Solver(kodkod.engine.Solver) Bounds(kodkod.instance.Bounds) Solution(kodkod.engine.Solution)

Example 9 with Solver

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

the class ToyFilesystem method main.

/**
 * Usage: java examples.alloy.ToyFilesystem
 */
public static void main(String[] args) {
    final ToyFilesystem toy = new ToyFilesystem();
    final Formula f = toy.constraints();
    System.out.println(PrettyPrinter.print(f, 2));
    final Bounds b = toy.bounds();
    final Solver solver = new Solver();
    solver.options().setSolver(SATFactory.MiniSat);
    final Solution s = solver.solve(f, b);
    System.out.println(s);
}
Also used : Formula(kodkod.ast.Formula) Solver(kodkod.engine.Solver) Bounds(kodkod.instance.Bounds) Solution(kodkod.engine.Solution)

Example 10 with Solver

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

the class IntConstraints method main.

/**
 * Usage: java examples.IntConstraints
 */
public static void main(String[] args) {
    final IntConstraints model = new IntConstraints();
    final Bounds bounds = model.bounds();
    final Formula formula = model.formula();
    final Solver solver = new Solver();
    solver.options().setBitwidth(32);
    solver.options().setSolver(SATFactory.MiniSat);
    final Solution sol = solver.solve(formula, bounds);
    model.print(sol, solver.options());
}
Also used : Formula(kodkod.ast.Formula) Solver(kodkod.engine.Solver) Bounds(kodkod.instance.Bounds) 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