From cb8f090e2ba53eb40bb741400fb096b729fface4 Mon Sep 17 00:00:00 2001 From: imcovangent <I.vanGent@tudelft.nl> Date: Mon, 23 Jul 2018 15:29:07 +0200 Subject: [PATCH] Added determination and export of executableBlocksOrder in the ProcessGraph metadata element. Former-commit-id: bf820ef7284a8826d6661ec4a73b6872e7de3b90 --- kadmos/graph/graph_kadmos.py | 1 + kadmos/graph/graph_process.py | 28 ++++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/kadmos/graph/graph_kadmos.py b/kadmos/graph/graph_kadmos.py index e47369237..7461448f2 100644 --- a/kadmos/graph/graph_kadmos.py +++ b/kadmos/graph/graph_kadmos.py @@ -1495,6 +1495,7 @@ class KadmosGraph(nx.DiGraph, EquationMixin, VistomsMixin): mpg = copy.deepcopy(mpg) mpg.relabel_function_nodes(mapping) mpg.graph['process_hierarchy'] = mpg.get_process_hierarchy() # Needs to be updated to meet convention + mpg.graph['executable_blocks_order'] = mpg.get_process_order() # Needs to be updated to meet convention # Set basic variables and create CMDOWS element cmdows_version = str(graph.CMDOWS_VERSION) diff --git a/kadmos/graph/graph_process.py b/kadmos/graph/graph_process.py index 4e909f18c..31d36a723 100644 --- a/kadmos/graph/graph_process.py +++ b/kadmos/graph/graph_process.py @@ -70,7 +70,10 @@ class MdaoProcessGraph(ProcessGraph): cmdows_meta = cmdows_process_graph.add('metadata') cmdows_loop_nesting = cmdows_meta.add('loopNesting') cmdows_loop_nesting.add_process_hierarchy(self.graph['process_hierarchy'], self) - + cmdows_executable_blocks_order = cmdows_meta.add('executableBlocksOrder') + for index, item in enumerate(self.graph['executable_blocks_order']): + # Create .../metadata/executableBlocksOrder/executableBlock + cmdows_executable_blocks_order.add('executableBlock', item, attrib={'position': str(index + 1)}) return cmdows_process_graph # ---------------------------------------------------------------------------------------------------------------- # @@ -788,6 +791,24 @@ class MdaoProcessGraph(ProcessGraph): return process_list + def get_process_order(self, only_executable_block=True): + """Method to receive a list with the right order of the process based on process step numbers.""" + # Find first diagonal node + # Find the step 0 node + start_nodes = self.find_all_nodes(attr_cond=['process_step', '==', 0]) + assert len(start_nodes) == 1, 'There can only be one start node with process step number 0.' + first_node = start_nodes[0] + assert 'converger_step' in self.nodes[first_node], 'Start node should have a converger_step attribute.' + max_step = self.nodes[first_node]['converger_step'] + process_list = [] + for step in range(max_step + 1): + process_step_nodes = self.find_all_nodes(attr_cond=['process_step', '==', step]) + for process_step_node in process_step_nodes: + if self.nodes[process_step_node]['architecture_role'] in self.ARCHITECTURE_ROLES_FUNS[:4]: + process_step_nodes.remove(process_step_node) + process_list.extend(process_step_nodes) + return process_list + def get_process_hierarchy(self): """Method to assess the hierarchy of the process based on the process lines in a ProcessGraph. @@ -839,7 +860,6 @@ class MdaoProcessGraph(ProcessGraph): _, idx = self.get_lowest_psn(cycle) return cycle[idx:] + cycle[:idx] - 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. @@ -884,7 +904,8 @@ class MdaoProcessGraph(ProcessGraph): 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 + 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]))): @@ -897,7 +918,6 @@ class MdaoProcessGraph(ProcessGraph): else: sub_list[1].insert(i + 1, node) break - return sub_list -- GitLab