Package kodkod.engine.bool

Examples of kodkod.engine.bool.BooleanFactory


   * @requires breaker.bounds = this.bounds
   * @return toCNF(circuit && breaker.generateSBP(interpreter))
   */
  private Translation generateSBP(BooleanAccumulator circuit, LeafInterpreter interpreter, SymmetryBreaker breaker) {
    options.reporter().generatingSBP();
    final BooleanFactory factory = interpreter.factory();
    circuit.add(breaker.generateSBP(interpreter, options.symmetryBreaking()));
    return toCNF((BooleanFormula)factory.accumulate(circuit), factory.numberOfVariables(), interpreter.vars());
  }
View Full Code Here


   * @throws TrivialFormulaException - flattening the circuit and the predicate yields a constant
   */
  private Translation generateSBP(AnnotatedNode<Formula> annotated, BooleanFormula circuit, LeafInterpreter interpreter, SymmetryBreaker breaker)
  throws TrivialFormulaException {
    options.reporter().generatingSBP();
    final BooleanFactory factory = interpreter.factory();
    final BooleanValue sbp = breaker.generateSBP(interpreter, options.symmetryBreaking());
    return flatten(annotated, (BooleanFormula)factory.and(circuit, sbp), interpreter);
  }
View Full Code Here

   *   toCNF(flatten(circuit), interpreter.factory().numberOfVariables(), interpreter.vars()) else
   *  toCNF(circuit, interpreter.factory().numberOfVariables(), interpreter.vars())
   * @throws TrivialFormulaException - flattening the circuit yields a constant
   */
  private Translation flatten(AnnotatedNode<Formula> annotated, BooleanFormula circuit, LeafInterpreter interpreter) throws TrivialFormulaException
    final BooleanFactory factory = interpreter.factory();
    if (options.flatten()) {
      options.reporter().flattening(circuit);
      final BooleanValue flatCircuit = BooleanFormulaFlattener.flatten(circuit, factory);
      if (flatCircuit.op()==Operator.CONST) {
        throw new TrivialFormulaException(annotated.node(), bounds, (BooleanConstant)flatCircuit, null);
      } else {
        return toCNF((BooleanFormula)flatCircuit, factory.numberOfVariables(), interpreter.vars());
      }
    } else {
      return toCNF(circuit, factory.numberOfVariables(), interpreter.vars());
    }
  }
View Full Code Here

   */
  final BooleanValue generateSBP(LeafInterpreter interpreter, int predLength) {
    if (symmetries.isEmpty() || predLength==0) return BooleanConstant.TRUE;
   
    final List<RelationParts> relParts = relParts();
    final BooleanFactory factory = interpreter.factory();
    final BooleanAccumulator sbp = BooleanAccumulator.treeGate(Operator.AND);
    final List<BooleanValue> original = new ArrayList<BooleanValue>(predLength);
    final List<BooleanValue> permuted = new ArrayList<BooleanValue>(predLength);
   
    for(IntSet sym : symmetries) {
   
      IntIterator indeces = sym.iterator();
      for(int prevIndex = indeces.next(); indeces.hasNext(); ) {
        int curIndex = indeces.next();
        for(Iterator<RelationParts> rIter = relParts.iterator(); rIter.hasNext() && original.size() < predLength;) {
         
          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);     
          }
        }
               
        sbp.add(leq(factory, original, permuted));
        original.clear();
        permuted.clear();
        prevIndex = curIndex;
      }
    }
   
    return factory.accumulate(sbp);
  }
View Full Code Here

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

   * @param matrix boolean matrix that will retain the final results; should be an empty matrix of dimensions universe.size^decls.length initially
   * @effects the given matrix contains the translation of the comprehension "{ decls | formula }"
   */
  private final void comprehension(Decls decls, Formula formula, int currentDecl,
      BooleanValue declConstraints, int partialIndex, BooleanMatrix matrix) {
    final BooleanFactory factory = interpreter.factory();

    if (currentDecl==decls.size()) {
      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

   * @param acc the accumulator that contains the top level conjunction; should be an empty AND accumulator initially
   * @effects the given accumulator contains the translation of the formula "all decls | formula"
   */
  private void all(Decls decls, Formula formula, int currentDecl, BooleanValue declConstraints, BooleanAccumulator acc) {
    if (acc.isShortCircuited()) return;
    final BooleanFactory factory = interpreter.factory();

    if (decls.size()==currentDecl) {
      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

   * @param acc the accumulator that contains the top level conjunction; should be an empty OR accumulator initially
   * @effects the given accumulator contains the translation of the formula "some decls | formula"
   */
  private void some(Decls decls, Formula formula, int currentDecl, BooleanValue declConstraints, BooleanAccumulator acc) {
    if (acc.isShortCircuited()) return;
    final BooleanFactory factory = interpreter.factory();

    if (decls.size()==currentDecl) {
      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

    if (ret!=null) return ret;

    final BooleanValue left = binFormula.left().accept(this);
    final BooleanValue right = binFormula.right().accept(this);
    final FormulaOperator op = binFormula.op();
    final BooleanFactory f = interpreter.factory();

    switch(op) {
    case AND    : ret = f.and(left, right); break;
    case OR      : ret = f.or(left, right); break;
    case IMPLIES  : ret = f.implies(left, right); break;
    case IFF    : ret = f.iff(left, right); break;
    default :
      throw new IllegalArgumentException("Unknown operator: " + op);
    }
    return cache(binFormula, ret);
  }
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;
View Full Code Here

TOP

Related Classes of kodkod.engine.bool.BooleanFactory

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.