Search in sources :

Example 6 with IntBitSet

use of kodkod.util.ints.IntBitSet in project org.alloytools.alloy by AlloyTools.

the class DynamicRCEStrategy method sortByRelevance.

/**
 * Returns an array R of longs such that for each i, j in [0..R.length) i < j
 * implies that the formula identified by (int)R[i] in this.hits contributes
 * fewer clauses to the core of the given trace than the formula identified by
 * (int)R[j].
 *
 * @return an array as described above
 */
private long[] sortByRelevance(ResolutionTrace trace, IntSet relevantVars) {
    hits.indices().retainAll(relevantVars);
    if (hits.get(hits.indices().min()) == null) {
        // 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();
            for (IntSet reachableVars : hits.values()) {
                if (reachableVars.contains(maxVar)) {
                    for (IntIterator lits = clause.literals(); lits.hasNext(); ) {
                        reachableVars.add(StrictMath.abs(lits.next()));
                    }
                }
            }
        }
    }
    final long[] counts = new long[hits.size()];
    for (Iterator<Clause> clauseItr = trace.iterator(trace.core()); clauseItr.hasNext(); ) {
        final Clause clause = clauseItr.next();
        final int maxVar = clause.maxVariable();
        int i = 0;
        for (IntSet reachableVars : hits.values()) {
            if (reachableVars.contains(maxVar)) {
                counts[i]++;
            }
            i++;
        }
    }
    int i = 0;
    for (IntIterator varItr = hits.indices().iterator(); varItr.hasNext(); ) {
        final int var = varItr.next();
        counts[i] = (counts[i] << 32) | var;
        i++;
    }
    Arrays.sort(counts);
    return counts;
}
Also used : IntBitSet(kodkod.util.ints.IntBitSet) IntIterator(kodkod.util.ints.IntIterator) IntSet(kodkod.util.ints.IntSet) Clause(kodkod.engine.satlab.Clause)

Example 7 with IntBitSet

use of kodkod.util.ints.IntBitSet in project org.alloytools.alloy by AlloyTools.

the class HybridStrategy method coreClausesWithMaxVar.

/**
 * Returns the indices of the clauses in the unsatisfiable core of the given
 * trace that have the specified maximum variable.
 *
 * @return { i: trace.core() | trace[i].maxVariable() = maxVariable }
 */
private static IntSet coreClausesWithMaxVar(ResolutionTrace trace, int maxVariable) {
    final IntSet core = trace.core();
    final IntSet restricted = new IntBitSet(core.max() + 1);
    final Iterator<Clause> clauses = trace.iterator(core);
    final IntIterator indices = core.iterator();
    while (clauses.hasNext()) {
        Clause clause = clauses.next();
        int index = indices.next();
        if (clause.maxVariable() == maxVariable)
            restricted.add(index);
    }
    return restricted;
}
Also used : IntBitSet(kodkod.util.ints.IntBitSet) IntIterator(kodkod.util.ints.IntIterator) IntSet(kodkod.util.ints.IntSet) Clause(kodkod.engine.satlab.Clause)

Example 8 with IntBitSet

use of kodkod.util.ints.IntBitSet in project org.alloytools.alloy by AlloyTools.

the class LazyTrace method reachable.

/**
 * Returns the indices of all clauses in the given trace that are reachable from
 * the conflict clause through the resolvents in trace[roots..trace.length-1].
 * This method assumes that that the last trace[roots..trace.length-1] clauses
 * encode resolvents as specified by the {@linkplain #LazyTrace(int[][], int)}
 * constructor.
 *
 * @return indices of all clauses in the given trace that are reachable from the
 *         conflict clause through the resolvents in
 *         trace[roots..trace.length-1]
 */
private static IntSet reachable(int[][] trace, int roots) {
    final IntSet reachable = new IntBitSet(trace.length);
    reachable.add(trace.length - 1);
    for (int i = trace.length - 1; i >= roots; i--) {
        if (reachable.contains(i)) {
            int[] resolvent = trace[i];
            for (int j = 0; j < resolvent.length; j++) {
                reachable.add(resolvent[j]);
            }
        }
    }
    return reachable;
}
Also used : IntBitSet(kodkod.util.ints.IntBitSet) IntSet(kodkod.util.ints.IntSet)

Example 9 with IntBitSet

use of kodkod.util.ints.IntBitSet in project org.alloytools.alloy by AlloyTools.

the class MiniSatProver method format.

/**
 * Modifies the given raw trace so that it conforms to the specification of
 * {@linkplain LazyTrace#LazyTrace(int[][], int)}, if the array contains no null
 * entries, and to the specfication of
 * {@linkplain LazyTrace#LazyTrace(LazyTrace, IntSet, int[][])} otherwise.
 *
 * @ensures modifies the trace so that it conforms to the specification of one
 *          of the LazyTrace 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)
                // correctly positioned, do nothing
                continue;
            int[] resolvent = trace[i];
            System.arraycopy(trace, i + 1, trace, i, pos - i);
            trace[pos] = resolvent;
        }
    }
    assert axioms == numberOfClauses();
    return trace;
}
Also used : IntBitSet(kodkod.util.ints.IntBitSet) IntIterator(kodkod.util.ints.IntIterator) IntSet(kodkod.util.ints.IntSet)

Example 10 with IntBitSet

use of kodkod.util.ints.IntBitSet in project org.alloytools.alloy by AlloyTools.

the class BugTests method testEmina_01192006.

public final void testEmina_01192006() {
    IntBitSet s = new IntBitSet(64);
    for (int i = 4; i < 8; i++) {
        for (int j = 0; j < 4; j++) {
            s.add(i * 8 + j);
        }
    }
    // System.out.println(s);
    for (int i = 4; i < 8; i++) {
        assertTrue(s.iterator(i * 8, (i + 1) * 8 - 1).hasNext());
        int count = 0;
        for (IntIterator iter = s.iterator(i * 8, (i + 1) * 8 - 1); iter.hasNext(); ) {
            count += iter.next() % 8;
        }
        assertEquals(count, 6);
    }
    for (int i = 4; i < 8; i++) {
        assertTrue(s.iterator((i + 1) * 8 - 1, i * 8).hasNext());
        int count = 0;
        for (IntIterator iter = s.iterator((i + 1) * 8 - 1, i * 8); iter.hasNext(); ) {
            count += iter.next() % 8;
        }
        assertEquals(count, 6);
    }
}
Also used : IntBitSet(kodkod.util.ints.IntBitSet) IntIterator(kodkod.util.ints.IntIterator)

Aggregations

IntBitSet (kodkod.util.ints.IntBitSet)10 IntSet (kodkod.util.ints.IntSet)9 IntIterator (kodkod.util.ints.IntIterator)7 Clause (kodkod.engine.satlab.Clause)4 IntTreeSet (kodkod.util.ints.IntTreeSet)1