def run(liczba): v = liczba wierzcholki = [] dell = DEL_lkrawedzi(v) dfs = DFS_lkrawedz(v) for i in range(liczba): for z in range(liczba): if z > i: razem = str(i) + str(z) w1 = int(i) w2 = int(z) dell.addEdge(w1, w2) dfs.addEdge(w1, w2) wierzcholki.append(razem) print("Sortowanie topologiczne przez usuwanie: ") timer_sort_topological = Timer() timer_sort_topological.start() dell.topologicalSort_DEL() # print("Lista krawedzi posortowana DELL") ilko = 0 for znajdz in listadell: for iins in wierzcholki: if znajdz == int(iins[0]): ilko = ilko + 1 timer_sort_topological.stop() if not S: timer_sort_topological_dfs = Timer() timer_sort_topological_dfs.start() dfs.topologicalSort_DFS() # print("Lista krawedzi posortowana DFS") ilko2 = 0 for znajdz in listadfs: for iins in wierzcholki: if znajdz == int(iins[0]): ilko2 = ilko2 + 1 'print("(", iins[0], ",", iins[1], ")")' timer_sort_topological_dfs.stop() return { 'sort_top_del': timer_sort_topological.get_mean_time(), 'sort_top_dfs': timer_sort_topological_dfs.get_mean_time() } else: return False
def run(liczba): v = liczba wierzcholki = [] b= [[0]*v for _ in range(v)] dell = DEL_lkrawedzi(v) dfs = DFS_lkrawedz(v) for i in range(liczba): for z in range(liczba): if z>i: razem = str(i)+str(z) w1 = int(i) w2 = int(z) dell.addEdge(w1,w2) dfs.addEdge(w1,w2) b[w1][w2] = 1 wierzcholki.append(razem) print("Sortowanie topologiczne przez usuwanie: ") timer_sort_topological_del = Timer() timer_sort_topological_del.start() dell.topologicalSort_DEL() #print("Macierz sasiedztwa posortowana DELL:") for kl in listadell: 'print(kl," - " ,b[kl])' timer_sort_topological_del.stop() if S == False: print("\n") print("Sortowanie topologiczne metoda DFS: ") timer_sort_topological_dfs = Timer() timer_sort_topological_dfs.start() #print("Macierz sasiedztwa posortowana DFS:") dfs.topologicalSort_DFS() timer_sort_topological_dfs.stop() return { 'sort_top_del': timer_sort_topological_del.get_mean_time(), 'sort_top_dfs': timer_sort_topological_dfs.get_mean_time() } else: return False
def run(liczba): v = liczba wierzcholki = [] dell = DEL_lkrawedzi(v) dfs = DFS_lkrawedz(v) for i in range(liczba): for z in range(liczba): if z>i: razem = str(i)+str(z) w1 = int(i) w2 = int(z) dell.addEdge(w1,w2) dfs.addEdge(w1,w2) wierzcholki.append(razem) print("Sortowanie topologiczne przez usuwanie: ") timer_sort_topological_del = Timer() timer_sort_topological_del.start() dell.topologicalSort_DEL() klopsy = [] i = 0 wierzcholkidell= [] wierzcholkidfs =[] #print(wierzcholki, "soema") for znajdz in listadell: for iins in wierzcholki: if znajdz == int(iins[0]): razem = iins[0]+iins[1:len(iins)] wierzcholkidell.append(razem) pusta =[] opal = [] poprzedni = wierzcholkidell[0][0] for znajdz in listadell: for iins in wierzcholki: if znajdz == int(iins[0]): opal.append(iins[1]) else: if opal: klopsy.append(opal) opal = [] if len(klopsy) != len(listadell): klopsy.append("['_']") glob = 0 #print("Lista nastepnikow dla sortowania dell:") '''for glop in listadell: print("(", glop, ") -", klopsy[glob]) glob = glob +1 print("\n")''' timer_sort_topological_del.stop() print("Sortwanie topologiczne metoda dfs: ") timer_sort_topological_dfs = Timer() timer_sort_topological_dfs.start() dfs.topologicalSort_DFS() for znajdz in listadfs: for iins in wierzcholki: if znajdz == int(iins[0]): razem = iins[0]+iins[1] wierzcholkidfs.append(razem) klopsy = [] pusta =[] opal = [] poprzedni = wierzcholkidell[0][0] for znajdz in listadfs: for iins in wierzcholki: if znajdz == int(iins[0]): opal.append(iins[1]) else: if opal: klopsy.append(opal) opal = [] klopsy.append("['_']") glob = 0 #print("Lista nastepnikow dla sortowania dfs:") '''for glop in listadfs: print("(", glop, ") -", klopsy[glob]) glob = glob + 1''' timer_sort_topological_dfs.stop() return { 'sort_top_del': timer_sort_topological_del.get_mean_time(), 'sort_top_dfs': timer_sort_topological_dfs.get_mean_time() }