TarjanとKosarajuの両方を調べ中
1 parent f8c267e commit fb8e43f262f9c7186c97650dbe6f9afe3f64ef49
yoichiro authored on 20 Sep 2019
Showing 1 changed file
View
67
AlgebraicDataflowArchitectureModel/src/algorithm/UpdateConflictCheck.java
package algorithm;
 
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
 
import models.*;
import models.dataFlowModel.DataFlowModel;
 
public class UpdateConflictCheck {
DataFlowModel graph = new DataFlowModel();
Map<Node, Boolean> comp = new HashMap<>();
Map<Integer, Node> root = new HashMap<>();
int i = 0;
int index = 0;
 
public void setup(DataFlowModel graph) {
this.graph = graph;
}
 
public boolean check() {
boolean result = true;
Map<Integer, Node> root = new HashMap<>();
for (Node node : graph.getResourceDependencyGraph().getNodes()) {
if (node.getIndegree() > 1)
result = false;
}
private Node search(Node node, boolean reverse) {
comp.put(node, true);
if (!reverse) {
for (Node out : node.getSuccessors()) {
if (comp.containsKey(out)) {
if (comp.containsKey(out)&&root.containsValue(out)) {
return search(out, reverse);
}
}
} else {
for (Node out : node.getPredecessors()) {
if (comp.containsKey(out)) {
if (comp.containsKey(out)&&root.containsValue(out)) {
return search(out, reverse);
}
}
}
if (!reverse)
i++;
return node;
}
/*
public Set<Integer> kosaraju(){
int n = graph.size(), sz = 0;
Graph rg(n);
std::vector<int> stk, cmp(n, -1), added(n), visited(n), ord(n);
for (auto &es : g) {
for (auto e : es) {
std::swap(e.src, e.dst);
rg[e.src].emplace_back(e);
}
sz += es.size();
}
stk.resize(n + sz);
sz = 0;
for (int i = 0; i < n; i++) {
if (visited[i]) continue;
int s = 0;
stk[s++] = i;
while (s != 0) {
int v = stk[s - 1];
visited[v] = true;
bool pushed = false;
for (auto &e : g[v]) {
int dst = e.dst;
if (!visited[dst]) {
stk[s++] = dst;
pushed = true;
}
}
if (pushed) continue;
int t = stk[s - 1];
if (!added[t]) {
added[t] = true;
ord[n - ++sz] = t;
}
--s;
}
}
int k = 0;
for (int &u : ord) {
if (cmp[u] != -1) continue;
int s = 0;
stk[s++] = u;
while (s != 0) {
int v = stk[--s];
cmp[v] = k;
for (auto &e : rg[v]) {
int d = e.dst;
if (cmp[d] == -1) stk[s++] = d;
}
}
++k;
}
return cmp;
}*/
public Set<Node> tarjan(){
}
}