Search in sources :

Example 76 with Relation

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());
}
Also used : Formula(kodkod.ast.Formula) Relation(kodkod.ast.Relation) Bounds(kodkod.instance.Bounds) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe) Solution(kodkod.engine.Solution)

Example 77 with Relation

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;
}
Also used : Options(kodkod.engine.config.Options) TupleSet(kodkod.instance.TupleSet) Relation(kodkod.ast.Relation) IntExpression(kodkod.ast.IntExpression) IntRange(kodkod.util.ints.IntRange) TupleFactory(kodkod.instance.TupleFactory)

Example 78 with Relation

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());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Solver(kodkod.engine.Solver) Variable(kodkod.ast.Variable) Decls(kodkod.ast.Decls) Bounds(kodkod.instance.Bounds) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe) Decl(kodkod.ast.Decl) Formula(kodkod.ast.Formula) Relation(kodkod.ast.Relation) AbstractReporter(kodkod.engine.config.AbstractReporter) Solution(kodkod.engine.Solution)

Example 79 with Relation

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());
}
Also used : Formula(kodkod.ast.Formula) Relation(kodkod.ast.Relation) Variable(kodkod.ast.Variable) IntExpression(kodkod.ast.IntExpression) Expression(kodkod.ast.Expression) Bounds(kodkod.instance.Bounds) Universe(kodkod.instance.Universe) Solution(kodkod.engine.Solution)

Example 80 with Relation

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());
}
Also used : Solver(kodkod.engine.Solver) Variable(kodkod.ast.Variable) Bounds(kodkod.instance.Bounds) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe) Decl(kodkod.ast.Decl) LinkedList(java.util.LinkedList) Formula(kodkod.ast.Formula) Relation(kodkod.ast.Relation) IntExpression(kodkod.ast.IntExpression) Expression(kodkod.ast.Expression) Solution(kodkod.engine.Solution)

Aggregations

Relation (kodkod.ast.Relation)87 Bounds (kodkod.instance.Bounds)49 Formula (kodkod.ast.Formula)45 TupleFactory (kodkod.instance.TupleFactory)45 Universe (kodkod.instance.Universe)45 TupleSet (kodkod.instance.TupleSet)43 Solution (kodkod.engine.Solution)30 Expression (kodkod.ast.Expression)26 IntExpression (kodkod.ast.IntExpression)24 Solver (kodkod.engine.Solver)24 ArrayList (java.util.ArrayList)23 Variable (kodkod.ast.Variable)23 Instance (kodkod.instance.Instance)15 Decls (kodkod.ast.Decls)13 Evaluator (kodkod.engine.Evaluator)9 Tuple (kodkod.instance.Tuple)8 IntSet (kodkod.util.ints.IntSet)7 BinaryExpression (kodkod.ast.BinaryExpression)6 Decl (kodkod.ast.Decl)6 LinkedHashSet (java.util.LinkedHashSet)4