Search in sources :

Example 6 with Edge

use of com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.Edge in project Dat3M by hernanponcedeleon.

the class CartesianGraph method forwardPropagate.

@Override
@SuppressWarnings("unchecked")
public Collection<Edge> forwardPropagate(CAATPredicate changedSource, Collection<? extends Derivable> added) {
    List<Edge> addedEdges = new ArrayList<>();
    Collection<Element> addedElems = (Collection<Element>) added;
    if (changedSource == first) {
        for (Element a : addedElems) {
            for (Element b : second.elements()) {
                addedEdges.add(derive(a, b));
            }
        }
    } else if (changedSource == second) {
        for (Element b : addedElems) {
            for (Element a : first.elements()) {
                addedEdges.add(derive(a, b));
            }
        }
    }
    return addedEdges;
}
Also used : Element(com.dat3m.dartagnan.solver.caat.predicates.sets.Element) ArrayList(java.util.ArrayList) Collection(java.util.Collection) Edge(com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.Edge)

Example 7 with Edge

use of com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.Edge in project Dat3M by hernanponcedeleon.

the class CompositionGraph method forwardPropagate.

@Override
@SuppressWarnings("unchecked")
public Collection<Edge> forwardPropagate(CAATPredicate changedSource, Collection<? extends Derivable> added) {
    ArrayList<Edge> newEdges = new ArrayList<>();
    Collection<Edge> addedEdges = (Collection<Edge>) added;
    if (changedSource == first) {
        // (A+R);B = A;B + R;B
        for (Edge e : addedEdges) {
            updateFirst(e, newEdges);
        }
    }
    if (changedSource == second) {
        // A;(B+R) = A;B + A;R
        for (Edge e : addedEdges) {
            updateSecond(e, newEdges);
        }
    }
    // So we add (A+R);R and R;(A+R), which is done by doing both of the above update procedures
    return newEdges;
}
Also used : Edge(com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.Edge)

Example 8 with Edge

use of com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.Edge in project Dat3M by hernanponcedeleon.

the class IntersectionGraph method forwardPropagate.

@Override
@SuppressWarnings("unchecked")
public Collection<Edge> forwardPropagate(CAATPredicate changedSource, Collection<? extends Derivable> added) {
    if (changedSource == first || changedSource == second) {
        RelationGraph other = (changedSource == first) ? second : first;
        Collection<Edge> addedEdges = (Collection<Edge>) added;
        List<Edge> newlyAdded = new ArrayList<>();
        for (Edge e1 : addedEdges) {
            Edge e2 = other.get(e1);
            if (e2 != null) {
                Edge e = derive(e1, e2);
                simpleGraph.add(e);
                newlyAdded.add(e);
            }
        }
        return newlyAdded;
    } else {
        return Collections.emptyList();
    }
}
Also used : RelationGraph(com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.RelationGraph) Edge(com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.Edge)

Example 9 with Edge

use of com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.Edge in project Dat3M by hernanponcedeleon.

the class PathAlgorithm method findShortestPath.

/*
        This uses a bidirectional BFS to find a shortest path.
        A <filter> can be provided to skip certain edges during the search.
     */
public static List<Edge> findShortestPath(RelationGraph graph, int start, int end, Predicate<Edge> filter) {
    queue1.clear();
    queue2.clear();
    Arrays.fill(parentMap1, null);
    System.arraycopy(parentMap1, 0, parentMap2, 0, Math.min(parentMap1.length, parentMap2.length));
    queue1.add(start);
    queue2.add(end);
    boolean found = false;
    boolean doForwardBFS = true;
    int cur = -1;
    while (!found && (!queue1.isEmpty() || !queue2.isEmpty())) {
        if (doForwardBFS) {
            // Forward BFS
            int curSize = queue1.size();
            while (curSize-- > 0 && !found) {
                for (Edge next : graph.outEdges(queue1.poll())) {
                    if (!filter.test(next)) {
                        continue;
                    }
                    cur = next.getSecond();
                    if (cur == end || parentMap2[cur] != null) {
                        parentMap1[cur] = next;
                        found = true;
                        break;
                    } else if (parentMap1[cur] == null) {
                        parentMap1[cur] = next;
                        queue1.add(cur);
                    }
                }
            }
            doForwardBFS = false;
        } else {
            // Backward BFS
            int curSize = queue2.size();
            while (curSize-- > 0 && !found) {
                for (Edge next : graph.inEdges(queue2.poll())) {
                    if (!filter.test(next)) {
                        continue;
                    }
                    cur = next.getFirst();
                    if (parentMap1[cur] != null) {
                        parentMap2[cur] = next;
                        found = true;
                        break;
                    } else if (parentMap2[cur] == null) {
                        parentMap2[cur] = next;
                        queue2.add(cur);
                    }
                }
            }
            doForwardBFS = true;
        }
    }
    if (!found) {
        return Collections.emptyList();
    }
    LinkedList<Edge> path = new LinkedList<>();
    int e = cur;
    do {
        Edge backEdge = parentMap1[e];
        path.addFirst(backEdge);
        e = backEdge.getFirst();
    } while (e != start);
    e = cur;
    while (e != end) {
        Edge forwardEdge = parentMap2[e];
        path.addLast(forwardEdge);
        e = forwardEdge.getSecond();
    }
    return path;
}
Also used : Edge(com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.Edge)

Example 10 with Edge

use of com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.Edge in project Dat3M by hernanponcedeleon.

the class AcyclicityConstraint method strongConnect.

private void strongConnect(Node v) {
    v.index = index;
    v.lowlink = index;
    stack.push(v);
    v.isOnStack = true;
    index++;
    for (Edge e : constrainedGraph.outEdges(v.id)) {
        Node w = nodeMap[e.getSecond()];
        if (!w.wasVisited()) {
            strongConnect(w);
            v.lowlink = Math.min(v.lowlink, w.lowlink);
        } else if (w.isOnStack) {
            v.lowlink = Math.min(v.lowlink, w.index);
        }
        if (w == v) {
            v.hasSelfLoop = true;
        }
    }
    if (v.lowlink == v.index) {
        Node w;
        do {
            w = stack.pop();
            w.isOnStack = false;
            TEMP_LIST.add(w.id);
        } while (w != v);
        if (v.hasSelfLoop || TEMP_LIST.size() > 1) {
            DenseIntegerSet scc = SET_COLLECTION_POOL.get();
            scc.ensureCapacity(domain.size());
            scc.clear();
            scc.addAll(TEMP_LIST);
            violatingSccs.add(scc);
        }
        TEMP_LIST.clear();
    }
}
Also used : DenseIntegerSet(com.dat3m.dartagnan.solver.caat.misc.DenseIntegerSet) Edge(com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.Edge)

Aggregations

Edge (com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.Edge)22 EventData (com.dat3m.dartagnan.verification.model.EventData)10 EdgeDirection (com.dat3m.dartagnan.solver.caat.misc.EdgeDirection)7 Stream (java.util.stream.Stream)6 java.util (java.util)5 Function (java.util.function.Function)5 Thread (com.dat3m.dartagnan.program.Thread)3 BigInteger (java.math.BigInteger)3 RelationGraph (com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.RelationGraph)2 Element (com.dat3m.dartagnan.solver.caat.predicates.sets.Element)2 Conjunction (com.dat3m.dartagnan.utils.logic.Conjunction)2 Iterators (com.google.common.collect.Iterators)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 Spliterator (java.util.Spliterator)2 IntStream (java.util.stream.IntStream)2 StreamSupport (java.util.stream.StreamSupport)2 Event (com.dat3m.dartagnan.program.event.core.Event)1 RMWStore (com.dat3m.dartagnan.program.event.core.rmw.RMWStore)1