Changed generation of graphs. Generated new dataset.
This commit is contained in:
parent
68d87448b5
commit
83c6b3e879
@ -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()
|
||||
|
@ -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)
|
13792
dataset/graphs/graph1
13792
dataset/graphs/graph1
File diff suppressed because it is too large
Load Diff
543494
dataset/graphs/graph10
543494
dataset/graphs/graph10
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
14922
dataset/graphs/graph3
14922
dataset/graphs/graph3
File diff suppressed because it is too large
Load Diff
21084
dataset/graphs/graph4
21084
dataset/graphs/graph4
File diff suppressed because it is too large
Load Diff
21850
dataset/graphs/graph5
21850
dataset/graphs/graph5
File diff suppressed because it is too large
Load Diff
36766
dataset/graphs/graph6
36766
dataset/graphs/graph6
File diff suppressed because it is too large
Load Diff
72982
dataset/graphs/graph7
72982
dataset/graphs/graph7
File diff suppressed because it is too large
Load Diff
138854
dataset/graphs/graph8
138854
dataset/graphs/graph8
File diff suppressed because it is too large
Load Diff
267982
dataset/graphs/graph9
267982
dataset/graphs/graph9
File diff suppressed because it is too large
Load Diff
148152
dataset/grids/grid1
148152
dataset/grids/grid1
File diff suppressed because it is too large
Load Diff
1225720
dataset/grids/grid10
1225720
dataset/grids/grid10
File diff suppressed because it is too large
Load Diff
77988
dataset/grids/grid2
77988
dataset/grids/grid2
File diff suppressed because it is too large
Load Diff
135300
dataset/grids/grid3
135300
dataset/grids/grid3
File diff suppressed because it is too large
Load Diff
159010
dataset/grids/grid4
159010
dataset/grids/grid4
File diff suppressed because it is too large
Load Diff
267900
dataset/grids/grid5
267900
dataset/grids/grid5
File diff suppressed because it is too large
Load Diff
118866
dataset/grids/grid6
118866
dataset/grids/grid6
File diff suppressed because it is too large
Load Diff
179042
dataset/grids/grid7
179042
dataset/grids/grid7
File diff suppressed because it is too large
Load Diff
405228
dataset/grids/grid8
405228
dataset/grids/grid8
File diff suppressed because it is too large
Load Diff
655726
dataset/grids/grid9
655726
dataset/grids/grid9
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user