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