Search in sources :

Example 86 with TupleSet

use of kodkod.instance.TupleSet 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);
}
Also used : TupleSet(kodkod.instance.TupleSet) Relation(kodkod.ast.Relation) Solver(kodkod.engine.Solver) IntExpression(kodkod.ast.IntExpression) Expression(kodkod.ast.Expression) Bounds(kodkod.instance.Bounds) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe)

Example 87 with TupleSet

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

Example 88 with TupleSet

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

Example 89 with TupleSet

use of kodkod.instance.TupleSet 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;
}
Also used : TupleSet(kodkod.instance.TupleSet) Bounds(kodkod.instance.Bounds) ArrayList(java.util.ArrayList) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe)

Aggregations

TupleSet (kodkod.instance.TupleSet)89 TupleFactory (kodkod.instance.TupleFactory)55 Bounds (kodkod.instance.Bounds)53 Universe (kodkod.instance.Universe)50 Relation (kodkod.ast.Relation)43 ArrayList (java.util.ArrayList)30 Formula (kodkod.ast.Formula)29 Solution (kodkod.engine.Solution)23 Solver (kodkod.engine.Solver)21 Expression (kodkod.ast.Expression)20 IntExpression (kodkod.ast.IntExpression)18 Variable (kodkod.ast.Variable)15 Instance (kodkod.instance.Instance)13 Tuple (kodkod.instance.Tuple)12 Decls (kodkod.ast.Decls)10 Sig (edu.mit.csail.sdg.ast.Sig)7 PrimSig (edu.mit.csail.sdg.ast.Sig.PrimSig)7 Evaluator (kodkod.engine.Evaluator)7 Field (edu.mit.csail.sdg.ast.Sig.Field)5 Map (java.util.Map)5