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

cleaning

parent cf328862
No related branches found
No related tags found
No related merge requests found
python3 program1.py -a/-d
......
......@@ -76,12 +76,14 @@ def init_table():
def rec_func(node, counter, global_fra):
counter += node.time
if node.fra == global_fra:
if node.node == global_fra:
return counter
else:
rec_func(node.prev, counter, global_fra)
node = [a for a in res_arr if a.node == node.prev][0]
rec_func(node, counter, global_fra)
def calculate_shortest_path(b, i, a, global_fra):
print('in calculate')
count_a = 0
count_a = rec_func(a, count_a, global_fra)
count_b = 0
......@@ -96,32 +98,39 @@ def calculate_shortest_path(b, i, a, global_fra):
queue = []
def dijkstras(global_fra, fra, til):
for i in edge_arr:
if i.fra == fra:
a = [a for a in res_arr if a.node == i.til][0]
if a:
if a.visited == False:
print(queue)
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:
if current_neighbour.visited == False:
print(f'fra: {fra}, a: {current_neighbour.visited}, til {tmp_edge.til}')
if global_fra == fra:
if i.time < a.time:
a.time = i.time
a.prev = fra
if i.til not in queue:
if i.til == til:
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:
current_node.visited = True
queue.pop(0)
dijkstras(global_fra, til, til)
else:
queue.append(i.til)
elif a.visited == True:
b = [b for b in res_arr if b.node == i.fra][0]
if calculate_shortest_path(b, i.time, a, global_fra):
a.prev = i.fra
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):
current_neighbour.prev = tmp_edge.fra
if fra == til:
#not finished
for i in res_arr:
if i.time != inf:
print(i.node, i.time, i.prev)
print(i.node, i.time, i.prev, i.visited)
exit()
else:
queue.pop(0)
current_node.visited = True
dijkstras(global_fra,queue[0],til)
......@@ -139,8 +148,8 @@ def init_things():
til = 1
init_table()
queue.append(fra)
a = [a for a in res_arr if a.node == fra][0]
a.time = 0
a_start_node = [a for a in res_arr if a.node == fra][0]
a_start_node.time = 0
dijkstras(fra, fra, til)
elif sys.argv[1] == '-a':
print('A* not yet implemented')
......@@ -149,7 +158,6 @@ def init_things():
else:
print('Missing argument')
print(edge_arr[0].fra)
init_things()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment