Package kodkod.util.ints

Examples of kodkod.util.ints.IntSet


   * negative phase in trace.core.
   * @return { v: [1..) | (some p, n: trace.core | v in trace.elts[p].literals and -v in trace.elts[n].literals) }
   */
  public static IntSet coreVars(ResolutionTrace trace) {

    final IntSet posVars = new IntTreeSet(), negVars = new IntTreeSet();
   
    for(Iterator<Clause> iter = trace.iterator(trace.core()); iter.hasNext();) {
      Clause clause = iter.next();
      for(IntIterator lits = clause.literals(); lits.hasNext(); ) {
        int lit = lits.next();
        if (lit > 0) posVars.add(lit);
        else negVars.add(-lit);
      }
    }
   
    posVars.retainAll(negVars);
   
    assert !posVars.isEmpty();
    final IntSet ret = new IntBitSet(posVars.max()+1);
    ret.addAll(posVars);
   
    return ret;
  }
View Full Code Here


   * Returns the set of all variables in the core of the given trace
   * that form unit clauses.
   * @return { v: [1..) | some c: trace.core | c.size() = 1 and c.maxVariable() = v }
   */
  public static IntSet coreUnits(ResolutionTrace trace) {
    final IntSet units = new IntTreeSet();
   
    for(Iterator<Clause> itr = trace.reverseIterator(trace.core()); itr.hasNext(); ) {  
      Clause c = itr.next();
      if (c.size()==1) {
        units.add(c.maxVariable());
      }
    }
   
    if (units.isEmpty()) return Ints.EMPTY_SET;
   
    return Ints.asSet(units.toArray());
  }
View Full Code Here

   * that form unit clauses. 
   * @return the consecutive variables at the tail of the core of the given trace
   * that form unit clauses
   */
  static IntSet coreTailUnits(ResolutionTrace trace) {
    final IntSet units = new IntTreeSet();
   
    for(Iterator<Clause> itr = trace.reverseIterator(trace.core()); itr.hasNext(); ) {  
      Clause c = itr.next();
      if (c.size()==1) {
        units.add(c.maxVariable());
      } else {
        break;
      }
    }
   
View Full Code Here

   *     T = { c1, c2: C | c2.maxVariable() in abs(c1.literals) } |
   *     C.*T
   */
  static IntSet clausesFor(ResolutionTrace trace, IntSet relevantVars) {
//    System.out.println("relevant: " + relevantVars);
    final IntSet axioms = trace.axioms();

    final IntSet reachableVars = new IntBitSet(relevantVars.max()+1);
    reachableVars.addAll(relevantVars);

    final IntSet relevantAxioms = new IntBitSet(axioms.size());
   
    final Iterator<Clause> itr = trace.reverseIterator(axioms);
    for(int i = axioms.max(); i >= 0; i--) {
      Clause clause = itr.next();
      int maxVar = clause.maxVariable();
      if (reachableVars.contains(maxVar)) {
        for(IntIterator lits = clause.literals(); lits.hasNext(); ) {
          reachableVars.add(StrictMath.abs(lits.next()));
        }
        relevantAxioms.add(i);
      }
    }
   
    return  relevantAxioms;
  }
View Full Code Here

   * of one of the ArrayTrace constructors.
   * @return trace
   */
  private int[][] format(int[][] trace) {
    final int length = trace.length;
    final IntSet resolvents = new IntBitSet(length);
    final int offset = numberOfVariables() + 1;
    for(int i = 0; i < length; i++) {
      int[] clause = trace[i];
      if (clause!=null && clause[0]>=offset) {
        clause[0] -= offset;
        resolvents.add(i);
      }
    }
       
    final int axioms = length - resolvents.size();
    if (resolvents.min()<axioms) {
      final int[] position = new int[length];
      for(int i = 0, axiomIndex = 0, resolventIndex = axioms; i < length; i++) {
        if (resolvents.contains(i)) {
          position[i] = resolventIndex++;
          int[] resolvent = trace[i];
          for(int j = 0, resLength = resolvent.length; j < resLength; j++) {
            resolvent[j] = position[resolvent[j]];
          }
        } else {
          position[i] = axiomIndex++;
        }
      }

      for(IntIterator itr = resolvents.iterator(length, 0); itr.hasNext(); ) {
        int i = itr.next();
        int pos = position[i];
        if (i==pos) continue; // correctly positioned, do nothing
        int[] resolvent = trace[i];
        System.arraycopy(trace, i+1, trace, i, pos-i);
View Full Code Here

   * {@inheritDoc}
   * @see kodkod.engine.satlab.ReductionStrategy#next(kodkod.engine.satlab.ResolutionTrace)
   */
  public IntSet next(ResolutionTrace trace) {
    if (hits.isEmpty()) return Ints.EMPTY_SET; // tried everything
    final IntSet relevantVars = StrategyUtils.coreTailUnits(trace);
   
    final long[] byRelevance = sortByRelevance(trace, relevantVars);
    if (DBG) printRelevant(byRelevance);
     for(int i = byRelevance.length-1; i>=0; i--) {
      final int var = (int)byRelevance[i];
      if (hits.remove(var)!=null) {
        // remove maxVar from the set of relevant variables
        relevantVars.remove(var);
        if (relevantVars.isEmpty()) break; // there was only one root formula left
        // get all axioms and resolvents corresponding to the clauses that
        // form the translations of formulas identified by relevant vars
        final IntSet relevantClauses = clausesFor(trace, relevantVars);
        assert !relevantClauses.isEmpty() && !relevantClauses.contains(trace.size()-1);
       
        if (DBG) System.out.println("relevant clauses: " + relevantClauses.size() + ", removed " + var);
       
        return relevantClauses;
      }
    }
   
View Full Code Here

    hits.indices().retainAll(relevantVars);
   
    if (hits.get(hits.indices().min())==null) { // first call, initialize the hits
      for(IntIterator varItr = relevantVars.iterator(); varItr.hasNext(); ) {
        final int var = varItr.next();
        final IntSet varReachable = new IntBitSet(var+1);
        varReachable.add(var);
        hits.put(var, varReachable);
      }
      for(Iterator<Clause> clauseItr = trace.reverseIterator(trace.axioms()); clauseItr.hasNext();) {
        final Clause clause = clauseItr.next();
        final int maxVar = clause.maxVariable();
View Full Code Here

    final double coreRatio = ((double) trace.core().size() / (double) trace.axioms().size());
   
    if (DBG) System.out.println("trace size: " + trace.size() + ", axioms: " + trace.axioms().size() + ", core: " + trace.core().size() + ", resolvents: " + trace.resolvents().size());
    if (DBG) System.out.println("hardness: " + hardness + ", coreRatio: " + coreRatio);
   
    final IntSet relevantAxioms = StrategyUtils.clausesFor(trace, relevantVars);
    if (DBG) System.out.println("relevant axioms:  " + relevantAxioms.size());
   
    if (coreRatio < noRecycleRatio) {
      return relevantAxioms;
    } else if (hardness < hardnessCutOff) {
      return trace.learnable(relevantAxioms);
    } else {
      IntSet current = relevantAxioms, last;
      final int maxRelevant = (int) Math.rint(relevantAxioms.size()*recycleLimit);
      do {
        last = current;
        current = trace.directlyLearnable(current);
      } while (last.size() < current.size() && current.size() < maxRelevant);
     
      if (DBG) System.out.println("last: " + last.size() +", current: " + current.size() + ", maxRelevant: " + maxRelevant);
     
      return current.size() < maxRelevant ? current : last;
    }
       
  }
View Full Code Here

   * {@inheritDoc}
   * @see kodkod.engine.satlab.ReductionStrategy#next(kodkod.engine.satlab.ResolutionTrace)
   */
  public IntSet next(ResolutionTrace trace) {
    if (varsToTry.isEmpty()) return Ints.EMPTY_SET; // tried everything
    final IntSet relevantVars = StrategyUtils.coreTailUnits(trace);
       
    for(IntIterator varItr = varsToTry.iterator(); varItr.hasNext();) {
      final int var = varItr.next();
      varItr.remove();
      if (relevantVars.remove(var)) { // remove maxVar from the set of relevant variables
        if (relevantVars.isEmpty()) break; // there was only root formula left
        // get all axioms corresponding to the clauses that
        // form the translations of formulas identified by relevant vars
        final IntSet relevantClauses = StrategyUtils.clausesFor(trace, relevantVars);
        assert !relevantClauses.isEmpty() && !relevantClauses.contains(trace.size()-1);
        return relevantClauses;
      }
    }
    varsToTry.clear();   
    return Ints.EMPTY_SET;
View Full Code Here

    final int first = varsToTry.iterator().next();//varsToTry.min();
    varsToTry.remove(first);
    coreVars.remove(first);
    // get all axioms corresponding to the clauses that
    // form the translations of formulas identified by coreVars
    final IntSet relevantClauses = StrategyUtils.clausesFor(trace, coreVars);
    assert !relevantClauses.isEmpty() && !relevantClauses.contains(trace.size()-1);
    return relevantClauses;
  }
View Full Code Here

TOP

Related Classes of kodkod.util.ints.IntSet

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.