Search in sources :

Example 41 with Variable

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

the class Hotel method invsForCheckout.

/**
 * Returns the invariants for Checkout and its fields.
 *
 * @return invariants for Checkout and its fields.
 */
public Formula invsForCheckout() {
    // sig Checkout extends HotelEvent { }
    // {
    // some occ.pre.guest
    // 
    // -- DNJ: can comment these out and still unsat
    // occ.post = occ.pre - Room -> guest
    // prev.unchanged
    // holds.unchanged
    // key.unchanged
    // }
    final List<Formula> invs = new ArrayList<Formula>();
    invs.add(Checkout.in(HotelEvent));
    final Variable c = Variable.unary("n");
    invs.add(occ.join(pre(c)).join(guest(c)).some().forAll(c.oneOf(Checkout)));
    invs.add(occ.join(post(c)).eq(occ.join(pre(c)).difference(Room.product(guest(c)))).forAll(c.oneOf(Checkout)));
    invs.add(unchanged(c, prev).forAll(c.oneOf(Checkout)));
    invs.add(unchanged(c, holds).forAll(c.oneOf(Checkout)));
    invs.add(unchanged(c, key).forAll(c.oneOf(Checkout)));
    return Formula.and(invs);
}
Also used : Formula(kodkod.ast.Formula) Variable(kodkod.ast.Variable) ArrayList(java.util.ArrayList)

Example 42 with Variable

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

the class Hotel method noBadEntry.

/**
 * Returns NoBadEntry formula.
 *
 * @return NoBadEntry formula.
 */
public Formula noBadEntry() {
    // all e: Enter | let occs = occ.(e.pre) [e.room] |
    // some occs => e.guest in occs
    final Variable e = Variable.unary("e");
    final Expression occs = e.join(room).join(occ.join(e.join(pre)));
    return occs.some().implies(e.join(guest).in(occs)).forAll(e.oneOf(Enter));
}
Also used : Variable(kodkod.ast.Variable) Expression(kodkod.ast.Expression)

Example 43 with Variable

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

the class Hotel method initInvariant.

/**
 * Returns init fact.
 *
 * @return init fact.
 */
public Formula initInvariant() {
    // pred init (t: Time) {
    // prev.t = key.t
    // key.t in Room lone -> Key
    // no holds.t and no occ.t
    // }
    // fact {first.init}
    final List<Formula> invs = new ArrayList<Formula>();
    invs.add(prev.join(first).eq(key.join(first)));
    invs.add(key.join(first).in(Room.product(Key)));
    final Variable k = Variable.unary("k");
    invs.add(key.join(first).join(k).lone().forAll(k.oneOf(Key)));
    invs.add(holds.join(first).no());
    invs.add(occ.join(first).no());
    return Formula.and(invs);
}
Also used : Formula(kodkod.ast.Formula) Variable(kodkod.ast.Variable) ArrayList(java.util.ArrayList)

Example 44 with Variable

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

the class Toughnut method checkBelowTooDoublePrime.

/**
 * Returns the covering predicate. Note that we don't need to specify the first
 * two lines of the predicate, since they can be expressed as bounds
 * constraints.
 *
 * @return the covering predicate
 */
public Formula checkBelowTooDoublePrime() {
    final Variable x = Variable.unary("x");
    final Variable y = Variable.unary("y");
    final Decls d = x.oneOf(Cell).and(y.oneOf(Cell));
    final Expression xy = y.join(x.join(covered));
    // covering relation is symmetric
    Formula symm = xy.product(x.product(y)).in(covered).forAll(d);
    // each pair of cells on the board should be covered
    // by a domino, which also covers ONE of its neighbors
    Expression xNeighbors = (prev(x).union(next(x))).product(y);
    Expression yNeighbors = x.product(prev(y).union(next(y)));
    Formula covering = (xy.one().and(xy.in(xNeighbors.union(yNeighbors)))).forAll(d);
    return symm.and(covering);
}
Also used : Formula(kodkod.ast.Formula) Variable(kodkod.ast.Variable) Decls(kodkod.ast.Decls) Expression(kodkod.ast.Expression)

Example 45 with Variable

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

the class ToyLists method spec.

/**
 * Returns the toylists spec.
 *
 * @return toylists spec
 */
public Formula spec() {
    final Variable a = Variable.unary("a"), b = Variable.unary("b"), e = Variable.unary("e");
    final List<Formula> spec = new ArrayList<Formula>();
    spec.add(list.eq(nonEmptyList.union(emptyList)));
    spec.add(nonEmptyList.intersection(emptyList).no());
    spec.add(car.in(nonEmptyList.product(thing)));
    spec.add(car(a).one().forAll(a.oneOf(nonEmptyList)));
    spec.add(cdr.in(nonEmptyList.product(list)));
    spec.add(cdr(a).one().forAll(a.oneOf(nonEmptyList)));
    spec.add(e.in(a.join(cdr.reflexiveClosure())).forSome(e.oneOf(emptyList)).forAll(a.oneOf(list)));
    spec.add(equivTo.in(list.product(list)));
    spec.add(equiv(a, b).iff(car(a).eq(car(b)).and(equivTo(cdr(a)).eq(equivTo(cdr(b))))).forAll(a.oneOf(list).and(b.oneOf(list))));
    spec.add(prefixes.in(list.product(list)));
    spec.add(prefix(e, a).forAll(e.oneOf(emptyList).and(a.oneOf(list))));
    spec.add(prefix(a, e).not().forAll(e.oneOf(emptyList).and(a.oneOf(nonEmptyList))));
    spec.add(prefix(a, b).iff(car(a).eq(car(b)).and(prefix(cdr(a), cdr(b)))).forAll(a.oneOf(nonEmptyList).and(b.oneOf(nonEmptyList))));
    return Formula.and(spec);
}
Also used : Formula(kodkod.ast.Formula) Variable(kodkod.ast.Variable) ArrayList(java.util.ArrayList)

Aggregations

Variable (kodkod.ast.Variable)221 Formula (kodkod.ast.Formula)151 Expression (kodkod.ast.Expression)80 Decls (kodkod.ast.Decls)24 Solution (kodkod.engine.Solution)24 Relation (kodkod.ast.Relation)23 IntExpression (kodkod.ast.IntExpression)22 Bounds (kodkod.instance.Bounds)21 Universe (kodkod.instance.Universe)21 ArrayList (java.util.ArrayList)19 TupleFactory (kodkod.instance.TupleFactory)19 TupleSet (kodkod.instance.TupleSet)15 Solver (kodkod.engine.Solver)14 Decl (kodkod.ast.Decl)12 QuantifiedFormula (kodkod.ast.QuantifiedFormula)10 Test (org.junit.Test)10 Instance (kodkod.instance.Instance)8 BinaryExpression (kodkod.ast.BinaryExpression)5 SumExpression (kodkod.ast.SumExpression)3 Expr (edu.mit.csail.sdg.ast.Expr)2