Search in sources :

Example 41 with Formula

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

the class DNACuts method show.

/**
 * Returns the show predicate.
 *
 * @return the show predicate.
 */
public Formula show() {
    final Formula f0 = Base.in(Link.join(base));
    final Formula f1 = JoinLink.some();
    final Formula f2 = CutLink.some();
    return declarations().and(cutChainLength()).and(cutLinkUniqueness()).and(f0).and(f1).and(f2);
}
Also used : Formula(kodkod.ast.Formula)

Example 42 with Formula

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

the class DNACuts method cutChainLength.

/**
 * Returns the cutChainLength constraint. (Similar to CutChainsAtMost6BasesLong
 * fact, but with the cut chain length as specified during construction.)
 *
 * @return the cutChainLength constraint
 */
public Formula cutChainLength() {
    Formula ret = Formula.FALSE;
    final Variable c = Variable.unary("c");
    for (int i = 0; i < neighbor.length; i++) {
        ret = ret.or(c.join(neighbor[i]).in(JoinLink));
    }
    return ret.forAll(c.oneOf(CutLink));
}
Also used : Formula(kodkod.ast.Formula) Variable(kodkod.ast.Variable)

Example 43 with Formula

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

the class DNACuts method cutLinkUniqueness.

/**
 * Returns the cutLinkUniqueness constraint.
 *
 * @return the cutLinkUniqueness constraint.
 */
public Formula cutLinkUniqueness() {
    final Variable c1 = Variable.unary("c1");
    final Variable c2 = Variable.unary("c2");
    final Formula f0 = c1.eq(c2).not().and(next.join(c1).in(JoinLink)).and(next.join(c2).in(JoinLink));
    Formula f = c1.join(base).in(c2.join(base).union(c2.join(base).join(partner))).not();
    for (int i = 0; i < neighbor.length; i++) {
        Expression c1n = c1.join(neighbor[i]), c2n = c2.join(neighbor[i]);
        f = f.or(c1n.in(JoinLink)).or(c2n.in(JoinLink));
        f = f.or(c1n.join(base).in(c2n.join(base).union(c2n.join(base).join(partner))).not());
    }
    return f0.implies(f).forAll(c1.oneOf(CutLink).and(c2.oneOf(CutLink)));
}
Also used : Formula(kodkod.ast.Formula) Variable(kodkod.ast.Variable) Expression(kodkod.ast.Expression)

Example 44 with Formula

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

the class Dijkstra method grabOrRelease.

/**
 * Returns the GrabOrRelease predicate.
 *
 * @return
 *
 *         <pre>
 * pred GrabOrRelease () {
 *    Initial(so/first()) &&
 *    (
 *    all pre: State - so/last () | let post = so/next (pre) |
 *       (post.holds = pre.holds && post.waits = pre.waits)
 *        ||
 *       (some p: Process, m: Mutex | pre::GrabMutex (p, m, post))
 *        ||
 *       (some p: Process, m: Mutex | pre::ReleaseMutex (p, m, post))
 *
 *    )
 * }
 *         </pre>
 */
public Formula grabOrRelease() {
    final Variable pre = Variable.unary("pre");
    final Expression post = pre.join(sord);
    final Formula f1 = post.join(holds).eq(pre.join(holds));
    final Formula f2 = post.join(waits).eq(pre.join(waits));
    final Variable p = Variable.unary("p");
    final Variable m = Variable.unary("m");
    final Decls d = p.oneOf(Process).and(m.oneOf(Mutex));
    final Formula f3 = grabMutex(pre, post, p, m).forSome(d);
    final Formula f4 = releaseMutex(pre, post, p, m).forSome(d);
    return initial(sfirst).and(((f1.and(f2)).or(f3).or(f4)).forAll(pre.oneOf(State.difference(slast))));
}
Also used : Formula(kodkod.ast.Formula) Variable(kodkod.ast.Variable) Decls(kodkod.ast.Decls) Expression(kodkod.ast.Expression)

Example 45 with Formula

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

the class Dijkstra method main.

/**
 * Usage: java examples.Dijkstra [# states] [# processes] [# mutexes]
 */
public static void main(String[] args) {
    if (args.length < 3)
        usage();
    final Dijkstra model = new Dijkstra();
    final Solver solver = new Solver();
    solver.options().setSolver(SATFactory.MiniSat);
    try {
        final Formula noDeadlocks = model.checkDijkstraPreventsDeadlocks();
        final int states = Integer.parseInt(args[0]);
        final int processes = Integer.parseInt(args[1]);
        final int mutexes = Integer.parseInt(args[2]);
        final Bounds bounds = model.bounds(states, processes, mutexes);
        System.out.println("*****check DijkstraPreventsDeadlocks for " + states + " State, " + processes + " Process, " + mutexes + " Mutex*****");
        System.out.println(noDeadlocks);
        // System.out.println(bounds);
        Solution sol1 = solver.solve(noDeadlocks, bounds);
        System.out.println(sol1);
    // System.out.println(solver.solve(model.grabOrRelease().and(model.declarations()).
    // and(model.waits.some()).and(model.deadlock()), bounds));
    } catch (NumberFormatException nfe) {
        usage();
    }
}
Also used : Formula(kodkod.ast.Formula) Solver(kodkod.engine.Solver) 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