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

KJØR

parent 6d7f8117
Branches
No related tags found
No related merge requests found
...@@ -75,19 +75,32 @@ def init_table(): ...@@ -75,19 +75,32 @@ def init_table():
for i in range(num_of_nodes): for i in range(num_of_nodes):
res_arr.append(results(i, max_num.time+1, False, None)) res_arr.append(results(i, max_num.time+1, False, None))
def rec_func(node, counter, global_fra): path=[]
def rec_func(node, counter, global_fra, end_switch):
if not end_switch:
counter += node.time counter += node.time
if node.node == global_fra: if node.node == global_fra:
return counter return counter
else: else:
node = [a for a in res_arr if a.node == node.prev][0] node = [a for a in res_arr if a.node == node.prev][0]
return rec_func(node, counter, global_fra) return rec_func(node, counter, global_fra, end_switch)
elif end_switch:
counter += node.time
path.append(node.node)
if node.node == global_fra:
return counter, path
else:
node = [a for a in res_arr if a.node == node.prev][0]
return rec_func(node, counter, global_fra, end_switch)
def calculate_shortest_path(current_node, time, current_neighbour, slutt): def calculate_shortest_path(current_node, time, current_neighbour, slutt):
end_switch = False
count_a = 0 count_a = 0
count_a = rec_func(current_neighbour, count_a, slutt) count_a = rec_func(current_neighbour, count_a, slutt, end_switch)
count_b = 0 count_b = 0
count_b = rec_func(current_node, count_b, slutt) count_b = rec_func(current_node, count_b, slutt, end_switch )
count_b += time count_b += time
if count_b < count_a: if count_b < count_a:
return True return True
...@@ -133,11 +146,12 @@ def dijkstras(slutt, fra, start): ...@@ -133,11 +146,12 @@ def dijkstras(slutt, fra, start):
current_neighbour.prev = tmp_edge.fra current_neighbour.prev = tmp_edge.fra
if we_soon_to_be_done and not len(end_que): if we_soon_to_be_done and not len(end_que):
#not finished #not finished
print('ferdig, resultater er: node, tid, prev, besøkt') end_node = [b for b in res_arr if b.node == slutt][0]
for i in res_arr: total_time = 0
if i.time != max_num.time + 1: end_switch = True
print(i.node, i.time, i.prev, i.visited) total_time,travel_arr = rec_func(end_node, total_time, start, end_switch)
print('que when done is: ', queue) travel_arr = reversed(travel_arr)
print(f'total time: {total_time}\nshortest path: {"->".join(str(v) for v in travel_arr)}')
exit() exit()
else: else:
if we_soon_to_be_done: if we_soon_to_be_done:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment