LAB Manual Part A: Experiment No.03
LAB Manual Part A: Experiment No.03
LAB Manual Part A: Experiment No.03
LAB Manual
PART A
Experiment No.03
A.1 Aim: To Implement informed A* search methods using C /python/Java.
A.2 Prerequisite: Data Structure, Searching Techniques
A.3 Outcome:
After successful completion of this experiment students
will be able to
Ability to analyse the local and global impact of computing in searching techniques.
Understand, identify, analyse and design the problem, implement and validate the
solution for the A* search method.
Ability to applying knowledge of computing in search technique areas.
A.4 Theory:
An informed search strategy-one that uses problem-specific knowledge-can find solutions
more efficiently.A key component of these algorithms is a heuristic function h(n).
h(n) = estimated cost of the cheapest path from node n to a goal node.Admissible /heuristic
never over estimated i.e. h(n)≤ Actual cost.
For example, Distance between two nodes(cities)=> straight line distance and for 8-puzzel
problem- Admissible heuristic can be number of misplaced tiles h(n)= 8.
A* Search technique:
It is informed search technique. It uses additional information beyond problem formulation
and tree. Search is based on Evaluation function f(n). Evaluation function is based on both
heuristic function h(n) and g(n).
f(n)=g(n) + h(n)
It uses two queues for its implementation: open, close Queue. Open queue is a priority queue
which is arranged in ascending order of f(n)
Algorithm:
1. Create a single member queue comprising of Root node
2. If FIRST member of queue is goal then goto step 5
3. If first member of queue is not goal then remove it from queue and add to
close queue.
4. Consider its children if any, and add them to queue in ascending order of
evaluation function f(n).
5. If queue is not empty then goto step 2.
6. If queue is empty then goto step 6
7. Print ‘success’ and stop
8. Print ‘failure’ and stop.
Performance Comparison:
Completeness: yes
Optimality: yes
Time complexity :o(bd)
Limitation:
It generate same node again and again
Large Memory is required
Observation
Although A*generate many nodes it never uses those nodes for which f(n)> c* where c* is
optimum cost.
(Students must submit the soft copy as per following segments within
two hours of the practical. The soft copy must be uploaded on the
Blackboard or emailed to the concerned lab in charge faculties at the
end of the practical in case the there is no Black board access available)
class AStarGraph(object):
def __init__(self):
self.barriers = []
self.barriers.append([(2,4),(2,5),(2,6),(3,6),(4,6),(5,6),(5,5),(5,4),(5,3),(5,2),
(4,2),(3,2)])
D=1
D2 = 1
dx = abs(start[0] - goal[0])
dy = abs(start[1] - goal[1])
n = []
x2 = pos[0] + dx
y2 = pos[1] + dy
continue
n.append((x2, y2))
return n
if b in barrier:
return 100
G = {}
F = {}
G[start] = 0
closedVertices = set()
openVertices = set([start])
cameFrom = {}
current = None
currentFscore = None
currentFscore = F[pos]
current = pos
if current == end:
path = [current]
current = cameFrom[current]
path.append(current)
path.reverse()
openVertices.remove(current)
closedVertices.add(current)
if neighbour in closedVertices:
continue
openVertices.add(neighbour)
continue
cameFrom[neighbour] = current
G[neighbour] = candidateG
H = graph.heuristic(neighbour, end)
F[neighbour] = G[neighbour] + H
if __name__=="__main__":
graph = AStarGraph()
B.3 Conclusion:
In this experiment we Implement informed A* search methods using Python.
Ans: b
Explanation: A key point of informed search strategy is heuristic function, So it is called as
heuristic function.