use of kodkod.engine.satlab.Clause in project org.alloytools.alloy by AlloyTools.
the class StrategyUtils method clausesFor.
/**
* Returns the indices of all axioms in the given trace that form the
* translations of the formulas identified by the given variables. This method
* assumes that the axioms in the given trace were generated by the Kodkod
* {@linkplain Translator}.
*
* @return let C = { c: trace.prover.clauses | c.maxVariable() in relevantVars
* }, 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;
}
use of kodkod.engine.satlab.Clause in project org.alloytools.alloy by AlloyTools.
the class StrategyUtils method coreVars.
/**
* Returns the variables that correspond to the roots of log.formula, in the
* order in which they were specified in log.formula.
*
* @return variables that correspond to the roots of log.formula, in the order
* in which they were specified in log.formula.
*/
// static IntVector orderedRootVars(TranslationLog log) {
// final Set<Formula> roots = log.roots();
// final Map<Formula,int[]> maxRootVar = new
// LinkedHashMap<Formula,int[]>(roots.size());
// final RecordFilter filter = new RecordFilter() {
// public boolean accept(Node node, int literal, Map<Variable, TupleSet>
// env) {
// return roots.contains(node) && env.isEmpty();
// }
// };
// for(Iterator<TranslationRecord> itr = log.replay(filter); itr.hasNext();)
// {
// TranslationRecord record = itr.next();
// int[] var = maxRootVar.get(record.node());
// if (var==null) {
// var = new int[1];
// maxRootVar.put((Formula)record.node(), var);
// }
// var[0] = StrictMath.abs(record.literal());
// }
// final IntSet uniqueRoots = new IntTreeSet();
// final IntVector orderedRoots = new ArrayIntVector(roots.size());
// for(int[] var : maxRootVar.values()) {
// int topVar = var[0];
// if (topVar != Integer.MAX_VALUE) // formula simplified to TRUE
// if (uniqueRoots.add(var[0])) {
// orderedRoots.add(var[0]);
// };
// }
// return orderedRoots;
// }
/**
* Returns relevant core variables; that is, all variables that occur both in
* the positive and 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;
}
use of kodkod.engine.satlab.Clause 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;
}
use of kodkod.engine.satlab.Clause 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.engine.satlab.Clause 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;
}
Aggregations