Changed generated datasets to include more graphs and split them into groups by nodes count and number of edges. Started working on code for experiments using those data.

This commit is contained in:
Bartosz 2022-10-19 10:47:47 +02:00
parent 83c6b3e879
commit e7626bef27
23 changed files with 160 additions and 3512534 deletions

View File

@ -1,4 +1,5 @@
import random import random
from pathlib import Path
def generate_tree_from_prufer_code(code): def generate_tree_from_prufer_code(code):
@ -37,31 +38,26 @@ def generate_prufers_code(n: int):
return code return code
def generate_random_graph(n: int, log=False): def generate_random_graph(n: int, edges_number: int, log=False):
code = generate_prufers_code(n) code = generate_prufers_code(n)
edges = generate_tree_from_prufer_code(code) edges = generate_tree_from_prufer_code(code)
number_of_edges_to_add = random.randint(n//4, int(n/3)) edges_dict = {}
if log: for index in range(len(edges)):
print("number of edges to add:", number_of_edges_to_add) edges_dict[(edges[index][0], edges[index][1])] = True
counter = 0 while len(edges_dict) < edges_number:
while counter < number_of_edges_to_add:
node1 = random.randint(1, n) node1 = random.randint(1, n)
node2 = random.randint(1, n) node2 = random.randint(1, n)
while node1 == node2: while node1 == node2:
node2 = random.randint(1, n) node2 = random.randint(1, n)
if node1 < node2: if node1 < node2:
if [node1, node2] not in edges: edges_dict[(node1, node2)] = True
edges.append([node1, node2])
counter += 1
else: else:
if [node2, node1] not in edges: if [node2, node1] not in edges:
edges.append([node2, node1]) edges_dict[(node2, node1)] = True
counter += 1 return edges_dict.keys()
return edges
def write_graph_to_file(graph, filename, path="graphs/"): def write_graph_to_file(graph, filename, path="graphs/"):
print("writing to file")
with open(path + filename, 'w') as file: with open(path + filename, 'w') as file:
for edge in graph: for edge in graph:
weight = random.randint(1, 100) weight = random.randint(1, 100)
@ -103,10 +99,17 @@ def read_graph_from_file(filename, path="graphs/"):
if __name__ == '__main__': if __name__ == '__main__':
n = [100, 500, 1_000, 2_500, 5_000, 10_000, 25_000, 50_000, 100_000, 200_000] n = [200, 500, 1_000, 2_000, 5_000, 10_000, 20_000, 50_000]
for i in range(1, 11): for k in [5]:
print("generating graph:", i, "of", 10, "with", n[i-1], "nodes") group = str(k) + "n"
g = generate_random_graph(n[i-1], log=True) print("generating graph group:", str(k) + "n")
f = "graph" + str(i) for i in range(1, len(n)+1):
write_graph_to_file(g, f) print("generating graphs group:", group, "with", n[i - 1], "nodes and", int(k * n[i - 1]), "edges")
p = "graphs/" + group + "/" + str(n[i-1]) + "/"
for j in range(1, 51):
print("graph:", j, "of", 50)
g = generate_random_graph(n[i-1], int(k * n[i - 1]), log=True)
f = "graph" + str(j)
Path(p).mkdir(parents=True, exist_ok=True)
write_graph_to_file(g, f, p)
print() print()

View File

@ -1,4 +1,5 @@
import random as rand import random as rand
from pathlib import Path
def generate_grid(height: int, width: int, fill_percent: int = 70): def generate_grid(height: int, width: int, fill_percent: int = 70):
@ -155,11 +156,14 @@ def read_grid_graph_from_file(filename, path="grids/"):
if __name__ == "__main__": if __name__ == "__main__":
n = [(20, 20), (50, 50), (100, 100), (150, 150), (250, 250), (400, 400), (500, 500), n = [(20, 20), (50, 50), (100, 100), (150, 150), (250, 250), (500, 500)]
(600, 600), (750, 750), (1000, 1000)] for i in range(1, len(n)+1):
for i in range(1, 11): p = "grids/" + str(n[i-1][0]) + "x" + str(n[i-1][1]) + "/"
print("generating graph:", i, "of", 10, "with size", n[i-1]) print("generating graphs group:", n[i - 1])
f = "grid" + str(i) for j in range(1, 51):
f = "grid" + str(j)
print(f)
g = generate_grid(n[i-1][0]+2, n[i-1][1]+2) g = generate_grid(n[i-1][0]+2, n[i-1][1]+2)
print("writing to file") Path(p).mkdir(parents=True, exist_ok=True)
write_grid_as_graph_to_file(g, f) write_grid_as_graph_to_file(g, f, p)
print()

View File

@ -1,256 +0,0 @@
1 24 87
24 1 87
5 49 52
49 5 52
7 11 41
11 7 41
9 90 12
90 9 12
3 11 51
11 3 51
14 17 89
17 14 89
15 73 74
73 15 74
17 85 89
85 17 89
18 94 43
94 18 43
10 19 52
19 10 52
10 45 88
45 10 88
20 43 13
43 20 13
25 41 7
41 25 7
26 88 16
88 26 16
30 34 18
34 30 18
24 32 36
32 24 36
24 85 83
85 24 83
35 47 30
47 35 30
3 37 50
37 3 50
40 46 84
46 40 84
6 44 63
44 6 63
6 16 64
16 6 64
47 72 15
72 47 15
51 74 86
74 51 86
52 85 40
85 52 40
39 53 74
53 39 74
21 54 47
54 21 47
21 68 17
68 21 17
55 63 36
63 55 36
57 92 32
92 57 32
29 59 57
59 29 57
48 62 70
62 48 70
2 65 33
65 2 33
2 99 1
99 2 1
28 67 91
67 28 91
68 78 83
78 68 83
45 70 49
70 45 49
39 45 60
45 39 60
22 39 37
39 22 37
33 75 95
75 33 95
33 49 40
49 33 40
76 82 30
82 76 30
77 90 47
90 77 47
79 95 11
95 79 11
34 80 95
80 34 95
29 34 19
34 29 19
28 29 41
29 28 41
48 82 46
82 48 46
83 84 63
84 83 63
50 83 62
83 50 62
49 50 5
50 49 5
23 49 94
49 23 94
64 85 69
85 64 69
16 64 77
64 16 77
16 60 84
60 16 84
60 74 20
74 60 20
71 74 64
74 71 64
71 72 79
72 71 79
56 86 17
86 56 17
56 58 71
58 56 71
36 58 94
58 36 94
88 95 16
95 88 16
90 97 43
97 90 43
81 91 12
91 81 12
43 81 54
81 43 54
43 87 59
87 43 59
8 92 17
92 8 17
8 48 14
48 8 14
13 48 47
48 13 47
13 41 81
41 13 81
3 41 82
41 3 82
3 22 25
22 3 25
22 38 70
38 22 70
73 94 100
94 73 100
46 73 93
73 46 93
23 46 42
46 23 42
23 42 47
42 23 47
42 100 78
100 42 78
89 95 22
95 89 22
4 89 75
89 4 75
38 96 52
96 38 52
28 38 64
38 28 64
12 28 60
28 12 60
12 63 16
63 12 16
27 63 84
63 27 84
4 98 13
98 4 13
4 31 13
31 4 13
27 31 97
31 27 97
27 72 8
72 27 8
72 93 63
93 72 63
69 93 51
93 69 51
69 97 31
97 69 31
87 97 49
97 87 49
66 87 69
87 66 69
61 66 72
66 61 72
36 61 62
61 36 62
36 99 82
99 36 82
78 99 28
99 78 28
78 100 41
100 78 41
5 78 62
78 5 62
22 81 46
81 22 46
19 52 87
52 19 87
4 77 38
77 4 38
62 69 86
69 62 86
10 95 63
95 10 63
52 92 86
92 52 86
30 36 8
36 30 8
18 34 3
34 18 3
2 61 65
61 2 65
61 84 96
84 61 96
93 100 25
100 93 25
10 84 83
84 10 83
49 71 50
71 49 50
1 30 56
30 1 56
61 69 78
69 61 78
39 80 21
80 39 21
33 98 40
98 33 40
17 60 12
60 17 12
18 70 57
70 18 57
52 64 100
64 52 100
72 90 31
90 72 31
48 50 41
50 48 41
77 98 63
98 77 63
18 45 95
45 18 95
27 83 31
83 27 31
40 41 47
41 40 47
35 81 40
81 35 40
13 97 38
97 13 38

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,244 +0,0 @@
1 10,2 10,1
1 10,1 11,1
1 11,1 10,1
2 5,3 5,1
2 5,2 6,1
2 6,2 5,1
2 10,1 10,1
2 10,3 10,1
3 5,2 5,1
3 5,4 5,1
3 7,4 7,1
3 9,4 9,1
3 9,3 10,1
3 10,2 10,1
3 10,3 9,1
3 10,3 11,1
3 11,4 11,1
3 11,3 10,1
3 11,3 12,1
3 12,3 11,1
4 4,4 5,1
4 5,3 5,1
4 5,5 5,1
4 5,4 4,1
4 7,3 7,1
4 7,5 7,1
4 9,3 9,1
4 9,5 9,1
4 11,3 11,1
5 5,4 5,1
5 5,5 6,1
5 6,5 5,1
5 6,5 7,1
5 7,4 7,1
5 7,6 7,1
5 7,5 6,1
5 7,5 8,1
5 8,6 8,1
5 8,5 7,1
5 8,5 9,1
5 9,4 9,1
5 9,5 8,1
5 9,5 10,1
5 10,6 10,1
5 10,5 9,1
5 12,6 12,1
6 2,7 2,1
6 7,5 7,1
6 7,7 7,1
6 7,6 8,1
6 8,5 8,1
6 8,6 7,1
6 10,5 10,1
6 10,7 10,1
6 12,5 12,1
6 12,7 12,1
6 15,7 15,1
7 2,6 2,1
7 2,8 2,1
7 5,8 5,1
7 7,6 7,1
7 7,8 7,1
7 10,6 10,1
7 10,8 10,1
7 10,7 11,1
7 11,7 10,1
7 11,7 12,1
7 12,6 12,1
7 12,8 12,1
7 12,7 11,1
7 12,7 13,1
7 13,7 12,1
7 15,6 15,1
7 15,7 16,1
7 16,7 15,1
7 16,7 17,1
7 17,8 17,1
7 17,7 16,1
8 2,7 2,1
8 2,8 3,1
8 3,9 3,1
8 3,8 2,1
8 3,8 4,1
8 4,8 3,1
8 4,8 5,1
8 5,7 5,1
8 5,9 5,1
8 5,8 4,1
8 5,8 6,1
8 6,8 5,1
8 6,8 7,1
8 7,7 7,1
8 7,9 7,1
8 7,8 6,1
8 7,8 8,1
8 8,8 7,1
8 10,7 10,1
8 12,7 12,1
8 12,9 12,1
8 14,9 14,1
8 17,7 17,1
8 17,9 17,1
8 17,8 18,1
8 18,8 17,1
9 3,8 3,1
9 3,10 3,1
9 5,8 5,1
9 7,8 7,1
9 7,10 7,1
9 9,10 9,1
9 12,8 12,1
9 12,10 12,1
9 12,9 13,1
9 13,9 12,1
9 13,9 14,1
9 14,8 14,1
9 14,9 13,1
9 14,9 15,1
9 15,10 15,1
9 15,9 14,1
9 15,9 16,1
9 16,9 15,1
9 16,9 17,1
9 17,8 17,1
9 17,10 17,1
9 17,9 16,1
10 2,10 3,1
10 3,9 3,1
10 3,10 2,1
10 7,9 7,1
10 7,11 7,1
10 9,9 9,1
10 9,11 9,1
10 11,11 11,1
10 11,10 12,1
10 12,9 12,1
10 12,10 11,1
10 15,9 15,1
10 15,11 15,1
10 17,9 17,1
11 4,12 4,1
11 4,11 5,1
11 5,11 4,1
11 5,11 6,1
11 6,11 5,1
11 6,11 7,1
11 7,10 7,1
11 7,12 7,1
11 7,11 6,1
11 7,11 8,1
11 8,11 7,1
11 8,11 9,1
11 9,10 9,1
11 9,11 8,1
11 9,11 10,1
11 10,12 10,1
11 10,11 9,1
11 10,11 11,1
11 11,10 11,1
11 11,11 10,1
11 13,11 14,1
11 14,11 13,1
11 14,11 15,1
11 15,10 15,1
11 15,12 15,1
11 15,11 14,1
11 15,11 16,1
11 16,11 15,1
12 1,13 1,1
12 1,12 2,1
12 2,12 1,1
12 2,12 3,1
12 3,13 3,1
12 3,12 2,1
12 3,12 4,1
12 4,11 4,1
12 4,12 3,1
12 7,11 7,1
12 10,11 10,1
12 10,13 10,1
12 15,11 15,1
12 15,13 15,1
13 1,12 1,1
13 1,14 1,1
13 3,12 3,1
13 3,14 3,1
13 8,13 9,1
13 9,14 9,1
13 9,13 8,1
13 9,13 10,1
13 10,12 10,1
13 10,13 9,1
13 14,13 15,1
13 15,12 15,1
13 15,14 15,1
13 15,13 14,1
13 15,13 16,1
13 16,13 15,1
14 1,13 1,1
14 3,13 3,1
14 3,14 4,1
14 4,15 4,1
14 4,14 3,1
14 6,15 6,1
14 9,13 9,1
14 9,15 9,1
14 11,15 11,1
14 15,13 15,1
15 4,14 4,1
15 6,14 6,1
15 6,16 6,1
15 6,15 7,1
15 7,16 7,1
15 7,15 6,1
15 9,14 9,1
15 9,16 9,1
15 9,15 10,1
15 10,15 9,1
15 10,15 11,1
15 11,14 11,1
15 11,16 11,1
15 11,15 10,1
16 6,15 6,1
16 6,16 7,1
16 7,15 7,1
16 7,16 6,1
16 7,16 8,1
16 8,17 8,1
16 8,16 7,1
16 8,16 9,1
16 9,15 9,1
16 9,16 8,1
16 11,15 11,1
16 11,17 11,1
17 8,16 8,1
17 8,18 8,1
17 11,16 11,1
18 8,17 8,1
18 8,19 8,1
19 7,19 8,1
19 8,18 8,1
19 8,20 8,1
19 8,19 7,1
20 8,19 8,1

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

215
main.py
View File

@ -8,18 +8,29 @@ import tracemalloc
import os import os
import random as rand import random as rand
if __name__ == '__main__':
current_graph = [] def do_experiments():
nodes_chosen = [] current_group = []
dijkstra_mean_time, dijkstra_mean_memory, dijkstra_mean_error = [], [], []
a_star_mean_time, a_star_mean_memory, a_star_mean_weight = [], [], []
bidirectional_mean_time, bidirectional_mean_memory, bidirectional_mean_weight = [], [], []
graph_groups1 = os.listdir("dataset/grids/")
graph_groups2 = ["200", "500", "1000", "2000", "5000", "10000", "20000", "50000"]
grid_groups = os.listdir("dataset/grids/")
print(grid_groups)
def get_measurements_graph(group1, group2):
dijkstra_time, dijkstra_memory, dijkstra_weight = [], [], [] dijkstra_time, dijkstra_memory, dijkstra_weight = [], [], []
a_star_time, a_star_memory, a_star_weight = [], [], [] a_star_time, a_star_memory, a_star_weight = [], [], []
bidirectional_time, bidirectional_memory, bidirectional_weight = [], [], [] bidirectional_time, bidirectional_memory, bidirectional_weight = [], [], []
for i in range(1, len(os.listdir('dataset/graphs')) + 1): error_a_star, error_bi = [], []
for i in range(1, len(os.listdir("dataset/graphs/" + group1 + "/" + group2)) + 1):
filename = "graph" + str(i) filename = "graph" + str(i)
print(filename) print(filename)
N, A, A_b, w = gen_graph.read_graph_from_file(filename, path="dataset/graphs/") N, A, A_b, w = gen_graph.read_graph_from_file(filename, path="dataset/graphs/" + group1 + "/" + group2)
for j in range(3): for j in range(3):
current_graph.append(filename)
start_node_index = rand.randint(0, len(N) - 1) start_node_index = rand.randint(0, len(N) - 1)
goal_node_index = rand.randint(0, len(N) - 1) goal_node_index = rand.randint(0, len(N) - 1)
while goal_node_index == start_node_index: while goal_node_index == start_node_index:
@ -33,7 +44,7 @@ if __name__ == '__main__':
start_node = node start_node = node
if start_node is not None and goal_node is not None: if start_node is not None and goal_node is not None:
break break
nodes_chosen.append((start_node, goal_node))
startTime = time.time() startTime = time.time()
tracemalloc.start() tracemalloc.start()
weight = dijkstra.dijkstra_algorithm(start_node, goal_node, N, A, w)[1] weight = dijkstra.dijkstra_algorithm(start_node, goal_node, N, A, w)[1]
@ -52,66 +63,23 @@ if __name__ == '__main__':
startTime = time.time() startTime = time.time()
tracemalloc.start() tracemalloc.start()
weight = bidirectional.bidirectional_algorithm(start_node, goal_node, N, A, A_b, w, a_star.heuristic_cost)[1] weight = bidirectional.bidirectional_algorithm(start_node, goal_node, N, A, A_b, w, a_star.heuristic_cost)[
1]
bidirectional_memory.append(tracemalloc.get_traced_memory()[1]) bidirectional_memory.append(tracemalloc.get_traced_memory()[1])
bidirectional_time.append((time.time() - startTime)) bidirectional_time.append((time.time() - startTime))
bidirectional_weight.append(weight) bidirectional_weight.append(weight)
tracemalloc.stop() tracemalloc.stop()
with open("output/graphs_times.out", "w", encoding="utf-8") as file: for i in range(len(dijkstra_weight)):
file.write("\\begin{table}[]\n") error_a_star.append((a_star_weight[i] - dijkstra_weight[i]) / dijkstra_weight[i])
file.write("\\begin{tabular}{|l|l|l|l|l|}\n") error_bi.append((bidirectional_weight[i] - dijkstra_weight[i]) / dijkstra_weight[i])
file.write("\\hline\n")
file.write("nazwa grafu & (s, t) & Dijkstra & A* & Bi A* \\\\ \\hline\n")
with open("output/graphs_memory.out", "w", encoding="utf-8") as file: return sum(dijkstra_time) / len(dijkstra_time), sum(dijkstra_memory) / len(dijkstra_memory), 0, \
file.write("\\begin{table}[]\n") sum(a_star_time) / len(a_star_time), sum(a_star_memory) / len(a_star_memory), sum(error_a_star) / len(error_a_star),\
file.write("\\begin{tabular}{|l|l|l|l|l|}\n") sum(bidirectional_time) / len(bidirectional_time), sum(bidirectional_memory) / len(bidirectional_memory), sum(error_bi) / len(error_bi)
file.write("\\hline\n")
file.write("nazwa grafu & (s, t) & Dijkstra & A* & Bi A* \\\\ \\hline\n")
with open("output/graph_weights.out", "w", encoding="utf-8") as file:
file.write("\\begin{table}[]\n")
file.write("\\begin{tabular}{|l|l|l|l|l|}\n")
file.write("\\hline\n")
file.write("nazwa grafu & (s, t) & Dijkstra & A* & Bi A* \\\\ \\hline\n")
with open("output/graphs_times.out", "a", encoding="utf-8") as file: def get_measurements_grids():
for j in range(len(dijkstra_time)):
file.write(" " + current_graph[j] + " & " + str(nodes_chosen[j]) + " & " + str(round(dijkstra_time[j], 5))
+ " & " + str(round(a_star_time[j], 5)) + " & " + str(round(bidirectional_time[j], 5)) +
" \\\\ \\hline\n")
file.write("\\hline\n")
file.write(" & średnia & " + str(round(sum(dijkstra_time) / len(dijkstra_time), 5))
+ " & " + str(round(sum(a_star_time) / len(a_star_time), 5))
+ " & " + str(round(sum(bidirectional_time) / len(bidirectional_time), 5))
+ " \\\\ \\hline\n")
file.write("\\end{tabular}\n")
file.write("\\end{table}\n")
with open("output/graphs_memory.out", "a", encoding="utf-8") as file:
for j in range(len(dijkstra_time)):
file.write(" " + current_graph[j] + " & " + str(nodes_chosen[j]) + " & " + str(dijkstra_memory[j])
+ " & " + str(a_star_memory[j]) + " & " + str(bidirectional_memory[j]) + " \\\\ \\hline\n")
file.write("\\hline\n")
file.write(" & średnia & " + str(sum(dijkstra_memory) // len(dijkstra_memory))
+ " & " + str(sum(a_star_memory) // len(a_star_memory))
+ " & " + str(sum(bidirectional_memory) // len(bidirectional_memory))
+ " \\\\ \\hline\n")
file.write("\\end{tabular}\n")
file.write("\\end{table}\n")
with open("output/graph_weights.out", "a", encoding="utf-8") as file:
for j in range(len(dijkstra_time)):
file.write(" " + current_graph[j] + " & " + str(nodes_chosen[j]) + " & " +
str(dijkstra_weight[j]) + " & " + str(a_star_weight[j]) + " & " +
str(bidirectional_weight[j]) + " \\\\ \\hline\n")
file.write("\\end{tabular}\n")
file.write("\\end{table}\n")
current_graph = []
nodes_chosen = []
dijkstra_time, dijkstra_memory, dijkstra_weight = [], [], [] dijkstra_time, dijkstra_memory, dijkstra_weight = [], [], []
a_star_time, a_star_memory, a_star_weight = [], [], [] a_star_time, a_star_memory, a_star_weight = [], [], []
bidirectional_time, bidirectional_memory, bidirectional_weight = [], [], [] bidirectional_time, bidirectional_memory, bidirectional_weight = [], [], []
@ -121,7 +89,7 @@ if __name__ == '__main__':
print(filename) print(filename)
N, A, A_b, w = gen_grid.read_grid_graph_from_file(filename, path="dataset/grids/") N, A, A_b, w = gen_grid.read_grid_graph_from_file(filename, path="dataset/grids/")
for j in range(3): for j in range(3):
current_graph.append(filename)
start_node_index = rand.randint(0, len(N) - 1) start_node_index = rand.randint(0, len(N) - 1)
goal_node_index = rand.randint(0, len(N) - 1) goal_node_index = rand.randint(0, len(N) - 1)
while goal_node_index == start_node_index: while goal_node_index == start_node_index:
@ -135,7 +103,6 @@ if __name__ == '__main__':
start_node = node start_node = node
if start_node is not None and goal_node is not None: if start_node is not None and goal_node is not None:
break break
nodes_chosen.append((start_node, goal_node))
startTime = time.time() startTime = time.time()
tracemalloc.start() tracemalloc.start()
weight = dijkstra.dijkstra_algorithm(start_node, goal_node, N, A, w)[1] weight = dijkstra.dijkstra_algorithm(start_node, goal_node, N, A, w)[1]
@ -161,6 +128,62 @@ if __name__ == '__main__':
bidirectional_weight.append(weight) bidirectional_weight.append(weight)
tracemalloc.stop() tracemalloc.stop()
def write_output_table_graph():
with open("output/graphs_times.out", "w", encoding="utf-8") as file:
file.write("\\begin{table}[]\n")
file.write("\\begin{tabular}{|l|l|l|l|l|}\n")
file.write("\\hline\n")
file.write("grupa & (s, t) & Dijkstra & A* & Bi A* \\\\ \\hline\n")
with open("output/graphs_memory.out", "w", encoding="utf-8") as file:
file.write("\\begin{table}[]\n")
file.write("\\begin{tabular}{|l|l|l|l|l|}\n")
file.write("\\hline\n")
file.write("grupa & (s, t) & Dijkstra & A* & Bi A* \\\\ \\hline\n")
with open("output/graph_weights.out", "w", encoding="utf-8") as file:
file.write("\\begin{table}[]\n")
file.write("\\begin{tabular}{|l|l|l|l|l|}\n")
file.write("\\hline\n")
file.write("nazwa grafu & (s, t) & Dijkstra & A* & Bi A* \\\\ \\hline\n")
# with open("output/graphs_times.out", "a", encoding="utf-8") as file:
# for j in range(len(dijkstra_time)):
# file.write(" " + current_graph[j] + " & " + str(nodes_chosen[j]) + " & " + str(round(dijkstra_time[j], 5))
# + " & " + str(round(a_star_time[j], 5)) + " & " + str(round(bidirectional_time[j], 5)) +
# " \\\\ \\hline\n")
# file.write("\\hline\n")
# file.write(" & średnia & " + str(round(sum(dijkstra_time) / len(dijkstra_time), 5))
# + " & " + str(round(sum(a_star_time) / len(a_star_time), 5))
# + " & " + str(round(sum(bidirectional_time) / len(bidirectional_time), 5))
# + " \\\\ \\hline\n")
#
# file.write("\\end{tabular}\n")
# file.write("\\end{table}\n")
#
# with open("output/graphs_memory.out", "a", encoding="utf-8") as file:
# for j in range(len(dijkstra_time)):
# file.write(" " + current_graph[j] + " & " + str(nodes_chosen[j]) + " & " + str(dijkstra_memory[j])
# + " & " + str(a_star_memory[j]) + " & " + str(bidirectional_memory[j]) + " \\\\ \\hline\n")
# file.write("\\hline\n")
# file.write(" & średnia & " + str(sum(dijkstra_memory) // len(dijkstra_memory))
# + " & " + str(sum(a_star_memory) // len(a_star_memory))
# + " & " + str(sum(bidirectional_memory) // len(bidirectional_memory))
# + " \\\\ \\hline\n")
# file.write("\\end{tabular}\n")
# file.write("\\end{table}\n")
#
# with open("output/graph_weights.out", "a", encoding="utf-8") as file:
# for j in range(len(dijkstra_time)):
# file.write(" " + current_graph[j] + " & " + str(nodes_chosen[j]) + " & " +
# str(dijkstra_weight[j]) + " & " + str(a_star_weight[j]) + " & " +
# str(bidirectional_weight[j]) + " \\\\ \\hline\n")
# file.write("\\end{tabular}\n")
# file.write("\\end{table}\n")
def write_output_table_grid():
with open("output/grids_times.out", "w", encoding="utf-8") as file: with open("output/grids_times.out", "w", encoding="utf-8") as file:
file.write("\\begin{table}[]\n") file.write("\\begin{table}[]\n")
file.write("\\begin{tabular}{|l|l|l|l|l|}\n") file.write("\\begin{tabular}{|l|l|l|l|l|}\n")
@ -179,38 +202,42 @@ if __name__ == '__main__':
file.write("\\hline\n") file.write("\\hline\n")
file.write("nazwa siatki & (s, t) & Dijkstra & A* & Bi A* \\\\ \\hline\n") file.write("nazwa siatki & (s, t) & Dijkstra & A* & Bi A* \\\\ \\hline\n")
with open("output/grids_times.out", "a", encoding="utf-8") as file: # with open("output/grids_times.out", "a", encoding="utf-8") as file:
for j in range(len(dijkstra_time)): # for j in range(len(dijkstra_time)):
file.write( # file.write(
" " + current_graph[j] + # " " + current_graph[j] +
" & " + str(nodes_chosen[j]) + " & " # " & " + str(nodes_chosen[j]) + " & "
+ str(round(dijkstra_time[j], 5)) # + str(round(dijkstra_time[j], 5))
+ " & " + str(round(a_star_time[j], 5)) + " & " + str(round(bidirectional_time[j], 5)) + # + " & " + str(round(a_star_time[j], 5)) + " & " + str(round(bidirectional_time[j], 5)) +
" \\\\ \\hline\n") # " \\\\ \\hline\n")
file.write("\\hline\n") # file.write("\\hline\n")
file.write(" & średnia & " + str(round(sum(dijkstra_time) / len(dijkstra_time), 5)) # file.write(" & średnia & " + str(round(sum(dijkstra_time) / len(dijkstra_time), 5))
+ " & " + str(round(sum(a_star_time) / len(a_star_time), 5)) # + " & " + str(round(sum(a_star_time) / len(a_star_time), 5))
+ " & " + str(round(sum(bidirectional_time) / len(bidirectional_time), 5)) # + " & " + str(round(sum(bidirectional_time) / len(bidirectional_time), 5))
+ " \\\\ \\hline\n") # + " \\\\ \\hline\n")
file.write("\\end{tabular}\n") # file.write("\\end{tabular}\n")
file.write("\\end{table}\n") # file.write("\\end{table}\n")
#
# with open("output/grids_memory.out", "a", encoding="utf-8") as file:
# for j in range(len(dijkstra_time)):
# file.write(" " + current_graph[j] + " & " + str(nodes_chosen[j]) + " & " + str(dijkstra_memory[j])
# + " & " + str(a_star_memory[j]) + " & " + str(bidirectional_memory[j]) + " \\\\ \\hline\n")
# file.write("\\hline\n")
# file.write(" & średnia & " + str(sum(dijkstra_memory) // len(dijkstra_memory))
# + " & " + str(sum(a_star_memory) // len(a_star_memory))
# + " & " + str(sum(bidirectional_memory) // len(bidirectional_memory))
# + " \\\\ \\hline\n")
# file.write("\\end{tabular}\n")
# file.write("\\end{table}\n")
#
# with open("output/grids_weights.out", "a", encoding="utf-8") as file:
# for j in range(len(dijkstra_time)):
# file.write(" " + current_graph[j] + " & " + str(nodes_chosen[j]) + " & " +
# str(dijkstra_weight[j]) + " & " + str(a_star_weight[j]) + " & " +
# str(bidirectional_weight[j]) + " \\\\ \\hline\n")
# file.write("\\end{tabular}\n")
# file.write("\\end{table}\n")
with open("output/grids_memory.out", "a", encoding="utf-8") as file:
for j in range(len(dijkstra_time)):
file.write(" " + current_graph[j] + " & " + str(nodes_chosen[j]) + " & " + str(dijkstra_memory[j])
+ " & " + str(a_star_memory[j]) + " & " + str(bidirectional_memory[j]) + " \\\\ \\hline\n")
file.write("\\hline\n")
file.write(" & średnia & " + str(sum(dijkstra_memory) // len(dijkstra_memory))
+ " & " + str(sum(a_star_memory) // len(a_star_memory))
+ " & " + str(sum(bidirectional_memory) // len(bidirectional_memory))
+ " \\\\ \\hline\n")
file.write("\\end{tabular}\n")
file.write("\\end{table}\n")
with open("output/grids_weights.out", "a", encoding="utf-8") as file: if __name__ == '__main__':
for j in range(len(dijkstra_time)): do_experiments()
file.write(" " + current_graph[j] + " & " + str(nodes_chosen[j]) + " & " +
str(dijkstra_weight[j]) + " & " + str(a_star_weight[j]) + " & " +
str(bidirectional_weight[j]) + " \\\\ \\hline\n")
file.write("\\end{tabular}\n")
file.write("\\end{table}\n")