use of kodkod.ast.Formula in project org.alloytools.alloy by AlloyTools.
the class DiffEg method decls.
/**
* Returns the formulas implicit in the declarations.
*
* @return formulas implicit in:
*
* <pre>
* sig Subject {}
* sig Resource {}
* sig Action {}
* one sig Request {s : Subject, r : Resource, a : Action }
* sig Conflicted {s : Subject, r : Resource}
* </pre>
*/
public final Formula decls() {
// one Request
final Formula f0 = Request.one();
// s is a function from Request to Subject
final Formula f1 = sRequest.function(Request, Subject);
// r is a function from Request to Resource
final Formula f2 = rRequest.function(Request, Resource);
// a is a function from Request to Action
final Formula f3 = action.function(Request, Action);
// s is a function from Conflicted to Subject
final Formula f4 = sConflicted.function(Conflicted, Subject);
// r is a function from Conflicted to Resource
final Formula f5 = rConflicted.function(Conflicted, Resource);
return f0.and(f1).and(f2).and(f3).and(f4).and(f5);
}
use of kodkod.ast.Formula in project org.alloytools.alloy by AlloyTools.
the class FileSystem method decls.
/**
* Returns the declaration constraints.
*
* @return declaration constraints
*/
public final Formula decls() {
// File and Dir partition object
final Formula f0 = Obj.eq(File.union(Dir)).and(File.intersection(Dir).no());
// Root and Cur are in Dir and do not intersect
final Formula f1 = Root.in(Dir).and(Cur.in(Dir)).and(Root.intersection(Cur).no());
// don't need to specify that Dir, Name, and DirEntry are disjoint;
// implied by bounds
final Formula f2 = entries.in(Dir.product(DirEntry));
final Formula f3 = parent.partialFunction(Dir, Dir);
final Formula f4 = name.function(DirEntry, Name);
final Formula f5 = contents.function(DirEntry, Obj);
return f0.and(f1).and(f2).and(f3).and(f4).and(f5);
}
use of kodkod.ast.Formula in project org.alloytools.alloy by AlloyTools.
the class FileSystem method main.
/**
* Usage: java examples.alloy.FileSystem [scope]
*/
public static void main(String[] args) {
if (args.length < 1)
usage();
try {
final int n = Integer.parseInt(args[0]);
final FileSystem model = new FileSystem();
final Formula f = model.checkNoDirAliases();
System.out.println(f);
final Bounds b = model.bounds(n);
final Solver solver = new Solver();
solver.options().setSolver(SATFactory.MiniSat);
final Solution s = solver.solve(f, b);
System.out.println(s);
} catch (NumberFormatException nfe) {
usage();
} catch (HigherOrderDeclException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnboundLeafException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of kodkod.ast.Formula in project org.alloytools.alloy by AlloyTools.
the class Hotel method freshIssue.
/**
* Returns FreshIssue fact.
*
* @return FressIssue fact.
*/
public Formula freshIssue() {
// -- don't issue same key twice
// all disj e1, e2: Checkin | e1.card.k2 != e2.card.k2
// -- don't issue key initially installed in lock
// all e: Checkin | e.card.k2 !in Room.key.first
final List<Formula> invs = new ArrayList<Formula>();
final Variable e1 = Variable.unary("e1");
final Variable e2 = Variable.unary("e2");
final Variable e = Variable.unary("e");
invs.add(e1.eq(e2).not().implies(e1.join(card).join(k2).eq(e2.join(card).join(k2)).not()).forAll(e1.oneOf(Checkin).and(e2.oneOf(Checkin))));
invs.add(e.join(card).join(k2).in(Room.join(key).join(first)).not().forAll(e.oneOf(Checkin)));
return Formula.and(invs);
}
use of kodkod.ast.Formula in project org.alloytools.alloy by AlloyTools.
the class Hotel method noIntervening.
/**
* Returns the noIntervening fact.
*
* @return noIntervening fact.
*/
public Formula noIntervening() {
// fact NoIntervening {
// all c: Checkin - pre.last |
// some e: Enter | e.pre = c.post and e.room = c.room and e.guest =
// c.guest
// }
final Variable c = Variable.unary("c");
final Variable e = Variable.unary("e");
final Formula f = e.join(pre).eq(c.join(post)).and(e.join(room).eq(c.join(room))).and(e.join(guest).eq(c.join(guest)));
return f.forSome(e.oneOf(Enter)).forAll(c.oneOf(Checkin.difference(pre.join(last))));
}
Aggregations