Skip to content
Snippets Groups Projects
Commit 68cd6d91 authored by u214892's avatar u214892
Browse files

a_star with sets instead of lists: cleanup

parent 0304a317
No related branches found
No related tags found
No related merge requests found
...@@ -54,7 +54,6 @@ def validate_new_transition(rail_trans, rail_array, prev_pos, current_pos, new_p ...@@ -54,7 +54,6 @@ def validate_new_transition(rail_trans, rail_array, prev_pos, current_pos, new_p
else: else:
# check if matches existing layout # check if matches existing layout
new_trans = rail_trans.set_transition(new_trans, current_dir, new_dir, 1) new_trans = rail_trans.set_transition(new_trans, current_dir, new_dir, 1)
# new_trans = rail_trans.set_transition(new_trans, mirror(new_dir), mirror(current_dir), 1)
else: else:
# set the forward path # set the forward path
new_trans = rail_trans.set_transition(new_trans, current_dir, new_dir, 1) new_trans = rail_trans.set_transition(new_trans, current_dir, new_dir, 1)
...@@ -69,7 +68,6 @@ def validate_new_transition(rail_trans, rail_array, prev_pos, current_pos, new_p ...@@ -69,7 +68,6 @@ def validate_new_transition(rail_trans, rail_array, prev_pos, current_pos, new_p
else: else:
# check if matches existing layout # check if matches existing layout
new_trans_e = rail_trans.set_transition(new_trans_e, new_dir, new_dir, 1) new_trans_e = rail_trans.set_transition(new_trans_e, new_dir, new_dir, 1)
# new_trans_e = rail_trans.set_transition(new_trans_e, mirror(new_dir), mirror(new_dir), 1)
if not rail_trans.is_valid(new_trans_e): if not rail_trans.is_valid(new_trans_e):
return False return False
...@@ -114,12 +112,6 @@ def a_star(rail_trans, rail_array, start, end): ...@@ -114,12 +112,6 @@ def a_star(rail_trans, rail_array, start, end):
closed_list = set() closed_list = set()
open_list.add(start_node) open_list.add(start_node)
# this could be optimized
def is_node_in_list(node, the_list):
if node in the_list:
return node
return None
while len(open_list) > 0: while len(open_list) > 0:
# get node with current shortest est. path (lowest f) # get node with current shortest est. path (lowest f)
current_node = None current_node = None
...@@ -169,8 +161,7 @@ def a_star(rail_trans, rail_array, start, end): ...@@ -169,8 +161,7 @@ def a_star(rail_trans, rail_array, start, end):
# loop through children # loop through children
for child in children: for child in children:
# already in closed list? # already in closed list?
closed_node = is_node_in_list(child, closed_list) if child in closed_list:
if closed_node is not None:
continue continue
# create the f, g, and h values # create the f, g, and h values
...@@ -183,9 +174,7 @@ def a_star(rail_trans, rail_array, start, end): ...@@ -183,9 +174,7 @@ def a_star(rail_trans, rail_array, start, end):
child.f = child.g + child.h child.f = child.g + child.h
# already in the open list? # already in the open list?
open_node = is_node_in_list(child, open_list) if child in open_list:
if open_node is not None:
open_node.update_if_better(child)
continue continue
# add the child to the open list # add the child to the open list
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment