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

KJØR

parent 6d7f8117
No related branches found
No related tags found
No related merge requests found
......@@ -75,19 +75,32 @@ def init_table():
for i in range(num_of_nodes):
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
if node.node == global_fra:
return counter
else:
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):
end_switch = False
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 = rec_func(current_node, count_b, slutt)
count_b = rec_func(current_node, count_b, slutt, end_switch )
count_b += time
if count_b < count_a:
return True
......@@ -133,11 +146,12 @@ def dijkstras(slutt, fra, start):
current_neighbour.prev = tmp_edge.fra
if we_soon_to_be_done and not len(end_que):
#not finished
print('ferdig, resultater er: node, tid, prev, besøkt')
for i in res_arr:
if i.time != max_num.time + 1:
print(i.node, i.time, i.prev, i.visited)
print('que when done is: ', queue)
end_node = [b for b in res_arr if b.node == slutt][0]
total_time = 0
end_switch = True
total_time,travel_arr = rec_func(end_node, total_time, start, end_switch)
travel_arr = reversed(travel_arr)
print(f'total time: {total_time}\nshortest path: {"->".join(str(v) for v in travel_arr)}')
exit()
else:
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