Search in sources :

Example 36 with Relation

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

the class BugTests method testFelix_01062007.

public final void testFelix_01062007() {
    Relation x1 = Relation.nary("A", 1);
    List<String> atomlist = Arrays.asList("A");
    Universe universe = new Universe(atomlist);
    TupleFactory factory = universe.factory();
    Bounds bounds = new Bounds(universe);
    TupleSet x1_upper = factory.noneOf(1);
    x1_upper.add(factory.tuple("A"));
    bounds.bound(x1, x1_upper);
    Solver solver = new Solver();
    solver.options().setSolver(SATFactory.MiniSat);
    Iterator<Solution> sols = solver.solveAll(Formula.TRUE, bounds);
    assertNotNull(sols.next().instance());
    assertNotNull(sols.next().instance());
    assertNull(sols.next().instance());
// Solution sol1=sols.next();
// System.out.println("Solution1:"+sol1.instance());
// 
// Solution sol2=sols.next();
// System.out.println("Solution2:"+sol2.instance());
// 
// Solution sol3=sols.next();
// System.out.println("Solution3:"+sol3.instance());
}
Also used : TupleSet(kodkod.instance.TupleSet) 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 37 with Relation

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

the class BugTests method testFelix_05072008.

public final void testFelix_05072008() {
    Relation A = Relation.unary("A"), first = Relation.unary("OrdFirst"), last = Relation.unary("OrdLast"), next = Relation.nary("OrdNext", 2);
    List<String> atomlist = Arrays.asList("A1", "A2", "A3");
    Universe universe = new Universe(atomlist);
    TupleFactory factory = universe.factory();
    Bounds bounds = new Bounds(universe);
    TupleSet all = factory.setOf("A1", "A2", "A3");
    bounds.boundExactly(A, all);
    bounds.bound(first, all);
    bounds.bound(last, all);
    bounds.bound(next, all.product(all));
    Formula form = next.totalOrder(A, first, last);
    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);
    assertTrue(sol.hasNext());
    assertEquals(sol.next().outcome(), Solution.Outcome.TRIVIALLY_SATISFIABLE);
    assertTrue(sol.hasNext());
    assertEquals(sol.next().outcome(), Solution.Outcome.TRIVIALLY_UNSATISFIABLE);
    assertFalse(sol.hasNext());
// int i=1;
// 
// while (sol.hasNext()) {
// System.out.println("================================== "+i+"
// ===================================");
// System.out.println(sol.next());
// System.out.flush();
// i++;
// }
}
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 38 with Relation

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

the class EvaluatorTest method testEvalTransitiveClosure.

public final void testEvalTransitiveClosure() {
    // // ^(Hilary->Jocelyn) = Hilary->Jocelyn
    // assertEquals(eval(hilary.product(jocelyn).closure()),
    // eval(hilary.product(jocelyn)));
    // // ^spouse = spouse + spouse.spouse
    // assertEquals(eval(spouse.closure()),
    // eval(spouse.union(spouse.join(spouse))));
    // // Hilary.^shaken = univ - (univ - Person.shaken)
    // assertEquals(eval(hilary.join(shaken.closure())),
    // eval(univ.difference(univ.difference(person.join(shaken)))));
    // try {
    // eval(person.closure());
    // fail("Expected IllegalArgumentException");
    // } catch (IllegalArgumentException iae) {}
    // ^r = value(^r)
    final Relation r = Relation.binary("r");
    final Universe u = evaluator.instance().universe();
    final TupleFactory f = u.factory();
    final Instance instance = new Instance(u);
    // value(r) = u[0]->u[1] + u[1]->u[2] + u[2]->u[3] + u[3]->u[4]
    TupleSet s = f.noneOf(r.arity());
    for (int i = 0; i < 4; i++) s.add(f.tuple(u.atom(i), u.atom(i + 1)));
    instance.add(r, s);
    // value(^r) = value(r) + u[0]->u[2] + u[0]->u[3] + u[0]->u[4] +
    // u[1]->u[3] u[1]->u[4] + u[2]->u[4]
    Set<Tuple> result = new HashSet<Tuple>();
    for (int i = 0; i < 4; i++) {
        for (int j = i + 1; j < 5; j++) {
            result.add(f.tuple(u.atom(i), u.atom(j)));
        }
    }
    assertEquals((new Evaluator(instance)).evaluate(r.closure()), result);
    // value(*r) = value(^r) + iden
    for (int i = 0; i < 10; i++) {
        result.add(f.tuple(u.atom(i), u.atom(i)));
    }
    assertEquals((new Evaluator(instance)).evaluate(r.reflexiveClosure()), result);
}
Also used : TupleSet(kodkod.instance.TupleSet) Relation(kodkod.ast.Relation) Instance(kodkod.instance.Instance) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe) Evaluator(kodkod.engine.Evaluator) Tuple(kodkod.instance.Tuple) HashSet(java.util.HashSet)

Example 39 with Relation

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

the class ALG195_1 method bounds.

/**
 * Returns the partial bounds the problem (axioms 1, 4, 9-11).
 *
 * @return the partial bounds for the problem
 */
public Bounds bounds() {
    final List<String> atoms = new ArrayList<String>(14);
    for (int i = 0; i < 7; i++) atoms.add("e1" + i);
    for (int i = 0; i < 7; i++) atoms.add("e2" + i);
    final Universe u = new Universe(atoms);
    final Bounds b = new Bounds(u);
    final TupleFactory f = u.factory();
    final TupleSet s1bound = f.range(f.tuple("e10"), f.tuple("e16"));
    final TupleSet s2bound = f.range(f.tuple("e20"), f.tuple("e26"));
    b.boundExactly(s1, s1bound);
    b.boundExactly(s2, s2bound);
    // axioms 9, 10, 11
    for (int i = 0; i < 7; i++) {
        b.boundExactly(e1[i], f.setOf("e1" + i));
        b.boundExactly(e2[i], f.setOf("e2" + i));
    }
    // axom 1
    b.bound(op1, f.area(f.tuple("e10", "e10", "e10"), f.tuple("e16", "e16", "e16")));
    // axiom 4
    b.bound(op2, f.area(f.tuple("e20", "e20", "e20"), f.tuple("e26", "e26", "e26")));
    final TupleSet hbound = s1bound.product(s2bound);
    for (Relation r : h) {
        b.bound(r, hbound);
    }
    return b;
}
Also used : TupleSet(kodkod.instance.TupleSet) Relation(kodkod.ast.Relation) Bounds(kodkod.instance.Bounds) ArrayList(java.util.ArrayList) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe)

Example 40 with Relation

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

the class ALG195_1 method co1h.

/**
 * Returns the part of the conjecture 1 that applies to the given h.
 *
 * @return the part of the conjecture 1 that applies to the given h.
 */
private final Formula co1h(Relation h) {
    Formula f = Formula.TRUE;
    for (Relation x : e1) {
        for (Relation y : e1) {
            // h(op1(x,y))
            Expression expr0 = (y.join(x.join(op1))).join(h);
            // op2(h(x),h(y))
            Expression expr1 = (y.join(h)).join((x.join(h)).join(op2));
            f = f.and(expr0.eq(expr1));
        }
    }
    return f.and(s2.eq(s1.join(h)));
}
Also used : Formula(kodkod.ast.Formula) Relation(kodkod.ast.Relation) Expression(kodkod.ast.Expression)

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