drepr.planning.topological_sorting#
Functions
|
Try to break cycles using invert DFS. |
|
Generate a topological order of class nodes in the semantic model. |
|
Reverse DFS to visit all ancestors of a node |
suppose we have a semantic model, that may contains circle, our task is to generate a topological order from the directed cyclic graph, and a set of edges involved in the cycles that are removed in order to generate the topo-order |
Classes
|
- class ReversedTopoSortResult(topo_order: 'list[str]', removed_outgoing_edges: 'dict[int, bool]')[source]#
Bases:
object
- topological_sorting(sm: SemanticModel) ReversedTopoSortResult[source]#
suppose we have a semantic model, that may contains circle, our task is to generate a topological order from the directed cyclic graph, and a set of edges involved in the cycles that are removed in order to generate the topo-order
- Parameters:
sm (SemanticModel) –
- Return type:
- dfs_reverse_topo_sort(sm: SemanticModel, topo_order: list[str], node: str, visited_nodes: dict[str, bool], tmp_visited_nodes: dict[str, bool], removed_outgoing_edges: dict[int, bool])[source]#
Generate a topological order of class nodes in the semantic model. The graph must be acyclic before using this function
Based on DFS algorithm in here: https://en.wikipedia.org/wiki/Topological_sorting
- dfs_breaking_cycle(sm: SemanticModel, node: str, visited_path: list[str], removed_outgoing_edges: dict[int, bool]) bool[source]#
Try to break cycles using invert DFS. It returns true when break one cycle, and it terminates immediately. Thus, requires you to run this function many times until it return false