p2code
p2code
finding problem
Code:
class Graph:
def init (self, adjac_lis):
self.adjac_lis = adjac_lis
return H[n]
poo = {}
poo[start] = 0
par = {}
par[start] = start
if n == None:
print('Path does not exist!')
return None
if n == stop:
reconst_path = []
while par[n] != n:
reconst_path.append(n)
n = par[n]
reconst_path.append(start)
reconst_path.reverse()
else:
if poo[m] > poo[n] + weight:
poo[m] = poo[n] + weight
par[m] = n
if m in closed_lst:
closed_lst.remove(m)
open_lst.add(m)
open_lst.remove(n)
closed_lst.add(n)
adjac_lis = {
'A': [('B', 1), ('C', 3), ('D', 7)],
'B': [('D', 5)],
'C': [('D', 12)]
}
graph1 = Graph(adjac_lis)
graph1.a_star_algorithm('A', 'D')
Output:
Path found: ['A', 'B', 'D']
Code:
from queue import PriorityQueue
v = 14
graph = [[] for i in range(v)]
for v, c in graph[u]:
if visited[v] == False:
visited[v] = True
pq.put((c, v))
print()
source = 0
target = 9
best_first_search(source, target, v)
Output:
0 1 3 2 8 9