Java Code Examples for kodkod.ast.Expression#one()

The following examples show how to use kodkod.ast.Expression#one() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BoundsComputer.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method that returns the constraint that the sig has exactly "n"
 * elements, or at most "n" elements
 */
private Formula size(Sig sig, int n, boolean exact) {
    Expression a = sol.a2k(sig);
    if (n <= 0)
        return a.no();
    if (n == 1)
        return exact ? a.one() : a.lone();
    Formula f = exact ? Formula.TRUE : null;
    Decls d = null;
    Expression sum = null;
    while (n > 0) {
        n--;
        Variable v = Variable.unary("v" + Integer.toString(TranslateAlloyToKodkod.cnt++));
        kodkod.ast.Decl dd = v.oneOf(a);
        if (d == null)
            d = dd;
        else
            d = dd.and(d);
        if (sum == null)
            sum = v;
        else {
            if (f != null)
                f = v.intersection(sum).no().and(f);
            sum = v.union(sum);
        }
    }
    if (f != null)
        return sum.eq(a).and(f).forSome(d);
    else
        return a.no().or(sum.eq(a).forSome(d));
}
 
Example 2
Source File: GraphColoring.java    From kodkod with MIT License 3 votes vote down vote up
/**
 * Returns a formula stating that all vertices
 * have  one color, and that no two adjacent
 * vertices have intersecting colors.
 * @return a formula stating that all vertices
 * have one color, and that no two adjacent
 * vertices have intersecting colors.
 */
public Formula coloring() {
	final Variable v = Variable.unary("v");
	final Expression vcolor = v.join(v2c);
	final Formula f0 = vcolor.one();
	final Formula f1 = vcolor.intersection(v.join(edges).join(v2c)).no();
	return f0.and(f1).forAll(v.oneOf(vertex));
}