Search in sources :

Example 6 with IntSet

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;
}
Also used : Relation(kodkod.ast.Relation) IntIterator(kodkod.util.ints.IntIterator) IntSet(kodkod.util.ints.IntSet) ArrayList(java.util.ArrayList) Comparator(java.util.Comparator)

Example 7 with IntSet

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;
}
Also used : SATSolver(kodkod.engine.satlab.SATSolver) TupleSet(kodkod.instance.TupleSet) Relation(kodkod.ast.Relation) IntIterator(kodkod.util.ints.IntIterator) Instance(kodkod.instance.Instance) IntSet(kodkod.util.ints.IntSet) TupleFactory(kodkod.instance.TupleFactory)

Example 8 with IntSet

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;
}
Also used : IntSet(kodkod.util.ints.IntSet)

Example 9 with IntSet

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;
}
Also used : IntIterator(kodkod.util.ints.IntIterator) IntSet(kodkod.util.ints.IntSet)

Example 10 with IntSet

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());
}
Also used : IntSet(kodkod.util.ints.IntSet)

Aggregations

IntSet (kodkod.util.ints.IntSet)45 IntIterator (kodkod.util.ints.IntIterator)21 IntBitSet (kodkod.util.ints.IntBitSet)9 IntTreeSet (kodkod.util.ints.IntTreeSet)8 Relation (kodkod.ast.Relation)7 Clause (kodkod.engine.satlab.Clause)6 TupleSet (kodkod.instance.TupleSet)6 BooleanMatrix (kodkod.engine.bool.BooleanMatrix)5 Map (java.util.Map)4 Set (java.util.Set)4 LinkedHashMap (java.util.LinkedHashMap)3 LinkedHashSet (java.util.LinkedHashSet)3 Formula (kodkod.ast.Formula)3 Node (kodkod.ast.Node)3 BooleanFactory (kodkod.engine.bool.BooleanFactory)3 RecordFilter (kodkod.engine.fol2sat.RecordFilter)3 TranslationRecord (kodkod.engine.fol2sat.TranslationRecord)3 Bounds (kodkod.instance.Bounds)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2