Package kodkod.engine.bool

Examples of kodkod.engine.bool.Int


   * @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);
//    System.out.println(sol);
    return sol.value();
  }
View Full Code Here


   */
  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))));
      }
      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)) {
View Full Code Here

   * calls cache(...) on it and returns it.
   * @return let t = lookup(intExpr) | some t => t,
   *       cache(intExpr, intExpr.condition.accept(this).choice(intExpr.then.accept(this), intExpr.else.accept(this)))
   */
  public final Int visit(IfIntExpression intExpr) {
    Int ret = lookup(intExpr);
    if (ret!=null) return ret;

    final BooleanValue condition = intExpr.condition().accept(this);
    final Int thenExpr = intExpr.thenExpr().accept(this);
    final Int elseExpr = intExpr.elseExpr().accept(this);
    ret = thenExpr.choice(condition, elseExpr);

    return cache(intExpr, ret);
  }
View Full Code Here

    else if (low==high) {
      int i = iter.next();
      return interpreter.factory().integer(i, m.get(interpreter.interpret(i)));
    } else {
      final int mid = (low + high) / 2;
      final Int lsum = sum(m, iter, low, mid);
      final Int hsum = sum(m, iter, mid+1, high);
      return lsum.plus(hsum);
    }
  }
View Full Code Here

   * calls cache(...) on it and returns it.
   * @return let t = lookup(intExpr) | some t => t,
   *   cache(intExpr, translate(intExpr))
   */
  public final Int visit(ExprToIntCast intExpr) {
    Int ret = lookup(intExpr);
    if (ret!=null) return ret;
    switch(intExpr.op()) {
    case CARDINALITY :
      ret = intExpr.expression().accept(this).cardinality(); break;
    case SUM         :
View Full Code Here

   * calls cache(...) on it and returns it.
   * @return let t = lookup(intExpr) | some t => t,
   *   cache(intExpr, intExpr.left.accept(this) intExpr.op intExpr.right.accept(this))
   */
  public final Int visit(BinaryIntExpression intExpr) {
    Int ret = lookup(intExpr);
    if (ret!=null) return ret;
    final Int left = intExpr.left().accept(this);
    final Int right = intExpr.right().accept(this);
    switch(intExpr.op()) {
    case PLUS      : ret = left.plus(right); break;
    case MINUS     : ret = left.minus(right); break;
    case MULTIPLY   : ret = left.multiply(right); break;
    case DIVIDE   : ret = left.divide(right); break;
View Full Code Here

   * calls cache(...) on it and returns it.
   * @return let t = lookup(intExpr) | some t => t,
   *   cache(intExpr, intExpr.left.accept(this) intExpr.op intExpr.right.accept(this))
   */
  public final Int visit(NaryIntExpression intExpr) {
    Int ret = lookup(intExpr);
    if (ret!=null) return ret;
    final Int first = intExpr.child(0).accept(this);
    final Int[] rest = new Int[intExpr.size()-1];
    for(int i = 0; i < rest.length; i++) {   rest[i] = intExpr.child(i+1).accept(this); }
    switch(intExpr.op()) {
    case PLUS      : ret = first.plus(rest); break;
    case MULTIPLY   : ret = first.multiply(rest); break;
    case AND    : ret = first.and(rest); break;
    case OR      : ret = first.or(rest); break;
    default    :
      throw new IllegalArgumentException("Unknown nary operator: " + intExpr.op());
    }
    return cache(intExpr, ret);
  }
View Full Code Here

   * calls cache(...) on it and returns it.
   * @return let t = lookup(intExpr) | some t => t,
   *   cache(intExpr, intExpr.op(intExpr.expression.accept(this)))
   */
  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);
  }
View Full Code Here

   * calls cache(...) on it and returns it.
   * @return let t = lookup(intExpr) | some t => t,
   *   cache(intExpr, translate(intExpr))
   */
  public final Int visit(SumExpression intExpr) {
    final Int ret = lookup(intExpr);
    if (ret!=null) return ret;
    final List<Int> values = new ArrayList<Int>();
    sum(intExpr.decls(), intExpr.intExpr(), 0, BooleanConstant.TRUE, values);
    for(int sums = values.size(); sums > 1; sums -= sums/2) {
      final int max = sums-1;
View Full Code Here

   *   cache(intComp, intComp.left.accept(this) intComp.op intComp.right.accept(this))
   */
  public final BooleanValue visit(IntComparisonFormula intComp) {
    BooleanValue ret = lookup(intComp);
    if (ret!=null) return ret;
    final Int left = intComp.left().accept(this);
    final Int right = intComp.right().accept(this);
    switch(intComp.op()) {
    case EQ  : ret = left.eq(right); break;
    case LT  : ret = left.lt(right); break;
    case LTE : ret = left.lte(right); break;
    case GT  : ret = left.gt(right); break;
View Full Code Here

TOP

Related Classes of kodkod.engine.bool.Int

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.