Exemple #1
0
 def test_case_consistencia2(self):
     for i in range(2, 100):
         p = random.random()
         graph, start = generator(i, p)
         bin_dij = dijkstra(graph, start, BinaryHeap(i))
         fib_dij = dijkstra(graph, start, FibonacciHeap(i))
         self.assertEqual(bin_dij, fib_dij)
Exemple #2
0
 def test_case_3_dijkstra_fibonacci(self):
     resultado = dijkstra(self.tc_3_graph, self.tc_3_start,
                          FibonacciHeap(10))
     self.assertEqual(
         resultado,
         "2465443114 1882404708 1258058452 1204145551 1175352843 289571756 0 11214701 604946066 1402469184"
     )
Exemple #3
0
def dijkstra_controller():
    graph = {}
    vertices, aristas = list(map(int, input().split()))
    for i in range(vertices):
        graph[i + 1] = {}
    for i in range(aristas):
        u, v, s = list(map(int, input().split()))
        graph[u][v] = s
        graph[v][u] = s
    print(graph)
    start = int(input())
    if sys.argv[1] == "FibonacciHeap":
        queue = FibonacciHeap(vertices)
    else:
        queue = BinaryHeap(vertices)
    print(dijkstra(graph, start, queue))
def exp(v_range, p_range):
    """
    FIJAR P Y PROBAR CON DIFERENTES V
    """
    out = {"fib": {}, "bin": {}}
    for v in v_range:
        fib_current_v = {}
        bin_current_v = {}
        for p in p_range:
            fib_list_k = []
            fib_list_memory_current = []
            fib_list_memory_peak = []
            bin_list_k = []
            bin_list_memory_current = []
            bin_list_memory_peak = []
            for i in range(3):
                graph, start = generator(v, p)

                tracemalloc.start()
                fib_ti = time.time()
                dijkstra(graph, start, FibonacciHeap(v))
                fib_tf = time.time()
                fib_current, fib_peak = tracemalloc.get_traced_memory()
                tracemalloc.stop()

                tracemalloc.start()
                bin_ti = time.time()
                dijkstra(graph, start, BinaryHeap(v))
                bin_tf = time.time()
                bin_current, bin_peak = tracemalloc.get_traced_memory()
                tracemalloc.stop()
                bin_dt = bin_tf - bin_ti

                bin_list_k.append(bin_dt)
                bin_list_memory_current.append(bin_current)
                bin_list_memory_peak.append(bin_peak)

                fib_dt = fib_tf - fib_ti
                fib_list_k.append(fib_dt)
                fib_list_memory_current.append(fib_current)
                fib_list_memory_peak.append(fib_peak)

            fib_current_v[p] = {
                "time_mean": statistics.mean(fib_list_k),
                "time_std": statistics.stdev(fib_list_k),
                "memory_current_mean":
                statistics.mean(fib_list_memory_current),
                "memory_current_std":
                statistics.stdev(fib_list_memory_current),
                "memory_peak_mean": statistics.mean(fib_list_memory_peak),
                "memory_peak_std": statistics.stdev(fib_list_memory_peak)
            }
            bin_current_v[p] = {
                "time_mean": statistics.mean(bin_list_k),
                "time_std": statistics.stdev(bin_list_k),
                "memory_current_mean":
                statistics.mean(bin_list_memory_current),
                "memory_current_std":
                statistics.stdev(bin_list_memory_current),
                "memory_peak_mean": statistics.mean(bin_list_memory_peak),
                "memory_peak_std": statistics.stdev(bin_list_memory_peak)
            }
            print("[{}][V = {}][p = {}]".format(time.ctime(time.time()), v, p))
        out["fib"][v] = fib_current_v
        out["bin"][v] = bin_current_v
    return out
Exemple #5
0
 def test_case_2_dijkstra_fibonacci(self):
     resultado = dijkstra(self.tc_2_graph, self.tc_2_start,
                          FibonacciHeap(3))
     self.assertEqual(resultado, "2 1 0")
Exemple #6
0
 def test_case_1_dijkstra_fibonacci(self):
     resultado = dijkstra(self.tc_1_graph, self.tc_1_start,
                          FibonacciHeap(5))
     self.assertEqual(resultado, "0 2 4 1 5")
Exemple #7
0
 def test_base_dijkstra_fibonacci(self):
     resultado = dijkstra(self.base_graph, self.base_start,
                          FibonacciHeap(6))
     self.assertEqual(resultado, "0 2 1 3 5 6")
Exemple #8
0
 def test_case_2_dijkstra_binary(self):
     resultado = dijkstra(self.tc_2_graph, self.tc_2_start, BinaryHeap(3))
     self.assertEqual(resultado, "2 1 0")
Exemple #9
0
 def test_case_1_dijkstra_binary(self):
     resultado = dijkstra(self.tc_1_graph, self.tc_1_start, BinaryHeap(5))
     self.assertEqual(resultado, "0 2 4 1 5")
Exemple #10
0
 def test_base_dijkstra_binary(self):
     resultado = dijkstra(self.base_graph, self.base_start, BinaryHeap(6))
     self.assertEqual(resultado, "0 2 1 3 5 6")
Exemple #11
0
 def test_case_aaah(self):
     resultado = dijkstra(self.base_graph, self.base_start,
                          aFibonacciHeap(6))
     self.assertEqual(resultado, "0 2 1 3 5 6")