use of kodkod.util.ints.IntSet in project org.alloytools.alloy by AlloyTools.
the class SymmetryBreaker method relParts.
/**
* Returns a list of RelationParts that map each non-constant r in
* this.bounds.relations to the representatives of the sets from this.symmetries
* contained in the upper bound of r. The entries are sorted by relations'
* arities and names.
*
* @return a list of RelationParts that contains an entry for each non-constant
* r in this.bounds.relations and the representatives of sets from
* this.symmetries contained in the upper bound of r.
*/
private List<RelationParts> relParts() {
final List<RelationParts> relParts = new ArrayList<RelationParts>(bounds.relations().size());
for (Relation r : bounds.relations()) {
IntSet upper = bounds.upperBound(r).indexView();
if (upper.size() == bounds.lowerBound(r).size())
// skip constant relation
continue;
IntSet reps = Ints.bestSet(usize);
for (IntIterator tuples = upper.iterator(); tuples.hasNext(); ) {
for (int tIndex = tuples.next(), i = r.arity(); i > 0; i--, tIndex /= usize) {
for (IntSet symm : symmetries) {
if (symm.contains(tIndex % usize)) {
reps.add(symm.min());
break;
}
}
}
}
relParts.add(new RelationParts(r, reps));
}
final Comparator<RelationParts> cmp = new Comparator<RelationParts>() {
@Override
public int compare(RelationParts o1, RelationParts o2) {
final int acmp = o1.relation.arity() - o2.relation.arity();
return acmp != 0 ? acmp : String.valueOf(o1.relation.name()).compareTo(String.valueOf(o2.relation.name()));
}
};
Collections.sort(relParts, cmp);
return relParts;
}
use of kodkod.util.ints.IntSet in project org.alloytools.alloy by AlloyTools.
the class Translation method interpret.
public Instance interpret(Bounds bounds) {
final SATSolver solver = cnf();
final Instance instance = new Instance(bounds.universe());
final TupleFactory f = bounds.universe().factory();
for (IndexedEntry<TupleSet> entry : bounds.intBounds()) {
instance.add(entry.index(), entry.value());
}
for (Relation r : bounds.relations()) {
// if (bnds != bounds && bnds.findRelByName(r.name()) == null)
// continue;
TupleSet lower = bounds.lowerBound(r);
IntSet indices = Ints.bestSet(lower.capacity());
indices.addAll(lower.indexView());
IntSet vars = primaryVariables(r);
if (!vars.isEmpty()) {
// System.out.println(r + ": [" + vars.min() + ", " + vars.max()
// + "]");
int lit = vars.min();
for (IntIterator iter = bounds.upperBound(r).indexView().iterator(); iter.hasNext(); ) {
final int index = iter.next();
if (!indices.contains(index) && solver.valueOf(lit++))
indices.add(index);
}
}
instance.add(r, f.setOf(r.arity(), indices));
}
return instance;
}
use of kodkod.util.ints.IntSet in project org.alloytools.alloy by AlloyTools.
the class DynamicRCEStrategy method next.
/**
* {@inheritDoc}
*
* @see kodkod.engine.satlab.ReductionStrategy#next(kodkod.engine.satlab.ResolutionTrace)
*/
@Override
public IntSet next(ResolutionTrace trace) {
if (hits.isEmpty())
// tried everything
return Ints.EMPTY_SET;
final IntSet relevantVars = StrategyUtils.coreTailUnits(trace);
final long[] byRelevance = sortByRelevance(trace, relevantVars);
if (DBG)
printRelevant(byRelevance);
for (int i = byRelevance.length - 1; i >= 0; i--) {
final int var = (int) byRelevance[i];
if (hits.remove(var) != null) {
// remove maxVar from the set of relevant variables
relevantVars.remove(var);
if (relevantVars.isEmpty())
// there was only one root formula left
break;
// get all axioms and resolvents corresponding to the clauses
// that
// form the translations of formulas identified by relevant vars
final IntSet relevantClauses = clausesFor(trace, relevantVars);
assert !relevantClauses.isEmpty() && !relevantClauses.contains(trace.size() - 1);
if (DBG)
System.out.println("relevant clauses: " + relevantClauses.size() + ", removed " + var);
return relevantClauses;
}
}
hits.clear();
return Ints.EMPTY_SET;
}
use of kodkod.util.ints.IntSet in project org.alloytools.alloy by AlloyTools.
the class RCEStrategy method next.
/**
* {@inheritDoc}
*
* @see kodkod.engine.satlab.ReductionStrategy#next(kodkod.engine.satlab.ResolutionTrace)
*/
@Override
public IntSet next(ResolutionTrace trace) {
if (varsToTry.isEmpty())
// tried everything
return Ints.EMPTY_SET;
final IntSet relevantVars = StrategyUtils.coreTailUnits(trace);
for (IntIterator varItr = varsToTry.iterator(); varItr.hasNext(); ) {
final int var = varItr.next();
varItr.remove();
if (relevantVars.remove(var)) {
// relevant variables
if (relevantVars.isEmpty())
// there was only root formula left
break;
// get all axioms and resolvents corresponding to the clauses
// that
// form the translations of formulas identified by relevant vars
final IntSet relevantClauses = clausesFor(trace, relevantVars);
assert !relevantClauses.isEmpty() && !relevantClauses.contains(trace.size() - 1);
return relevantClauses;
}
}
varsToTry.clear();
return Ints.EMPTY_SET;
}
use of kodkod.util.ints.IntSet in project org.alloytools.alloy by AlloyTools.
the class RCEStrategy method clausesFor.
/**
* Returns the indices of all axioms and resolvents 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) }, A = C.*T
* | trace.backwardReachable(A) - trace.backwardReachable(trace.axioms()
* - A)
*/
private IntSet clausesFor(ResolutionTrace trace, IntSet relevantVars) {
final IntSet relevantAxioms = StrategyUtils.clausesFor(trace, relevantVars);
if (dist < trace.resolvents().size()) {
IntSet relevant = relevantAxioms;
for (int i = 0, lastSize = 0; lastSize < relevant.size() && i < dist; i++) {
lastSize = relevant.size();
relevant = trace.directlyLearnable(relevant);
}
return relevant;
} else {
// return all resolvents
return trace.learnable(relevantAxioms);
}
// System.out.println("level 1 resolvents " +
// (relevant.size()-relevantAxioms.size()) + ", axioms " +
// relevantAxioms.size());
}
Aggregations