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);
}
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));
}
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);
}
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);
}
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);
}
Aggregations