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