Python - Speed up an A Star Pathfinding Algorithm

后端 未结 3 1513
星月不相逢
星月不相逢 2020-12-23 00:05

I\'ve coded my first slightly-complex algorithm, an implementation of the A Star Pathfinding algorithm. I followed some Python.org advice on implementing graphs so a diction

3条回答
  •  时光取名叫无心
    2020-12-23 00:29

    An easy optimization is to use sets instead of lists for the open and closed sets.

    openSet   = set()
    closedSet = set()
    

    This will make all of the in and not in tests O(1) instead of O(n).

提交回复
热议问题