def textToGraph(inFile): #recuperation des infos a partir du fichier f = open(inFile, "r") vertexes = [] for line in f: print(line) vertex = [int(i) for i in line.rstrip().split(' ')] vertexes.append(vertex) f.close() #construction de la matrice nbVert = getNbVertexFromBranchMatrix(vertexes) matrix = [] for i in range(nbVert): matrix.append([-1] * nbVert) #ajout des aretes dans la matrice for vertex in vertexes: x = vertex[0] - 1 # - 1 car notre matrice commence à 0 for i in range(1, len(vertex), 2): y = vertex[i] - 1 # idem w = vertex[i + 1] matrix[x][y] = w matrix[y][x] = w #symétrie de la matrice return gv.GraphValue(matrix)
def moyenne50Temps(n,p,algo) : if algo == 0: print("algoPrim", n, "sommets", p, "proba") elif algo == 1 : print("algoKruskal", n, "sommets", p, "proba") temps = [] couleurs = [] for i in range(50) : graph = gv.graphAlea(n,15,p) start_time = time.time() if algo == 0 : graph.algoPrim() elif algo == 1 : graph.algoKruskal() interval = time.time() - start_time temps.append(interval) sommeT = sum(temps) return float(sommeT)/50.
def moyenne50Temps(n, p, algo): if algo == 0: print("algoPrim", n, "sommets", p, "proba") elif algo == 1: print("algoKruskal", n, "sommets", p, "proba") temps = [] couleurs = [] for i in range(50): graph = gv.graphAlea(n, 15, p) start_time = time.time() if algo == 0: graph.algoPrim() elif algo == 1: graph.algoKruskal() interval = time.time() - start_time temps.append(interval) sommeT = sum(temps) return float(sommeT) / 50.
def moyenne50Couverture(n,p,algo) : if algo == 0: print("algoPrim", n, "sommets", p, "proba") elif algo == 1 : print("algoKruskal", n, "sommets", p, "proba") couvertures = [] couleurs = [] for i in range(50) : graph = gv.graphAlea(n,15,p) couv = 0 if algo == 0 : for arete in graph.algoPrim()[0]: couv += arete.poids elif algo == 1 : for arete in graph.algoKruskal()[0]: couv += arete.poids couvertures.append(couv) sommeC = sum(couvertures) return float(sommeC)/50.
def moyenne50Couverture(n, p, algo): if algo == 0: print("algoPrim", n, "sommets", p, "proba") elif algo == 1: print("algoKruskal", n, "sommets", p, "proba") couvertures = [] couleurs = [] for i in range(50): graph = gv.graphAlea(n, 15, p) couv = 0 if algo == 0: for arete in graph.algoPrim()[0]: couv += arete.poids elif algo == 1: for arete in graph.algoKruskal()[0]: couv += arete.poids couvertures.append(couv) sommeC = sum(couvertures) return float(sommeC) / 50.