use of kodkod.instance.Universe in project org.alloytools.alloy by AlloyTools.
the class BugTests method testEmina_05072008.
public final void testEmina_05072008() {
Relation A = Relation.unary("A"), first = Relation.unary("OrdFirst"), last = Relation.unary("OrdLast"), next = Relation.nary("OrdNext", 2);
Relation B = Relation.unary("B"), acyclic = Relation.binary("acyclic");
List<String> atomlist = Arrays.asList("A1", "A2", "A3", "B1", "B2", "B3", "C1", "C2");
Universe universe = new Universe(atomlist);
TupleFactory factory = universe.factory();
Bounds bounds = new Bounds(universe);
TupleSet allA = factory.setOf("A1", "A2", "A3");
TupleSet allB = factory.setOf("B1", "B2", "B3");
TupleSet allC = factory.setOf("C1", "C2");
bounds.boundExactly(A, allA);
bounds.bound(first, allA);
bounds.bound(last, allA);
bounds.bound(next, allA.product(allA));
bounds.boundExactly(B, allB);
bounds.bound(acyclic, allC.product(allC));
Variable v = Variable.unary("v");
Formula f0 = Formula.TRUE.forSome(v.setOf(B));
Formula f1 = next.totalOrder(A, first, last);
Formula f2 = acyclic.acyclic();
Formula form = f0.and(f1).and(f2);
Solver solver = new Solver();
solver.options().setSolver(SATFactory.MiniSat);
solver.options().setBitwidth(4);
// solver.options().setFlatten(false);
solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT);
solver.options().setSymmetryBreaking(0);
solver.options().setSkolemDepth(0);
Iterator<Solution> sol = solver.solveAll(form, bounds);
int i = 1;
while (sol.hasNext()) {
assertTrue(i <= 17);
sol.next();
i++;
}
}
use of kodkod.instance.Universe in project org.alloytools.alloy by AlloyTools.
the class BugTests method testEmina_10092006.
public final void testEmina_10092006() {
Relation r = Relation.ternary("r");
final Variable a = Variable.unary("A");
final Variable b = Variable.unary("B");
final Variable c = Variable.unary("C");
final Variable d = Variable.unary("D");
final Formula f0 = (b.join(a.join(r))).eq(d.join(c.join(r)));
final Formula f1 = a.in(c).and(b.in(d));
final Formula f = f0.implies(f1).forAll(a.oneOf(UNIV).and(b.oneOf(UNIV)).and(c.oneOf(UNIV)).and(d.oneOf(UNIV)));
final Universe u = new Universe(Arrays.asList("a0", "a1"));
final Bounds bounds = new Bounds(u);
bounds.bound(r, u.factory().allOf(3));
// System.out.println(f); System.out.println(bounds);
solver.options().setSymmetryBreaking(0);
// solver.options().setFlatten(false);
final Solution s = solver.solve(f, bounds);
// System.out.println(s);
assertEquals(Solution.Outcome.SATISFIABLE, s.outcome());
}
use of kodkod.instance.Universe in project org.alloytools.alloy by AlloyTools.
the class BugTests method testFelix_10272008.
public final void testFelix_10272008() {
Relation x0 = Relation.unary("Int/min");
Relation x1 = Relation.unary("Int/zero");
Relation x2 = Relation.unary("Int/max");
Relation x3 = Relation.nary("Int/next", 2);
Relation x4 = Relation.unary("seq/Int");
Relation x5 = Relation.unary("this/X");
List<String> atomlist = Arrays.asList("-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "0", "1", "2", "3", "4", "5", "6", "7", "unused0", "unused1", "unused2");
Universe universe = new Universe(atomlist);
TupleFactory factory = universe.factory();
Bounds bounds = new Bounds(universe);
TupleSet x0_upper = factory.noneOf(1);
x0_upper.add(factory.tuple("-8"));
bounds.boundExactly(x0, x0_upper);
TupleSet x1_upper = factory.noneOf(1);
x1_upper.add(factory.tuple("0"));
bounds.boundExactly(x1, x1_upper);
TupleSet x2_upper = factory.noneOf(1);
x2_upper.add(factory.tuple("7"));
bounds.boundExactly(x2, x2_upper);
TupleSet x3_upper = factory.noneOf(2);
x3_upper.add(factory.tuple("-8").product(factory.tuple("-7")));
x3_upper.add(factory.tuple("-7").product(factory.tuple("-6")));
x3_upper.add(factory.tuple("-6").product(factory.tuple("-5")));
x3_upper.add(factory.tuple("-5").product(factory.tuple("-4")));
x3_upper.add(factory.tuple("-4").product(factory.tuple("-3")));
x3_upper.add(factory.tuple("-3").product(factory.tuple("-2")));
x3_upper.add(factory.tuple("-2").product(factory.tuple("-1")));
x3_upper.add(factory.tuple("-1").product(factory.tuple("0")));
x3_upper.add(factory.tuple("0").product(factory.tuple("1")));
x3_upper.add(factory.tuple("1").product(factory.tuple("2")));
x3_upper.add(factory.tuple("2").product(factory.tuple("3")));
x3_upper.add(factory.tuple("3").product(factory.tuple("4")));
x3_upper.add(factory.tuple("4").product(factory.tuple("5")));
x3_upper.add(factory.tuple("5").product(factory.tuple("6")));
x3_upper.add(factory.tuple("6").product(factory.tuple("7")));
bounds.boundExactly(x3, x3_upper);
TupleSet x4_upper = factory.noneOf(1);
x4_upper.add(factory.tuple("0"));
x4_upper.add(factory.tuple("1"));
x4_upper.add(factory.tuple("2"));
x4_upper.add(factory.tuple("3"));
bounds.boundExactly(x4, x4_upper);
TupleSet x5_upper = factory.noneOf(1);
x5_upper.add(factory.tuple("unused0"));
x5_upper.add(factory.tuple("unused1"));
x5_upper.add(factory.tuple("unused2"));
bounds.bound(x5, x5_upper);
bounds.boundExactly(-8, factory.range(factory.tuple("-8"), factory.tuple("-8")));
bounds.boundExactly(-7, factory.range(factory.tuple("-7"), factory.tuple("-7")));
bounds.boundExactly(-6, factory.range(factory.tuple("-6"), factory.tuple("-6")));
bounds.boundExactly(-5, factory.range(factory.tuple("-5"), factory.tuple("-5")));
bounds.boundExactly(-4, factory.range(factory.tuple("-4"), factory.tuple("-4")));
bounds.boundExactly(-3, factory.range(factory.tuple("-3"), factory.tuple("-3")));
bounds.boundExactly(-2, factory.range(factory.tuple("-2"), factory.tuple("-2")));
bounds.boundExactly(-1, factory.range(factory.tuple("-1"), factory.tuple("-1")));
bounds.boundExactly(0, factory.range(factory.tuple("0"), factory.tuple("0")));
bounds.boundExactly(1, factory.range(factory.tuple("1"), factory.tuple("1")));
bounds.boundExactly(2, factory.range(factory.tuple("2"), factory.tuple("2")));
bounds.boundExactly(3, factory.range(factory.tuple("3"), factory.tuple("3")));
bounds.boundExactly(4, factory.range(factory.tuple("4"), factory.tuple("4")));
bounds.boundExactly(5, factory.range(factory.tuple("5"), factory.tuple("5")));
bounds.boundExactly(6, factory.range(factory.tuple("6"), factory.tuple("6")));
bounds.boundExactly(7, factory.range(factory.tuple("7"), factory.tuple("7")));
Variable x11 = Variable.unary("c");
Expression x12 = x5.difference(x5);
Decls x10 = x11.oneOf(x12);
IntExpression x13 = IntConstant.constant(0);
IntExpression x9 = x13.sum(x10);
IntExpression x14 = IntConstant.constant(0);
Formula x8 = x9.eq(x14);
Formula x17 = x0.eq(x0);
Formula x18 = x2.eq(x2);
Formula x16 = x17.and(x18);
Formula x19 = x3.eq(x3);
Formula x15 = x16.and(x19);
Formula x7 = x8.and(x15);
Formula x22 = x1.eq(x1);
Formula x23 = x4.eq(x4);
Formula x21 = x22.and(x23);
Formula x24 = x5.eq(x5);
Formula x20 = x21.and(x24);
Formula x6 = x7.and(x20);
Solver solver = new Solver();
solver.options().setSolver(SATFactory.DefaultSAT4J);
solver.options().setBitwidth(4);
// solver.options().setFlatten(false);
solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT);
solver.options().setSymmetryBreaking(20);
solver.options().setSkolemDepth(0);
Solution sol = solver.solve(x6, bounds);
assertEquals(sol.outcome(), Solution.Outcome.TRIVIALLY_SATISFIABLE);
}
use of kodkod.instance.Universe in project org.alloytools.alloy by AlloyTools.
the class BugTests method testFelix_05152007_3.
public final void testFelix_05152007_3() {
Relation x5 = Relation.nary("A", 1);
List<String> atomlist = Arrays.asList("A[0]", "A[1]", "A[2]");
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("A[0]"));
x5_upper.add(factory.tuple("A[1]"));
x5_upper.add(factory.tuple("A[2]"));
bounds.bound(x5, x5_upper);
Formula a = x5.some();
Formula a1 = x5.no();
Formula b = a1.and(Formula.TRUE.and(Formula.TRUE));
Formula c = a.and(b);
Solver solver = new Solver();
solver.options().setLogTranslation(1);
solver.options().setSolver(SATFactory.DefaultSAT4J);
solver.options().setBitwidth(4);
solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT);
Solution sol = solver.solve(c, bounds);
Set<Formula> core = Nodes.minRoots(c, sol.proof().highLevelCore().values());
assertEquals(2, core.size());
assertTrue(core.contains(a));
assertTrue(core.contains(a1));
}
use of kodkod.instance.Universe 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()));
}
}
Aggregations