Search in sources :

Example 41 with IntSet

use of kodkod.util.ints.IntSet in project org.alloytools.alloy by AlloyTools.

the class MiniSatProver method format.

/**
 * Modifies the given raw trace so that it conforms to the specification of
 * {@linkplain LazyTrace#LazyTrace(int[][], int)}, if the array contains no null
 * entries, and to the specfication of
 * {@linkplain LazyTrace#LazyTrace(LazyTrace, IntSet, int[][])} otherwise.
 *
 * @ensures modifies the trace so that it conforms to the specification of one
 *          of the LazyTrace constructors.
 * @return trace
 */
private int[][] format(int[][] trace) {
    final int length = trace.length;
    final IntSet resolvents = new IntBitSet(length);
    final int offset = numberOfVariables() + 1;
    for (int i = 0; i < length; i++) {
        int[] clause = trace[i];
        if (clause != null && clause[0] >= offset) {
            clause[0] -= offset;
            resolvents.add(i);
        }
    }
    final int axioms = length - resolvents.size();
    if (resolvents.min() < axioms) {
        final int[] position = new int[length];
        for (int i = 0, axiomIndex = 0, resolventIndex = axioms; i < length; i++) {
            if (resolvents.contains(i)) {
                position[i] = resolventIndex++;
                int[] resolvent = trace[i];
                for (int j = 0, resLength = resolvent.length; j < resLength; j++) {
                    resolvent[j] = position[resolvent[j]];
                }
            } else {
                position[i] = axiomIndex++;
            }
        }
        for (IntIterator itr = resolvents.iterator(length, 0); itr.hasNext(); ) {
            int i = itr.next();
            int pos = position[i];
            if (i == pos)
                // correctly positioned, do nothing
                continue;
            int[] resolvent = trace[i];
            System.arraycopy(trace, i + 1, trace, i, pos - i);
            trace[pos] = resolvent;
        }
    }
    assert axioms == numberOfClauses();
    return trace;
}
Also used : IntBitSet(kodkod.util.ints.IntBitSet) IntIterator(kodkod.util.ints.IntIterator) IntSet(kodkod.util.ints.IntSet)

Example 42 with IntSet

use of kodkod.util.ints.IntSet in project org.alloytools.alloy by AlloyTools.

the class CRRStrategy method next.

/**
 * Returns the next subset of clauses in the given trace to be analyzed.
 *
 * @requires {@inheritDoc}
 * @ensures {@inheritDoc}
 * @return last(this.nexts')
 */
@Override
public final IntSet next(final ResolutionTrace trace) {
    final IntSet core = trace.core();
    if (excluded == null) {
        // the first time this method is called
        excluded = new HashSet<Clause>((int) (StrictMath.round(core.size() * .75)));
    }
    for (IntIterator iter = core.iterator(Integer.MAX_VALUE, Integer.MIN_VALUE); iter.hasNext(); ) {
        int index = iter.next();
        if (excluded.add(trace.get(index))) {
            // haven't tried excluding
            // this one
            // get all clauses reachable from the conflict clause
            IntSet next = trace.reachable(Ints.singleton(trace.size() - 1));
            // remove all clauses backward reachable from the excluded
            // clause
            next.removeAll(trace.backwardReachable(Ints.singleton(index)));
            return next;
        }
    }
    return Ints.EMPTY_SET;
}
Also used : IntIterator(kodkod.util.ints.IntIterator) IntSet(kodkod.util.ints.IntSet) Clause(kodkod.engine.satlab.Clause)

Example 43 with IntSet

use of kodkod.util.ints.IntSet in project org.alloytools.alloy by AlloyTools.

the class BenchmarkSymmStats2 method allSymms.

private static SymmInfo allSymms(Bounds bounds) {
    try {
        final long startGen = bean.getCurrentThreadUserTime();
        final File tmp = File.createTempFile("symmgraph", ".txt");
        final PrintStream stream = new PrintStream(new FileOutputStream(tmp));
        toNauty(bounds, stream);
        stream.close();
        final long endGen = bean.getCurrentThreadUserTime();
        final String cmd = "/Users/emina/Desktop/tools/nauty22/run_dreadnaut " + tmp.getAbsoluteFile();
        final ProcessRunner runner = new ProcessRunner(cmd.split("\\s"));
        runner.start();
        try {
            runner.join(BenchmarkDriver.FIVE_MIN);
            if (runner.getState() != Thread.State.TERMINATED) {
                System.out.print("t\\o\t");
                System.out.print("t\\o\t");
                runner.destroyProcess();
                destroy("dreadnaut");
                tmp.delete();
                return new SymmInfo(bounds.universe().size());
            }
            final BufferedReader out = new BufferedReader(new InputStreamReader(runner.processOutput(), "ISO-8859-1"));
            String line;
            String allSymms = null;
            long time = -1;
            final Set<IntSet> parts = new LinkedHashSet<IntSet>();
            final Matcher smatcher = Pattern.compile(".+grpsize=(.+?);.*").matcher("");
            final Matcher tmatcher = Pattern.compile(".+cpu time = (.+?)\\s.*").matcher("");
            final Matcher omatcher = Pattern.compile("invarproc \"adjacencies\"").matcher("");
            while ((line = out.readLine()) != null) {
                smatcher.reset(line);
                if (smatcher.matches()) {
                    allSymms = smatcher.group(1);
                } else {
                    tmatcher.reset(line);
                    if (tmatcher.matches()) {
                        time = (long) (Double.parseDouble(tmatcher.group(1)) * 1000);
                        if (time == 0)
                            time++;
                    } else {
                        omatcher.reset(line);
                        if (omatcher.find()) {
                            break;
                        }
                    }
                }
            }
            if (line != null) {
                final StringBuilder builder = new StringBuilder();
                while ((line = out.readLine()) != null) {
                    builder.append(line);
                }
                line = builder.toString();
                // System.out.println(line);
                final String[] orbits = line.split(";");
                final Matcher dmatcher = Pattern.compile("\\s*(\\d+)\\s*").matcher("");
                for (String n : orbits) {
                    String[] range = n.split(":");
                    if (range.length == 2) {
                        dmatcher.reset(range[0]);
                        dmatcher.matches();
                        final int min = Integer.parseInt(dmatcher.group(1));
                        if (min >= bounds.universe().size())
                            break;
                        dmatcher.reset(range[1]);
                        dmatcher.matches();
                        parts.add(Ints.rangeSet(Ints.range(min, Integer.parseInt(dmatcher.group(1)))));
                    } else {
                        range = n.split("\\s+");
                        final IntSet part = new IntTreeSet();
                        for (int i = 0; i < range.length; i++) {
                            dmatcher.reset(range[i]);
                            if (dmatcher.matches()) {
                                final int match = Integer.parseInt(dmatcher.group(1));
                                if (match < bounds.universe().size())
                                    part.add(match);
                                else
                                    break;
                            }
                        }
                        if (part.isEmpty())
                            break;
                        else
                            parts.add(part);
                    }
                }
            }
            out.close();
            tmp.delete();
            runner.destroyProcess();
            if (time < 0 || allSymms == null || parts.isEmpty())
                throw new IllegalStateException();
            return new SymmInfo(parts, String.valueOf(time + (endGen - startGen) / 1000000), allSymms);
        } catch (IOException e) {
            tmp.delete();
            runner.destroyProcess();
            destroy("dreadnaut");
            throw new IllegalStateException(e);
        } catch (InterruptedException e) {
            tmp.delete();
            runner.destroyProcess();
            destroy("dreadnaut");
            e.printStackTrace();
            throw new IllegalStateException(e);
        }
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) PrintStream(java.io.PrintStream) InputStreamReader(java.io.InputStreamReader) Matcher(java.util.regex.Matcher) IntSet(kodkod.util.ints.IntSet) IntTreeSet(kodkod.util.ints.IntTreeSet) IOException(java.io.IOException) FileOutputStream(java.io.FileOutputStream) BufferedReader(java.io.BufferedReader) ProcessRunner(tests.util.ProcessRunner) File(java.io.File)

Example 44 with IntSet

use of kodkod.util.ints.IntSet in project org.alloytools.alloy by AlloyTools.

the class SparseSequenceTest method testClone.

// public void testFirstLast() {
// for(int i = 0; i < 10; i++)
// s0.put(i, 0);
// IndexedEntry<Integer> e0 = s0.first();
// while (e0 != null) {
// System.out.println(e0);
// e0 = s0.successor(e0.index());
// }
// }
public void testClone() {
    final IntSet s = Ints.bestSet(3);
    s.add(1);
    s.add(2);
    s0 = new ArraySequence<Integer>(s);
    s0.put(1, 0);
    s0.put(2, 0);
    try {
        SparseSequence<Integer> s1 = s0.clone();
        assertTrue(s1.equals(s0));
        assertNotSame(s1, s0);
        SparseSequence<Integer> s2 = new ArraySequence<Integer>(s);
        s2.putAll(s0);
        s1.remove(1);
        assertTrue(s2.equals(s0));
        assertFalse(s1.equals(s0));
    } catch (CloneNotSupportedException e) {
        assert false;
    }
}
Also used : ArraySequence(kodkod.util.ints.ArraySequence) IntSet(kodkod.util.ints.IntSet)

Example 45 with IntSet

use of kodkod.util.ints.IntSet in project org.alloytools.alloy by AlloyTools.

the class BugTests method testEmina_02162006.

public final void testEmina_02162006() {
    final IntTreeSet s = new IntTreeSet();
    for (int i = 0; i < 5; i++) {
        s.add(i);
    }
    final IntTreeSet s1 = new IntTreeSet();
    s1.add(0);
    final IntSet intersection = new IntTreeSet(s);
    intersection.retainAll(s1);
    s.removeAll(intersection);
    assertSameContents(s, 1, 2, 3, 4);
    assertSameContents(s1, 0);
    assertSameContents(intersection, 0);
}
Also used : IntTreeSet(kodkod.util.ints.IntTreeSet) 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