Package kodkod.engine.bool

Examples of kodkod.engine.bool.BooleanMatrix


      matrix.set(partialIndex, factory.and(declConstraints, formula.accept(this)));
      return;
    }

    final Decl decl = decls.get(currentDecl);
    final BooleanMatrix declTransl = visit(decl);
    final int position = (int)StrictMath.pow(interpreter.universe().size(), decls.size()-currentDecl-1);
    final BooleanMatrix groundValue = factory.matrix(declTransl.dimensions());
    env = env.extend(decl.variable(), groundValue);
    for(IndexedEntry<BooleanValue> entry : declTransl) {
      groundValue.set(entry.index(), BooleanConstant.TRUE);
      comprehension(decls, formula, currentDecl+1, factory.and(entry.value(), declConstraints),
          partialIndex + entry.index()*position, matrix);
      groundValue.set(entry.index(), BooleanConstant.FALSE)
    }
    env = env.parent();
  }
View Full Code Here


   * calls cache(...) on it and returns it.
   * @return let t = lookup(cexpr) | some t => t,
   *      cache(cexpr, translate(cexpr))
   */
  public BooleanMatrix visit(Comprehension cexpr) {
    BooleanMatrix ret = lookup(cexpr);
    if (ret!=null) return ret;

    ret = interpreter.factory().matrix(Dimensions.square(interpreter.universe().size(), cexpr.decls().size()));
    comprehension(cexpr.decls(), cexpr.formula(), 0, BooleanConstant.TRUE, 0, ret);

View Full Code Here

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

    final BooleanValue condition = ifExpr.condition().accept(this);
    final BooleanMatrix thenExpr = ifExpr.thenExpr().accept(this);
    final BooleanMatrix elseExpr = ifExpr.elseExpr().accept(this);
    ret = thenExpr.choice(condition, elseExpr);

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

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

      acc.add(factory.or(declConstraints, formula.accept(this)));
      return;
    }

    final Decl decl = decls.get(currentDecl);
    final BooleanMatrix declTransl = visit(decl);
    final BooleanMatrix groundValue = factory.matrix(declTransl.dimensions());
    env = env.extend(decl.variable(), groundValue);
    for(IndexedEntry<BooleanValue> entry : declTransl) {
      groundValue.set(entry.index(), BooleanConstant.TRUE);
      all(decls, formula, currentDecl+1, factory.or(factory.not(entry.value()), declConstraints), acc);
      groundValue.set(entry.index(), BooleanConstant.FALSE)
    }
    env = env.parent();
   
  }
View Full Code Here

      acc.add(factory.and(declConstraints, formula.accept(this)));
      return;
    }

    final Decl decl = decls.get(currentDecl);
    final BooleanMatrix declTransl = visit(decl);
    final BooleanMatrix groundValue = factory.matrix(declTransl.dimensions());
    env = env.extend(decl.variable(), groundValue);
    for(IndexedEntry<BooleanValue> entry : declTransl) {
      groundValue.set(entry.index(), BooleanConstant.TRUE);
      some(decls, formula, currentDecl+1, factory.and(entry.value(), declConstraints), acc);
      groundValue.set(entry.index(), BooleanConstant.FALSE)
    }
    env = env.parent();

  }
View Full Code Here

   */
  public final BooleanValue visit(ComparisonFormula compFormula) {
    BooleanValue ret = lookup(compFormula);
    if (ret!=null) return ret;

    final BooleanMatrix left = compFormula.left().accept(this);
    final BooleanMatrix right = compFormula.right().accept(this);
    final ExprCompOperator op = compFormula.op();

    switch(op) {
    case SUBSET  : ret = left.subset(right); break;
    case EQUALS  : ret = left.eq(right); break;
View Full Code Here

   */
  public final BooleanValue visit(MultiplicityFormula multFormula) {
    BooleanValue ret = lookup(multFormula);
    if (ret!=null) return ret;

    final BooleanMatrix child = multFormula.expression().accept(this);
    final Multiplicity mult = multFormula.multiplicity();

    switch(mult) {
    case NO   : ret = child.none(); break;
    case SOME  : ret = child.some(); break;
    case ONE   : ret = child.one()break;
    case LONE   : ret = child.lone(); break;
    default :
      throw new IllegalArgumentException("Unknown multiplicity: " + mult);
    }

    return cache(multFormula, ret);
View Full Code Here

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

      values.add( expr.accept(this).choice(declConstraints, factory.integer(0)) );
      return;
    }

    final Decl decl = decls.get(currentDecl);
    final BooleanMatrix declTransl = visit(decl);
    final BooleanMatrix groundValue = factory.matrix(declTransl.dimensions());
    env = env.extend(decl.variable(), groundValue);
    for(IndexedEntry<BooleanValue> entry : declTransl) {
      groundValue.set(entry.index(), BooleanConstant.TRUE);
      sum(decls, expr, currentDecl+1, factory.and(entry.value(), declConstraints), values);
      groundValue.set(entry.index(), BooleanConstant.FALSE)
    }
    env = env.parent();
  }
View Full Code Here

TOP

Related Classes of kodkod.engine.bool.BooleanMatrix

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.