Search in sources :

Example 1 with IncrementalSolver

use of kodkod.engine.IncrementalSolver 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 2 with IncrementalSolver

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

the class IncrementalOverflowNumTest method testBasic.

@Test
public void testBasic() {
    Options opt = new Options();
    opt.setNoOverflow(true);
    opt.setBitwidth(2);
    IncrementalSolver solver = IncrementalSolver.solver(opt);
    Universe univ = new Universe("-2", "-1", "0", "1");
    Bounds b = new Bounds(univ);
    TupleFactory factory = univ.factory();
    b.boundExactly(-2, factory.range(factory.tuple("-2"), factory.tuple("-2")));
    b.boundExactly(-1, factory.range(factory.tuple("-1"), factory.tuple("-1")));
    b.boundExactly(0, factory.range(factory.tuple("0"), factory.tuple("0")));
    b.boundExactly(1, factory.range(factory.tuple("1"), factory.tuple("1")));
    Variable n = Variable.unary("n");
    Formula f = n.sum().plus(IntConstant.constant(1)).lte(n.sum()).forSome(n.oneOf(Expression.INTS));
    Solution sol = solver.solve(f, b);
    assertNoInstance(sol);
}
Also used : Options(kodkod.engine.config.Options) Formula(kodkod.ast.Formula) Variable(kodkod.ast.Variable) Bounds(kodkod.instance.Bounds) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe) IncrementalSolver(kodkod.engine.IncrementalSolver) Solution(kodkod.engine.Solution) Test(org.junit.Test)

Aggregations

Formula (kodkod.ast.Formula)2 IncrementalSolver (kodkod.engine.IncrementalSolver)2 Solution (kodkod.engine.Solution)2 Bounds (kodkod.instance.Bounds)2 Iterator (java.util.Iterator)1 Variable (kodkod.ast.Variable)1 Evaluator (kodkod.engine.Evaluator)1 Options (kodkod.engine.config.Options)1 TupleFactory (kodkod.instance.TupleFactory)1 Universe (kodkod.instance.Universe)1 Test (org.junit.Test)1