From f5c75c52776b269ebd61d5fc3b2253cf0bdd6fc9 Mon Sep 17 00:00:00 2001 From: George Marchment <georgemarchment@yahoo.fr> Date: Fri, 2 May 2025 09:34:41 +0200 Subject: [PATCH] Put the greddy version back -> it wans't working fully as expected --- src/code_.py | 4 +-- src/graph.py | 91 ++++++++++++++++++++++++++-------------------------- 2 files changed, 48 insertions(+), 47 deletions(-) diff --git a/src/code_.py b/src/code_.py index af4784a..e9eb67b 100644 --- a/src/code_.py +++ b/src/code_.py @@ -347,10 +347,10 @@ class Code: for r in to_replace: old, new = r + #Check that we have corretly extracted a ternary operator (this is a way to filter false positives) if(new.strip()!=''): self.add_to_ternary_operation_dico(old, new) - else: - print(f"old '{old}'", f"new '{new}'") + #Check if there is still a ternary operation in this case we cannot analyse it for match in re.finditer(pattern, code): diff --git a/src/graph.py b/src/graph.py index 8329f04..f6c0919 100644 --- a/src/graph.py +++ b/src/graph.py @@ -180,54 +180,55 @@ class Graph(): + #This is the greedy version #This is a dictionnary which links every node to it's connected process - #node_2_processes = copy.deepcopy(self.link_dico) - #already_searched = {} - #for nodeA in node_2_processes: - # already_searched[nodeA] = [nodeA] - #changed = True - #while(changed): - # changed = False - # for nodeA in node_2_processes: - # temp = node_2_processes[nodeA].copy() - # for give in node_2_processes[nodeA]: - # if(is_operation(give)): - # temp.remove(give) - # if(nodeA!=give and give not in already_searched[nodeA]): - # already_searched[nodeA] += give - # temp_temp = node_2_processes[give] - # for node_temp in already_searched[nodeA]: - # try: - # temp_temp.remove(node_temp) - # except: - # None - # temp+=temp_temp - # changed = True - # node_2_processes[nodeA] = list(set(temp)) + node_2_processes = copy.deepcopy(self.link_dico) + already_searched = {} + for nodeA in node_2_processes: + already_searched[nodeA] = [nodeA] + changed = True + while(changed): + changed = False + for nodeA in node_2_processes: + temp = node_2_processes[nodeA].copy() + for give in node_2_processes[nodeA]: + if(is_operation(give)): + temp.remove(give) + if(nodeA!=give and give not in already_searched[nodeA]): + already_searched[nodeA] += give + temp_temp = node_2_processes[give] + for node_temp in already_searched[nodeA]: + try: + temp_temp.remove(node_temp) + except: + None + temp+=temp_temp + changed = True + node_2_processes[nodeA] = list(set(temp)) #print(node_2_processes) - - topological_order = topological_sort(self.link_dico) - #topological_order.reverse() - node_2_processes = copy.deepcopy(self.link_dico) - for i in [len(topological_order)-1-x for x in range(len(topological_order))]: - updating = topological_order[i] - for y in [len(topological_order)-1-x for x in range(len(topological_order))]: - if(y>i): - fixed = topological_order[y] - if(is_operation(fixed)): - if(fixed in node_2_processes[updating]): - node_2_processes[updating]+=node_2_processes[fixed].copy() - node_2_processes[updating] = list(set(node_2_processes[updating])) - tab = [] - for give in node_2_processes[updating]: - if(is_process(give)): - tab.append(give) - #if(is_operation(give)): - # node_2_processes[updating].remove(give) - #else: - # print("**", give) - node_2_processes[updating] = tab + #This is the optimised version but it is based on the topological order -> thus far i can't get it to work when there is a loop in the workflow + #topological_order = topological_sort(self.link_dico) + ##topological_order.reverse() + #node_2_processes = copy.deepcopy(self.link_dico) + #for i in [len(topological_order)-1-x for x in range(len(topological_order))]: + # updating = topological_order[i] + # for y in [len(topological_order)-1-x for x in range(len(topological_order))]: + # if(y>i): + # fixed = topological_order[y] + # if(is_operation(fixed)): + # if(fixed in node_2_processes[updating]): + # node_2_processes[updating]+=node_2_processes[fixed].copy() + # node_2_processes[updating] = list(set(node_2_processes[updating])) + # tab = [] + # for give in node_2_processes[updating]: + # if(is_process(give)): + # tab.append(give) + # #if(is_operation(give)): + # # node_2_processes[updating].remove(give) + # #else: + # # print("**", give) + # node_2_processes[updating] = tab -- GitLab