def CHANGEROOT(set_): fb.write_in_file(set_["f_"], " --- Procedure CHANGEROOT ---\n") if set_["canal"][set_["mcan"]] == "branch": eq.send_to(set_["queues"][set_["mcan"]], set_["i"], set_["mcan"], "changeroot", None, None, None, set_["f_"]) else: eq.send_to(set_["queues"][set_["mcan"]], set_["i"], set_["mcan"], "connect", set_["niv"], None, None, set_["f_"]) register.change_var("canal["+set_["mcan"]+"]", set_["canal"][set_["mcan"]], "branch", set_["f_"]) set_["canal"][set_["mcan"]] = "branch" fb.write_in_file(set_["f_"], " --- Fin procedure CHANGEROOT ---\n") return set_
def bloc_connect(L, j, set_): if L < set_["niv"]: register.change_var("canal["+j+"]", set_["canal"][j], "branch", set_["f_"]) set_["canal"][j] = "branch" eq.send_to(set_["queues"][j], set_["i"], j, "initiate", set_["niv"], set_["nom"], set_["etat"], set_["f_"]) else: if set_["canal"][j] == "basic": time.sleep(1) eq.send_to(set_["queues"][set_["i"]], j, set_["i"], "connect", L, None, None, set_["f_"]) #traiter le message plus tard else: eq.send_to(set_["queues"][j], set_["i"], j, "initiate", set_["niv"]+1, set_["edges"][j], "find", set_["f_"]) return set_
def REPORT(set_): fb.write_in_file(set_["f_"], " - Procedure REPORT -\n") test = 0 for j, val in set_["canal"].items(): if val == "branch" and j != set_["pere"]: test = test + 1 if set_["recu"] == test and set_["testcan"] == None: register.change_var("etat", set_["etat"], "found", set_["f_"]) set_["etat"] = "found" eq.send_to(set_["queues"][set_["pere"]], set_["i"], set_["pere"], "report", set_["mpoids"], None, None, set_["f_"]) fb.write_in_file(set_["f_"], " - Fin procedure REPORT -\n") return set_
def bloc_test(L, F, j, set_): if L > set_["niv"]: time.sleep(1) eq.send_to(set_["queues"][set_["i"]], j, set_["i"], "test", L, F, None, set_["f_"]) # Traiter le msg plus tard else: if F == set_["nom"]: if set_["canal"][j] == "basic": register.change_var("canal["+j+"]", set_["canal"][j], "reject", set_["f_"]) set_["canal"][j] = "reject" if j != set_["testcan"]: eq.send_to(set_["queues"][j], set_["i"], j, "reject", None, None, None, set_["f_"]) else: set_ = TEST(set_) else: eq.send_to(set_["queues"][j], set_["i"], j, "accept", None, None, None, set_["f_"]) return set_
def TEST(set_): fb.write_in_file(set_["f_"], " -- Procedure TEST --\n") exists = {} for j, val in set_["canal"].items(): if val == "basic": exists[j] = set_["edges"][j] ##ici mis a jour !! if not bool(exists) == False: # bool(exists)=False when empty j = find_min_val_return_key_in_dict(exists) register.change_var("testcan", set_["testcan"], j, set_["f_"]) set_["testcan"] = j eq.send_to(set_["queues"][set_["testcan"]], set_["i"], set_["testcan"], "test", set_["niv"], set_["nom"], None, set_["f_"]) else: register.change_var("testcan", set_["testcan"], "None", set_["f_"]) set_["testcan"] = None set_ = REPORT(set_) fb.write_in_file(set_["f_"], " -- Fin procedure TEST --\n") return set_
def bloc_accept(j, set_): register.change_var("testcan", set_["testcan"], "None", set_["f_"]) set_["testcan"] = None if set_["edges"][j] < set_["mpoids"]: register.change_var("mpoids", set_["mpoids"], set_["edges"][j], set_["f_"]) set_["mpoids"] = set_["edges"][j] register.change_var("mcan", set_["mcan"], j, set_["f_"]) set_["mcan"] = j set_ = REPORT(set_) return set_
def bloc_report(poids, j, set_): if j != set_["pere"]: if poids < set_["mpoids"]: register.change_var("mpoids", set_["mpoids"], poids, set_["f_"]) set_["mpoids"] = poids register.change_var("mcan", set_["mcan"], j, set_["f_"]) set_["mcan"] = j register.change_var("recu", set_["recu"], set_["recu"]+1, set_["f_"]) set_["recu"] = set_["recu"] + 1 set_ = REPORT(set_) else: if set_["etat"] == "find": time.sleep(1) eq.send_to(set_["queues"][set_["i"]], j, set_["i"], "report", poids, None, None, set_["f_"]) # Traiter le msg plus tard else: if poids > set_["mpoids"]: set_ = CHANGEROOT(set_) else: if poids == set_["mpoids"] and set_["mpoids"] == math.inf: # register.set_state(set_, set_["f_"]) print(" ### "+set_["i"]+" à terminé l'algo ### ") eq.send_to(set_["queues"]['father'], set_["i"], "father", "termine", None, None, None, None) return set_ # //!\\ TERMINE return set_
def bloc_initiate(L, F, S, j, set_): register.change_var("niv", set_["niv"], L, set_["f_"]) set_["niv"] = L register.change_var("nom", set_["nom"], F, set_["f_"]) set_["nom"] = F register.change_var("etat", set_["etat"], S, set_["f_"]) set_["etat"] = S register.change_var("pere", set_["pere"], j, set_["f_"]) set_["pere"] = j register.change_var("mcan", set_["mcan"], "None", set_["f_"]) set_["mcan"] = None register.change_var("mpoids", set_["mpoids"], "inf", set_["f_"]) set_["mpoids"] = math.inf for k in set_["edges"]: if k != j and set_["canal"][k] == "branch": eq.send_to(set_["queues"][k], set_["i"], k, "initiate", L, F, S, set_["f_"]) if set_["etat"] == "find": register.change_var("recu", set_["recu"], 0, set_["f_"]) set_["recu"] = 0 set_ = TEST(set_) return set_
def bloc_reject(j, set_): if set_["canal"][j] == "basic": register.change_var("canal["+j+"]", set_["canal"][j], "reject", set_["f_"]) set_["canal"][j] = "reject" set_ = TEST(set_) return set_