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

kjør

parent 77408618
No related branches found
No related tags found
No related merge requests found
......@@ -69,26 +69,24 @@ for i in range(len(intresting_file)):
tmp_values = intresting_file[i].split()
intresting_arr.append(int_points(int(tmp_values[0]), int(tmp_values[1]), ' '.join(tmp_values[2:])))
max_num = max(edge_arr,key=lambda item:item.time)
res_arr = []
def init_table():
for i in range(num_of_nodes):
res_arr.append(results(i, inf, False, None))
res_arr.append(results(i, max_num.time+1, False, None))
def rec_func(node, counter, global_fra):
print('in recfunc')
counter += node.time
print(f'node: {node.node}, node_time: {node.time}, time_count: {counter}')
if node.node == global_fra:
return counter
else:
print(node.prev)
node = [a for a in res_arr if a.node == node.prev][0]
rec_func(node, counter, global_fra)
return rec_func(node, counter, global_fra)
def calculate_shortest_path(current_node, time, current_neighbour, slutt):
print('\nin calculate')
res_a = [c for c in res_arr if c.node == current_neighbour.node][0]
print(f'curr_node: {current_node.node}, edge_time: {time}, curr_neig_node: {current_neighbour.node}, curr_neig_prev: {current_neighbour.prev}, dist to curr_neig: {res_a.time}, global_fra: {slutt}')
count_a = 0
count_a = rec_func(current_neighbour, count_a, slutt)
count_b = 0
......@@ -100,24 +98,16 @@ def calculate_shortest_path(current_node, time, current_neighbour, slutt):
return False
round = 0
queue = []
def dijkstras(slutt, fra, start):
global round
round +=1
print('runde: ', round, ' queue: ', queue, 'start: ', start)
current_node = [b for b in res_arr if b.node == fra][0]
print(current_node.node)
for tmp_edge in edge_arr:
if tmp_edge.fra == fra:
current_neighbour = [a for a in res_arr if a.node == tmp_edge.til][0]
if current_neighbour.visited == False:
print(f'fra: {fra}, a: {current_neighbour.visited}, til {tmp_edge.til}')
if start == fra:
if tmp_edge.time < current_neighbour.time:
if current_neighbour.visited == False and current_neighbour.node not in queue:
current_neighbour.time = tmp_edge.time
current_neighbour.prev = fra
if tmp_edge.til not in queue:
if tmp_edge.til == slutt:
current_node.visited = True
queue.pop(0)
......@@ -125,17 +115,16 @@ def dijkstras(slutt, fra, start):
else:
queue.append(tmp_edge.til)
elif current_neighbour.visited == True and current_neighbour.node != start:
print(current_node.node, tmp_edge.time, current_neighbour.node, start)
elif 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 == slutt:
#not finished
print('sho')
print('ferdig, resultater er: node, tid, prev, besøkt')
for i in res_arr:
if i.time != inf:
if i.time != max_num.time + 1:
print(i.node, i.time, i.prev, i.visited)
exit()
......@@ -157,8 +146,8 @@ def init_things():
slutt = 2
init_table()
queue.append(start)
start_node = [a for a in res_arr if a.node == slutt][0]
start_node.time = 0
start_node = [a for a in res_arr if a.node == start][0]
start_node.time = 1
dijkstras(slutt, start, start)
elif sys.argv[1] == '-a':
print('A* not yet implemented')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment