use of kodkod.ast.Relation 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());
}
use of kodkod.ast.Relation in project org.alloytools.alloy by AlloyTools.
the class IntTest method nonConstants.
private IntExpression[] nonConstants() {
final Options options = solver.options();
final IntRange range = options.integers();
final int min = range.min(), max = range.max();
final int size = range.size();
final Relation[] r = new Relation[size];
final TupleFactory f = bounds.universe().factory();
for (int i = 0; i < size; i++) {
int arity = i % 3 + 1;
r[i] = Relation.nary("r" + i, arity);
TupleSet b = f.noneOf(arity);
for (int j = (i / 3) * ((int) Math.pow(SIZE, arity - 1)), jmax = j + size; j < jmax; j++) {
b.add(f.tuple(arity, j % b.capacity()));
}
bounds.bound(r[i], b);
}
final IntExpression[] vals = new IntExpression[max - min + 1];
for (int i = 0; i < size; i++) {
vals[i] = i + min < 0 ? r[i].count().negate() : r[i].count();
}
return vals;
}
use of kodkod.ast.Relation in project org.alloytools.alloy by AlloyTools.
the class BugTests method testFelix_11262007.
public final void testFelix_11262007() {
Relation x6 = Relation.unary("R2");
List<String> atomlist = Arrays.asList("X", "Y", "Z");
Universe universe = new Universe(atomlist);
TupleFactory factory = universe.factory();
Bounds bounds = new Bounds(universe);
bounds.bound(x6, factory.allOf(1));
final Variable x32 = Variable.unary("a");
final Decls x31 = x32.oneOf(x6);
final Variable x36 = Variable.unary("b");
final Decls x35 = x36.oneOf(x32.join(x6.product(x6)));
final Formula x29 = x36.some().forSome(x35).forSome(x31);
Solver solver = new Solver();
solver.options().setSolver(SATFactory.DefaultSAT4J);
solver.options().setBitwidth(4);
solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT);
solver.options().setSymmetryBreaking(20);
solver.options().setSkolemDepth(0);
final Set<Decl> decls = new LinkedHashSet<Decl>();
solver.options().setReporter(new AbstractReporter() {
@Override
public void skolemizing(Decl decl, Relation skolem, List<Decl> predecl) {
decls.add(decl);
}
});
Solution sol = solver.solve(x29, bounds);
assertEquals(2, decls.size());
assertTrue(decls.contains(x31));
assertTrue(decls.contains(x35));
assertNotNull(sol.instance());
}
use of kodkod.ast.Relation in project org.alloytools.alloy by AlloyTools.
the class BugTests method testFelix_10182006.
public final void testFelix_10182006() {
// (some x: one { y: one SIG | true } | true)
Relation sig = Relation.unary("SIG");
final Variable x = Variable.unary("x");
final Variable y = Variable.unary("y");
final Expression e0 = Formula.TRUE.comprehension(y.oneOf(sig));
final Formula f0 = Formula.TRUE.forSome(x.oneOf(e0));
final Universe u = new Universe(Arrays.asList("a0"));
final Bounds bounds = new Bounds(u);
bounds.bound(sig, u.factory().allOf(1));
final Solution s = solver.solve(f0, bounds);
assertEquals(Solution.Outcome.SATISFIABLE, s.outcome());
}
use of kodkod.ast.Relation in project org.alloytools.alloy by AlloyTools.
the class BugTests method doTestAleks_03102013.
private final void doTestAleks_03102013() {
Relation r = Relation.unary("R");
Relation s = Relation.binary("f");
Variable v = Variable.unary("e");
Decl decl = v.oneOf(r);
Expression shared = v.join(s);
Formula expr = (shared.difference(shared)).one().forAll(decl);
Formula fin = expr.and(expr.not());
List<Object> atomlist = new LinkedList<Object>();
atomlist.add("R$0");
atomlist.add("R$1");
atomlist.add("R$2");
Universe universe = new Universe(atomlist);
TupleFactory factory = universe.factory();
Bounds bounds = new Bounds(universe);
bounds.bound(r, factory.allOf(1));
bounds.bound(s, factory.allOf(2));
Solver solver = new Solver();
solver.options().setSolver(SATFactory.DefaultSAT4J);
solver.options().setBitwidth(4);
solver.options().setSkolemDepth(0);
solver.options().setLogTranslation(0);
Solution sol = solver.solve(fin, bounds);
assertNull(sol.instance());
}
Aggregations