Skip to content
Snippets Groups Projects
Commit f5c75c52 authored by George Marchment's avatar George Marchment
Browse files

Put the greddy version back -> it wans't working fully as expected

parent cdf71c86
No related branches found
No related tags found
No related merge requests found
Pipeline #14677 failed with stage
in 3 minutes and 59 seconds
...@@ -347,10 +347,10 @@ class Code: ...@@ -347,10 +347,10 @@ class Code:
for r in to_replace: for r in to_replace:
old, new = r old, new = r
#Check that we have corretly extracted a ternary operator (this is a way to filter false positives)
if(new.strip()!=''): if(new.strip()!=''):
self.add_to_ternary_operation_dico(old, new) 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 #Check if there is still a ternary operation in this case we cannot analyse it
for match in re.finditer(pattern, code): for match in re.finditer(pattern, code):
......
...@@ -180,54 +180,55 @@ class Graph(): ...@@ -180,54 +180,55 @@ class Graph():
#This is the greedy version
#This is a dictionnary which links every node to it's connected process #This is a dictionnary which links every node to it's connected process
#node_2_processes = copy.deepcopy(self.link_dico) node_2_processes = copy.deepcopy(self.link_dico)
#already_searched = {} already_searched = {}
#for nodeA in node_2_processes: for nodeA in node_2_processes:
# already_searched[nodeA] = [nodeA] already_searched[nodeA] = [nodeA]
#changed = True changed = True
#while(changed): while(changed):
# changed = False changed = False
# for nodeA in node_2_processes: for nodeA in node_2_processes:
# temp = node_2_processes[nodeA].copy() temp = node_2_processes[nodeA].copy()
# for give in node_2_processes[nodeA]: for give in node_2_processes[nodeA]:
# if(is_operation(give)): if(is_operation(give)):
# temp.remove(give) temp.remove(give)
# if(nodeA!=give and give not in already_searched[nodeA]): if(nodeA!=give and give not in already_searched[nodeA]):
# already_searched[nodeA] += give already_searched[nodeA] += give
# temp_temp = node_2_processes[give] temp_temp = node_2_processes[give]
# for node_temp in already_searched[nodeA]: for node_temp in already_searched[nodeA]:
# try: try:
# temp_temp.remove(node_temp) temp_temp.remove(node_temp)
# except: except:
# None None
# temp+=temp_temp temp+=temp_temp
# changed = True changed = True
# node_2_processes[nodeA] = list(set(temp)) node_2_processes[nodeA] = list(set(temp))
#print(node_2_processes) #print(node_2_processes)
#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 = topological_sort(self.link_dico)
#topological_order.reverse() ##topological_order.reverse()
node_2_processes = copy.deepcopy(self.link_dico) #node_2_processes = copy.deepcopy(self.link_dico)
for i in [len(topological_order)-1-x for x in range(len(topological_order))]: #for i in [len(topological_order)-1-x for x in range(len(topological_order))]:
updating = topological_order[i] # updating = topological_order[i]
for y in [len(topological_order)-1-x for x in range(len(topological_order))]: # for y in [len(topological_order)-1-x for x in range(len(topological_order))]:
if(y>i): # if(y>i):
fixed = topological_order[y] # fixed = topological_order[y]
if(is_operation(fixed)): # if(is_operation(fixed)):
if(fixed in node_2_processes[updating]): # if(fixed in node_2_processes[updating]):
node_2_processes[updating]+=node_2_processes[fixed].copy() # node_2_processes[updating]+=node_2_processes[fixed].copy()
node_2_processes[updating] = list(set(node_2_processes[updating])) # node_2_processes[updating] = list(set(node_2_processes[updating]))
tab = [] # tab = []
for give in node_2_processes[updating]: # for give in node_2_processes[updating]:
if(is_process(give)): # if(is_process(give)):
tab.append(give) # tab.append(give)
#if(is_operation(give)): # #if(is_operation(give)):
# node_2_processes[updating].remove(give) # # node_2_processes[updating].remove(give)
#else: # #else:
# print("**", give) # # print("**", give)
node_2_processes[updating] = tab # node_2_processes[updating] = tab
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment