From f695c0c93f5fa9488d0b5f4a3490a1e4138b9216 Mon Sep 17 00:00:00 2001 From: George Marchment <georgemarchment@yahoo.fr> Date: Wed, 16 Apr 2025 15:32:57 +0200 Subject: [PATCH] Update draw from pool and check dependency function --- src/workflow.py | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/workflow.py b/src/workflow.py index ec9c12b..27a2fd9 100644 --- a/src/workflow.py +++ b/src/workflow.py @@ -392,6 +392,17 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen #This function draws processes from a pool and checks if they are direclty dependend on each other def draw_pool_and_check_dependencies(self, pool, alpha=-1): edges_create_cycles = self.graph.get_edges_that_create_cycle() + def get_object(address): + address = int(re.findall(r"\dx\w+", address)[0], base=16) + return ctypes.cast(address, ctypes.py_object).value + + edges_create_cycles_names = [] + for e in edges_create_cycles: + n1, n2 = e + obj1, obj2 = get_object(n1), get_object(n2) + edges_create_cycles_names.append((obj1.get_alias(), obj2.get_alias())) + + import random #Random value between 0 and 1, centered at 0.5 @@ -400,29 +411,17 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen return val searching = True - while(searching): + timeout = 0 + random_pool = True + if(alpha != -1): + random_pool = False + while(searching and timeout<constant.WHILE_UPPER_BOUND): searching = False - if(alpha == -1): + if(random_pool): alpha = get_value() - else: - if(0<=alpha and alpha<=1): - None - else: - raise BioFlowInsightError("alpha is not in the interval [0; 1]") nb_2_select = int(alpha*len(pool)) sampled = random.sample(set(pool), nb_2_select) - - def get_object(address): - address = int(re.findall(r"\dx\w+", address)[0], base=16) - return ctypes.cast(address, ctypes.py_object).value - - edges_create_cycles_names = [] - for e in edges_create_cycles: - n1, n2 = e - obj1, obj2 = get_object(n1), get_object(n2) - edges_create_cycles_names.append((obj1.get_alias(), obj2.get_alias())) - sampled_str = [] for s in sampled: sampled_str.append(s.get_alias()) @@ -436,6 +435,10 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen for p in sampled: name_select.append(p.get_alias()) return name_select + timeout+=1 + if(timeout>=constant.WHILE_UPPER_BOUND): + raise BioFlowInsightError(f"The WHILE_UPPER_BOUND was exceeded. BioFlow-Insight was unable to select random processes.", type="Unable to select random processes") + #This methods generates a random set of processes to consider as relavant -- GitLab