Mercurial > codeOptimizer
changeset 8:8952a4f7aa95
Fix off by one error, and simplify.
| author | Tom Fredrik Blenning Klaussen <bfg@blenning.no> |
|---|---|
| date | Mon, 24 Sep 2012 10:36:03 +0200 |
| parents | 94b1959b0108 |
| children | 2263a283203c |
| files | DepGraph.py |
| diffstat | 1 files changed, 4 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/DepGraph.py Mon Sep 24 10:32:09 2012 +0200 +++ b/DepGraph.py Mon Sep 24 10:36:03 2012 +0200 @@ -1,4 +1,4 @@ -import copy, sys +import copy from types import * class DepGraph: @@ -43,14 +43,13 @@ @staticmethod def identifyStronglyConnectedComponents(deps): - index=0 S=[] vindex={} lowlink={} retVal=[] for v in range(len(deps)): if not v in vindex: - retVal.extend(DepGraph.strongconnect(deps, v, index, vindex, lowlink, S)) + retVal.extend(DepGraph.strongconnect(deps, v, 0, vindex, lowlink, S)) return retVal @staticmethod @@ -60,7 +59,6 @@ vindex[v] = index lowlink[v] = index #print index - index += 1 S.append(v) # Consider successors of v @@ -69,7 +67,7 @@ continue if not w in vindex: # Successor w has not yet been visited; recurse on it - res = DepGraph.strongconnect(deps, w, index, vindex, lowlink, S) + res = DepGraph.strongconnect(deps, w, index + 1, vindex, lowlink, S) retVal.extend(res) lowlink[v] = min(lowlink[v], lowlink[w]) elif w in S: @@ -94,6 +92,7 @@ while dissolved: dissolved = False strong = DepGraph.identifyStronglyConnectedComponents(deps) + print strong for s in strong: if len(s) > 1: #We remove the first dependency, and see how it goes. @@ -105,7 +104,6 @@ dissolved = True break return deps - sys.exit(1) @staticmethod def directedGraphInternal(deps):
