Search in sources :

Example 26 with Relation

use of kodkod.ast.Relation in project org.alloytools.alloy by AlloyTools.

the class BugTests method testEmina_05072008.

public final void testEmina_05072008() {
    Relation A = Relation.unary("A"), first = Relation.unary("OrdFirst"), last = Relation.unary("OrdLast"), next = Relation.nary("OrdNext", 2);
    Relation B = Relation.unary("B"), acyclic = Relation.binary("acyclic");
    List<String> atomlist = Arrays.asList("A1", "A2", "A3", "B1", "B2", "B3", "C1", "C2");
    Universe universe = new Universe(atomlist);
    TupleFactory factory = universe.factory();
    Bounds bounds = new Bounds(universe);
    TupleSet allA = factory.setOf("A1", "A2", "A3");
    TupleSet allB = factory.setOf("B1", "B2", "B3");
    TupleSet allC = factory.setOf("C1", "C2");
    bounds.boundExactly(A, allA);
    bounds.bound(first, allA);
    bounds.bound(last, allA);
    bounds.bound(next, allA.product(allA));
    bounds.boundExactly(B, allB);
    bounds.bound(acyclic, allC.product(allC));
    Variable v = Variable.unary("v");
    Formula f0 = Formula.TRUE.forSome(v.setOf(B));
    Formula f1 = next.totalOrder(A, first, last);
    Formula f2 = acyclic.acyclic();
    Formula form = f0.and(f1).and(f2);
    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(0);
    solver.options().setSkolemDepth(0);
    Iterator<Solution> sol = solver.solveAll(form, bounds);
    int i = 1;
    while (sol.hasNext()) {
        assertTrue(i <= 17);
        sol.next();
        i++;
    }
}
Also used : TupleSet(kodkod.instance.TupleSet) Solver(kodkod.engine.Solver) Variable(kodkod.ast.Variable) Bounds(kodkod.instance.Bounds) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe) Formula(kodkod.ast.Formula) Relation(kodkod.ast.Relation) Solution(kodkod.engine.Solution)

Example 27 with Relation

use of kodkod.ast.Relation in project org.alloytools.alloy by AlloyTools.

the class BugTests method testEmina_10092006.

public final void testEmina_10092006() {
    Relation r = Relation.ternary("r");
    final Variable a = Variable.unary("A");
    final Variable b = Variable.unary("B");
    final Variable c = Variable.unary("C");
    final Variable d = Variable.unary("D");
    final Formula f0 = (b.join(a.join(r))).eq(d.join(c.join(r)));
    final Formula f1 = a.in(c).and(b.in(d));
    final Formula f = f0.implies(f1).forAll(a.oneOf(UNIV).and(b.oneOf(UNIV)).and(c.oneOf(UNIV)).and(d.oneOf(UNIV)));
    final Universe u = new Universe(Arrays.asList("a0", "a1"));
    final Bounds bounds = new Bounds(u);
    bounds.bound(r, u.factory().allOf(3));
    // System.out.println(f); System.out.println(bounds);
    solver.options().setSymmetryBreaking(0);
    // solver.options().setFlatten(false);
    final Solution s = solver.solve(f, bounds);
    // System.out.println(s);
    assertEquals(Solution.Outcome.SATISFIABLE, s.outcome());
}
Also used : Formula(kodkod.ast.Formula) Relation(kodkod.ast.Relation) Variable(kodkod.ast.Variable) Bounds(kodkod.instance.Bounds) Universe(kodkod.instance.Universe) Solution(kodkod.engine.Solution)

Example 28 with Relation

use of kodkod.ast.Relation in project org.alloytools.alloy by AlloyTools.

the class BugTests method testFelix_10272008.

public final void testFelix_10272008() {
    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");
    Relation x5 = Relation.unary("this/X");
    List<String> atomlist = Arrays.asList("-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "0", "1", "2", "3", "4", "5", "6", "7", "unused0", "unused1", "unused2");
    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"));
    x4_upper.add(factory.tuple("1"));
    x4_upper.add(factory.tuple("2"));
    x4_upper.add(factory.tuple("3"));
    bounds.boundExactly(x4, x4_upper);
    TupleSet x5_upper = factory.noneOf(1);
    x5_upper.add(factory.tuple("unused0"));
    x5_upper.add(factory.tuple("unused1"));
    x5_upper.add(factory.tuple("unused2"));
    bounds.bound(x5, x5_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 x11 = Variable.unary("c");
    Expression x12 = x5.difference(x5);
    Decls x10 = x11.oneOf(x12);
    IntExpression x13 = IntConstant.constant(0);
    IntExpression x9 = x13.sum(x10);
    IntExpression x14 = IntConstant.constant(0);
    Formula x8 = x9.eq(x14);
    Formula x17 = x0.eq(x0);
    Formula x18 = x2.eq(x2);
    Formula x16 = x17.and(x18);
    Formula x19 = x3.eq(x3);
    Formula x15 = x16.and(x19);
    Formula x7 = x8.and(x15);
    Formula x22 = x1.eq(x1);
    Formula x23 = x4.eq(x4);
    Formula x21 = x22.and(x23);
    Formula x24 = x5.eq(x5);
    Formula x20 = x21.and(x24);
    Formula x6 = x7.and(x20);
    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);
    Solution sol = solver.solve(x6, bounds);
    assertEquals(sol.outcome(), Solution.Outcome.TRIVIALLY_SATISFIABLE);
}
Also used : TupleSet(kodkod.instance.TupleSet) Solver(kodkod.engine.Solver) Variable(kodkod.ast.Variable) Decls(kodkod.ast.Decls) Bounds(kodkod.instance.Bounds) IntExpression(kodkod.ast.IntExpression) 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 29 with Relation

use of kodkod.ast.Relation in project org.alloytools.alloy by AlloyTools.

the class BugTests method testFelix_05152007_3.

public final void testFelix_05152007_3() {
    Relation x5 = Relation.nary("A", 1);
    List<String> atomlist = Arrays.asList("A[0]", "A[1]", "A[2]");
    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("A[0]"));
    x5_upper.add(factory.tuple("A[1]"));
    x5_upper.add(factory.tuple("A[2]"));
    bounds.bound(x5, x5_upper);
    Formula a = x5.some();
    Formula a1 = x5.no();
    Formula b = a1.and(Formula.TRUE.and(Formula.TRUE));
    Formula c = a.and(b);
    Solver solver = new Solver();
    solver.options().setLogTranslation(1);
    solver.options().setSolver(SATFactory.DefaultSAT4J);
    solver.options().setBitwidth(4);
    solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT);
    Solution sol = solver.solve(c, bounds);
    Set<Formula> core = Nodes.minRoots(c, sol.proof().highLevelCore().values());
    assertEquals(2, core.size());
    assertTrue(core.contains(a));
    assertTrue(core.contains(a1));
}
Also used : TupleSet(kodkod.instance.TupleSet) Formula(kodkod.ast.Formula) Relation(kodkod.ast.Relation) Solver(kodkod.engine.Solver) Bounds(kodkod.instance.Bounds) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe) Solution(kodkod.engine.Solution)

Example 30 with Relation

use of kodkod.ast.Relation in project org.alloytools.alloy by AlloyTools.

the class BugTests method testFelix_05152007_2.

public final void testFelix_05152007_2() {
    Relation x5 = Relation.nary("A", 1);
    List<String> atomlist = Arrays.asList("A0", "A1", "A2");
    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("A2"));
    x5_upper.add(factory.tuple("A1"));
    x5_upper.add(factory.tuple("A0"));
    bounds.bound(x5, x5_upper);
    Formula x7 = x5.eq(x5).not();
    Solver solver = new Solver();
    solver.options().setLogTranslation(1);
    solver.options().setSolver(SATFactory.MiniSatProver);
    solver.options().setBitwidth(4);
    solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT);
    Solution sol = solver.solve(x7, bounds);
    Set<Formula> core = Nodes.minRoots(x7, sol.proof().highLevelCore().values());
    assertEquals(1, core.size());
    assertTrue(core.contains(x7));
}
Also used : TupleSet(kodkod.instance.TupleSet) Formula(kodkod.ast.Formula) Relation(kodkod.ast.Relation) Solver(kodkod.engine.Solver) Bounds(kodkod.instance.Bounds) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe) 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