a) · Web viewb) 8-queens The goal of the 8-queens problem is to place eight queens on a chessboard...
Transcript of a) · Web viewb) 8-queens The goal of the 8-queens problem is to place eight queens on a chessboard...
13CS4102 - ARTIFICIAL INTELLIGENCE
Hours / Week : 4 Sessional Marks : 40Credits : 4 End Examination Marks : 60
UNIT - IIntroduction: A.I, History of A.I, The state of the Art, Intelligent Agents: Agents and Environments, Good behavior, The nature of Environments, the Structure of Agents.
UNIT – IIProblem Solving: Problem solving agents, toy problems, Real-world problems, searching for solutions, Uninformed Search strategies: BFS, DFS, Depth-limited search, Informed Search strategies: GBFS, A* search, Local search algorithms: Hill-climbing.
UNIT – IIIConstraint Satisfaction Problems: Constraint Satisfaction Problems, Backtracking Search for CSPs, Local search for CSPs, The structure of the problem, Adversarial Search: Games, optimal decision in games, Alpha-Beta pruning, Imperfect, Real-Time Decisions, Games that include an Element of Chance, State-of-the-Art Game Programs.
UNIT – IVKnowledge and reasoning: Logical Agents: Knowledge -based Agents, The WUMPUS world, Logic, Propositional Logic, Reasoning Patterns in Propositional logic, Resolution, Forward and Backward chaining. First-order Logic: Syntax and Semantics of First-Order Logic, Using FOL- Assertions and queries in FOL.
UNIT –VLearning: Learning from Observations- Forms of Learning, Inductive Learning, Learning Decision Trees, Ensemble Learning, Knowledge in Learning: A Logical formulation of learning, knowledge in learning, Explanation-Based Learning, Learning using Relevance Information.
TEXT BOOKS1. Artificial Intelligence- A Modern Approach, Stuart Russell, Peter Norvig (Person Education) ,2nd
edition.
REFERENCE BOOKS1. Artificial Intelligence- Rich E & Knight K (TMH), 4th edition.2. Artificial Intelligence Structures and Strategies complex problem Solving – George F. Lugar
Pearson Education.
UNIT – IIProblem Solving: Problem solving agents, toy problems, Real-world problems, searching for solutions, Uninformed Search strategies: BFS, DFS, Depth-limited search, Informed Search strategies: GBFS, A* search, Local search algorithms: Hill-climbing.
1. Problem solving agents (Goal-based agents):
NBKRIST IV B.TECH I SEM PREPARED BY: BSR Page 1
This is one kind of goal-based agent called a problem-solving agent. Problem-solving agents decide what
to do by finding sequences of actions that lead to desirable states. Intelligent agents are supposed to
maximize their performance measures. Achieving this is sometimes simplified if the agent can adopt a
goal and aim at satisfying it.
Four general steps in problem solving:
a) Goal Formulation: What are the successful world states
b) Problem formulation: what actions and states to consider given the goal.
c) Search: Determine the possible sequence of actions that lead to the states of known values and the
choosing the best sequence.
d) Execute: Give the solution perform the action.
Example: Road map of Romania
NBKRIST IV B.TECH I SEM PREPARED BY: BSR Page 2
On holiday in Romania; currently in Arad
Flight leaves tomorrow from Bucharest
Goal Formulation:
Be in Bucharest
Problem Formulation:
States: Various cities
Action: Drive between cities
Find Solution:
Sequence of cities: E.g.: Arad, Sibiu, Fagaras, Bucharest
1.1 Well defined Problems and Solutions (Formulating Problems):
Goal Formulation is the first step in problem solving.
Then we need the problem formulation: Which is defined by four components
1. Initial state: That the agent starts in e.g. In(Arad)
2. Successor function (or operator): A description of the possible actions available to the agent, it is
common to describe it by means of a successor function, given state x then SUCCESSOR-FN(x) returns a
set of ordered pairs <action, successor>
Example: {<Go(Sibiu),In(Sibiu)>, <Go(Timisoara),In(Timisoara)>, <Go(Zeind),In(Zerind)> }
The initial state and the successor function together defined what is called state space which is the set of
all possible states reachable from the initial state.
NBKRIST IV B.TECH I SEM PREPARED BY: BSR Page 3
3. Goal test: It determines whether a given state is a goal state. E.g. { In (Bucharest) }
4. Path cost: A function that assigns a numeric value to each path
1.2 Formulating Problems:
A solution to a problem is a path from the initial state to the goal state. Solution quality is measured by
the path cost function and an optimal solution has the lowest path cost among all solutions.
Example: Road map of Romania
Goal Formulation:
Be in Bucharest
Problem Formulation:
States: Various cities
Action: Drive between cities
Find Solution:
Sequence of cities: E.g.: Arad, Sibiu, Fagaras, Bucharest
2. Example Problems:
NBKRIST IV B.TECH I SEM PREPARED BY: BSR Page 4
The problem-solving approach has been applied to a vast array of task environments. We list some of the
best known here
2.1. Toy problems: A toy problem is intended to illustrate or exercise various problem-solving methods.
2.2. Real-world problems: A real-world problem is one whose solutions people actually care about.
2.1. Toy problems:
a) Vacuum world b) 8-queens c) 8-puzzle
a) Vacuum world:
a) Vacuum world: This can be formulated as a problem as follows.
States: The agent is in one of two locations, each of which might or might not contain dirt. Thus
there are 2*22 =8 possible states.
Initial state: any state
Successor function: move left, move right, Suck
Goal test: This checks whether all squares are clean
Path cost: Each step cost 1, unit per action, so the path cost is the number of steps in the path.
b) 8-queens: The goal of the 8-queens problem is to place eight queens on a chessboard such that no
queen attacks any other.(A queen attacks any piece in the same row, column or diagonal).
NBKRIST IV B.TECH I SEM PREPARED BY: BSR Page 5
States: any arrangement of 0-8 queens on the board is a state
Initial state: no queens on the board
Successor function: add a queen to any empty square
Goal test: 8 queens are on the board, none attacked
path cost: zero
c) 8-puzzle: The fig: consists of a 3*3 board with eight numberd titles and a blank space. A title adjacent
to the blank space can slide into the space. The object is to reach a specified goal state, such as the one
shown on the right of the fig: The standard formulation is as follows.
States: locations of tiles
Intitial state: any state
Successor function: move blank left, right, up, down
Goal test: goal state(This check whether the state matches the goal configuration)(other goal
configurations are possible)
Path cost: 1 per move
The 8-puzzle belongs to the family of sliding-block puzzles, which are often used as test problems for new
search algorithms in AI. This general class is known to be NP-complete. The 8-puzzle has 9!/2 =181,440
reachable states and is easily solved. The 15-puzzle(on a 4*4 board) has around 1.3 trillion states. The 24
puzzle (on a 5*5 board) has around 1025 states
NBKRIST IV B.TECH I SEM PREPARED BY: BSR Page 6
2.2. Real-world problems:
1. Route finding problem:
Route-finding algorithms are used in a variety of applications, such as routing in computer networks,
military operations planning, and air line travel planning systems. These problems are typically complex
to specify. Consider a simplified example of an airline travel problem specified as follows:
States: Each is represented by a location (e.g., an airport) and the current time.
Initial state: This is specified by the problem.
Successor Function: Airport transit time, from the current airport to another.
Goal test: Are we at the destination by some prespecified time?
Path cost: This is depends on monetary cost, waiting time, flight time, customs and immigration
procedures, seat quality, time of day, type of airplane, frequent-flyer mileage awards and so on.
2. Touring problem: Touring problems are closely related to route-finding problems, but with an
important difference. Consider, the example, the problem, “Visit every city at least once”, starting and
ending in Bucharest.
States: Various cities
Initial State: The initial state would be "In Bucharest; visited {Bucharest}"
Successor Function: Drive between cities
Goal test: would check whether the agent is in Bucharest and all 20 cities have been visited.
Path cost: 1 per move
3. Travelling salesperson problem (TSP): It is a touring problem in which each city must be visited
exactly once. The aim is to find the shortest tour. These algorithms have been used for tasks such as
planning movements of automatic circuit-board drills and of stocking machines on shop floors.
NBKRIST IV B.TECH I SEM PREPARED BY: BSR Page 7
4. VLSI layout design: Positioning millions of components and connections on a chip to minimize area,
minimize circuit delays, minimize stray capacitances, and maximize manufacturing yield.
5. Robot navigation: A robot can move in a continuous space with (in principle) an infinite set of
possible actions and states. For a circular robot moving on a flat surface, the space is essentially two-
dimensional. When the robot has arms and legs or wheels that must also be controlled, the search space
becomes many-dimensional.
Note: A search space is the set or domain through which an algorithm searches. In computer science,
the space may be a well-defined and finite data structure.
6. Internet searching: Looking for answers to question, for related information, or for shopping deals.
This is a good application for search techniques, because it is easy to conceptualize the internet as a graph
of nodes (pages) connected by links.
7. Automatic assembly sequencing: The aim is to find an order in which to assemble the parts of some
object. If the wrong order is chosen, there will be no way to add some part later in the sequence without
undoing some of the work already done.
Example: robotic assembly
States: real-valued coordinates of robot joint angles parts of the object to be assembled
Actions: continuous motions of robot joints
Goal test: complete assembly
Path cost: time to execute
8. Protein design: The goal is to find a sequence of amino acids that will fold into three-dimensional
protein with the right properties to cure some disease.
3. Searching for solutions:
NBKRIST IV B.TECH I SEM PREPARED BY: BSR Page 8
Solution to AI problems involves performing an action to go to one proper state among possible numerous
possible states of agent. Thus the processes of finding solution can be boiled down to searching of that
best state among all the possible states.
There are many ways to represent nodes, but we will assume that a node is a data structure with five
components:
STATE: The state in the state space to which the node corresponds;
PARENT-NODE: The node in the search tree that generated this node;
ACTION: The action that was applied to the parent to generate the node;
PATH-COST: The cost, traditionally denoted by g(n), of the path from the initial state to the node, as
indicated by the parent pointers.
DEPTH: The number of steps along the path from the initial state.
It is important to remember the distinction between nodes and states.
A node is a 'data structure used to represent the search tree’ includes state, parent, action, path cost g(n), depth. A
state is a (representation of) a physical configuration. The node data structure is depicted in Figure:
NBKRIST IV B.TECH I SEM PREPARED BY: BSR Page 9
The collection of nodes can be implemented as a queue. The queue operations on a queue are as follows:
Make-Queue(element,…): Creates a queue with the given element(s).
Empty(Queue): Returns true only if there are no more elements in the queue.
First(Queue): Returns the first element of the queue.
Remove-First(Queue): Returns First(Queue) and removes it from the queue.
Insert(element,Queue): Insert an element into the queue and returns the resulting queue.
Insert-All(elements, Queue): Inserts a set of elements into the queue and returns the resulting queue.
3.1 Measuring problem-solving performance:
The output of a problem-solving algorithm is either failure or a solution. We will evaluate an algorithm’s
performance in four ways:
Completeness: Is the algorithm guaranteed to find a solution when there is one?
Optimality: Does the strategy find the optimal solution?
Time complexity: How long does it take to find a solution?
Space complexity: How much memory is needed to perform the search?
NBKRIST IV B.TECH I SEM PREPARED BY: BSR Page 10
4. Uninformed Search strategies (Blind search):Uninformed search strategies Informed search strategies
Searching without information. Ex: BFS(We just generate all
successor state (child node) for current state and find is there
is a goal state among them.(Brute force)
Searching with information. Ex: A* algorithm. We have
information about distance between start point and each
available location.(Heuristic)
Uninformed search strategies or brute force or blind, uses no
knowledge about problem.
Informed Search Technique-heuristic or intelligent, uses prior
knowledge about problem.
Not efficient Efficient
Uninformed search methods: Breadth-first, depth-first,
depth-limited, uniform-cost, depth-first iterative deepening,
bidirectional
Informed search methods: Hill climbing, best-first, greedy
search, beam search, A, A*
The heading of uninformed search also called blind search. This search strategies use only the
information available in the problem definition. The different search strategies are:
1. Breadth-first search
2. Uniform cost search
3. Depth first search
4. Depth limited search
5. Iterative deepening search
6. Bidirectional search
4.1. Breadth-first search: We traverse the tree level wise from left to right starting from the root. It is
implemented using Queue (FIFO).
Algorithm:
1. Temp=root
2. Add temp into queue
3. Remove temp from queue
4. Display data of temp
5. If temp has left child, add it to the queue
6. If temp has right child, add it to the queue
7. Repeat from step3 till queue becomes empty
8. Stop
Example: Step 1:
NBKRIST IV B.TECH I SEM PREPARED BY: BSR Page 11
Queue: 2, 3
The starting node 1 has two children 2, 3 the nodes 2 and 3 are added to the queue. Visit 1.
Step 2:
Queue: 3, 4, 5
Delete the node 2 and node 2 have the child 4 and 5 so add 4, 5 to queue. Visit 2
Step 3:
Queue: 4, 5
Delete 3 the node have child 5 add 5 to the queue. Visit 3.
Step 4:
Queue: 5, 6, 7
Delete 4, the nodes 6, 7 are added to queue. Visit 4.
Step 5:
Queue: 5, 6, 7, 8
Delete 5 the node 8 is added. Visit 5
Step 6:
Queue: 6, 7, 8
Delete 6. The node 9 is added. Visit 6.
Step 7:
Queue: 8, 9
Delete 7. Visit 7
Step 8:
Queue: 9
Delete 8. Visit 8
Step 9:
Queue: Empty
NBKRIST IV B.TECH I SEM PREPARED BY: BSR Page 12
Delete 9. Visit 9.
Result: The BFS will be 1,2,3,4,5,6,7,8,9.
Now suppose that the solution is at depth d. In the worst case, we would expand all but the last node at
level d(since the goal itself is not expanded),generating bd+1-b nodes at level d+1. Then the total number of
nodes is
. The time complexity is
The fig: It lists the time and space required for a breadth-first search with branching factor b=10, for
various values of the solution depth d. The table assumes that 10,000 nodes can be generated per second
and that a node requires 1000 bytes of storage.
Properties of BFS:
1. Complete
2. The algorithm is optimal if all operators have the same cost.
3. The algorithm has exponential time and space complexity.
Advantages Disadvantages
NBKRIST IV B.TECH I SEM PREPARED BY: BSR Page 13
In this procedure at any way it will find the goal BFS consumes large memory space.
It does not follow a single unfruitful path for a long time. Its time complexity is more. (If your problem
has a solution at depth 12, then (given
our assumptions) it will takes 35 years
for BFS to find it)
It finds the minimal solution in case of multiple paths It has long pathways, when all paths to a
destination are on approximately the same search
depth
4.2 Uniform Cost Search (UCS):
It is one of the best search algorithm compare to DFS or BFS because it determines the best path
through the actual path cost NOT just count number of nodes. It is implementing with priority queues.
Uniform Cost Search is the best algorithm for a search problem, which does not involve the use of heuristics. It can solve any general graph for optimal cost. Uniform Cost Search as it sounds searches in branches which are more or less the same in cost.
Uniform Cost Search again demands the use of a priority queue. Recall that Depth First Search used a priority queue with the depth up to a particular node being the priority and the path from the root to the node being the element stored. The priority queue used here is similar with the priority being the cumulative cost up to the node. Unlike Depth First Search where the maximum depth had the maximum priority, Uniform Cost Search gives the minimum cumulative cost the maximum priority. The algorithm using this priority queue is the following:
Insert the root into the queueWhile the queue is not empty Dequeue the maximum priority element from the queue (If priorities are same, alphabetically smaller path is chosen) If the path is ending in the goal state, print the path and exit Else Insert all the children of the dequeued element, with the cumulative costs as priority
Now let us apply the algorithm on the above search tree and see what it gives us. We will go through each iteration and look at the final output. Each element of the priority queue is written as [path,cumulative cost].
NBKRIST IV B.TECH I SEM PREPARED BY: BSR Page 14
Initialization: { [ S , 0 ] }Iteration1: { [ S->A , 1 ] , [ S->G , 12 ] }Iteration2: { [ S->A->C , 2 ] , [ S->A->B , 4 ] , [ S->G , 12] }Iteration3: { [ S->A->C->D , 3 ] , [ S->A->B , 4 ] , [ S->A->C->G , 4 ] , [ S->G , 12 ] }Iteration4: { [ S->A->B , 4 ] , [ S->A->C->G , 4 ] , [ S->A->C->D->G , 6 ] , [ S->G , 12 ] }Iteration5: { [ S->A->C->G , 4 ] , [ S->A->C->D->G , 6 ] , [ S->A->B->D , 7 ] , [ S->G , 12 ] }Iteration6 gives the final output as S->A->C->G.
Things worth mentioning:
The creation of the tree is not a part of the algorithm. It is just for visualization.
The algorithm returns the first path encountered. It does not search for all paths.
The algorithm returns a path which is optimal in terms of cost.
NBKRIST IV B.TECH I SEM PREPARED BY: BSR Page 15
4.3 Depth-first search: We start from the root and traverse left as far as we can go. Once the left most
end is reached, we go to the right child of the node in the path and move to its left most end. The DFS can
be implemented by using Stack (LIFO).
Algorithm:
1. Temp=root
2. Push temp into the stack
3. Pop temp from stack
4. Display data of temp
5. If temp has right child, push right child into the stack.
6. If temp has left child, push left child into the stack
7. Repeat from step 3 till stack is empty
8. Stop
Example:
Step 1: Push 1, 2,4,6,9 to stack.
Step 2: Pop 9, for the node 9, there is no unprocessed adjacent nodes.
Step 3: Pop 6, for the node 6 no unprocessed adjacent nodes.
Step 4: The node 4 has adjacent node 7. Push 4 and 7. Visit 7
Step 5: The node 7 has no unprocessed adjacent nodes.
Step 6: Pop 4, nodes is already processed.
Step 7: The node 2 have adjacent node 5. So 2 and 5 are pushed into the stack. Visit 5
Step 8: The node 5 have adjacent node 8 so 5, 8 are pushed.
Step 9: Pop 8. There are no unprocessed adjacent nodes.
Step 10: The node 5 and 3 to stack. Visit 3
Step 11: Pop 3, 5, 2, 1. No unprocessed adjacent nodes.
Result: 1,2,4,6,9,7,5,8,3
NBKRIST IV B.TECH I SEM PREPARED BY: BSR Page 16
Properties of DFS:
1. The algorithm takes exponential time.
2. Time taken by the algorithm is related to the maximum depth of the search tree.
Advantages Disadvantages
DFS Consumes very less memory space It is possible that may states keep reoccurring
It will reach at the goal node in a less time period than
BFS if it traverse in a right path
There is no guarantee of finding the goal node
It may find a solution without examining much of search
because we may get the desired solution
Sometimes the states may also enter into infinite
loops
Time complexity (worst case: solution is at m): O(bm)
4.4 Depth Limited Search (DLS):
NBKRIST IV B.TECH I SEM PREPARED BY: BSR Page 17
It is basically similar to depth first search with following modification. Depth-limited search
avoids the pitfalls of depth-first search by imposing a cutoff on the maximum depth of a path.
This cutoff can be implemented with a special depth-limited search algorithm, or by using the
general search algorithm with operators that keep track of the depth.
To avoid the infinite depth problem of DFS, we can decide to only search until depth L, i.e. we
don’t expand beyond depth L.
DLS algorithm returns Failure (no solution)
The reason is that the goal is beyond the limit (Limit=2): The goal depth is (d=4)
Note: There is no guarantee of finding the goal node
4.5 Iterative Deepening Search (IDS):
NBKRIST IV B.TECH I SEM PREPARED BY: BSR Page 18
It is similar to DFS. Depth is not knows. Increasing the depth limit with each iteration until it reaches d,
the depth of the goal state. Increase the level and apply DFS.
Summary of algorithms:
NBKRIST IV B.TECH I SEM PREPARED BY: BSR Page 19
4.6 Bidirectional search:
Bidirectional search is a graph search algorithm that finds a shortest path from an initial vertex to a goal
vertex in a directed graph. It runs two simultaneous searches: one forward from the initial state, and one
backward from the goal, stopping when the two meet in the middle.
We can consider bidirectional approach when-
Both initial and goal states are unique and completely defined.
The branching factor is exactly the same in both directions.
5. Informed Search strategies:
NBKRIST IV B.TECH I SEM PREPARED BY: BSR Page 20
Informed search strategies use problem specific knowledge beyond the definition of the problem itself.
In making this decision, these look at the states inside the nodes. It is also known as “Heuristic search”.
[OR]
Informed search strategies employ problem specific knowledge to make a choice of which node to select
next. This knowledge is formulated in the form of a function f(x).
Informed search methods: Hill climbing, best-first, Greedy Best First Search, A* search.
Heuristic function: It maps each state to a numerical value which depicts goodness of a node.
H(n)=value where, H( ) is a heuristic function and ‘n’ is the current state.
Generate-and-Test :( Algorithm):
1. Generate a possible solution
2. Test and confirm if this is the actual solution (Goal test)
3. If solution found, quit, else go to step 1
1) Best-First Search:
The idea of Best First Search is to use an evaluation function to decide which adjacent is
most promising and then explore. Best First Search falls under the category of Heuristic
Search or Informed Search.
Note: Best first search can be implemented by using priority queue.
[An algorithm in which a node is selected for expansion based on an evaluation function f(n).
-Choose the node that appears to be the best.
There is a whole family of Best-First Search algorithms with different evaluation functions
-Each has a heuristic function h(n)
h(n)= estimated cost of the cheapest path from node n to a goal node.]
Example: In route planning the estimate of the cost of the cheapest path might be the straight line distance
between two cities.
f(n)= Evaluation function to select a node for expansion(usually the lowest cost node)
h(n)=Estimated cost of the cheapest path from node n to a goal node
g(n)= Cost from the initial state to the current state n
NBKRIST IV B.TECH I SEM PREPARED BY: BSR Page 21
Example:
We start from source "S" and search for goal "I" using given costs and Best First search.
Step 1: Priority queue initially contains S We remove s from and process unvisited, neighbors of S to
priority queue. Priority queue now contains {A, C, B}
Step 2: We remove A from priority queue and process unvisited, neighbors of A to priority queue. Priority
queue now contains {C, B, E, D}
Step 3: We remove C from priority queue and process unvisited, neighbors of C to priority queue. Priority
queue now contains {B, H, E, D}
Step 4: We remove B from priority queue and process unvisited, neighbors of B to priority queue. Priority
queue now contains {H, E, D, F, G}
Step 5: We remove H from priority queue. Since our goal "I" is a neighbor of H, we return.
2. Greedy Best First Search (GBFS):
Best First Search(BFS) Greedy Best First Search(GBFS)In which a node is selected for expansion based on an evaluation function f(n)
It tries to expand the node that is closest to the goal.(i.e. it evaluates nodes by using just the heuristic function: f(n)=h(n) )
It tries to expand the node that is closest to the goal. It evaluates nodes by using just the heuristic
function: f(n)=h(n). Let us see how this works for route-finding problems in Romania, using the straight-
line distance heuristic, which we will call hSLD. If the goal is Bucharest, we will need to know the straight-
line distance to Bucharest, which are shown in fig:
Example:
NBKRIST IV B.TECH I SEM PREPARED BY: BSR Page 22
Sol:
NBKRIST IV B.TECH I SEM PREPARED BY: BSR Page 23
The fig: shows the progress of a greedy best first search using hSLD to find a path from Arad to Bucharest.
The first node to be expanded from Arad will be Sibiu, because it is closer to Bucharest than either Zerind
or Timisoara.
The next node to be expanded will be Fagaras, because it is closest. Fagaras in turn generates
Bucharest, which is the goal.
The worst-case time and space complexity is O(bm)
Best First Search Hill Climbing
One move is selected, but the others are kept stored so that
they can be revisited later, if the now selected path becomes
less promising.
One move is selected and all others are rejected, and will
never be reconsidered.
The best available state is selected, even if that state value,
less promising than the one just explored.
Algorithm stops if no better states are available than current
state.
3. A* Search:
What is A* Search Algorithm?
A* Search algorithm is one of the best and popular technique used in path-finding and graph traversals. It
evaluates nodes by combining g(n), the cost to reach the node and h(n), the cost to get from the node to the
goal.
f(n)=g(n)+h(n)
Where g(n) Path cost from the start node to node n
h(n)Estimated cost of the cheapest path from n to the goal
f(n) Estimated cost of the cheapest solution through n
Example 1:
NBKRIST IV B.TECH I SEM PREPARED BY: BSR Page 24
Sol:
NBKRIST IV B.TECH I SEM PREPARED BY: BSR Page 25
Example 2:
NBKRIST IV B.TECH I SEM PREPARED BY: BSR Page 26
6. Local search algorithms: Local search algorithms operate using a single current state (rather than multiple paths) and generally
move only to neighbors of that state. Local search algorithms are not systematic.
We have an objective function that tells us how “good” a given state is, and we want to
find the solution (goal) by minimizing or maximizing the value of this function.
Advantages:
1. They use very little memory
2. They can often find reasonable solutions in large or infinite.
Local search algorithms work as follows:
• Pick a “solution” from the search space and evaluate it. Define this as the current solution.
• Apply a transformation to the current solution to generate and evaluate a new solution.
• If the new solution is better than the current solution then exchange it with the current solution;
otherwise discard the new solution.
• Repeat steps 2 and 3 until no transformation in the given set improves the current solution.
Note: A search space is the set or domain (area or field) through which an algorithm searches.
Example: n-queens problem
Put n queens on an n × n board with no two queens on the same row, column or diagonal.
State Space: All possible n-queens configurations (formations)
What is the objective function?
--Number of pairwise conflicts
NBKRIST IV B.TECH I SEM PREPARED BY: BSR Page 27
Example: Traveling salesman problem:
Find the shortest tour connecting a given set of cities
State Space: all possible tours
Objective function: length of tour
In many optimization problems, the state space is the space of all possible complete solutions.
We have an objective function that tells us how “good” a given state is, and we want to find the
solution(goal) by minimizing or maximizing the value of this function.
The start state may not be specified
The path to the goal doesn’t matter
In such cases, we can use local search algorithms that keep a single “current state” and gradually try to
improve it.
Example: n-queens problem
Put n queens on an n × n board with no two queens on the same row, column or diagonal
State Space: All possible n-queen configurations
Objective function: Number of pairwise conflicts
What’s a possible local improvement strategy?
--Move one queen within its column to reduce conflicts
NBKRIST IV B.TECH I SEM PREPARED BY: BSR Page 28
To understand local search, we will find it very useful to consider the state space land-space
shown in fig: The landscape has both “location” (defined by state) and “elevation” (defined
by the heuristic cost function or objective function).
Global minimum: If elevation (height) corresponding to an objective function, then the aim is to
find the lowest peak.
Global maximum: If elevation (height) corresponding to an objective function, then the aim is to
find the highest peak.
Local maximum: A local maximum is a peak that is higher than each of its neighboring states, but
lower than the global maximum.
NBKRIST IV B.TECH I SEM PREPARED BY: BSR Page 29
1) Hill-Climbing Search (also known as Greedy local search):
“Continuously moves in the direction of increasing value”
-- It terminates when a peak is reached
Looks one step ahead to determine if any successor is better than the current state; if there
is, move to the best successor.
If there exists a successor s for the current state n such that
--H(s) < h (n). Then move from n to s. Otherwise, halt at n.
[OR]
Hill –Climbing Search Algorithm:
1. Algorithm generally moves up in the direction of increasing value that is uphill
2. It breaks its “moving up loop” when it reaches a “peak”
3. It does not maintain a search tree
4. It only looks out for immediate neighbor of current state.
NBKRIST IV B.TECH I SEM PREPARED BY: BSR Page 30
NBKRIST IV B.TECH I SEM PREPARED BY: BSR Page 31
Example:
Problems for Hill-Climbing
Local maxima (also called foothill problem)
A local maximum is a peak that is higher than each of its neighboring states, but lower than the
global maximum.
Plateau
All local steps look alike
Ridges
o There is a direction in which we would like to move but none of the allowed operators
takes us in that direction
NBKRIST IV B.TECH I SEM PREPARED BY: BSR Page 32