I am experimenting with a search algorithm, and I am trying to use an A* algorithm to solve the problem.
I am using a list of dictionaries to mantain the internal node structure. Each node is characterised by a certain state and associated cost. The selection function should return the node with the lowest cost. To be able to do this, I am filtering the list every time. I found this is very fast if the problem is very small, but in the case the list is very big, this function uses 84% of the total time of the algorithm.
My question is if there is a more efficient way of doing this.
def select(self, frontier):
frontier.sort(key = lambda x: x['f_cost'])
#select the node with the lowest f_cost
return frontier.pop(0)