diff --git a/AlgebraicDataflowArchitectureModel/src/algorithm/UpdateConflictCheck.java b/AlgebraicDataflowArchitectureModel/src/algorithm/UpdateConflictCheck.java index 44f78ed..b09bf07 100644 --- a/AlgebraicDataflowArchitectureModel/src/algorithm/UpdateConflictCheck.java +++ b/AlgebraicDataflowArchitectureModel/src/algorithm/UpdateConflictCheck.java @@ -9,12 +9,21 @@ private int index = 0; private Deque stack = new ArrayDeque<>(); private Set> strong = new HashSet<>(); - private Map ids = new HashMap<>(); + private Map ids = new HashMap<>(); private Map lowlink = new HashMap<>(); private Map onStack = new HashMap<>(); + private void init() { + index = 0; + stack = new ArrayDeque<>(); + strong = new HashSet<>(); + ids = new HashMap<>(); + lowlink = new HashMap<>(); + onStack = new HashMap<>(); + } + private void strongconnect(Node node) { - ids.put(index, node); + ids.put(node, index); lowlink.put(node, index); index++; stack.push(node); @@ -24,19 +33,30 @@ if (lowlink.containsKey(n)) { strongconnect(n); if (lowlink.get(node) > lowlink.get(n)) { - lowlink.replace(node, lowlink.get(node), lowlink.get(n)); + lowlink.replace(node, lowlink.get(n)); } } else if (onStack.get(n)) { if (lowlink.get(node) > lowlink.get(n)) { - lowlink.replace(node, lowlink.get(node), lowlink.get(n)); + lowlink.replace(node, lowlink.get(n)); } } } + if (lowlink.get(node) == ids.get(node)) { + Set tmp = new HashSet<>(); + Node w; + do { + w = stack.pop(); + onStack.replace(node, false); + tmp.add(w); + } while (node != w); + strong.add(tmp); + } } public boolean run(DataFlowModel model) { + init(); for (Node node : model.getResourceDependencyGraph().getNodes()) { - if (ids.get(index) == null) { + if (ids.containsKey(node)) { strongconnect(node); } }