use of kodkod.engine.bool.Int in project org.alloytools.alloy by AlloyTools.
the class FOL2BoolTranslator method visit.
/**
* Calls lookup(project) and returns the cached value, if any. If a translation
* has not been cached, translates the expression, calls cache(...) on it and
* returns it.
*
* @return let t = lookup(project) | some t => t, cache(project,
* project.expression.accept(this).project(translate(project.columns))
*/
@Override
public final BooleanMatrix visit(ProjectExpression project) {
BooleanMatrix ret = lookup(project);
if (ret != null)
return ret;
final Int[] cols = new Int[project.arity()];
for (int i = 0, arity = project.arity(); i < arity; i++) {
cols[i] = project.column(i).accept(this);
}
return cache(project, project.expression().accept(this).project(cols));
}
use of kodkod.engine.bool.Int in project org.alloytools.alloy by AlloyTools.
the class FOL2BoolTranslator method visit.
/**
* Calls lookup(intExpr) and returns the cached value, if any. If a translation
* has not been cached, translates the expression, calls cache(...) on it and
* returns it.
*
* @return let t = lookup(intExpr) | some t => t, cache(intExpr,
* intExpr.op(intExpr.expression.accept(this)))
*/
@Override
public final Int visit(UnaryIntExpression intExpr) {
Int ret = lookup(intExpr);
if (ret != null)
return ret;
final Int child = intExpr.intExpr().accept(this);
switch(intExpr.op()) {
case NEG:
ret = child.negate();
break;
case NOT:
ret = child.not();
break;
case ABS:
ret = child.abs();
break;
case SGN:
ret = child.sgn();
break;
default:
throw new IllegalArgumentException("Unknown operator: " + intExpr.op());
}
return cache(intExpr, ret);
}
use of kodkod.engine.bool.Int in project org.alloytools.alloy by AlloyTools.
the class FOL2BoolTranslator method visit.
/**
* Calls lookup(castExpr) and returns the cached value, if any. If a translation
* has not been cached, translates the expression, calls cache(...) on it and
* returns it.
*
* @return let t = lookup(castExpr) | some t => t, cache(castExpr,
* translate(castExpr))
*/
@Override
public BooleanMatrix visit(IntToExprCast castExpr) {
BooleanMatrix ret = lookup(castExpr);
if (ret != null)
return ret;
final Int child = castExpr.intExpr().accept(this);
final BooleanFactory factory = interpreter.factory();
final IntSet ints = interpreter.ints();
ret = factory.matrix(Dimensions.square(interpreter.universe().size(), 1));
switch(castExpr.op()) {
case INTCAST:
for (IntIterator iter = ints.iterator(); iter.hasNext(); ) {
int i = iter.next();
int atomIndex = interpreter.interpret(i);
ret.set(atomIndex, factory.or(ret.get(atomIndex), child.eq(factory.integer(i))));
}
ret.setDefCond(child.defCond());
break;
case BITSETCAST:
final List<BooleanValue> twosComplement = child.twosComplementBits();
final int msb = twosComplement.size() - 1;
// handle all bits but the sign bit
for (int i = 0; i < msb; i++) {
int pow2 = 1 << i;
if (ints.contains(pow2)) {
ret.set(interpreter.interpret(pow2), twosComplement.get(i));
}
}
// handle the sign bit
if (ints.contains(-1 << msb)) {
ret.set(interpreter.interpret(-1 << msb), twosComplement.get(msb));
}
break;
default:
throw new IllegalArgumentException("Unknown cast operator: " + castExpr.op());
}
return cache(castExpr, ret);
}
use of kodkod.engine.bool.Int in project org.alloytools.alloy by AlloyTools.
the class Evaluator method evaluate.
/**
* Evaluates the specified int expession with respect to the relation-tuple
* mappings given by this.instance and using this.options.
*
* @return the integer to which the expression evaluates given the mappings in
* this.instance and the options in this.options.
* @throws kodkod.engine.fol2sat.HigherOrderDeclException intExpr contains a
* higher order declaration
* @throws kodkod.engine.fol2sat.UnboundLeafException intExpr contains an
* undeclared variable or a relation not mapped by this.instance
*/
public int evaluate(IntExpression intExpr) {
if (intExpr == null)
throw new NullPointerException("intexpression");
final Int sol = Translator.evaluate(intExpr, instance, options);
this.wasOverflow = sol.defCond().getAccumOverflow() == BooleanConstant.TRUE;
return sol.value();
}
use of kodkod.engine.bool.Int in project org.alloytools.alloy by AlloyTools.
the class FOL2BoolTranslator method visit.
/**
* Calls lookup(intExpr) and returns the cached value, if any. If a translation
* has not been cached, translates the expression, calls cache(...) on it and
* returns it.
*
* @return let t = lookup(intExpr) | some t => t, cache(intExpr,
* translate(intExpr))
*/
@Override
public final Int visit(ExprToIntCast intExpr) {
Int ret = lookup(intExpr);
if (ret != null)
return ret;
vars = vars.createNested();
BooleanMatrix expr = intExpr.expression().accept(this);
switch(intExpr.op()) {
case CARDINALITY:
ret = expr.cardinality();
break;
case SUM:
final IntSet ints = interpreter.ints();
ret = sum(expr, ints.iterator(), 0, ints.size() - 1);
break;
default:
throw new IllegalArgumentException("unknown operator: " + intExpr.op());
}
for (Variable v : vars) ret.defCond().addVar(v);
vars = vars.parent();
return cache(intExpr, ret);
}
Aggregations