use of kodkod.ast.Formula in project org.alloytools.alloy by AlloyTools.
the class Trees method inCycle.
/**
* Returns the inCycle predicate.
*
* @return
*
* <pre>
* pred InCycle(v: V, c: V -> V) {
* v in v.c or
* some v': v.c | v' in v.^(c - v->v' - v'->v)
* }
* </pre>
*/
public final Formula inCycle(Expression v, Expression c) {
final Formula f0 = v.in(v.join(c));
final Variable vp = Variable.unary("v'");
final Formula f1 = vp.in(v.join((c.difference(v.product(vp)).difference(vp.product(v))).closure()));
return f0.or(f1.forSome(vp.oneOf(v.join(c))));
}
use of kodkod.ast.Formula in project org.alloytools.alloy by AlloyTools.
the class Trees method statement2.
/**
* Returns statement 2.
*
* @return
*
* <pre>
* pred Statement2() {
* Connected(E) and
* all u: V | all v: u.E | not Connected( E - (u->v) - (v->u) )
* }
* </pre>
*/
public final Formula statement2() {
final Variable u = Variable.unary("u");
final Variable v = Variable.unary("v");
final Formula f0 = connected(E);
final Formula f1 = connected(E.difference(u.product(v)).difference(v.product(u))).not();
final Formula f2 = f1.forAll(v.oneOf(u.join(E))).forAll(u.oneOf(V));
return f0.and(f2);
}
use of kodkod.ast.Formula in project org.alloytools.alloy by AlloyTools.
the class Bigconfig method invariants.
/**
* Returns the invariants predicate.
*
* @return pred invariants() { -- every site has at least one router Site in
* Router.site -- links are symmetric and non-reflexive link = ~link no
* link & iden }
*/
public Formula invariants() {
Formula atLeastARouter = Site.in(Router.join(site));
Formula linksSymmetric = link.eq(link.transpose());
Formula linksNotReflexive = link.intersection(Expression.IDEN).no();
return atLeastARouter.and(linksSymmetric).and(linksNotReflexive);
}
use of kodkod.ast.Formula in project org.alloytools.alloy by AlloyTools.
the class IntConstraints method main.
/**
* Usage: java examples.IntConstraints
*/
public static void main(String[] args) {
final IntConstraints model = new IntConstraints();
final Bounds bounds = model.bounds();
final Formula formula = model.formula();
final Solver solver = new Solver();
solver.options().setBitwidth(32);
solver.options().setSolver(SATFactory.MiniSat);
final Solution sol = solver.solve(formula, bounds);
model.print(sol, solver.options());
}
use of kodkod.ast.Formula in project org.alloytools.alloy by AlloyTools.
the class IntConstraints method formula.
/**
* Returns the formula a1 <= v1 <= a2 <= v2 .... a1000<=v1000
*
* @return the formula
*/
public final Formula formula() {
final List<Formula> constraints = new ArrayList<Formula>(2000);
final List<IntConstant> constants = new ArrayList<IntConstant>(1001);
for (int i = low; i <= high; i += 10) {
constants.add(IntConstant.constant(i));
}
for (int i = 0; i < 1000; i++) {
// convert to primitive int
IntExpression varExpr = var[i].sum();
// a_i <= v_i
constraints.add(constants.get(i).lte(varExpr));
// v_i <=
constraints.add(varExpr.lte(constants.get(i + 1)));
// a_(i+1)
}
return Formula.and(constraints);
}
Aggregations