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;
}
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;
}
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();
}
}
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;
}
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();
}
}
Aggregations