use of kodkod.instance.Bounds 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.instance.Bounds 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.instance.Bounds in project org.alloytools.alloy by AlloyTools.
the class IntTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
bounds = new Bounds(factory.universe());
solver.options().setSolver(SATFactory.MiniSat);
}
use of kodkod.instance.Bounds 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));
}
use of kodkod.instance.Bounds in project org.alloytools.alloy by AlloyTools.
the class BugTests method testFelix_11192007.
public final void testFelix_11192007() {
List<String> atomlist = Arrays.asList("A", "B", "C");
Universe universe = new Universe(atomlist);
Bounds bounds = new Bounds(universe);
Solver solver = new Solver();
solver.options().setLogTranslation(2);
solver.options().setSolver(SATFactory.MiniSatProver);
solver.options().setBitwidth(4);
solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT);
solver.options().setSymmetryBreaking(20);
solver.options().setSkolemDepth(0);
Solution sol = solver.solve(Formula.TRUE, bounds);
assertNotNull(sol.instance());
}
Aggregations