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);
}
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;
}
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;
}
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;
}
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;
}
Aggregations