From 1cb43ccaa1cd0704f9e5f40208354ae934a5f28a Mon Sep 17 00:00:00 2001 From: cnavacch Date: Thu, 29 Oct 2020 15:20:35 +0100 Subject: [PATCH] introduced sorting by 'result' --- src/openeo_pg_parser/graph.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/openeo_pg_parser/graph.py b/src/openeo_pg_parser/graph.py index 0600767..07f1c6f 100644 --- a/src/openeo_pg_parser/graph.py +++ b/src/openeo_pg_parser/graph.py @@ -592,8 +592,10 @@ def sort(self, by='dependency'): ---------- by : str Sorting strategy: - - 'dependency': Sorts graph by each node dependency, + - 'dependency': Sorts graph by each processing dependency, i.e., nodes being dependent on another node come after this node. + - 'result': Sorts the graph also by processing dependency, but this time it puts the node order + following the result data flow. - 'depth': Sorts graph by the depth level of the nodes, from lower to higher depth. Returns @@ -607,6 +609,10 @@ def sort(self, by='dependency'): # use internal algo and igraph for topological sorting ordered_node_ids = self._linear_sorting() nodes_ordered = [self[ordered_node_id] for ordered_node_id in ordered_node_ids] + elif by == "result": + # use internal algo and igraph for topological sorting + ordered_node_ids = self._linear_sorting(use_in_nodes=False) + nodes_ordered = [self[ordered_node_id] for ordered_node_id in ordered_node_ids] elif by == "depth": depths = [node.depth for node in self.nodes] node_order = np.argsort(depths)