use of kodkod.engine.Solution in project org.alloytools.alloy by AlloyTools.
the class IntTest method testBitsetCast.
public void testBitsetCast() {
final int width = 4, msb = width - 1;
solver.options().setBitwidth(width);
final List<Integer> atoms = new ArrayList<Integer>(width);
for (int i = 0; i < msb; i++) {
atoms.add(Integer.valueOf(1 << i));
}
atoms.add(Integer.valueOf(-1 << msb));
final Bounds b = new Bounds(new Universe(atoms));
final TupleFactory f = b.universe().factory();
for (Integer i : atoms) {
b.boundExactly(i, f.setOf(i));
}
b.bound(r1, f.allOf(1));
for (int i = -1 << msb, max = 1 << msb; i < max; i++) {
Formula test = r1.sum().toBitset().eq(IntConstant.constant(i).toBitset());
Solution sol = solver.solve(test, b);
Instance inst = sol.instance();
assertNotNull(inst);
Evaluator eval = new Evaluator(inst, solver.options());
assertEquals(i, eval.evaluate(r1.sum()));
}
}
use of kodkod.engine.Solution in project org.alloytools.alloy by AlloyTools.
the class IntTest method testUnOp.
private final void testUnOp(IntOperator op, IntExpression ei, int i, int result, int mask) {
final IntExpression e = ei.apply(op);
final Formula f = ei.eq(constant(i)).and(e.eq(constant(result)));
final Solution s = solve(f);
if (overflows(ei, i, result)) {
assertNull(f.toString(), s.instance());
} else {
assertNotNull(f.toString(), s.instance());
final Evaluator eval = new Evaluator(s.instance(), solver.options());
assertEquals(result & mask, eval.evaluate(e) & mask);
}
}
use of kodkod.engine.Solution in project org.alloytools.alloy by AlloyTools.
the class IntTest method testIfIntExpr.
private void testIfIntExpr(Options.IntEncoding encoding) {
solver.options().setIntEncoding(encoding);
bounds.bound(r1, factory.setOf("15"), factory.setOf("15"));
Formula f = (r1.some().thenElse(r1.count(), IntConstant.constant(5))).eq(IntConstant.constant(1));
Solution s = solve(f);
assertNotNull(s.instance());
assertEquals(Ints.singleton(15), s.instance().tuples(r1).indexView());
f = (r1.some().thenElse(r1.sum(), IntConstant.constant(5))).eq(IntConstant.constant(1));
s = solve(f);
assertNull(s.instance());
bounds.bound(r1, factory.setOf("3"), factory.allOf(1));
bounds.boundExactly(3, factory.setOf("3"));
bounds.boundExactly(1, factory.setOf("1"));
f = ((r1.count().eq(IntConstant.constant(2))).thenElse(r1.sum(), IntConstant.constant(5))).eq(IntConstant.constant(4));
s = solve(f);
assertNotNull(s.instance());
assertTrue(s.instance().tuples(r1).indexView().contains(1));
assertTrue(s.instance().tuples(r1).indexView().contains(3));
assertEquals(2, s.instance().tuples(r1).size());
f = Formula.TRUE.thenElse(IntConstant.constant(2), IntConstant.constant(3)).eq(IntConstant.constant(4));
s = solve(f);
assertEquals(Solution.Outcome.TRIVIALLY_UNSATISFIABLE, s.outcome());
f = Formula.FALSE.thenElse(IntConstant.constant(2), IntConstant.constant(3)).eq(IntConstant.constant(3));
s = solve(f);
assertEquals(Solution.Outcome.TRIVIALLY_SATISFIABLE, s.outcome());
}
use of kodkod.engine.Solution in project org.alloytools.alloy by AlloyTools.
the class IntTest method testIntSum.
private void testIntSum(Options.IntEncoding encoding) {
solver.options().setIntEncoding(encoding);
final Variable x = Variable.unary("x");
bounds.bound(r1, factory.setOf("13", "14", "15"), factory.setOf("13", "14", "15"));
Formula f = IntConstant.constant(3).eq(IntConstant.constant(1).sum(x.oneOf(r1)));
Solution s = solve(f);
assertNotNull(s.instance());
bounds.bound(r1, factory.noneOf(1), factory.setOf("1", "3", "5"));
bounds.boundExactly(1, factory.setOf("1"));
bounds.boundExactly(3, factory.setOf("3"));
bounds.boundExactly(5, factory.setOf("5"));
f = IntConstant.constant(9).eq(x.sum().sum(x.oneOf(r1)));
s = solve(f);
assertNotNull(s.instance());
assertEquals(s.instance().tuples(r1), factory.setOf("1", "3", "5"));
}
use of kodkod.engine.Solution in project org.alloytools.alloy by AlloyTools.
the class BugTests method testFelix_05152007_2.
public final void testFelix_05152007_2() {
Relation x5 = Relation.nary("A", 1);
List<String> atomlist = Arrays.asList("A0", "A1", "A2");
Universe universe = new Universe(atomlist);
TupleFactory factory = universe.factory();
Bounds bounds = new Bounds(universe);
TupleSet x5_upper = factory.noneOf(1);
x5_upper.add(factory.tuple("A2"));
x5_upper.add(factory.tuple("A1"));
x5_upper.add(factory.tuple("A0"));
bounds.bound(x5, x5_upper);
Formula x7 = x5.eq(x5).not();
Solver solver = new Solver();
solver.options().setLogTranslation(1);
solver.options().setSolver(SATFactory.MiniSatProver);
solver.options().setBitwidth(4);
solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT);
Solution sol = solver.solve(x7, bounds);
Set<Formula> core = Nodes.minRoots(x7, sol.proof().highLevelCore().values());
assertEquals(1, core.size());
assertTrue(core.contains(x7));
}
Aggregations