Search in sources :

Example 6 with TranslationRecord

use of kodkod.engine.fol2sat.TranslationRecord in project org.alloytools.alloy by AlloyTools.

the class TrivialProof method minimize.

/**
 * Minimizes the current core using the trivial strategy that does one of the
 * following: (1) if there is a root that simplified to FALSE, sets the minimal
 * core to that root; or (2) if not, there must be two roots that translated to
 * x and -x, where x is a boolean literal, so we pick those two as the minimal
 * core. The strategy argument is ignored (it can be null).
 *
 * @see Proof#minimize(ReductionStrategy)
 */
@Override
public void minimize(ReductionStrategy strategy) {
    final Map<Formula, int[]> rootLits = new LinkedHashMap<Formula, int[]>();
    final Map<Formula, Node> rootNodes = new LinkedHashMap<Formula, Node>();
    final Set<Formula> roots = log().roots();
    for (Iterator<TranslationRecord> itr = core(); itr.hasNext(); ) {
        final TranslationRecord rec = itr.next();
        if (roots.contains(rec.translated())) {
            // simply record the most recent output value for each formula:
            // this is guaranteed to be the final output value for that
            // formula because of the translation log guarantee that the
            // log is replayed in the order of translation: i.e. a child's
            // output value is always recorded before the parent's
            int[] val = rootLits.get(rec.translated());
            if (val == null) {
                val = new int[1];
                rootLits.put(rec.translated(), val);
            }
            val[0] = rec.literal();
            rootNodes.put(rec.translated(), rec.node());
        }
    }
    final SparseSequence<Formula> lits = new TreeSequence<Formula>();
    for (Map.Entry<Formula, int[]> entry : rootLits.entrySet()) {
        final int lit = entry.getValue()[0];
        if (lit == -Integer.MAX_VALUE) {
            coreRoots = Collections.singletonMap(entry.getKey(), rootNodes.get(entry.getKey()));
            break;
        } else if (lits.containsIndex(-lit)) {
            final Formula f0 = lits.get(-lit);
            final Formula f1 = entry.getKey();
            coreRoots = new LinkedHashMap<Formula, Node>(3);
            coreRoots.put(f0, rootNodes.get(f0));
            coreRoots.put(f1, rootNodes.get(f1));
            coreRoots = Collections.unmodifiableMap(coreRoots);
            break;
        } else {
            lits.put(lit, entry.getKey());
        }
    }
    coreFilter = null;
    assert coreRoots.size() == 1 && rootLits.get(coreRoots.keySet().iterator().next())[0] == -Integer.MAX_VALUE || coreRoots.size() == 2;
}
Also used : Node(kodkod.ast.Node) TranslationRecord(kodkod.engine.fol2sat.TranslationRecord) LinkedHashMap(java.util.LinkedHashMap) BinaryFormula(kodkod.ast.BinaryFormula) MultiplicityFormula(kodkod.ast.MultiplicityFormula) QuantifiedFormula(kodkod.ast.QuantifiedFormula) ConstantFormula(kodkod.ast.ConstantFormula) NotFormula(kodkod.ast.NotFormula) ComparisonFormula(kodkod.ast.ComparisonFormula) NaryFormula(kodkod.ast.NaryFormula) Formula(kodkod.ast.Formula) IntComparisonFormula(kodkod.ast.IntComparisonFormula) TreeSequence(kodkod.util.ints.TreeSequence) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 7 with TranslationRecord

use of kodkod.engine.fol2sat.TranslationRecord in project org.alloytools.alloy by AlloyTools.

the class TrivialProof method highLevelCore.

/**
 * {@inheritDoc}
 *
 * @see kodkod.engine.Proof#highLevelCore()
 */
@Override
public final Map<Formula, Node> highLevelCore() {
    if (coreRoots == null) {
        final Iterator<TranslationRecord> itr = core();
        final Set<Formula> roots = log().roots();
        coreRoots = new LinkedHashMap<Formula, Node>();
        while (itr.hasNext()) {
            TranslationRecord rec = itr.next();
            if (roots.contains(rec.translated()))
                coreRoots.put(rec.translated(), rec.node());
        }
        coreRoots = Collections.unmodifiableMap(coreRoots);
    }
    return coreRoots;
}
Also used : BinaryFormula(kodkod.ast.BinaryFormula) MultiplicityFormula(kodkod.ast.MultiplicityFormula) QuantifiedFormula(kodkod.ast.QuantifiedFormula) ConstantFormula(kodkod.ast.ConstantFormula) NotFormula(kodkod.ast.NotFormula) ComparisonFormula(kodkod.ast.ComparisonFormula) NaryFormula(kodkod.ast.NaryFormula) Formula(kodkod.ast.Formula) IntComparisonFormula(kodkod.ast.IntComparisonFormula) Node(kodkod.ast.Node) TranslationRecord(kodkod.engine.fol2sat.TranslationRecord)

Aggregations

Formula (kodkod.ast.Formula)7 Node (kodkod.ast.Node)7 TranslationRecord (kodkod.engine.fol2sat.TranslationRecord)7 LinkedHashMap (java.util.LinkedHashMap)5 Map (java.util.Map)5 RecordFilter (kodkod.engine.fol2sat.RecordFilter)4 BinaryFormula (kodkod.ast.BinaryFormula)3 IntSet (kodkod.util.ints.IntSet)3 IntTreeSet (kodkod.util.ints.IntTreeSet)3 IdentityHashMap (java.util.IdentityHashMap)2 Set (java.util.Set)2 ComparisonFormula (kodkod.ast.ComparisonFormula)2 ConstantFormula (kodkod.ast.ConstantFormula)2 IntComparisonFormula (kodkod.ast.IntComparisonFormula)2 MultiplicityFormula (kodkod.ast.MultiplicityFormula)2 NaryFormula (kodkod.ast.NaryFormula)2 NotFormula (kodkod.ast.NotFormula)2 QuantifiedFormula (kodkod.ast.QuantifiedFormula)2 TupleSet (kodkod.instance.TupleSet)2 IdentityHashSet (kodkod.util.collections.IdentityHashSet)2