Search in sources :

Example 41 with Solver

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

the class Toughnut method main.

/**
 * Usage: java examples.Toughnut [size of one side of the board; optional]
 */
public static void main(String[] args) {
    try {
        int n = args.length == 0 ? 4 : Integer.parseInt(args[0]);
        final Toughnut nut = new Toughnut();
        final Solver solver = new Solver();
        solver.options().setSolver(SATFactory.MiniSat);
        final Formula covering = nut.checkBelowTooDoublePrime();
        final Bounds bounds = nut.bounds(n);
        // System.out.println(covering);
        // System.out.println(bounds);
        final Solution sol = solver.solve(covering, bounds);
        System.out.println(sol);
    } catch (NumberFormatException nfe) {
        System.out.println("Usage: java examples.Toughnut [size of one side of the board; optional]");
    }
}
Also used : Formula(kodkod.ast.Formula) Solver(kodkod.engine.Solver) Bounds(kodkod.instance.Bounds) Solution(kodkod.engine.Solution)

Example 42 with Solver

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

the class Viktor method main.

/**
 * Usage: java tests.Viktor
 */
public static void main(String[] args) {
    final Viktor model = new Viktor();
    final Solver solver = new Solver();
    solver.options().setSolver(SATFactory.MiniSat);
    solver.options().setReporter(new ConsoleReporter());
    solver.options().setBitwidth(7);
    final Formula f = model.checkEquations();
    final Bounds b = model.bounds();
    System.out.println(f);
    System.out.println(b);
    final Solution sol = solver.solve(f, b);
    System.out.println(sol);
    if (sol.instance() != null)
        model.display(sol.instance(), solver.options());
}
Also used : Formula(kodkod.ast.Formula) Solver(kodkod.engine.Solver) ConsoleReporter(kodkod.engine.config.ConsoleReporter) Bounds(kodkod.instance.Bounds) Solution(kodkod.engine.Solution)

Example 43 with Solver

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

the class ConfigAssure method main.

/**
 * Usage: java examples.ConfigAssure <ipAddresses file> <subnets file>
 */
public static void main(String[] args) {
    if (args.length < 2)
        usage();
    try {
        final ConfigAssure ca = new ConfigAssure();
        final Solver solver = new Solver();
        solver.options().setBitwidth(32);
        solver.options().setSolver(SATFactory.MiniSat);
        final Formula formula = ca.requirements();
        final Bounds bounds = ca.bounds(args[0], args[1]);
        System.out.println("---explicit requirements (others are implicit in the bounds)---");
        System.out.println(PrettyPrinter.print(formula, 2));
        System.out.println("\n---solving with config files " + args[0] + " and " + args[1] + "---");
        final Solution sol = solver.solve(formula, bounds);
        System.out.println("\n---OUTCOME---");
        System.out.println(sol.outcome());
        System.out.println("\n---STATS---");
        System.out.println(sol.stats());
        if (sol.instance() != null) {
            System.out.println("\n---INSTANCE--");
            ca.display(sol.instance(), solver.options());
        }
    } catch (IOException ioe) {
        ioe.printStackTrace();
        usage();
    }
}
Also used : Formula(kodkod.ast.Formula) Solver(kodkod.engine.Solver) Bounds(kodkod.instance.Bounds) IOException(java.io.IOException) Solution(kodkod.engine.Solution)

Example 44 with Solver

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

the class Netconfig method main.

/**
 * Usage: java examples.Netconfig [# sites] [# hq] [# routers] [# time steps]
 */
public static void main(String[] args) {
    if (args.length < 4)
        usage();
    final Netconfig model = new Netconfig();
    final Solver solver = new Solver();
    // solver.options().setSolver(SATFactory.ZChaffMincost);
    solver.options().setSolver(SATFactory.MiniSat);
    try {
        final Formula show = model.show();
        final Solution sol = solver.solve(show, model.bounds(Integer.parseInt(args[0]), Integer.parseInt(args[1]), Integer.parseInt(args[2]), Integer.parseInt(args[3])));
        // System.out.println(show);
        // System.out.println("p cnf " +
        // (solver.numberOfIntermediateVariables()+solver.numberOfPrimaryVariables())
        // + " " + solver.numberOfClauses());
        System.out.println(sol.outcome());
        System.out.println(sol.stats());
    } catch (NumberFormatException nfe) {
        usage();
    }
}
Also used : Formula(kodkod.ast.Formula) Solver(kodkod.engine.Solver) Solution(kodkod.engine.Solution)

Example 45 with Solver

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

the class ALG212 method main.

/**
 * Usage: java examples.tptp.ALG212 [univ size]
 */
public static void main(String[] args) {
    if (args.length < 1)
        usage();
    try {
        final int n = Integer.parseInt(args[0]);
        if (n < 1)
            usage();
        final ALG212 model = new ALG212();
        final Solver solver = new Solver();
        solver.options().setSolver(SATFactory.MiniSat);
        // solver.options().setSymmetryBreaking(n*n);
        // solver.options().setFlatten(false);
        final Formula f = model.checkDistLong();
        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)

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