Package kodkod.engine.bool

Examples of kodkod.engine.bool.BooleanMatrix


   * @throws kodkod.engine.fol2sat.UnboundLeafException - the expression contains an undeclared variable or
   * a relation not mapped by this.instance
   */
  public TupleSet evaluate(Expression expression){
    if (expression == null) throw new NullPointerException("expression");
    final BooleanMatrix sol = Translator.evaluate(expression,instance,options);
    return instance.universe().factory().setOf(expression.arity(), sol.denseIndices());
  }
View Full Code Here


    if (!lowers.containsKey(r))
      throw new UnboundLeafException("Unbound relation: ", r);
    final IntSet lowerBound = lowers.get(r).indexView();
    final IntSet upperBound = uppers.get(r).indexView();
   
    final BooleanMatrix m = factory.matrix(Dimensions.square(universe().size(), r.arity()), upperBound, lowerBound);
   
    if (upperBound.size() > lowerBound.size()) {
      int varId = vars.get(r).min();
      for (IntIterator indeces = upperBound.iterator(); indeces.hasNext();) {
        int tupleIndex = indeces.next();
        if (!lowerBound.contains(tupleIndex)) 
          m.set(tupleIndex, factory.variable(varId++));
      }
    }
    return m;
  }
View Full Code Here

      }
      skolemEnv = skolemEnv.extend(info.decl.variable(), info.upperBound);
      skolemExpr = info.decl.variable().join(skolemExpr);
    }

    BooleanMatrix matrixBound = upperBound(skolemDecl.expression(), skolemEnv);
    for(int i = depth-1; i >= 0; i--) {
      matrixBound = nonSkolems.get(i).upperBound.cross(matrixBound);
    }

    final TupleSet skolemBound = bounds.universe().factory().setOf(arity, matrixBound.denseIndices());
    bounds.bound(skolem, skolemBound);

    return skolemExpr;
 
View Full Code Here

          RelationParts rparts = rIter.next();
          Relation r = rparts.relation;
         
          if (!rparts.representatives.contains(sym.min())) continue// r does not range over sym
         
          BooleanMatrix m = interpreter.interpret(r);
          for(IndexedEntry<BooleanValue> entry : m) {
            int permIndex = permutation(r.arity(), entry.index(), prevIndex, curIndex);
            BooleanValue permValue = m.get(permIndex);
            if (permIndex==entry.index() || atSameIndex(original, permValue, permuted, entry.value()))
              continue;
           
            original.add(entry.value());
            permuted.add(permValue);     
View Full Code Here

   **/
  @SuppressWarnings("unchecked")
  static final BooleanMatrix approximate(AnnotatedNode<Expression> annotated, LeafInterpreter interpreter, Environment<BooleanMatrix> env) {
    final FOL2BoolTranslator approximator = new FOL2BoolTranslator(new FOL2BoolCache(annotated), interpreter, env) {
      public final BooleanMatrix visit(BinaryExpression binExpr) {
        final BooleanMatrix ret = lookup(binExpr);
        if (ret!=null) return ret;
        switch(binExpr.op()){
        case DIFFERENCE  : return cache(binExpr, binExpr.left().accept(this));
        case OVERRIDE    : return cache(binExpr, binExpr.left().accept(this).or(binExpr.right().accept(this)));
        default      : return super.visit(binExpr);
        }
      }
      public final BooleanMatrix visit(Comprehension cexpr) {
        final BooleanMatrix ret = lookup(cexpr);
        return ret!=null ? ret : cache(cexpr, super.visit((Comprehension)Formula.TRUE.comprehension(cexpr.decls())));
      }
      public BooleanMatrix visit(IfExpression ifExpr) {
        final BooleanMatrix ret = lookup(ifExpr);
        return ret!=null ? ret : cache(ifExpr, ifExpr.thenExpr().accept(this).or(ifExpr.elseExpr().accept(this)));
      }
      public BooleanMatrix visit(IntToExprCast castExpr) {
        BooleanMatrix ret = lookup(castExpr);
        if (ret!=null) return ret;
        switch(castExpr.op()) {
        case INTCAST  : return cache(castExpr, Expression.INTS.accept(this));
        case BITSETCAST  :
          final BooleanFactory factory = super.interpreter.factory();
          ret = factory.matrix(Dimensions.square(super.interpreter.universe().size(), 1));
          final IntSet ints = super.interpreter.ints();
          final int msb = factory.bitwidth()-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(super.interpreter.interpret(pow2), BooleanConstant.TRUE);
            }
          }
          // handle the sign bit
          if (ints.contains(-1<<msb)) {
            ret.set(super.interpreter.interpret(-1<<msb), BooleanConstant.TRUE);
          }
          return cache(castExpr, ret);
        default : throw new IllegalArgumentException("Unknown operator: " + castExpr.op());
        }

View Full Code Here

   * calls cache(...) on it and returns it.
   * @return let t = lookup(decl) |
   *   some t => t, cache(decl, decl.expression.accept(this))
   */
  public final BooleanMatrix visit(Decl decl) {
    BooleanMatrix matrix = lookup(decl);
    if (matrix!=null) return matrix;
    if (decl.multiplicity()!=Multiplicity.ONE)
      throw new HigherOrderDeclException(decl);
    return cache(decl, decl.expression().accept(this));
  }
View Full Code Here

   * given variable. If no binding is found, an UnboundLeafException is thrown.
   * @return this.env.lookup(variable)
   * @throws UnboundLeafException - no this.env.lookup(variable)
   */
  public final BooleanMatrix visit(Variable variable) {
    final BooleanMatrix ret = env.lookup(variable);
    if (ret != null) return ret;
    else throw new UnboundLeafException("Unbound variable", variable);
  }
View Full Code Here

   * @return let t = lookup(binExpr) | some t => t,
   *      let op = (binExpr.op).(UNION->or + INTERSECTION->and + DIFFERENCE->difference + OVERRIDE->override + JOIN->dot + PRODUCT->cross) |
   *       cache(binExpr, op(binExpr.left.accept(this), binExpr.right.accept(this)))
   */
  public BooleanMatrix visit(BinaryExpression binExpr) {
    BooleanMatrix ret = lookup(binExpr);
    if (ret!=null) return ret;

    final BooleanMatrix left = binExpr.left().accept(this);
    final BooleanMatrix right = binExpr.right().accept(this);
    final ExprOperator op = binExpr.op();

    switch(op) {
    case UNION          : ret = left.or(right); break;
    case INTERSECTION  : ret = left.and(right); break;
View Full Code Here

   * @return let t = lookup(expr) | some t => t,
   *      let op = (expr.op).(UNION->or + INTERSECTION->and + DIFFERENCE->difference + OVERRIDE->override + JOIN->dot + PRODUCT->cross) |
   *       cache(expr, op(expr.left.accept(this), expr.right.accept(this)))
   */
  public BooleanMatrix visit(NaryExpression expr) {
    BooleanMatrix ret = lookup(expr);
    if (ret!=null) return ret;

    final ExprOperator op = expr.op();
    final BooleanMatrix first = expr.child(0).accept(this);   
    final BooleanMatrix[] rest = new BooleanMatrix[expr.size()-1];
    for(int i = 0; i < rest.length; i++) {   rest[i] = expr.child(i+1).accept(this); }
   
    switch(op) {
    case UNION          : ret = first.or(rest); break;
    case INTERSECTION  : ret = first.and(rest); break;
    case OVERRIDE     : ret = first.override(rest); break;
    case PRODUCT    : ret = first.cross(rest); break;
    default :
      throw new IllegalArgumentException("Unknown associative operator: " + op);
    }

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

   * @return let t = lookup(unaryExpr) | some t => t,
   *      let op = (unaryExpr.op).(TRANSPOSE->transpose + CLOSURE->closure + REFLEXIVE_CLOSURE->(lambda(m)(m.closure().or(iden))) |
   *       cache(unaryExpr, op(unaryExpr.child))
   */
  public final BooleanMatrix visit(UnaryExpression unaryExpr) {
    BooleanMatrix ret = lookup(unaryExpr);
    if (ret!=null) return ret;

    final BooleanMatrix child = unaryExpr.expression().accept(this);
    final ExprOperator op = unaryExpr.op();

    switch(op) {
    case TRANSPOSE           : ret = child.transpose(); break;
    case CLOSURE             : ret = child.closure(); break;
    case REFLEXIVE_CLOSURE  : ret = child.closure().or(visit((ConstantExpression)Expression.IDEN)); break;
    default :
      throw new IllegalArgumentException("Unknown operator: " + op);
    }
    return cache(unaryExpr,ret);
  }
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.