Search in sources :

Example 36 with IntSet

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

Example 37 with IntSet

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

Example 38 with IntSet

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

Example 39 with IntSet

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

Example 40 with IntSet

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