Detects if there are cycles in the DAG managed by this class. If a cycle is found, it returns the list of nodes involved in the cycle. If no cycle is found, it returns None. Returns: - A list of nodes forming a cycle, or None if no cycles are found.
(self)
| 31 | self.graph.nodes[node_id][attr] = value |
| 32 | |
| 33 | def detect_cycles(self): |
| 34 | """ |
| 35 | Detects if there are cycles in the DAG managed by this class. |
| 36 | If a cycle is found, it returns the list of nodes involved in the cycle. |
| 37 | If no cycle is found, it returns None. |
| 38 | |
| 39 | Returns: |
| 40 | - A list of nodes forming a cycle, or None if no cycles are found. |
| 41 | """ |
| 42 | try: |
| 43 | cycle = list(nx.find_cycle(self.graph, orientation='original')) |
| 44 | print("Cycle detected:") |
| 45 | return cycle |
| 46 | except nx.exception.NetworkXNoCycle: |
| 47 | return None |
| 48 | |
| 49 | def get_node(self, node_id: str) -> Optional[Dict]: |
| 50 | """ |
no outgoing calls
no test coverage detected