Sort the graph topologically. Returns: List: of objects in the order in which they must be handled.
(self)
| 61 | self.adjacent.update(graph.adjacent) |
| 62 | |
| 63 | def topsort(self): |
| 64 | """Sort the graph topologically. |
| 65 | |
| 66 | Returns: |
| 67 | List: of objects in the order in which they must be handled. |
| 68 | """ |
| 69 | graph = DependencyGraph() |
| 70 | components = self._tarjan72() |
| 71 | |
| 72 | NC = { |
| 73 | node: component for component in components for node in component |
| 74 | } |
| 75 | for component in components: |
| 76 | graph.add_arc(component) |
| 77 | for node in self: |
| 78 | node_c = NC[node] |
| 79 | for successor in self[node]: |
| 80 | successor_c = NC[successor] |
| 81 | if node_c != successor_c: |
| 82 | graph.add_edge(node_c, successor_c) |
| 83 | return [t[0] for t in graph._khan62()] |
| 84 | |
| 85 | def valency_of(self, obj): |
| 86 | """Return the valency (degree) of a vertex in the graph.""" |