I'm going to use Astar algorithm to find a path between two selected points.And I used the following code for that.Is there any way I could convert my Road Layer shapefile into a graph, which can be use in this function? I'm new to QGIS and please help me to find a solution to this problem.
def astarSearch(self, graphAstar, current, end):
openSet = set()
openHeap = []
closedSet = set()
def retracePath(c):
path = [c]
while c.parent is not None:
c = c.parent
path.append(c)
path.reverse()
return path
openSet.add(current)
openHeap.append((0,current))
while openSet:
print "come2"
current = heapq.heappop(openHeap)[1]
if current == end:
print "come3"
return retracePath(current)
openSet.remove(current)
closedSet.add(current)
for tile in graphAstar[current]:
print "come4"
if tile not in closedSet:
tile.H = (abs(end.x-tile.x)+abs(end.y-tile.y))*10
if tile not in openSet:
openSet.add(tile)
heapq.heappush(openHeap, (tile.H,tile))
tile.parent = current
return []