use of kodkod.instance.TupleFactory in project org.alloytools.alloy by AlloyTools.
the class BugTests method testGreg_11232005.
public final void testGreg_11232005() {
final List<String> atoms = new ArrayList<String>(3);
atoms.add("-1");
atoms.add("0");
atoms.add("1");
final Universe u = new Universe(atoms);
final TupleFactory t = u.factory();
final Relation inc = Relation.binary("inc"), add = Relation.ternary("add"), one = Relation.unary("1"), param0 = Relation.unary("param0"), ints = Relation.unary("int");
// (one param0 && ((1 . (param0 . add)) in (param0 . ^inc)))
final Formula f = param0.one().and((one.join(param0.join(add))).in(param0.join(inc.closure())));
final Bounds b = new Bounds(u);
b.bound(param0, t.allOf(1));
b.boundExactly(one, t.setOf(t.tuple("1")));
b.boundExactly(ints, t.allOf(1));
b.boundExactly(inc, t.setOf(t.tuple("-1", "0"), t.tuple("0", "1")));
// [1, 1, -1], [1, -1, 0], [1, 0, 1], [-1, 1, 0], [-1, -1, 1],
// [-1, 0, -1], [0, 1, 1], [0, -1, -1], [0, 0, 0]]
b.boundExactly(add, t.setOf(t.tuple("1", "1", "-1"), t.tuple("1", "-1", "0"), t.tuple("1", "0", "1"), t.tuple("-1", "1", "0"), t.tuple("-1", "-1", "1"), t.tuple("-1", "0", "-1"), t.tuple("0", "1", "1"), t.tuple("0", "-1", "-1"), t.tuple("0", "0", "0")));
// System.out.println(f);
// System.out.println(b);
final Instance instance = solver.solve(f, b).instance();
assertTrue((new Evaluator(instance)).evaluate(f));
// System.out.println(instance);
// System.out.println((new Evaluator(instance)).evaluate(f ));
}
use of kodkod.instance.TupleFactory in project org.alloytools.alloy by AlloyTools.
the class BugTests method testFelix_03162009.
public final void testFelix_03162009() {
Relation x = Relation.unary("X");
Relation y = Relation.unary("Y");
Relation q = Relation.unary("Q");
Relation f = Relation.nary("f", 2);
List<String> atomlist = Arrays.asList("X", "Y");
Universe universe = new Universe(atomlist);
TupleFactory factory = universe.factory();
Bounds bounds = new Bounds(universe);
TupleSet x_upper = factory.noneOf(1);
x_upper.add(factory.tuple("X"));
bounds.boundExactly(x, x_upper);
TupleSet y_upper = factory.noneOf(1);
y_upper.add(factory.tuple("Y"));
bounds.boundExactly(y, y_upper);
TupleSet q_upper = factory.noneOf(1);
q_upper.add(factory.tuple("X"));
q_upper.add(factory.tuple("Y"));
bounds.bound(q, q_upper);
TupleSet f_upper = factory.noneOf(2);
f_upper.add(factory.tuple("X").product(factory.tuple("X")));
f_upper.add(factory.tuple("X").product(factory.tuple("Y")));
f_upper.add(factory.tuple("Y").product(factory.tuple("X")));
f_upper.add(factory.tuple("Y").product(factory.tuple("Y")));
bounds.bound(f, f_upper);
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);
Expression test = f.override(q.product(y));
TupleSet approx = factory.setOf(test.arity(), Translator.approximate(test, bounds, solver.options()).denseIndices());
assertEquals(f_upper, approx);
}
use of kodkod.instance.TupleFactory in project org.alloytools.alloy by AlloyTools.
the class BugTests method testBGP_03172011.
public final void testBGP_03172011() {
Relation x5 = Relation.unary("s012");
Relation x8 = Relation.unary("zero");
Relation x9 = Relation.unary("one");
Relation x12 = Relation.nary("next", 2);
Universe universe = new Universe(Arrays.asList("0", "1", "2", "3"));
TupleFactory factory = universe.factory();
Bounds bounds = new Bounds(universe);
bounds.boundExactly(x5, factory.setOf("0", "1", "2"));
bounds.boundExactly(x8, factory.setOf("0"));
bounds.bound(x9, factory.setOf("1"), factory.setOf("1", "2"));
TupleSet x12_upper = factory.noneOf(2);
x12_upper.add(factory.tuple("1", "2"));
x12_upper.add(factory.tuple("2", "3"));
bounds.boundExactly(x12, x12_upper);
Variable x714 = Variable.unary("x714");
Decls x713 = x714.oneOf(x8.union(x9));
Variable x720 = Variable.unary("x720");
Expression x723 = x8.union(x9);
Expression x724 = x9.join(x12);
Expression x722 = x723.union(x724);
Expression x721 = x722.difference(x714);
Decls x719 = x720.oneOf(x721);
Variable x727 = Variable.unary("x727");
Expression x732 = x714.union(x720);
Expression x728 = x5.difference(x732);
Decls x726 = x727.oneOf(x728);
Variable x735 = Variable.unary("x735");
Decls x734 = x735.oneOf(x8);
Variable x893 = Variable.unary("x893");
Decls x892 = x893.oneOf(x727);
Formula x894 = x720.no();
Formula x891 = x894.forAll(x892);
Formula x712 = x891.forSome(x713.and(x719).and(x726).and(x734));
Formula x267 = Formula.FALSE.or(x712);
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(20);
solver.options().setSkolemDepth(0);
final Solution sol = solver.solve(x267, bounds);
assertEquals(sol.outcome(), Solution.Outcome.TRIVIALLY_UNSATISFIABLE);
}
use of kodkod.instance.TupleFactory in project org.alloytools.alloy by AlloyTools.
the class BugTests method testFelix_06192008.
public final void testFelix_06192008() {
Relation x5 = Relation.unary("R");
List<String> atomlist = Arrays.asList("X");
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("X"));
bounds.bound(x5, x5_upper);
Variable x10 = Variable.unary("a");
Expression x11 = x5.difference(x5);
Decls x9 = x10.oneOf(x11);
Variable x14 = Variable.nary("b", 2);
Expression x15 = x5.product(x5);
Decls x13 = x14.setOf(x15);
Expression x19 = x5.product(x5);
Formula x17 = x14.in(x19);
Expression x22 = x10.product(x10);
Formula x21 = x22.eq(x14);
Formula x16 = x17.and(x21);
Formula x12 = x16.forSome(x13);
Formula x7 = x12.forAll(x9);
// System.out.println(x7);
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);
// System.out.println("Depth=0..."); System.out.flush();
solver.options().setSkolemDepth(0);
assertEquals(Solution.Outcome.TRIVIALLY_SATISFIABLE, solver.solve(x7, bounds).outcome());
// System.out.println("Depth=1..."); System.out.flush();
solver.options().setSkolemDepth(1);
final Solution sol = solver.solve(x7, bounds);
assertEquals(Solution.Outcome.SATISFIABLE, sol.outcome());
assertEquals(2, sol.instance().relations().size());
for (Relation r : sol.instance().relations()) {
assertTrue(sol.instance().tuples(r).isEmpty());
}
}
use of kodkod.instance.TupleFactory in project org.alloytools.alloy by AlloyTools.
the class NUM378 method bounds.
/**
* Returns bounds for the problem.
*
* @return bounds for the problem.
*/
public final Bounds bounds() {
final int n = 21;
final List<String> atoms = new ArrayList<String>(n);
atoms.add("goal");
for (int i = 0; i < n; i++) atoms.add("n" + i);
final Universe u = new Universe(atoms);
final Bounds bound = new Bounds(u);
final TupleFactory f = u.factory();
final TupleSet succBound = f.noneOf(2);
for (int i = 0; i < n; i++) {
succBound.add(f.tuple("n" + i, "n" + ((i + 1) % n)));
}
bound.boundExactly(succ, succBound);
final TupleSet sumBound = f.noneOf(3);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
sumBound.add(f.tuple("n" + i, "n" + j, "n" + ((i + j) % n)));
}
}
bound.boundExactly(sum, sumBound);
return bound;
}
Aggregations