Search in sources :

Example 96 with Solution

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

the class AbstractWorldDefinitions method main.

/**
 * Usage: java examples.AbstractWorldDefinitions [A241 | AbOp_total |
 * AbIgnore_inv | AbTransfer_inv] [univ size]
 */
public static void main(String[] args) {
    if (args.length < 2)
        usage();
    try {
        final String assertion = args[0];
        final int n = Integer.parseInt(args[1]);
        if (n < 1)
            usage();
        final AbstractWorldDefinitions model = new AbstractWorldDefinitions();
        final Solver solver = new Solver();
        solver.options().setSolver(SATFactory.MiniSat);
        solver.options().setReporter(new ConsoleReporter());
        // solver.options().setFlatten(true);
        final Method method = model.getClass().getMethod(assertion);
        final Formula f = model.decls().and(((Formula) method.invoke(model)).not());
        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();
    } catch (SecurityException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        usage();
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : Solver(kodkod.engine.Solver) ConsoleReporter(kodkod.engine.config.ConsoleReporter) Bounds(kodkod.instance.Bounds) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) Formula(kodkod.ast.Formula) Solution(kodkod.engine.Solution)

Example 97 with Solution

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

the class DNACuts method main.

/**
 * Usage: java examples.alloy.DNACuts [cut chain length] [# links]
 */
public static void main(String[] args) {
    if (args.length < 2)
        usage();
    try {
        final DNACuts model = new DNACuts(Integer.parseInt(args[0]));
        final Solver solver = new Solver();
        solver.options().setSolver(SATFactory.DefaultSAT4J);
        Formula f = model.show();
        Bounds b = model.bounds(Integer.parseInt(args[1]));
        System.out.println("solving...");
        Solution sol = solver.solve(f, b);
        // System.out.println(f);
        // System.out.println(b);
        System.out.println(sol.outcome());
        System.out.println(sol.stats());
    } catch (NumberFormatException nfe) {
        usage();
    }
}
Also used : Formula(kodkod.ast.Formula) Solver(kodkod.engine.Solver) Bounds(kodkod.instance.Bounds) Solution(kodkod.engine.Solution)

Example 98 with Solution

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

the class SET948 method main.

/**
 * Usage: java examples.tptp.SET948 [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 SET948 model = new SET948();
        final Solver solver = new Solver();
        solver.options().setSolver(SATFactory.MiniSat);
        // solver.options().setSymmetryBreaking(n*n);
        // solver.options().setFlatten(false);
        final Formula f = model.checkT101_zfmisc_1();
        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 99 with Solution

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

the class GEO159 method main.

/**
 * Usage: ava examples.tptp.GEO159 [scope]
 */
public static void main(String[] args) {
    if (args.length < 1)
        usage();
    try {
        final int n = Integer.parseInt(args[0]);
        final Solver solver = new Solver();
        solver.options().setSolver(SATFactory.MiniSat);
        final GEO159 model = new GEO159();
        final Formula f = model.checkDefs();
        final Bounds b = model.bounds(n);
        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 100 with Solution

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

the class KK method main.

public static void main(String[] args) throws Exception {
    Relation x6 = Relation.unary("R");
    int[] ints = new int[] { 0, 1, 2 };
    List<Object> atomlist = new LinkedList<Object>();
    atomlist.add("R$0");
    atomlist.add("R$1");
    atomlist.add("R$2");
    for (int i : ints) atomlist.add(i);
    Universe universe = new Universe(atomlist);
    TupleFactory factory = universe.factory();
    Bounds bounds = new Bounds(universe);
    TupleSet x6_upper = factory.noneOf(1);
    x6_upper.add(factory.tuple("R$0"));
    x6_upper.add(factory.tuple("R$1"));
    x6_upper.add(factory.tuple("R$2"));
    bounds.bound(x6, x6_upper);
    for (int i : ints) {
        bounds.boundExactly(i, factory.setOf(i));
    }
    Formula x11 = x6.some();
    IntExpression x5 = x6.count();
    Formula x9 = x11.implies(x5.gt(IntConstant.constant(0)));
    Formula x7 = x9.not();
    Solver solver = new Solver();
    solver.options().setSolver(SATFactory.DefaultSAT4J);
    solver.options().setBitwidth(2);
    // solver.options().setFlatten(false);
    solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT);
    solver.options().setSymmetryBreaking(20);
    solver.options().setSkolemDepth(0);
    System.out.println("Solving...");
    System.out.println(PrettyPrinter.print(x7, 0));
    System.out.println(bounds);
    Solution sol = solver.solve(x7, bounds);
    System.out.println(sol.toString());
    Instance inst = sol.instance();
    Evaluator ev = new Evaluator(inst);
    System.out.println(ev.evaluate(x6.some()));
    System.out.println(ev.evaluate(x5));
    System.out.println(ev.evaluate(x5.gt(IntConstant.constant(0))));
    System.out.println(ev.evaluate(x6.some().implies(x5.gt(IntConstant.constant(0))).not()));
    System.out.println(ev.evaluate(x7));
}
Also used : TupleSet(kodkod.instance.TupleSet) Solver(kodkod.engine.Solver) Instance(kodkod.instance.Instance) Bounds(kodkod.instance.Bounds) IntExpression(kodkod.ast.IntExpression) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe) Evaluator(kodkod.engine.Evaluator) LinkedList(java.util.LinkedList) Formula(kodkod.ast.Formula) Relation(kodkod.ast.Relation) Solution(kodkod.engine.Solution)

Aggregations

Solution (kodkod.engine.Solution)153 Formula (kodkod.ast.Formula)101 Bounds (kodkod.instance.Bounds)75 Solver (kodkod.engine.Solver)72 Universe (kodkod.instance.Universe)32 Relation (kodkod.ast.Relation)30 TupleFactory (kodkod.instance.TupleFactory)30 TupleSet (kodkod.instance.TupleSet)25 Variable (kodkod.ast.Variable)24 IntExpression (kodkod.ast.IntExpression)19 Expression (kodkod.ast.Expression)17 Test (org.junit.Test)16 QuantifiedFormula (kodkod.ast.QuantifiedFormula)15 Decls (kodkod.ast.Decls)11 Evaluator (kodkod.engine.Evaluator)10 HigherOrderDeclException (kodkod.engine.fol2sat.HigherOrderDeclException)7 UnboundLeafException (kodkod.engine.fol2sat.UnboundLeafException)7 ConsoleReporter (kodkod.engine.config.ConsoleReporter)6 Instance (kodkod.instance.Instance)6 ArrayList (java.util.ArrayList)5