diff options
| author | Shanta Kabra <shanta.kabra@gmail.com> | 2008-09-05 15:15:46 +0530 |
|---|---|---|
| committer | Shanta Kabra <shanta.kabra@gmail.com> | 2008-09-05 15:15:46 +0530 |
| commit | fd8f74ca728d9adc3d09f4788ec3d0c6e178570b (patch) | |
| tree | 368bb530fa69fe2c251beb00768206206e23c307 /bin/tools/graph.py | |
| parent | 8c725d3cfe237218d09bd30c538fd44d33d92fb8 (diff) | |
* Modifications in the strategy to add edge for the nodes with no ancesters
bzr revid: shanta.kabra@gmail.com-20080905094546-oj9xbxoiykwk541k
Diffstat (limited to 'bin/tools/graph.py')
| -rw-r--r-- | bin/tools/graph.py | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/bin/tools/graph.py b/bin/tools/graph.py index fd4f3c28052..d1fe2d50c57 100644 --- a/bin/tools/graph.py +++ b/bin/tools/graph.py @@ -507,18 +507,13 @@ class graph(object): max_level = max(map(lambda x: len(x), self.levels.values())) if max_level%2: - self.result[self.start]['x'] = (max_level+1)/2 + self.max_order + self.result[self.start]['x'] = (max_level+1)/2 + self.max_order +1 else: - self.result[self.start]['x'] = (max_level)/2 + self.max_order + self.result[self.start]['x'] = (max_level)/2 + self.max_order + 1 if self.Is_Cyclic: self.graph_order() - #for flat edges ie. source an destination nodes are on the same rank - for src in self.transitions: - for des in self.transitions[src]: - if (self.result[des]['y'] - self.result[src]['y'] == 0): - self.result[src]['y'] += 0.08 - self.result[des]['y'] -= 0.08 + else: self.result[self.start]['x'] = 0 self.tree_order(self.start, 0) @@ -634,7 +629,6 @@ class graph(object): self.order_heuristic() self.process_order() - def process(self, starting_node): """Process the graph to find ranks and order of the nodes @@ -649,18 +643,22 @@ class graph(object): if self.nodes: if self.start_nodes: #add dummy edges to the nodes which does not have any incoming edges - for node in self.no_ancester: - self.transitions[self.start_nodes[0]].append(node) - + tree = self.make_acyclic(None, self.start_nodes[0], 0, []) + for node in self.no_ancester: + for sec_node in self.transitions.get(node, []): + if sec_node in self.partial_order.keys(): + self.transitions[self.start_nodes[0]].append(node) + break + self.partial_order = {} tree = self.make_acyclic(None, self.start_nodes[0], 0, []) # if graph is disconnected or no start-node is given #than to find starting_node for each component of the node if len(self.nodes) > len(self.partial_order): - self.find_starts() - + self.find_starts() + self.max_order = 0 #for each component of the graph find ranks and order of the nodes for s in self.start_nodes: @@ -668,6 +666,7 @@ class graph(object): self.rank() # First step:Netwoek simplex algorithm self.order_in_rank() #Second step: ordering nodes within ranks + def __str__(self): result = '' @@ -681,6 +680,13 @@ class graph(object): """Computes actual co-ordiantes of the nodes """ + #for flat edges ie. source an destination nodes are on the same rank + for src in self.transitions: + for des in self.transitions[src]: + if (self.result[des]['y'] - self.result[src]['y'] == 0): + self.result[src]['y'] += 0.08 + self.result[des]['y'] -= 0.08 + for node in self.result: self.result[node]['x'] = (self.result[node]['x']) * maxx + plusx2 self.result[node]['y'] = (self.result[node]['y']) * maxy + plusy2 |
