Package kodkod.engine.bool

Examples of kodkod.engine.bool.BooleanAccumulator


   
    final LeafInterpreter interpreter = LeafInterpreter.exact(bounds, options);
   
    if (options.logTranslation()>0) {
      final TranslationLogger logger = options.logTranslation()==1 ? new MemoryLogger(annotated, bounds) : new FileLogger(annotated, bounds);
      final BooleanAccumulator circuit = FOL2BoolTranslator.translate(annotated, interpreter, logger);
      log = logger.log();
      if (circuit.isShortCircuited()) {
        throw new TrivialFormulaException(annotated.node(), bounds, circuit.op().shortCircuit(), log);
      } else if (circuit.size()==0) {
        throw new TrivialFormulaException(annotated.node(), bounds, circuit.op().identity(), log);
      }
      return generateSBP(circuit, interpreter, breaker);
    } else {
      final BooleanValue circuit = (BooleanValue)FOL2BoolTranslator.translate(annotated, interpreter);
      if (circuit.op()==Operator.CONST) {
        throw new TrivialFormulaException(annotated.node(), bounds, (BooleanConstant)circuit, null);
      }
      return generateSBP(annotated, (BooleanFormula)circuit, interpreter, breaker);
    }
  }
View Full Code Here


    } else { // construct a gate that corresponds to the multigate
//      System.out.println("Unflattenable: " + multigate);
      BooleanValue replacement = cache.get(multigate);

      if (replacement == null) {
        final BooleanAccumulator newGate = BooleanAccumulator.treeGate(op);
        for(Iterator<BooleanFormula> inputs = multigate.iterator(); inputs.hasNext();) {
          if (inputs.next().accept(this,newGate)==op.shortCircuit()) {
            return op.shortCircuit();
          }
        }
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;
      }
    }
View Full Code Here

   * to the string of bits reprented by l1.
   * @requires l0.size()==l1.size()
   * @return a circuit that compares l0 and l1
   */
  private static final BooleanValue leq(BooleanFactory f, List<BooleanValue> l0, List<BooleanValue> l1) {
    final BooleanAccumulator cmp = BooleanAccumulator.treeGate(Operator.AND);
    BooleanValue prevEquals = BooleanConstant.TRUE;
    for(int i = 0; i < l0.size(); i++) {
      cmp.add(f.implies(prevEquals, f.implies(l0.get(i), l1.get(i))));
      prevEquals = f.and(prevEquals, f.iff(l0.get(i), l1.get(i)));
    }
    return f.accumulate(cmp);
  }
View Full Code Here

      BooleanValue cache(Formula formula, BooleanValue translation) {
        logger.log(formula, translation, super.env);
        return super.cache(formula, translation);
     
    };
    final BooleanAccumulator acc = BooleanAccumulator.treeGate(Operator.AND);
   
    for(Formula root : Nodes.conjuncts(annotated.node())) {  
      acc.add(root.accept(translator));
    }
    logger.close();
    return acc;
  }
View Full Code Here

    final Quantifier quantifier = quantFormula.quantifier();

    switch(quantifier) {
    case ALL    :
      final BooleanAccumulator and = BooleanAccumulator.treeGate(Operator.AND);
      all(quantFormula.decls(), quantFormula.formula(), 0, BooleanConstant.FALSE, and);
      ret = interpreter.factory().accumulate(and);
      break;
    case SOME  :
      final BooleanAccumulator or = BooleanAccumulator.treeGate(Operator.OR);
      some(quantFormula.decls(), quantFormula.formula(), 0, BooleanConstant.TRUE, or);
      ret = interpreter.factory().accumulate(or);
      break;
    default :
      throw new IllegalArgumentException("Unknown quantifier: " + quantifier);
View Full Code Here

    case AND : boolOp = Operator.AND; break;
    case OR  : boolOp = Operator.OR;  break;
    default   : throw new IllegalArgumentException("Unknown nary operator: " + op);
    }
   
    final BooleanAccumulator acc = BooleanAccumulator.treeGate(boolOp);
    final BooleanValue shortCircuit = boolOp.shortCircuit();
    for(Formula child : formula) {
      if (acc.add(child.accept(this))==shortCircuit)
        break;
    }
   
    return cache(formula, interpreter.factory().accumulate(acc));
  }
View Full Code Here

TOP

Related Classes of kodkod.engine.bool.BooleanAccumulator

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.