From 51d5e46ffccffdc08b07392cd3416038cb712409 Mon Sep 17 00:00:00 2001 From: imcovangent <I.vanGent@tudelft.nl> Date: Mon, 23 Jul 2018 11:42:36 +0200 Subject: [PATCH] Added correct order of nodes in the sublist of the process hierarchy determination. Former-commit-id: 32d03642a7274315e4be4d2b029991d4a6352b1b --- kadmos/graph/graph_process.py | 98 +++++++++++++++++++++-------------- 1 file changed, 58 insertions(+), 40 deletions(-) diff --git a/kadmos/graph/graph_process.py b/kadmos/graph/graph_process.py index 9117c6feb..4e909f18c 100644 --- a/kadmos/graph/graph_process.py +++ b/kadmos/graph/graph_process.py @@ -803,7 +803,7 @@ class MdaoProcessGraph(ProcessGraph): cycles = self.get_ordered_cycles() # Start process hierarchy object - process_hierarchy = get_process_list_iteratively(start_node, cycles) + process_hierarchy = self.get_process_list_iteratively(start_node, cycles) return process_hierarchy def get_ordered_cycles(self): @@ -840,47 +840,65 @@ class MdaoProcessGraph(ProcessGraph): return cycle[idx:] + cycle[:idx] -def get_process_list_iteratively(cycle_node, cycles): - """Method to obtain the process list of a collection of cycles given an iterative cycle_node. The process is - iterative, since for every subcycle found the method is called again. + def get_process_list_iteratively(self, cycle_node, cycles): + """Method to obtain the process list of a collection of cycles given an iterative cycle_node. The process is + iterative, since for every subcycle found the method is called again. - :param cycle_node: the node that is starting and closing the cycle (e.g. coordinator, optimizer, etc.) - :type cycle_node: str - :param cycles: collection of cycles found in the graph - :type cycles: list - :return: the process list - :rtype: list + :param cycle_node: the node that is starting and closing the cycle (e.g. coordinator, optimizer, etc.) + :type cycle_node: str + :param cycles: collection of cycles found in the graph + :type cycles: list + :return: the process list + :rtype: list - .. note:: Example of a process list: - [COOR, A, [OPT, [CONV, D1, D2], F1, G1, G2]] - """ - sub_list = [cycle_node, []] - current_cycles = [cycle for cycle in cycles if cycle_node in cycle] - other_cycles = [cycle for cycle in cycles if cycle_node not in cycle] - subcycle_nodes = [] - for current_cycle in current_cycles: - cycle_nodes = [node for node in current_cycle if node != cycle_node] - for node in cycle_nodes: - node_in_other_subcycles = False - for other_cycle in other_cycles: - if node in other_cycle and cycle_node not in other_cycle: - node_in_other_subcycles = True - # If node is in other subcycles, perform function iteratively - # First filter out all cycles that contain the cycle_node -> filtered_cycles - # sublist[1].append(get_process_list_iteratively(node, filtered_cycles) - if node_in_other_subcycles: - if node not in subcycle_nodes: - filtered_cycles = list(cycles) - for cycle in list(filtered_cycles): - if cycle_node in cycle: - filtered_cycles.remove(cycle) - subcycle_nodes.append(node) - sub_list[1].append(get_process_list_iteratively(node, filtered_cycles)) - # If node is not in any other cycles, simply add to this one - else: - if node not in sub_list[1]: - sub_list[1].append(node) - return sub_list + .. note:: Example of a process list: + [COOR, A, [OPT, [CONV, D1, D2], F1, G1, G2]] + """ + sub_list = [cycle_node, []] + current_cycles = [cycle for cycle in cycles if cycle_node in cycle] + other_cycles = [cycle for cycle in cycles if cycle_node not in cycle] + subcycle_nodes = [] + for current_cycle in current_cycles: + cycle_nodes = [node for node in current_cycle if node != cycle_node] + for node in cycle_nodes: + node_in_other_subcycles = False + for other_cycle in other_cycles: + if node in other_cycle and cycle_node not in other_cycle: + node_in_other_subcycles = True + # If node is in other subcycles, perform function iteratively + # First filter out all cycles that contain the cycle_node -> filtered_cycles + # sublist[1].append(get_process_list_iteratively(node, filtered_cycles) + if node_in_other_subcycles: + if node not in subcycle_nodes: + filtered_cycles = list(cycles) + for cycle in list(filtered_cycles): + if cycle_node in cycle: + filtered_cycles.remove(cycle) + subcycle_nodes.append(node) + sub_list[1].append(self.get_process_list_iteratively(node, filtered_cycles)) + # If node is not in any other cycles, simply add to this one (at the right location based on the + # process_step number) + else: + if node not in sub_list[1]: + if len(sub_list[1]) == 0: # append if list still empty + sub_list[1].append(node) + elif isinstance(sub_list[1][-1], list): # append if last entry is a list instance + sub_list[1].append(node) + elif self.nodes[sub_list[1][-1]]['process_step'] <= self.nodes[node]['process_step']: # append if last entry has equal or lower step number + sub_list[1].append(node) + else: # insert if last entry has a higher step number + for i in reversed(range(len(sub_list[1]))): + if not isinstance(sub_list[1][i], list): + if self.nodes[sub_list[1][i]]['process_step'] <= self.nodes[node]['process_step']: + sub_list[1].insert(i + 1, node) + break + elif i == 0: + sub_list[1].insert(i, node) + else: + sub_list[1].insert(i + 1, node) + break + + return sub_list def get_executable_functions(coupling_matrix, sequence): -- GitLab