Search in sources :

Example 46 with Solution

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

the class ExamplesTest method testGEO158.

/**
 * Runs GEO158.checkConsistent for 6.
 */
public void testGEO158() {
    final GEO158 prob = new GEO158();
    final Solution sol = solve(prob.checkConsistent(), prob.bounds(6));
    check(prob.getClass().getSimpleName(), sol, UNSATISFIABLE, 407, 6968, 15413);
}
Also used : GEO158(examples.tptp.GEO158) Solution(kodkod.engine.Solution)

Example 47 with Solution

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

the class IncrementalOverflowEnumTest method solveAll.

@Override
protected Iterator<Solution> solveAll(final Formula formula) {
    final IncrementalSolver solver = IncrementalSolver.solver(options);
    return new Iterator<Solution>() {

        Solution sol;

        @Override
        public boolean hasNext() {
            return sol == null || sol.sat();
        }

        @Override
        public Solution next() {
            if (sol == null) {
                sol = solver.solve(formula, bounds);
            } else {
                Evaluator ev = new Evaluator(sol.instance());
                int a = evalInt(ev, op1);
                int b = evalInt(ev, op2);
                int r = evalInt(ev, ret);
                Formula f = op1.eq(IntConstant.constant(a).toExpression()).and(op2.eq(IntConstant.constant(b).toExpression())).and(ret.eq(IntConstant.constant(r).toExpression())).not();
                sol = solver.solve(f, new Bounds(factory.universe()));
            }
            return sol;
        }

        @Override
        public void remove() {
            throw new RuntimeException("Not supported");
        }
    };
}
Also used : Formula(kodkod.ast.Formula) Bounds(kodkod.instance.Bounds) Iterator(java.util.Iterator) Evaluator(kodkod.engine.Evaluator) IncrementalSolver(kodkod.engine.IncrementalSolver) Solution(kodkod.engine.Solution)

Example 48 with Solution

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

the class IntTest method testIntCast.

public void testIntCast() {
    solver.options().setBitwidth(6);
    TupleSet r1b = factory.setOf("1", "5", "9");
    bounds.bound(r1, r1b, r1b);
    Formula f = r1.sum().toExpression().eq(Expression.NONE);
    Solution s = solve(f);
    assertNotNull(s.instance());
    bounds.boundExactly(5, factory.setOf(factory.tuple("5")));
    f = r1.sum().toExpression().eq(IntConstant.constant(5).toExpression());
    s = solve(f);
    assertNotNull(s.instance());
    bounds.boundExactly(1, factory.setOf(factory.tuple("1")));
    bounds.boundExactly(6, factory.setOf(factory.tuple("6")));
    f = r1.sum().toExpression().eq(IntConstant.constant(6).toExpression());
    s = solve(f);
    assertNotNull(s.instance());
    bounds.bound(r1, r1b);
    f = r1.sum().toExpression().eq(IntConstant.constant(6).toExpression());
    s = solve(f);
    assertNotNull(s.instance());
    bounds.boundExactly(6, factory.setOf(factory.tuple("1")));
    f = r1.sum().toExpression().eq(IntConstant.constant(6).toExpression());
    s = solve(f);
    assertNull(s.instance());
}
Also used : TupleSet(kodkod.instance.TupleSet) Formula(kodkod.ast.Formula) Solution(kodkod.engine.Solution)

Example 49 with Solution

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

the class IntTest method testCompOp.

private final void testCompOp(IntCompOperator op, IntExpression ei, IntExpression ej, int i, int j, boolean result) {
    final Formula e = ei.compare(op, ej);
    final Formula f = ei.eq(constant(i)).and(ej.eq(constant(j))).and(result ? e : e.not());
    final Solution s = solve(f);
    if (overflows(ei, i, 0) || overflows(ej, j, 0)) {
        assertNull(f.toString(), s.instance());
    } else {
        assertNotNull(f.toString(), s.instance());
        final Evaluator eval = new Evaluator(s.instance(), solver.options());
        assertFalse(result ^ eval.evaluate(e));
    }
}
Also used : Formula(kodkod.ast.Formula) Evaluator(kodkod.engine.Evaluator) Solution(kodkod.engine.Solution)

Example 50 with Solution

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

the class IntTest method testBinOp.

private final void testBinOp(IntOperator op, IntExpression ei, IntExpression ej, int i, int j, int result, int realResult, int mask) {
    final IntExpression e = ei.compose(op, ej);
    final Formula f = ei.eq(constant(i)).and(ej.eq(constant(j))).and(e.eq(constant(result)));
    final Solution s = solve(f);
    Instance inst = s.instance();
    if (overflows(op, ei, ej, i, j, realResult)) {
        assertNull(f.toString(), inst);
    } else {
        assertNotNull(f.toString(), inst);
        final Evaluator eval = new Evaluator(inst, solver.options());
        assertEquals(f.toString(), result & mask, eval.evaluate(e) & mask);
    }
}
Also used : Formula(kodkod.ast.Formula) Instance(kodkod.instance.Instance) IntExpression(kodkod.ast.IntExpression) Evaluator(kodkod.engine.Evaluator) 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