use of kodkod.instance.TupleFactory in project org.alloytools.alloy by AlloyTools.
the class BugTests method testFelix_03062008.
public final void testFelix_03062008() {
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");
List<String> atomlist = Arrays.asList("-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "0", "1", "2", "3", "4", "5", "6", "7");
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"));
bounds.boundExactly(x4, x4_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 x9 = Variable.unary("x");
Decls x8 = x9.oneOf(Expression.INTS);
Variable x14 = Variable.unary("p_t'");
Expression x15 = Expression.INTS.difference(x9);
Decls x13 = x14.oneOf(x15);
Variable x20 = Variable.unary("p_v");
Decls x19 = x20.oneOf(Expression.INTS);
Formula x21 = x14.in(x9);
Expression x18 = x21.comprehension(x19);
IntExpression x17 = x18.count();
IntExpression x22 = IntConstant.constant(0);
Formula x16 = x17.gt(x22);
Formula x12 = x16.forAll(x13);
Formula x11 = x12.not();
Formula x7 = x11.forAll(x8);
Formula x25 = x0.eq(x0);
Formula x26 = x2.eq(x2);
Formula x24 = x25.and(x26);
Formula x27 = x3.eq(x3);
Formula x23 = x24.and(x27);
Formula x6 = x7.and(x23);
Formula x29 = x1.eq(x1);
Formula x30 = x4.eq(x4);
Formula x28 = x29.and(x30);
Formula x5 = x6.and(x28);
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(PrettyPrinter.print(x5, 2));
solver.options().setSkolemDepth(0);
Solution sol1 = solver.solve(x5, bounds);
assertNotNull(sol1.instance());
solver.options().setSkolemDepth(1);
Solution sol2 = solver.solve(x5, bounds);
assertNotNull(sol2.instance());
}
use of kodkod.instance.TupleFactory in project org.alloytools.alloy by AlloyTools.
the class IncrementalOverflowNumTest method testBasic.
@Test
public void testBasic() {
Options opt = new Options();
opt.setNoOverflow(true);
opt.setBitwidth(2);
IncrementalSolver solver = IncrementalSolver.solver(opt);
Universe univ = new Universe("-2", "-1", "0", "1");
Bounds b = new Bounds(univ);
TupleFactory factory = univ.factory();
b.boundExactly(-2, factory.range(factory.tuple("-2"), factory.tuple("-2")));
b.boundExactly(-1, factory.range(factory.tuple("-1"), factory.tuple("-1")));
b.boundExactly(0, factory.range(factory.tuple("0"), factory.tuple("0")));
b.boundExactly(1, factory.range(factory.tuple("1"), factory.tuple("1")));
Variable n = Variable.unary("n");
Formula f = n.sum().plus(IntConstant.constant(1)).lte(n.sum()).forSome(n.oneOf(Expression.INTS));
Solution sol = solver.solve(f, b);
assertNoInstance(sol);
}
use of kodkod.instance.TupleFactory in project org.alloytools.alloy by AlloyTools.
the class InstanceCreator method getInstance.
/**
* Fills the instance with the relations specified in this.document; if an error
* occurs during processing, the instance remains null
*/
private Instance getInstance() {
initAtomsAndRelations();
final Universe u = new Universe(atoms);
final TupleFactory f = u.factory();
final Instance instance = new Instance(u);
for (Map.Entry<Relation, Set<List<String>>> entry : relations.entrySet()) {
Relation r = entry.getKey();
TupleSet s = f.noneOf(r.arity());
for (List<?> atoms : entry.getValue()) {
s.add(f.tuple(atoms));
}
instance.add(r, s);
}
return instance;
}
use of kodkod.instance.TupleFactory in project org.alloytools.alloy by AlloyTools.
the class TranslatorTest method testFlattening.
public final void testFlattening() {
final List<String> atoms = new ArrayList<String>(9);
atoms.add("-1");
atoms.add("0");
atoms.add("1");
atoms.add("null");
for (int i = 0; i < 5; i++) {
atoms.add("m" + i);
}
final Universe u = new Universe(atoms);
final TupleFactory t = u.factory();
final Relation[] m = new Relation[5];
for (int i = 0; i < 5; i++) {
m[i] = Relation.unary("m" + i);
}
final Relation univ = Relation.unary("univ"), none = Relation.unary("none"), iden = Relation.binary("inden"), mutant = Relation.unary("mutant"), inc = Relation.binary("inc"), add = Relation.ternary("add"), i0 = Relation.unary("i0"), zero = Relation.unary("0"), one = Relation.unary("1"), ints = Relation.unary("int");
final Bounds b = new Bounds(u);
b.boundExactly(univ, t.allOf(1));
b.boundExactly(none, t.noneOf(1));
TupleSet idenSet = t.noneOf(2);
for (String atom : atoms) {
idenSet.add(t.tuple(atom, atom));
}
b.boundExactly(iden, idenSet);
b.bound(mutant, t.range(t.tuple("m0"), t.tuple("m4")));
for (int i = 0; i < 5; i++) {
b.boundExactly(m[i], t.setOf("m" + i));
}
b.bound(i0, t.range(t.tuple("-1"), t.tuple("1")));
b.boundExactly(zero, t.setOf(t.tuple("0")));
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")));
/*
* ((one i0 && one mutant) && !((if (i0 in (0 . ^~inc)) then ((add . 0) . i0)
* else i0) = (if !((if (mutant in m4) then (if (i0 in 0) then 1 else 0) else
* (if (mutant in m3) then (if ((i0 = 0) || (i0 in (0 . ^~inc))) then 1 else 0)
* else (if (mutant in m2) then (if (i0 in (0 . ^inc)) then 1 else 0) else (if
* (mutant in m1) then (if ((i0 = 0) || (i0 in (0 . ^inc))) then 1 else 0) else
* (if (mutant in m0) then (if !(i0 in 0) then 1 else 0) else (if (i0 in (0 .
* ^~inc)) then 1 else 0)))))) in 0) then ((add . 0) . i0) else i0)))
*/
final Formula[] cm = new Formula[5];
for (int i = 0; i < 5; i++) {
cm[i] = mutant.in(m[i]);
}
// (i0 in (0 . ^~inc))
final Formula fs0 = i0.in(zero.join(inc.transpose().closure()));
// (i0 in (0 . ^inc))
final Formula fs1 = i0.in(zero.join(inc.closure()));
// (i0 = 0)
final Formula fs2 = i0.eq(zero);
final Expression em0 = cm[0].thenElse(i0.in(zero).not().thenElse(one, zero), fs0.thenElse(one, zero));
final Expression em1 = cm[1].thenElse((fs2.or(fs1)).thenElse(one, zero), em0);
final Expression em2 = cm[2].thenElse(fs1.thenElse(one, zero), em1);
final Expression em3 = cm[3].thenElse(fs2.or(fs0).thenElse(one, zero), em2);
final Expression em4 = cm[4].thenElse(i0.in(zero).thenElse(one, zero), em3);
final Expression es1 = add.join(zero).join(i0);
final Expression expr2 = em4.in(zero).not().thenElse(es1, i0);
final Expression expr1 = fs0.thenElse(es1, i0);
final Formula f = i0.one().and(mutant.one()).and(expr1.eq(expr2).not());
final Instance instance = solver.solve(f, b).instance();
assertNotNull(instance);
// System.out.println(instance);
}
use of kodkod.instance.TupleFactory in project org.alloytools.alloy by AlloyTools.
the class EnumerationTest method testTrivial.
public final void testTrivial() {
final Relation r = Relation.unary("r");
final Universe u = new Universe(Arrays.asList("a", "b", "c"));
final TupleFactory f = u.factory();
final Bounds b = new Bounds(u);
b.bound(r, f.setOf("a"), f.allOf(1));
final Formula someR = r.some();
Iterator<Solution> sol = solver.solveAll(someR, b);
// has a trivial instance, followed by 2 non-trivial instances
assertEquals(Solution.Outcome.TRIVIALLY_SATISFIABLE, sol.next().outcome());
assertEquals(Solution.Outcome.SATISFIABLE, sol.next().outcome());
assertEquals(Solution.Outcome.SATISFIABLE, sol.next().outcome());
assertEquals(Solution.Outcome.UNSATISFIABLE, sol.next().outcome());
assertFalse(sol.hasNext());
}
Aggregations