Skip to content
Snippets Groups Projects
Commit dc383a71 authored by Jacob Theisen's avatar Jacob Theisen
Browse files

names

parent 9184f2ea
No related branches found
No related tags found
No related merge requests found
...@@ -47,7 +47,7 @@ with open('./test_files/kanter.txt','r') as file: ...@@ -47,7 +47,7 @@ with open('./test_files/kanter.txt','r') as file:
edge_file = file.read() edge_file = file.read()
edge_file = edge_file.split() edge_file = edge_file.split()
num_of_edges = edge_file[0] num_of_edges = int(edge_file[0])
edge_file.pop(0) edge_file.pop(0)
edge_arr = [] edge_arr = []
...@@ -60,7 +60,7 @@ with open('./test_files/interessepkt.txt','r') as file: ...@@ -60,7 +60,7 @@ with open('./test_files/interessepkt.txt','r') as file:
intresting_file = file.read() intresting_file = file.read()
intresting_file = intresting_file.split('\n') intresting_file = intresting_file.split('\n')
num_of_intresting = intresting_file[0] num_of_intresting = int(intresting_file[0])
intresting_file.pop(0) intresting_file.pop(0)
intresting_arr = [] intresting_arr = []
...@@ -84,6 +84,8 @@ def rec_func(node, counter, global_fra): ...@@ -84,6 +84,8 @@ def rec_func(node, counter, global_fra):
def calculate_shortest_path(b, i, a, global_fra): def calculate_shortest_path(b, i, a, global_fra):
print('in calculate') print('in calculate')
res_a = [a for a in res_arr if a == a.node]
print(f'curr_node: {b.node}, edge_time: {i}, curr_neig_node: {a.node}, curr_neig_prev: {a.prev}, global_fra: {global_fra}')
count_a = 0 count_a = 0
count_a = rec_func(a, count_a, global_fra) count_a = rec_func(a, count_a, global_fra)
count_b = 0 count_b = 0
...@@ -95,10 +97,12 @@ def calculate_shortest_path(b, i, a, global_fra): ...@@ -95,10 +97,12 @@ def calculate_shortest_path(b, i, a, global_fra):
return False return False
round = 0
queue = [] queue = []
def dijkstras(global_fra, fra, til): def dijkstras(slutt, fra, start):
print(queue) global round
round +=1
print('runde: ', round, ' queue: ', queue)
current_node = [b for b in res_arr if b.node == fra][0] current_node = [b for b in res_arr if b.node == fra][0]
print(current_node.node) print(current_node.node)
for tmp_edge in edge_arr: for tmp_edge in edge_arr:
...@@ -107,33 +111,36 @@ def dijkstras(global_fra, fra, til): ...@@ -107,33 +111,36 @@ def dijkstras(global_fra, fra, til):
if current_neighbour: if current_neighbour:
if current_neighbour.visited == False: if current_neighbour.visited == False:
print(f'fra: {fra}, a: {current_neighbour.visited}, til {tmp_edge.til}') print(f'fra: {fra}, a: {current_neighbour.visited}, til {tmp_edge.til}')
if global_fra == fra: if start == fra:
if tmp_edge.time < current_neighbour.time: if tmp_edge.time < current_neighbour.time:
current_neighbour.time = tmp_edge.time current_neighbour.time = tmp_edge.time
current_neighbour.prev = fra current_neighbour.prev = fra
if tmp_edge.til not in queue: if tmp_edge.til not in queue:
if tmp_edge.til == til: if tmp_edge.til == slutt:
current_node.visited = True current_node.visited = True
queue.pop(0) queue.pop(0)
dijkstras(global_fra, til, til) dijkstras(start, slutt, slutt)
else: else:
queue.append(tmp_edge.til) queue.append(tmp_edge.til)
elif current_neighbour.visited == True and current_neighbour.node != global_fra:
if calculate_shortest_path(current_node, tmp_edge.time, current_neighbour, global_fra): elif current_neighbour.visited == True and current_neighbour.node != start:
print(current_node.node, tmp_edge.time, current_neighbour.node, start)
if calculate_shortest_path(current_node, tmp_edge.time, current_neighbour, start):
current_neighbour.time = tmp_edge.time
current_neighbour.prev = tmp_edge.fra current_neighbour.prev = tmp_edge.fra
if fra == til: if fra == slutt:
#not finished #not finished
print('sho')
for i in res_arr: for i in res_arr:
if i.time != inf: if i.time != inf:
print(i.node, i.time, i.prev, i.visited) print(i.node, i.time, i.prev, i.visited)
exit() exit()
else: else:
queue.pop(0) queue.pop(0)
current_node.visited = True current_node.visited = True
dijkstras(global_fra,queue[0],til) dijkstras(start,queue[0],slutt)
...@@ -144,13 +151,13 @@ def init_things(): ...@@ -144,13 +151,13 @@ def init_things():
if len(sys.argv) > 1: if len(sys.argv) > 1:
if sys.argv[1] == '-d': if sys.argv[1] == '-d':
#node_id #node_id
fra = 0 start = 0
til = 1 slutt = 2
init_table() init_table()
queue.append(fra) queue.append(start)
a_start_node = [a for a in res_arr if a.node == fra][0] start_node = [a for a in res_arr if a.node == slutt][0]
a_start_node.time = 0 start_node.time = 0
dijkstras(fra, fra, til) dijkstras(slutt, start, start)
elif sys.argv[1] == '-a': elif sys.argv[1] == '-a':
print('A* not yet implemented') print('A* not yet implemented')
else: else:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment