Search in sources :

Example 91 with Formula

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

the class Hotel method recodeEnterInvariants.

/**
 * Returns the invariants for RecodeEnter and its fields.
 *
 * @return invariants for RecodeEnter and its fields.
 */
public Formula recodeEnterInvariants() {
    // sig RecodeEnter extends Enter { }
    // {
    // card.k1 = room.key.pre
    // key.post = key.pre ++ room -> card.k2
    // 
    // prev.unchanged
    // holds.unchanged
    // occ.unchanged
    // }
    final List<Formula> invs = new ArrayList<Formula>();
    invs.add(RecodeEnter.in(Enter));
    final Variable r = Variable.unary("n");
    invs.add(card(r).join(k1).eq(room(r).join(key).join(pre(r))).forAll(r.oneOf(RecodeEnter)));
    invs.add(key.join(post(r)).eq(key.join(pre(r)).override(room(r).product(card(r).join(k2)))).forAll(r.oneOf(RecodeEnter)));
    invs.add(unchanged(r, prev).forAll(r.oneOf(RecodeEnter)));
    invs.add(unchanged(r, holds).forAll(r.oneOf(RecodeEnter)));
    invs.add(unchanged(r, occ).forAll(r.oneOf(RecodeEnter)));
    return Formula.and(invs);
}
Also used : Formula(kodkod.ast.Formula) Variable(kodkod.ast.Variable) ArrayList(java.util.ArrayList)

Example 92 with Formula

use of kodkod.ast.Formula 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 93 with Formula

use of kodkod.ast.Formula 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 94 with Formula

use of kodkod.ast.Formula 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 95 with Formula

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

the class ToyLists method main.

/**
 * Usage: java examples.alloy.ToyLists <# of lists> <# of things> <id of
 * assertion to check or 0 to just run the spec>
 */
public static void main(String[] args) {
    if (args.length < 3)
        usage();
    try {
        final int l = Integer.parseInt(args[0]);
        final int t = Integer.parseInt(args[1]);
        final int a = Integer.parseInt(args[2]);
        final ToyLists model = new ToyLists();
        final Bounds b = model.bounds(l, t);
        final Solver solver = new Solver();
        solver.options().setSolver(SATFactory.MiniSatProver);
        solver.options().setLogTranslation(1);
        solver.options().setSymmetryBreaking(1000);
        final Formula f;
        switch(a) {
            case 0:
                f = model.spec();
                break;
            case 1:
                f = model.spec().and(model.equivPrefix().not());
                break;
            case 2:
                f = model.spec().and(model.loneList().not());
                break;
            case 3:
                f = model.spec().and(model.transitivePrefixes().not());
                break;
            case 4:
                f = model.spec().and(model.acyclicity().not());
                break;
            case 5:
                f = model.spec().and(model.equivReflexivity().not());
                break;
            default:
                usage();
                throw new AssertionError("dead code");
        }
        final Solution sol = solver.solve(f, b);
        if (sol.instance() != null) {
            System.out.println(sol);
        } else {
            System.out.println(sol.outcome());
            System.out.println(sol.stats());
            System.out.println("Top level formulas: " + sol.proof().log().roots().size());
            System.out.println("Initial core: " + sol.proof().highLevelCore().size());
            sol.proof().minimize(new AdaptiveRCEStrategy(sol.proof().log()));
            System.out.println("Minimal core: " + sol.proof().highLevelCore().size());
            final Set<Formula> core = Nodes.allRoots(f, sol.proof().highLevelCore().values());
            for (Formula c : core) {
                System.out.println(c);
            }
            System.out.print("checking the core ... ");
            if (solver.solve(Formula.and(core), b).instance() == null) {
                System.out.println("correct.");
            } else {
                System.out.println("incorrect!");
            }
        }
    } catch (NumberFormatException nfe) {
        usage();
    }
}
Also used : Formula(kodkod.ast.Formula) Solver(kodkod.engine.Solver) AdaptiveRCEStrategy(kodkod.engine.ucore.AdaptiveRCEStrategy) Bounds(kodkod.instance.Bounds) Solution(kodkod.engine.Solution)

Aggregations

Formula (kodkod.ast.Formula)346 Variable (kodkod.ast.Variable)151 Solution (kodkod.engine.Solution)101 Expression (kodkod.ast.Expression)95 Bounds (kodkod.instance.Bounds)83 QuantifiedFormula (kodkod.ast.QuantifiedFormula)72 Solver (kodkod.engine.Solver)67 BinaryFormula (kodkod.ast.BinaryFormula)50 NaryFormula (kodkod.ast.NaryFormula)49 Relation (kodkod.ast.Relation)45 NotFormula (kodkod.ast.NotFormula)43 ComparisonFormula (kodkod.ast.ComparisonFormula)40 IntExpression (kodkod.ast.IntExpression)40 IntComparisonFormula (kodkod.ast.IntComparisonFormula)39 MultiplicityFormula (kodkod.ast.MultiplicityFormula)39 Universe (kodkod.instance.Universe)37 ArrayList (java.util.ArrayList)35 TupleFactory (kodkod.instance.TupleFactory)35 ConstantFormula (kodkod.ast.ConstantFormula)29 TupleSet (kodkod.instance.TupleSet)29