use of kodkod.util.ints.IntSet in project org.alloytools.alloy by AlloyTools.
the class HybridStrategy method next.
/**
* {@inheritDoc}
*
* @see kodkod.engine.satlab.ReductionStrategy#next(kodkod.engine.satlab.ResolutionTrace)
*/
@Override
public IntSet next(ResolutionTrace trace) {
if (topVars.isEmpty())
// tried everything
return Ints.EMPTY_SET;
final IntSet core = trace.core();
for (Iterator<Clause> iter = trace.iterator(core); iter.hasNext(); ) {
Clause clause = iter.next();
int maxVar = clause.maxVariable();
if (topVars.remove(maxVar)) {
// get all core clauses with the given maximum variable
IntSet exclude = coreClausesWithMaxVar(trace, maxVar);
assert !exclude.isEmpty();
// get all clauses reachable from the conflict clause
IntSet next = trace.reachable(Ints.singleton(trace.size() - 1));
// remove all clauses backward reachable from the clauses with
// the given maxVar
next.removeAll(trace.backwardReachable(exclude));
if (!next.isEmpty()) {
return next;
}
}
}
topVars.clear();
return Ints.EMPTY_SET;
}
use of kodkod.util.ints.IntSet 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;
}
use of kodkod.util.ints.IntSet in project org.alloytools.alloy by AlloyTools.
the class NCEStrategy method next.
/**
* {@inheritDoc}
*
* @see kodkod.engine.satlab.ReductionStrategy#next(kodkod.engine.satlab.ResolutionTrace)
*/
@Override
public IntSet next(ResolutionTrace trace) {
if (varsToTry.isEmpty())
return Ints.EMPTY_SET;
// if the last attempt at reduction was unsuccessful,
// add the unit clauses that we tried to discard back to coreVars
coreVars.addAll(StrategyUtils.coreTailUnits(trace));
// varsToTry.min();
final int first = varsToTry.iterator().next();
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;
}
use of kodkod.util.ints.IntSet 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.IntSet 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;
}
Aggregations