Search in sources :

Example 26 with Formula

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))));
}
Also used : Formula(kodkod.ast.Formula) Variable(kodkod.ast.Variable)

Example 27 with Formula

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);
}
Also used : Formula(kodkod.ast.Formula) Variable(kodkod.ast.Variable)

Example 28 with Formula

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);
}
Also used : Formula(kodkod.ast.Formula)

Example 29 with Formula

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());
}
Also used : Formula(kodkod.ast.Formula) Solver(kodkod.engine.Solver) Bounds(kodkod.instance.Bounds) Solution(kodkod.engine.Solution)

Example 30 with Formula

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);
}
Also used : Formula(kodkod.ast.Formula) IntExpression(kodkod.ast.IntExpression) ArrayList(java.util.ArrayList) IntConstant(kodkod.ast.IntConstant)

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