Search in sources :

Example 71 with Universe

use of kodkod.instance.Universe in project org.alloytools.alloy by AlloyTools.

the class TranslatorTest method testFlattening.

public final void testFlattening() {
    final List<String> atoms = new ArrayList<String>(9);
    atoms.add("-1");
    atoms.add("0");
    atoms.add("1");
    atoms.add("null");
    for (int i = 0; i < 5; i++) {
        atoms.add("m" + i);
    }
    final Universe u = new Universe(atoms);
    final TupleFactory t = u.factory();
    final Relation[] m = new Relation[5];
    for (int i = 0; i < 5; i++) {
        m[i] = Relation.unary("m" + i);
    }
    final Relation univ = Relation.unary("univ"), none = Relation.unary("none"), iden = Relation.binary("inden"), mutant = Relation.unary("mutant"), inc = Relation.binary("inc"), add = Relation.ternary("add"), i0 = Relation.unary("i0"), zero = Relation.unary("0"), one = Relation.unary("1"), ints = Relation.unary("int");
    final Bounds b = new Bounds(u);
    b.boundExactly(univ, t.allOf(1));
    b.boundExactly(none, t.noneOf(1));
    TupleSet idenSet = t.noneOf(2);
    for (String atom : atoms) {
        idenSet.add(t.tuple(atom, atom));
    }
    b.boundExactly(iden, idenSet);
    b.bound(mutant, t.range(t.tuple("m0"), t.tuple("m4")));
    for (int i = 0; i < 5; i++) {
        b.boundExactly(m[i], t.setOf("m" + i));
    }
    b.bound(i0, t.range(t.tuple("-1"), t.tuple("1")));
    b.boundExactly(zero, t.setOf(t.tuple("0")));
    b.boundExactly(one, t.setOf(t.tuple("1")));
    b.boundExactly(ints, t.allOf(1));
    b.boundExactly(inc, t.setOf(t.tuple("-1", "0"), t.tuple("0", "1")));
    // [1, 1, -1], [1, -1, 0], [1, 0, 1], [-1, 1, 0], [-1, -1, 1],
    // [-1, 0, -1], [0, 1, 1], [0, -1, -1], [0, 0, 0]]
    b.boundExactly(add, t.setOf(t.tuple("1", "1", "-1"), t.tuple("1", "-1", "0"), t.tuple("1", "0", "1"), t.tuple("-1", "1", "0"), t.tuple("-1", "-1", "1"), t.tuple("-1", "0", "-1"), t.tuple("0", "1", "1"), t.tuple("0", "-1", "-1"), t.tuple("0", "0", "0")));
    /*
         * ((one i0 && one mutant) && !((if (i0 in (0 . ^~inc)) then ((add . 0) . i0)
         * else i0) = (if !((if (mutant in m4) then (if (i0 in 0) then 1 else 0) else
         * (if (mutant in m3) then (if ((i0 = 0) || (i0 in (0 . ^~inc))) then 1 else 0)
         * else (if (mutant in m2) then (if (i0 in (0 . ^inc)) then 1 else 0) else (if
         * (mutant in m1) then (if ((i0 = 0) || (i0 in (0 . ^inc))) then 1 else 0) else
         * (if (mutant in m0) then (if !(i0 in 0) then 1 else 0) else (if (i0 in (0 .
         * ^~inc)) then 1 else 0)))))) in 0) then ((add . 0) . i0) else i0)))
         */
    final Formula[] cm = new Formula[5];
    for (int i = 0; i < 5; i++) {
        cm[i] = mutant.in(m[i]);
    }
    // (i0 in (0 . ^~inc))
    final Formula fs0 = i0.in(zero.join(inc.transpose().closure()));
    // (i0 in (0 . ^inc))
    final Formula fs1 = i0.in(zero.join(inc.closure()));
    // (i0 = 0)
    final Formula fs2 = i0.eq(zero);
    final Expression em0 = cm[0].thenElse(i0.in(zero).not().thenElse(one, zero), fs0.thenElse(one, zero));
    final Expression em1 = cm[1].thenElse((fs2.or(fs1)).thenElse(one, zero), em0);
    final Expression em2 = cm[2].thenElse(fs1.thenElse(one, zero), em1);
    final Expression em3 = cm[3].thenElse(fs2.or(fs0).thenElse(one, zero), em2);
    final Expression em4 = cm[4].thenElse(i0.in(zero).thenElse(one, zero), em3);
    final Expression es1 = add.join(zero).join(i0);
    final Expression expr2 = em4.in(zero).not().thenElse(es1, i0);
    final Expression expr1 = fs0.thenElse(es1, i0);
    final Formula f = i0.one().and(mutant.one()).and(expr1.eq(expr2).not());
    final Instance instance = solver.solve(f, b).instance();
    assertNotNull(instance);
// System.out.println(instance);
}
Also used : TupleSet(kodkod.instance.TupleSet) Instance(kodkod.instance.Instance) Bounds(kodkod.instance.Bounds) ArrayList(java.util.ArrayList) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe) Formula(kodkod.ast.Formula) Relation(kodkod.ast.Relation) IntExpression(kodkod.ast.IntExpression) Expression(kodkod.ast.Expression)

Example 72 with Universe

use of kodkod.instance.Universe 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 73 with Universe

use of kodkod.instance.Universe 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 74 with Universe

use of kodkod.instance.Universe 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 75 with Universe

use of kodkod.instance.Universe 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

Universe (kodkod.instance.Universe)83 Bounds (kodkod.instance.Bounds)79 TupleFactory (kodkod.instance.TupleFactory)77 TupleSet (kodkod.instance.TupleSet)50 ArrayList (java.util.ArrayList)46 Relation (kodkod.ast.Relation)45 Formula (kodkod.ast.Formula)37 Solution (kodkod.engine.Solution)32 Solver (kodkod.engine.Solver)26 Variable (kodkod.ast.Variable)21 Expression (kodkod.ast.Expression)20 IntExpression (kodkod.ast.IntExpression)20 Instance (kodkod.instance.Instance)14 Decls (kodkod.ast.Decls)11 Evaluator (kodkod.engine.Evaluator)9 LinkedList (java.util.LinkedList)4 Tuple (kodkod.instance.Tuple)4 LinkedHashSet (java.util.LinkedHashSet)3 Map (java.util.Map)2 Set (java.util.Set)2