Search in sources :

Example 21 with IntIterator

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

the class TupleSet method project.

/**
 * Projects this TupleSet onto the given dimension.
 *
 * @return {s: TupleSet | s.arity = 1 && s.universe = this.universe && s.tuples
 *         = { t: Tuple | some q: this.tuples | q.atoms[dimension] =
 *         t.atoms[int] } }
 * @throws IllegalArgumentException dimension < 0 || dimension >= this.arity
 */
public TupleSet project(int dimension) {
    if (dimension < 0 || dimension >= arity) {
        throw new IllegalArgumentException("dimension < 0 || dimension >= this.arity");
    }
    final IntSet projection = Ints.bestSet(universe.size());
    final TupleFactory factory = universe.factory();
    for (IntIterator indexIter = tuples.iterator(); indexIter.hasNext(); ) {
        projection.add(factory.project(indexIter.next(), arity, dimension));
    }
    return new TupleSet(universe, 1, projection);
}
Also used : IntIterator(kodkod.util.ints.IntIterator) IntSet(kodkod.util.ints.IntSet)

Example 22 with IntIterator

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

the class LazyTrace method compress.

/**
 * Compresses the given src trace into a destination trace that contains the
 * same axioms as the source but only the resolvents that are reachable from the
 * conflict clause.
 *
 * @requires src and axioms are as specified by the
 *           {@linkplain #LazyTrace(int[][], int)} constructor
 * @requires reachable.elts = reachable(src, axioms).elts
 * @requires core.elts = core(reachable, axioms).elts
 * @ensures invalidates the contents of src; src should not be used after this
 *          method returns
 * @return a new trace that contains the same axioms as the source but only the
 *         resolvents that are reachable from the conflict clause.
 */
private static int[][] compress(int[][] src, int axioms, IntSet reachable, IntSet core) {
    final int[][] dest = new int[reachable.size() - core.size() + axioms][];
    System.arraycopy(src, 0, dest, 0, axioms);
    final int[] pos = new int[src.length - axioms];
    final IntIterator srcIdxs = reachable.iterator(axioms, src.length);
    for (int i = axioms; srcIdxs.hasNext(); i++) {
        int srcIdx = srcIdxs.next();
        pos[srcIdx - axioms] = i;
        // move the resolvent and adjust its antecedent indices
        int[] resolvent = src[srcIdx];
        dest[i] = resolvent;
        for (int j = 0, lastAnte = resolvent.length; j < lastAnte; j++) {
            int ante = resolvent[j];
            resolvent[j] = ante < axioms ? ante : pos[ante - axioms];
        }
    }
    return dest;
}
Also used : IntIterator(kodkod.util.ints.IntIterator)

Example 23 with IntIterator

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

the class LazyTrace method reconstruct.

/**
 * Fills the first indices.size() empty positions of the partial trace with the
 * corresponding clauses from the original trace and returns the number of
 * axioms in the reconstructed trace.
 *
 * @requires original, indices, and partial are as specified by
 *           {@linkplain #LazyTrace(LazyTrace, IntSet, int[][])} constructor
 * @ensures modifies partial so that it conforms to the {@linkplain #trace
 *          LazyTrace.trace} spec using the provided original trace and indices.
 * @return number of axioms in the modified partial trace
 */
private static int reconstruct(LazyTrace original, IntSet indices, int[][] partial) {
    int axiomCount = indices.size();
    // fill the partial[0..indices.size()-1] with the corresponding clauses
    // from original.trace[indices]
    final int[][] originalTrace = original.trace;
    final int[] position = new int[indices.max() + 1];
    IntIterator itr = indices.iterator();
    for (int i = 0, length = indices.size(); i < length; i++) {
        int index = itr.next();
        position[index] = i;
        if (original.axiom(index)) {
            // just set the ith pointer to original
            // literals
            partial[i] = originalTrace[index];
        } else {
            // copy the resolvent and adjust copy's antecedent indices
            int antes = originalTrace[index][0];
            int[] resolvent = new int[antes];
            for (int j = 0; j < antes; j++) {
                resolvent[j] = position[originalTrace[index][j + 1]];
            }
            partial[i] = resolvent;
            axiomCount--;
        }
    }
    return axiomCount;
}
Also used : IntIterator(kodkod.util.ints.IntIterator)

Example 24 with IntIterator

use of kodkod.util.ints.IntIterator 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 25 with IntIterator

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

the class CRRStrategy method next.

/**
 * Returns the next subset of clauses in the given trace to be analyzed.
 *
 * @requires {@inheritDoc}
 * @ensures {@inheritDoc}
 * @return last(this.nexts')
 */
@Override
public final IntSet next(final ResolutionTrace trace) {
    final IntSet core = trace.core();
    if (excluded == null) {
        // the first time this method is called
        excluded = new HashSet<Clause>((int) (StrictMath.round(core.size() * .75)));
    }
    for (IntIterator iter = core.iterator(Integer.MAX_VALUE, Integer.MIN_VALUE); iter.hasNext(); ) {
        int index = iter.next();
        if (excluded.add(trace.get(index))) {
            // haven't tried excluding
            // this one
            // get all clauses reachable from the conflict clause
            IntSet next = trace.reachable(Ints.singleton(trace.size() - 1));
            // remove all clauses backward reachable from the excluded
            // clause
            next.removeAll(trace.backwardReachable(Ints.singleton(index)));
            return next;
        }
    }
    return Ints.EMPTY_SET;
}
Also used : IntIterator(kodkod.util.ints.IntIterator) IntSet(kodkod.util.ints.IntSet) Clause(kodkod.engine.satlab.Clause)

Aggregations

IntIterator (kodkod.util.ints.IntIterator)27 IntSet (kodkod.util.ints.IntSet)21 IntBitSet (kodkod.util.ints.IntBitSet)7 Relation (kodkod.ast.Relation)5 Clause (kodkod.engine.satlab.Clause)5 BooleanMatrix (kodkod.engine.bool.BooleanMatrix)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 BooleanFactory (kodkod.engine.bool.BooleanFactory)2 BooleanValue (kodkod.engine.bool.BooleanValue)2 TupleFactory (kodkod.instance.TupleFactory)2 TupleSet (kodkod.instance.TupleSet)2 IntTreeSet (kodkod.util.ints.IntTreeSet)2 Comparator (java.util.Comparator)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 BooleanAccumulator (kodkod.engine.bool.BooleanAccumulator)1 Int (kodkod.engine.bool.Int)1 SATSolver (kodkod.engine.satlab.SATSolver)1 Instance (kodkod.instance.Instance)1