Package kodkod.ast

Examples of kodkod.ast.Formula


   * If not cached, visits the formula's children with appropriate settings
   * for the negated flag and the skolemDepth parameter.
   * @see kodkod.ast.visitor.AbstractReplacer#visit(kodkod.ast.BinaryFormula)
   */
  public final Formula visit(BinaryFormula bf) {
    Formula ret = lookup(bf);
    if (ret!=null) return ret;     
    final FormulaOperator op = bf.op();
    final int oldDepth = skolemDepth;
    if (op==IFF || (negated && op==AND) || (!negated && (op==OR || op==IMPLIES))) { // cannot skolemize in these cases
      skolemDepth = -1;
    }
    final Formula left, right;
    if (negated && op==IMPLIES) { // !(a => b) = !(!a || b) = a && !b
      negated = !negated;
      left = bf.left().accept(this);
      negated = !negated;
      right = bf.right().accept(this);
    } else {
      left = bf.left().accept(this);
      right = bf.right().accept(this);
    }
    skolemDepth = oldDepth;
    ret = (left==bf.left()&&right==bf.right()) ? bf : left.compose(op, right);
    return source(cache(bf,ret),bf);
  }
View Full Code Here


   * If not cached, visits the formula's children with appropriate settings
   * for the negated flag and the skolemDepth parameter.
   * @see kodkod.ast.visitor.AbstractReplacer#visit(kodkod.ast.NaryFormula)
   */
  public final Formula visit(NaryFormula bf) {
    Formula ret = lookup(bf);
    if (ret!=null) return ret;     
   
    final int oldDepth = skolemDepth;
    final FormulaOperator op = bf.op();
   
    switch(op) {
    case AND : if (negatedskolemDepth = -1; break;
    case OR  : if (!negated) skolemDepth = -1; break;
    default  : throw new IllegalArgumentException("Unknown nary operator: " + op);
    }
   
    final Formula[] visited = new Formula[bf.size()];
    boolean allSame = true;
    for(int i = 0; i < visited.length; i++) {
      final Formula child = bf.child(i);
      visited[i] = child.accept(this);
      allSame = allSame && (child==visited[i]);
    }
    ret = allSame ? bf : Formula.compose(op, visited);
   
    skolemDepth = oldDepth;
View Full Code Here

   * @return super.visit(icf)
   **/
  public final Formula visit(IntComparisonFormula icf) {
    final int oldDepth = skolemDepth;
    skolemDepth = -1; // cannot skolemize inside an int comparison formula
    final Formula ret = super.visit(icf);
    skolemDepth = oldDepth;
    return source(ret,icf);
  }
View Full Code Here

   * @return super.visit(cf)
   **/
  public final Formula visit(ComparisonFormula cf) {
    final int oldDepth = skolemDepth;
    skolemDepth = -1; // cannot skolemize inside a comparison formula
    final Formula ret = super.visit(cf);
    skolemDepth = oldDepth;
    return source(ret,cf);
  }
View Full Code Here

   * @return super.visit(mf)
   **/
  public final Formula visit(MultiplicityFormula mf) {
    final int oldDepth = skolemDepth;
    skolemDepth = -1; // cannot skolemize inside a multiplicity formula
    final Formula ret = super.visit(mf);
    skolemDepth = oldDepth;
    return source(ret,mf);
  }
View Full Code Here

   * @return super.visit(pred)
   **/
  public final Formula visit(RelationPredicate pred) {
    final int oldDepth = skolemDepth;
    skolemDepth = -1; // cannot skolemize inside a relation predicate
    final Formula ret = super.visit(pred);
    skolemDepth = oldDepth;
    return source(ret,pred);
  }
View Full Code Here

      final int lit = entry.getValue()[0];
      if (lit==-Integer.MAX_VALUE) {
        coreRoots = Collections.singletonMap(entry.getKey(), rootNodes.get(entry.getKey()));
        break;
      } else if (lits.containsIndex(-lit)) {
        final Formula f0 = lits.get(-lit);
        final Formula f1 = entry.getKey();
        coreRoots = new LinkedHashMap<Formula, Node>(3);
        coreRoots.put(f0, rootNodes.get(f0));
        coreRoots.put(f1, rootNodes.get(f1));
        coreRoots = Collections.unmodifiableMap(coreRoots);
        break;
View Full Code Here

     */
    public void visit(BinaryFormula binFormula) {
      if (visited(binFormula)) return;
      relevant.add(binFormula);
     
      final Formula l = binFormula.left(), r = binFormula.right();
      final Boolean lval = constNodes.get(l), rval = constNodes.get(r);
      final boolean lvisit, rvisit;
     
      switch(binFormula.op()) {
      case AND :
        lvisit = (lval==Boolean.FALSE || (lval==null && rval!=Boolean.FALSE));
        rvisit = (rval!=Boolean.TRUE && lval!=Boolean.FALSE);
        break;
      case OR :
        lvisit = (lval==Boolean.TRUE || (lval==null && rval!=Boolean.TRUE));
        rvisit = (rval!=Boolean.FALSE && lval!=Boolean.TRUE);
        break;
      case IMPLIES: // !l || r
        lvisit = (lval==Boolean.FALSE || (lval==null && rval!=Boolean.TRUE));
        rvisit = (rval!=Boolean.FALSE && lval!=Boolean.FALSE);
        break;
      case IFF: // (!l || r) && (l || !r)
        lvisit = rvisit = true;
        break;
      default :
        throw new IllegalArgumentException("Unknown operator: " + binFormula.op());
     
     
      if (lvisit) { l.accept(this); }
      if (rvisit) { r.accept(this); }
    }
View Full Code Here

    final Set<RelationPredicate> totals = preds.get(TOTAL_ORDERING);
    final Set<RelationPredicate> acyclics = preds.get(ACYCLIC);
    final Map<RelationPredicate, Formula> broken = new IdentityHashMap<RelationPredicate, Formula>();
   
    for(RelationPredicate.TotalOrdering pred : sort(totals.toArray(new RelationPredicate.TotalOrdering[totals.size()]))) {
      Formula replacement = breakTotalOrder(pred,aggressive);
      if (replacement!=null)
        broken.put(pred, replacement);
    }
   
    for(RelationPredicate.Acyclic pred : sort(acyclics.toArray(new RelationPredicate.Acyclic[acyclics.size()]))) {
      Formula replacement = breakAcyclic(pred,aggressive);
      if (replacement!=null)
        broken.put(pred, replacement);
    }
   
    return broken;
View Full Code Here

        final A4Options opt = originalOptions;
        long time = System.currentTimeMillis();
        rep.debug("Simplifying the bounds...\n");
        if (simp!=null && formulas.size()>0 && !simp.simplify(rep, this, formulas)) addFormula(Formula.FALSE, Pos.UNKNOWN);
        rep.translate(opt.solver.id(), bitwidth, maxseq, solver.options().skolemDepth(), solver.options().symmetryBreaking());
        Formula fgoal = Formula.and(formulas);
        rep.debug("Generating the solution...\n");
        kEnumerator = null;
        Solution sol = null;
        final Reporter oldReporter = solver.options().reporter();
        final boolean solved[] = new boolean[]{true};
View Full Code Here

TOP

Related Classes of kodkod.ast.Formula

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.