use of kodkod.ast.Variable 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.ast.Variable in project org.alloytools.alloy by AlloyTools.
the class BugTests method testFelix_03062008_2.
public final void testFelix_03062008_2() {
Relation x5 = Relation.unary("Role");
Relation x6 = Relation.unary("Session");
List<String> atomlist = Arrays.asList("Role$0", "Session$0", "Session$1");
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("Role$0"));
bounds.bound(x5, x5_upper);
TupleSet x6_upper = factory.noneOf(1);
x6_upper.add(factory.tuple("Session$0"));
x6_upper.add(factory.tuple("Session$1"));
bounds.bound(x6, x6_upper);
Variable x11 = Variable.unary("x_a");
Decls x10 = x11.oneOf(x6);
Variable x15 = Variable.unary("x_b");
Decls x14 = x15.oneOf(x5);
Variable x17 = Variable.unary("x_c");
Decls x16 = x17.oneOf(x5);
Decls x13 = x14.and(x16);
Expression x20 = x15.product(x17);
Expression x19 = x11.product(x20);
Formula x18 = x19.some();
Formula x12 = x18.forSome(x13);
Formula x9 = x12.forAll(x10);
Formula x24 = x5.some();
Formula x23 = x24.not();
Formula x28 = x5.eq(x5);
Formula x29 = x6.eq(x6);
Formula x25 = x28.and(x29);
Formula x22 = x23.and(x25);
Formula x8 = x9.and(x22).and(x5.no()).and(x6.no());
Solver solver = new Solver();
solver.options().setSolver(SATFactory.DefaultSAT4J);
solver.options().setBitwidth(2);
// solver.options().setFlatten(false);
solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT);
solver.options().setSymmetryBreaking(20);
solver.options().setSkolemDepth(2);
System.out.flush();
Solution sol = solver.solve(x8, bounds);
Instance inst = sol.instance();
assertNotNull(inst);
for (Relation rel : inst.relations()) {
if (rel != x5 && rel != x6) {
final TupleSet range = inst.tuples(x6).product(inst.tuples(x5));
assertTrue(range.containsAll(inst.tuples(rel)));
}
}
}
use of kodkod.ast.Variable in project org.alloytools.alloy by AlloyTools.
the class EvaluatorTest method testComprehension.
public final void testComprehension() {
final Variable[] vars = new Variable[3];
final Decl[] decls = new Decl[3];
for (int i = 0; i < 3; i++) {
Variable v = Variable.unary("v" + i);
Decl d = v.oneOf(person);
vars[i] = v;
decls[i] = d;
}
// {v0: Person | no v0.shaken} = univ - shaken.Person
assertEquals(eval(vars[0].join(shaken).no().comprehension(decls[0])), eval(univ.difference(shaken.join(person))));
// {v0, v1: Person | v1 in v0.shaken} = shaken
assertEquals(eval(vars[1].in(vars[0].join(shaken)).comprehension(decls[0].and(decls[1]))), value(shaken));
// {v0, v1, v2: Person | no v1.shaken} = Person->(univ -
// shaken.Person)->Person
assertEquals(eval(vars[1].join(shaken).no().comprehension(decls[0].and(decls[1]).and(decls[2]))), eval(person.product(univ.difference(shaken.join(person))).product(person)));
}
use of kodkod.ast.Variable in project org.alloytools.alloy by AlloyTools.
the class HOLSome4AllTest method testE1ii.
@Test
public void testE1ii() {
// SAT: some s: ints | all $s: set Node | #$s > s
Variable ns = Variable.unary("$s");
Formula f = ns.count().gt(si).forAll(ns.setOf(Node)).forSome(s.oneOf(Expression.INTS));
Solution sol = solve(f);
assertEquals(true, sol.sat());
assertEquals(-1, evalS(sol));
}
use of kodkod.ast.Variable in project org.alloytools.alloy by AlloyTools.
the class HOLSome4AllTest method testE1i.
@Test
public void testE1i() {
// SAT: some s: ints | all s: set Node | #s > s
Variable ns = Variable.unary("s");
Formula f = ns.count().gt(si).forAll(ns.setOf(Node)).forSome(s.oneOf(Expression.INTS));
Solution sol = solve(f);
assertEquals(true, sol.sat());
assertEquals(-1, evalS(sol));
}
Aggregations