You are on page 1of 18

Artificial Intelligence

CS-216
Institute of Southern Punjab
Multan

Syed Zohair Quain Haider


Lecturer ISP Multan
Lecture#6
In the Last Lecture:
• Informed Searches ( BFS, G-BF-S, A*)
• Heuristic
• Best-first search
• Greedy best-first search
• A* search
• Hill Climbing Algorithm

Last Discussion
Last Discussion
In Today’s Lecture
• Hill Climbing Algorithm
• Adversarial search

Today’s Discussion
Today’s Discussion
• Euclidean: Take the square root of the sum of the squares of the differences of
the coordinates.

• For example, if x=(a,b)x=(a,b) and y=(c,d), the Euclidean distance between xx and yy
is

• Manhattan: Take the sum of the absolute values of the differences of the
coordinates.

• For example, if x=(a,b)x=(a,b) and y=(c,d)y=(c,d), the Manhattan distance between xx


and yy is

|a−c|+|b−d|

Finding Distance
Finding Distance
• To use A* a heuristic function must be used that never overestimates the
number of steps to the goal

• h1=the number of misplaced tiles

• h2=the sum of the Manhattan distances of the tiles from their goal positions

Heuristic Function
Heuristic Function
• A problem with fewer restrictions on the actions is called a relaxed problem
• The cost of an optimal solution to a relaxed problem is an admissible
heuristic for the original problem

• If the rules of the 8-puzzle are relaxed so that a tile can move anywhere,
then h1(n) gives the shortest solution

• If the rules are relaxed so that a tile can move to any adjacent square, then
h2(n) gives the shortest solution

Relaxed problems
Relaxed problems
• They are useful for solving optimization problems
• Aim is to find a best state according to an objective function
• Many optimization problems do not fit the standard search model

• In such cases, we can use local search algorithms


• Main idea is to keep a single "current" state, try to improve it

Local Search Approaches


Local Search Approaches
Hill Climbing Algorithm:
• Hill climbing algorithm is a local search algorithm which continuously moves in the
direction of increasing elevation/value to find the peak of the mountain or best
solution to the problem. It terminates when it reaches a peak value where no
neighbor has a higher value.
• Hill climbing algorithm is a technique which is used for optimizing the
mathematical problems. One of the widely discussed examples of Hill climbing
algorithm is Traveling-salesman Problem in which we need to minimize the
distance traveled by the salesman.
• It is also called greedy local search as it only looks to its good immediate neighbor
state and not beyond that.
• A node of hill climbing algorithm has two components which are state and value.
• Hill Climbing is mostly used when a good heuristic is available.
• In this algorithm, we don't need to maintain and handle the search tree or graph as
it only keeps a single current state.

Hill Climbing Algorithm


Hill Climbing Algorithm
Features of Hill Climbing Algorithm:
• Generate and Test variant: Hill Climbing is the variant of Generate and Test method. The
Generate and Test method produce feedback which helps to decide which direction to
move in the search space.
• Greedy approach: Hill-climbing algorithm search moves in the direction which optimizes
the cost.
• No backtracking: It does not backtrack the search space, as it does not remember the
previous states.

Hill Climbing Algorithm


Hill Climbing Algorithm
State-space Diagram for Hill Climbing

Hill Climbing Algorithm


Hill Climbing Algorithm
State-space Diagram for Hill Climbing
• Generate nearby successor states to the current state
• Pick the best and replace the current state with that one.
• Loop

Hill Climbing Algorithm


Hill Climbing Algorithm
Start 3 1 2 3 1 2 3 1 2
4 5 8 h=5 4 5 8 h=4 4 5 h=3

6 7 6 7 6 7 8

3 1 2 3 1 2 1 2
4 5 h=2 4 5 h=1 3 4 5 h=0

6 7 8 6 7 8 6 7 8 Goal

Hill Climbing Example


Hill Climbing Example
Local maximum
A state that is better than all of its neighbours, but not
better than some other states far away.

Hill Climbing Problems


Hill Climbing Problems
Start 4 1 2 4 2 4 1 2
3 5 h=1 3 1 5 h=2 3 7 5 h=2
6 7 8 6 7 8 6 8

4 1 2 4 1 2 1 2
3 5 h=2 3 5 h=2 3 4 5 h=0

6 7 8 6 7 8 6 7 8 Goal

Hill Climbing Problems (Local Maxima )


Plateau/ Flat maximum

A flat area of the search space in which all neighbouring


states have the same value.

Hill Climbing Problems


Hill Climbing Problems
Ways Out
• Backtrack to some earlier node and try going in a different direction.
• Make a big jump to try to get in a new section.
• Moving in several directions at once.

Hill Climbing Problems


Hill Climbing Problems
Adversarial Search
Adversarial search is a search, where we examine the problem which arises when we try to
plan ahead of the world and other agents are planning against us.
• In previous topics, we have studied the search strategies which are only associated with a
single agent that aims to find the solution which often expressed in the form of a sequence
of actions.
• But, there might be some situations where more than one agent is searching for the
solution in the same search space, and this situation usually occurs in game playing.
• The environment with more than one agent is termed as multi-agent environment, in which
each agent is an opponent of other agent and playing against each other. Each agent
needs to consider the action of other agent and effect of that action on their performance.
• So, Searches in which two or more players with conflicting goals are trying to explore the
same search space for the solution, are called adversarial searches, often known as
Games.
• Games are modeled as a Search problem and heuristic evaluation function, and these are
the two main factors which help to model and solve games in AI.

Adversarial Search
Adversarial Search
Questions

Questions Session
Questions Session

You might also like