Changed generation of graphs. Generated new dataset.

This commit is contained in:
Bartosz 2022-10-04 15:36:17 +02:00
parent 68d87448b5
commit 83c6b3e879
22 changed files with 3288316 additions and 1226001 deletions

View File

@ -1,40 +1,32 @@
import random
def sort_edges(edges, edge):
if edge[0] > edge[1]:
temp = edge[0]
edge[0] = edge[1]
edge[1] = temp
index = 0
for i in edges:
if edge[0] < i[0]:
break
elif edge[0] == i[0] and edge[1] < i[1]:
break
else:
index += 1
edges.insert(index, edge)
def generate_tree_from_prufer_code(code):
L1 = code[:]
L1 = {}
L2 = []
edges = []
nodes = set()
for i in range(len(code)+2):
L2.append(i+1)
nodes.add(i+1)
for node in range(len(code)+2):
L2.append(node+1)
for node in L2:
L1[node] = 0
for node in code:
L1[node] += 1
for k in range(len(L1)):
current_node = L2[0]
counter = 1
while L1.count(current_node) > 0:
if len(L2) > 2:
while L1[current_node] > 0:
current_node = L2[counter]
counter += 1
sort_edges(edges, [code[k], current_node])
L1.remove(code[k])
if code[k] < current_node:
edges.append([code[k], current_node])
else:
edges.append([current_node, code[k]])
L1[code[k]] -= 1
L2.remove(current_node)
sort_edges(edges, [L2[0], L2[1]])
edges.append([L2[0], L2[1]])
return edges
@ -69,6 +61,7 @@ def generate_random_graph(n: int, log=False):
def write_graph_to_file(graph, filename, path="graphs/"):
print("writing to file")
with open(path + filename, 'w') as file:
for edge in graph:
weight = random.randint(1, 100)
@ -81,6 +74,7 @@ def read_graph_from_file(filename, path="graphs/"):
A = {}
A_b = {}
w = {}
with open(path + filename, 'r') as file:
line = file.readline()
while line != '':
@ -109,10 +103,10 @@ def read_graph_from_file(filename, path="graphs/"):
if __name__ == '__main__':
n = [100, 500, 1_000, 2_500, 5_000, 10_000, 25_000, 50_000, 100_000, 200_000]
for i in range(1, 11):
n = random.randint(3000, 6000)
print("generating graph:", i, "of", 10, "with", n, "nodes")
g = generate_random_graph(n, log=True)
print("generating graph:", i, "of", 10, "with", n[i-1], "nodes")
g = generate_random_graph(n[i-1], log=True)
f = "graph" + str(i)
write_graph_to_file(g, f)
print()

View File

@ -155,8 +155,11 @@ def read_grid_graph_from_file(filename, path="grids/"):
if __name__ == "__main__":
n = [(20, 20), (50, 50), (100, 100), (150, 150), (250, 250), (400, 400), (500, 500),
(600, 600), (750, 750), (1000, 1000)]
for i in range(1, 11):
print("generating graph:", i, "of", 10)
print("generating graph:", i, "of", 10, "with size", n[i-1])
f = "grid" + str(i)
g = generate_grid(rand.randint(202, 502), rand.randint(202, 502))
g = generate_grid(n[i-1][0]+2, n[i-1][1]+2)
print("writing to file")
write_grid_as_graph_to_file(g, f)

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

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

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff