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");
}
};
}
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);
}
Aggregations