Search in sources :

Example 21 with Solution

use of kodkod.engine.Solution 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 22 with Solution

use of kodkod.engine.Solution 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 23 with Solution

use of kodkod.engine.Solution 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 24 with Solution

use of kodkod.engine.Solution in project org.alloytools.alloy by AlloyTools.

the class TranslatorTest method testNary.

private final void testNary(ExprOperator op) {
    bounds.bound(r1[0], factory.range(factory.tuple(1, 0), factory.tuple(1, 3)));
    bounds.bound(r1[1], factory.range(factory.tuple(1, 2), factory.tuple(1, 5)));
    bounds.bound(r1[3], factory.range(factory.tuple(1, 3), factory.tuple(1, 6)));
    for (int i = 2; i <= 5; i++) {
        final Expression[] exprs = new Expression[i];
        exprs[0] = r1[0];
        Expression binExpr = r1[0];
        for (int j = 1; j < i; j++) {
            binExpr = binExpr.compose(op, r1[j % 4]);
            exprs[j] = r1[j % 4];
        }
        Expression nExpr = Expression.compose(op, exprs);
        final Solution sol = solver.solve(binExpr.eq(nExpr).not(), bounds);
        assertNull(sol.instance());
    }
}
Also used : IntExpression(kodkod.ast.IntExpression) Expression(kodkod.ast.Expression) Solution(kodkod.engine.Solution)

Example 25 with Solution

use of kodkod.engine.Solution in project org.alloytools.alloy by AlloyTools.

the class TranslatorTest method testNary.

private final void testNary(IntOperator op) {
    bounds.bound(r1[0], factory.range(factory.tuple(1, 0), factory.tuple(1, 3)));
    bounds.bound(r1[1], factory.range(factory.tuple(1, 2), factory.tuple(1, 5)));
    bounds.bound(r1[3], factory.range(factory.tuple(1, 3), factory.tuple(1, 6)));
    for (int i = 2; i <= 5; i++) {
        final IntExpression[] exprs = new IntExpression[i];
        exprs[0] = r1[0].count();
        IntExpression binExpr = r1[0].count();
        for (int j = 1; j < i; j++) {
            binExpr = binExpr.compose(op, r1[j % 4].count());
            exprs[j] = r1[j % 4].count();
        }
        IntExpression nExpr = IntExpression.compose(op, exprs);
        final Solution sol = solver.solve(binExpr.eq(nExpr).not(), bounds);
        assertNull(sol.instance());
    }
}
Also used : IntExpression(kodkod.ast.IntExpression) Solution(kodkod.engine.Solution)

Aggregations

Solution (kodkod.engine.Solution)153 Formula (kodkod.ast.Formula)101 Bounds (kodkod.instance.Bounds)75 Solver (kodkod.engine.Solver)72 Universe (kodkod.instance.Universe)32 Relation (kodkod.ast.Relation)30 TupleFactory (kodkod.instance.TupleFactory)30 TupleSet (kodkod.instance.TupleSet)25 Variable (kodkod.ast.Variable)24 IntExpression (kodkod.ast.IntExpression)19 Expression (kodkod.ast.Expression)17 Test (org.junit.Test)16 QuantifiedFormula (kodkod.ast.QuantifiedFormula)15 Decls (kodkod.ast.Decls)11 Evaluator (kodkod.engine.Evaluator)10 HigherOrderDeclException (kodkod.engine.fol2sat.HigherOrderDeclException)7 UnboundLeafException (kodkod.engine.fol2sat.UnboundLeafException)7 ConsoleReporter (kodkod.engine.config.ConsoleReporter)6 Instance (kodkod.instance.Instance)6 ArrayList (java.util.ArrayList)5