Java Code Examples for kodkod.ast.Expression#INTS

The following examples show how to use kodkod.ast.Expression#INTS . 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: LeafInterpreter.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a {@link kodkod.engine.bool.BooleanMatrix matrix} m of
 * {@link kodkod.engine.bool.BooleanValue boolean formulas} representing the
 * specified constant expression.
 *
 * @return { m: BooleanMatrix | let dset = [0..this.universe.size()^c.arity) |
 *         m.dimensions.dimensions = [0..c.arity) ->one this.universe.size() &&
 *         c = UNIV => m.elements[dset] = TRUE, c = NONE => m.elements[dset] =
 *         FALSE, c = IDEN => (all i: dset | (some j: int | i =
 *         j*(1+this.universe.size())) => m.elements[i] = TRUE, m.elements[i] =
 *         FALSE), c = INT => (all i: dset | (some j: int | this.interpret(j)=i)
 *         => m.elements[i] = TRUE, m.elements[i] = FALSE }
 */
public final BooleanMatrix interpret(ConstantExpression c) {
    final int univSize = universe().size();
    if (c == Expression.UNIV) {
        final IntSet all = Ints.rangeSet(Ints.range(0, univSize - 1));
        return factory().matrix(Dimensions.square(univSize, 1), all, all);
    } else if (c == Expression.IDEN) {
        final Dimensions dim2 = Dimensions.square(univSize, 2);
        final IntSet iden = Ints.bestSet(dim2.capacity());
        for (int i = 0; i < univSize; i++) {
            iden.add(i * univSize + i);
        }
        return factory().matrix(dim2, iden, iden);
    } else if (c == Expression.NONE) {
        return factory().matrix(Dimensions.square(univSize, 1), Ints.EMPTY_SET, Ints.EMPTY_SET);
    } else if (c == Expression.INTS) {
        final IntSet ints = Ints.bestSet(univSize);
        for (IntIterator iter = ints().iterator(); iter.hasNext();) {
            ints.add(interpret(iter.next()));
        }
        return factory().matrix(Dimensions.square(univSize, 1), ints, ints);
    } else {
        throw new IllegalArgumentException("unknown constant expression: " + c);
    }
}
 
Example 2
Source File: TranslateKodkodToJava.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public void visit(ConstantExpression x) {
    if (map.containsKey(x))
        return;
    String newname = null;
    if (x == Expression.NONE)
        newname = "Expression.NONE";
    else if (x == Expression.UNIV)
        newname = "Expression.UNIV";
    else if (x == Expression.IDEN)
        newname = "Expression.IDEN";
    else if (x == Expression.INTS)
        newname = "Expression.INTS";
    else
        throw new RuntimeException("Unknown kodkod ConstantExpression \"" + x + "\" encountered");
    map.put(x, newname);
}
 
Example 3
Source File: LeafInterpreter.java    From kodkod with MIT License 6 votes vote down vote up
/**
 * Returns a {@link kodkod.engine.bool.BooleanMatrix matrix} m of 
 * {@link kodkod.engine.bool.BooleanValue boolean formulas} representing
 * the specified constant expression.    
 * @return { m: BooleanMatrix | let dset = [0..this.universe.size()^c.arity) | 
 *           m.dimensions.dimensions = [0..c.arity) ->one this.universe.size() && 
 *           c = UNIV => m.elements[dset] = TRUE, c = NONE => m.elements[dset] = FALSE,
 *           c = IDEN => (all i: dset | (some j: int | i = j*(1+this.universe.size())) => m.elements[i] = TRUE, m.elements[i] = FALSE),
 *           c = INT => (all i: dset | (some j: int | this.interpret(j)=i) => m.elements[i] = TRUE, m.elements[i] = FALSE }
 */
public final BooleanMatrix interpret(ConstantExpression c) {
	final int univSize = universe().size();
	if (c==Expression.UNIV) {
		final IntSet all =  Ints.rangeSet(Ints.range(0, univSize-1));
		return factory().matrix(Dimensions.square(univSize, 1), all, all);
	} else if (c==Expression.IDEN) {
		final Dimensions dim2 = Dimensions.square(univSize, 2);
		final IntSet iden = Ints.bestSet(dim2.capacity());
		for(int i = 0; i < univSize; i++) {
			iden.add(i*univSize + i);
		}			
		return factory().matrix(dim2, iden, iden);
	} else if (c==Expression.NONE) {
		return factory().matrix(Dimensions.square(univSize, 1), Ints.EMPTY_SET, Ints.EMPTY_SET);
	} else if (c==Expression.INTS) {
		final IntSet ints = Ints.bestSet(univSize);
		for(IntIterator iter = ints().iterator(); iter.hasNext(); ) {
			ints.add(interpret(iter.next()));
		}
		return factory().matrix(Dimensions.square(univSize, 1), ints, ints);
	} else {
		throw new IllegalArgumentException("unknown constant expression: " + c);
	}
}
 
Example 4
Source File: BoundsComputer.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
/**
 * If ex is a simple combination of Relations, then return that combination,
 * else return null.
 */
private Expression sim(Expr ex) {
    while (ex instanceof ExprUnary) {
        ExprUnary u = (ExprUnary) ex;
        if (u.op != ExprUnary.Op.NOOP && u.op != ExprUnary.Op.EXACTLYOF)
            break;
        ex = u.sub;
    }
    if (ex instanceof ExprBinary) {
        ExprBinary b = (ExprBinary) ex;
        if (b.op == ExprBinary.Op.ARROW || b.op == ExprBinary.Op.PLUS || b.op == ExprBinary.Op.JOIN) {
            Expression left = sim(b.left);
            if (left == null)
                return null;
            Expression right = sim(b.right);
            if (right == null)
                return null;
            if (b.op == ExprBinary.Op.ARROW)
                return left.product(right);
            if (b.op == ExprBinary.Op.PLUS)
                return left.union(right);
            else
                return left.join(right);
        }
    }
    if (ex instanceof ExprConstant) {
        switch (((ExprConstant) ex).op) {
            case EMPTYNESS :
                return Expression.NONE;
        }
    }
    if (ex == Sig.NONE)
        return Expression.NONE;
    if (ex == Sig.SIGINT)
        return Expression.INTS;
    if (ex instanceof Sig)
        return sol.a2k((Sig) ex);
    if (ex instanceof Field)
        return sol.a2k((Field) ex);
    return null;
}