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