You are on page 1of 79

CS8691 – Artificial Intelligence

UNIT II PROBLEM SOLVING METHODS


Problem solving Methods - Search Strategies- Uninformed - Informed - Heuristics
- Local Search Algorithms and Optimization Problems - Searching with Partial
Observations - Constraint Satisfaction Problems – Constraint Propagation -
Backtracking Search - Game Playing - Optimal Decisions in Games – Alpha - Beta
Pruning - Stochastic Games.

I. Problem Solving Methods


1.1. Search Strategies
 Defn: Search algorithms that share basic structure to choose which
node/state to be expanded next
 Classification of Search strategies. The searching algorithms are divided into
two categories
1. Uninformed Search Algorithms (Blind Search)
2. Informed Search Algorithms (Heuristic Search)
 Measuring problem solving performance/ properties of search algorithms
1. Completeness: is algorithm guaranteed to find a solution when there is
one?
2. Optimality : Does the strategy find the optimal solution
3. Time Complexity: how long does it take to find a solution(Measured as
number of nodes generated)
4. Space Complexity : How much memory is needed to perform the
search(Measured as maximum number of nodes stored in memory)
1.1.1 Uninformed Search Algorithms
 While searching, there is no clue whether one non-goal state is better than
the other.
 Have no additional information about states beyond that provided in the
problem definition
 All they can do is 1) generate successors ii) differentiate a goal state from
non-goal state
 These algorithms solve any solvable problems
 Types of Uninformed search are
1 Breadth First Search
2 Uniform-cost search
3 Depth-first search
4 Depth-limited search
5 Iterative deepening depth-first search
6 Bidirectional Search
1. Breadth First Search
 is a simple strategy in which the root node is expanded first, then all the
successors of the root node are expanded next, then their successors, and so
on.

CSE – Panimalar Engineering College 1


CS8691 – Artificial Intelligence

 Is a general graph-search algorithm in which the shallowest unexpanded


node is chosen for expansion
 Is achieved by using queue
 Example : Route finding problem

Task: Find a path from S to G using BFS

The path in the 2nd depth level is selected, (i.e) SBG{or) SCG.
 Algorithm

function BREADTH-FIRST-SEARCH(problem) returns a solution, or


failure
node ←a node with STATE = problem.INITIAL-STATE, PATH-COST = 0
if problem.GOAL-TEST(node.STATE) then return SOLUTION(node)
frontier ←a FIFO queue with node as the only element
explored ←an empty set
loop do
if EMPTY?( frontier ) then return failure
node←POP( frontier ) /* chooses the shallowest node in frontier */
add node.STATE to explored
for each action in problem.ACTIONS(node.STATE) do
child ←CHILD-NODE(problem, node, action)
if child.STATE is not in explored or frontier then
if problem.GOAL-TEST(child.STATE) then return SOLUTION(child)
frontier ←INSERT(child, frontier )
 Performance Measure
1. Complete : Yes
2. Optimal: No
3. Time complexity
= 1 +b + b 2 + . . . . . . . + b d
= O(b d)
4. Space Complexity : O(bd)
 Advantage
 Guaranteed to find the single solution
 Not follow unfruitful path for a long time

CSE – Panimalar Engineering College 2


CS8691 – Artificial Intelligence

Disadvantage: Suitable for only smallest instances problem (because it occupies


more space)

2. Uniform-cost search[Known as Dijkstra’s Algorithm]


 An algorithm that is optimal with step cost function
 Expands the node ‘n’ with the lowest path cost
 Achieved by using priority queue

function UNIFORM-COST-SEARCH(problem) returns a solution, or failure


node ←a node with STATE = problem.INITIAL-STATE, PATH-COST = 0
frontier ←a priority queue ordered by PATH-COST, with node as the only element
explored ←an empty set
loop do
if EMPTY?( frontier ) then return failure
node←POP( frontier ) /* chooses the lowest-cost node in frontier */
if problem.GOAL-TEST(node.STATE) then return SOLUTION(node)
add node.STATE to explored
for each action in problem.ACTIONS(node.STATE) do
child ←CHILD-NODE(problem, node, action)
if child.STATE is not in explored or frontier then
frontier ←INSERT(child, frontier )
else if child.STATE is in frontier with higher PATH-COST then
replace that frontier node with child

 Note: if all step costs are equal , Uniform cost search is similar to
breadth first search
Difference between BFS and Uniform Cost Search
BFS Uniform cost search
Follows FIFO Follows Priority Queue
Goal test is applied to the node when it Goal test is applied to the node when it
is first generated is selected for expansion
No such test Test is added to find better path to a
node
 Uniform-cost search does not care about depth of a path but only about their
total cost.
 Performance Measure
1. Complete : Yes( when the cost is positive number)
2. Optimal: yes
3. Time complexity := O(b [1+C*/e])
4. Space Complexity : O(b [1+C*/e])

 Example: Route finding problem

Task: Find a minimum path cost from S to G

CSE – Panimalar Engineering College 3


CS8691 – Artificial Intelligence

Solution:

 Since the value of A is less it is expanded first, but it is not optimal.


 B to be expanded next

 SBG is the path with minimum path cost.


 No need to expand the next path SC, because its path cost is high to reach C
from S, as well as goal state is reached in the previous path with minimum
cost.
3. Depth-first search
 Peruse a single branch of tree until it yields solution or until a decision to
terminate the path is made.
 Terminating a path happens when it
 Reaches the dead end
 Produces a previous state
 is longer than some pre-specified “ futility limit”
 therefore DFS always expands the deepest node of the search tree
 To avoid termination of a path, backtracking is applied.
 i.e., most recently generated node is chosen for expansion
 uses last-in-first-out (LIFO) called as a stack.
 Example: Route finding problem
Task: Find a path from S to G using DFS

The path in the 3rd depth level is selected. (i.e. S-A-D-G)

CSE – Panimalar Engineering College 4


CS8691 – Artificial Intelligence

 Algorithm

function RECURSIVE-DFS(node, problem, limit ) returns a solution, or failure/cutoff


if problem.GOAL-TEST(node.STATE) then return SOLUTION(node)
for each action in problem.ACTIONS(node.STATE) do
child ←CHILD-NODE(problem, node, action)
RECURSIVE-DFS(child , problem)
 Advantages
 No extra memory
 Finds the solution without examining much of the search space
 If more than one solution exists (or) number of levels is high then DFS is
best
 Disadvantages
 Not guaranteed to find a solution because it might get stuck going down a
very long(infinite) path
 Performance measure
1. Completeness: No
2. Optimal : No
3. Time complexity: O(bm).
4. Space complexity: O(bm).
4. Depth - limited search
 is a variant of DFS with the pre-specified depth limit.
 Nodes at depth level ‘l’ are treated as if they have no successors
 Solve infinite path problem which exists in DFS
 DLF terminates with 2 kinds of failure
 The standard failure value indicates no solution
 No solution within depth limit=> cutoff
 Example: Route finding problem

Task : Find a path from A to E.


 The number of states in the given map is 5. So, it is possible to get the
goal state at a maximum depth of 4. Therefore the cutoff value is 4

CSE – Panimalar Engineering College 5


CS8691 – Artificial Intelligence

function DEPTH-LIMITED-SEARCH(problem, limit ) returns a solution, or failure/cutoff


return RECURSIVE-DLS(MAKE-NODE(problem.INITIAL-STATE), problem, limit )

function RECURSIVE-DLS(node, problem, limit ) returns a solution, or failure/cutoff


if problem.GOAL-TEST(node.STATE) then return SOLUTION(node)
else if limit = 0 then return cutoff
else
cutoff occurred?←false
for each action in problem.ACTIONS(node.STATE) do
child ←CHILD-NODE(problem, node, action)
result ←RECURSIVE-DLS(child , problem, limit − 1)
if result = cutoff then cutoff occurred?←true
else if result _= failure then return result
if cutoff occurred? then return cutoff else return failure

 Performance measure
1. Completeness: No
2. Optimal : No
3. Time complexity: O(bl).
4. Space complexity: O(bl).
5. Iterative deepening search
 Definition: Iterative deepening search is a strategy that sidesteps the issue
of choosing the best depth limit by trying all possible depth limits.
 Combines the benefits of DFS and BFS
 Like DFS=> Memory requirements are modest
 Like BFS=> explores a complete layer of new nodes at each iteration before
going to the next layer
 In each step, it gradually increase the depth limit until the goal is found
 Example: Route finding problem

Task: Find a path from A to G


Limit = 0 Limit = 1 Limit = 2

 Algorithm

function ITERATIVE-DEEPENING-SEARCH(problem) returns a solution, or failure


for depth = 0 to∞ do
result ←DEPTH-LIMITED-SEARCH(problem, depth)
if result _= cutoff then return result

CSE – Panimalar Engineering College 6


CS8691 – Artificial Intelligence

 Performance measure
1. Completeness: Yes
2. Optimal : Yes
3. Time complexity: O(bd).
4. Space complexity: O(bd).

 Advantage: is the preferred uninformed search when the search space is


large and the depth of the solution is not known
 Disadvantage: Many states are expanded multiple times. E.g., : The state D
is expanded twice in limit 2
6. Bidirectional search
 Defn: Bidirectional search is a strategy that run two simultaneously search
both the directions (i.e.) forward from the initial state and backward from the
goal, and stops when the two searches meet in the middle.
 Bidirectional search is implemented by replacing the goal test with the check
to see whether the frontiers of the two searches intersect=> if so, a solution
is found
 Example: Route finding problem

Task: Find a path from A to E.

Search from forward (A) : Search from backward (E) :

Solution path is A-C-E


 Performance measure
1. Completeness: Yes
2. Optimal : Yes
3. Time complexity: O(2bd/2) = O(bd/2).
4. Space complexity: O(bd/2) .

 Advantage: Time and space complexity is reduced.


 Disadvantage
 If two searches (forward, backward) do not meet at all, complexity arises
in the search technique.
 In backward search calculating predecessor is difficult task.

CSE – Panimalar Engineering College 7


CS8691 – Artificial Intelligence

 If more than one goal state 'exists then explicit, multiple state search is
required
Comparing uninformed search strategies

Criterion Breadth Uniform Depth Depth Iterative Bi


First Cost First Limited Deepening direction
Complete Yes Yes No No Yes Yes
Time O(bd) O(bd) O(bm) O(bl) O(bd) O(bd/2)
Space O(bd) O(bd) O(bm) O(bl) O(bd) O(bd/2)
Optimal Yes Yes No No Yes Yes

1.1.2 Informed Search


 Knows whether a non-goal state is “more promising” than the other
 Uses problem-specific knowledge
 Uses the idea of heuristic(a measure of how close we are to the target) , so
called as heuristics search
 Can find solutions more efficiently than uninformed search
 Defn of Heuristic search: a technique that improves the efficiency of a search
process by sacrificing claims of completeness
 Heuristic search uses Evaluation function to decide which node is select for
expanding next. Cost from current
 Evaluation function node to goal node
f(n)=g(n)+h(n) Cost from initial node
to current node
 A function to select a node for expansion
 Usually a lowest cost node
 Heuristic Function : is a way to inform the search about the direction to reach
a goal
Blind search Heuristic search
No information about the number of steps The path cost from the current state to the goal
(or) path cost from current state to goal state is calculated, to select the minimum path cost
state as the next state.
Less effective in search method More effective in search method
Problem to be solved with the given Additional information can be added as assumption
information to solve the problem

 One Classification of Informed Search is Best First Search


Best First Search/Global search
 A general heuristic based search technique
 One evaluation function(f(n)=g(n)+h(n)) is attached with every node
 Combines the advantage of BFS and DFS
 BFS=> it does not get trapped on dead-end of paths
 DFS=> goal can be reached without any need to compute all the states
 Allows us to switch between the paths and thus gets the benefit of both
 Implemented using priority queue

CSE – Panimalar Engineering College 8


CS8691 – Artificial Intelligence

 Algorithm (can read any one algorithm)


function BEST-FIRST-SEARCH(problem, Let fringe be a priority-queue containing the initial state
EVAL-FN) returns a solution sequence loop
inputs: problem, a problem if fringe is empty return failure
EVAL-FN, an evaluation function node<-remove-first(fringe)
QUEUEING -FN<- a function that if node is a goal then
orders nodes by EVAL-FN return the path from initial state to node
return TREE-SEARCH(problem, else
QUEUEING-FN) generate all successors of node and
put the newly generated nodes into fringe

 Variants of Best first search


1. Greedy Best first search : Expand the node closest to the goal state
using estimated cost as the evaluation
2. A* algorithm : Expand the node on the least cost solution path using
estimated cost and actual cost as the evaluation function
Greedy best first search (Minimize estimated cost to reach a goal)
- Expands the node which is closest to the goal => chooses less utility value=>
called greedy
- node expansion is purely based on the distance from goal (i.e., estimated
cost)
f(n)=h(n)
- leads to the solution quickly
- Disadvantage : not complete and therefore not optimal
- Algorithm
Function GREEDY-BEST-FIRST SEARCH Read Best-first search
(problem) returns a solution or failure algorithm
return BEST-FIRST-SEARCH (problem, h)

- Example
 Problem: Route finding from A to B

 Heuristic function: A good heuristic function for route-finding problems is


Straight-Line Distance to the goal and it is denoted as hSLD(n).

hSLD(n) = Straight-Line distance between n and the goal location

 Note: The values of hSLD(n) cannot be computed from the problem


description itself. Moreover, it takes a certain amount of experience
 Values of hSLD-straight-line distances to B

CSE – Panimalar Engineering College 9


CS8691 – Artificial Intelligence

Solution:
 For each node the evaluation function is f(n)=h(n)
 Apply the evaluation function h(n) to find a path from A to B

 From F, goal state B is reached. Therefore the path from A to Busing greedy
search is A - S - F - B = 450 (i.e) (140 + 99 + 211)
 Performance measure
1. Completeness: No
2. Optimal : No
m
3. Time complexity: O(b )
m
4. Space complexity: O(b ).

A* search ( Minimizing the total estimated solution cost)


 Created in 1968 by peter hart, Nils Nilsson, Bertram Raphacl at Stanford
University to help Shakey the Robol to navigate a room of obstacles
 Previously called as Algorithm A
 *(star) denotes Optimal
 Combines the best part of uniformed cost and best first search
 Avoid expanding the paths that are already expensive
 Make use f(n)= g(n)+ h(n)

CSE – Panimalar Engineering College 10


CS8691 – Artificial Intelligence

 Best first search is a simplified form of A* approach.

 A* search is both complete and optimal.

 A* Algorithm

function A* SEARCH(problem) returns a solution or failure


return BEST-FIRST-SEARCH (problem, g+h)

 Example : Route finding from A to B

Solution:
 From the given graph and estimated cost, the goal state is identified as B
from A
 Apply the evaluation function f(n) = g(n) +h(n) to find a path from A to B
 g(n)=g(p)+c(p,n)

CSE – Panimalar Engineering College 11


CS8691 – Artificial Intelligence

From P, goal state B is reached. Therefore the path from A to B using A* search is
A – S - R - P -B : 418 (ie) {140 + 80 + 97 + 101), that the path cost is less
than Greedy search path cost.
Performance Measure of A* Algorithm
Complete: yes
Optimal: Yes

Optimality of A*
- conditions for optimality: Admissiblity and Consistency
1. Admissiblity [Admissible heurisitc/optimistic heuristic]
 is the one that never overestimates the actual cost to reach the goal
h(n) ≤ c(n) where ,h(n) => estimated cost to reach the goal from n
c(n) /h*(n) => actual cost to reach the goal from b
2. Consistency/Monotonicity
A heuristic h(n) is consistent if, for evey node n and every successor n’ of
n, the estimated cost of reaching the goal from n [h(n)] is ≤ step cost of
getting to n’ [c(n,n’)] plus the estimated cost to reach the goal from n’
[h(n’)]
i.e., h(n) ≤ c(n,n') + h(n')

- A* Algorithm poses two properties regarding optimality


i) Tree-search version of A* is optimal if h(n) is admissible
ii) Graph-search version of A* is optimal if h(n) is consistent
 If h(n) is consistent, then the values of f(n) along any path are
nondecreasing(i.e. iff for all childeren n’ of n => f(n)≤f(n’))
 Proof : Suppose n’ is a successor of n, then g(n’)=g(n)+c(n.n’) 1
f(n’) = g(n’)+h(n’) => substitue equ 1 for g(n’)
= [g(n)+c(n,n’)] + h(n’) => substitue h(n)≤h(n’)+c(n.n’)
≥ g(n) + h(n)
f(n’) ≥ f(n)

Time complexity: Time complexity depends on the heuristic function and the
admissible heuristic value
Space complexity: remains in the exponential order, because A* keeps all
generated nodes in memory. Therefore A* usually runs our of space before it
runs out of time
Memory bounded heuristic search
- Reduces memory requirements of A*
- Different types of Memory bounded heuristic search are

CSE – Panimalar Engineering College 12


CS8691 – Artificial Intelligence

1. Iterative Deepening A* search


2. Recursive Best First Search
3. Memory bounded A* search
4. Simplified memory bounded A* search
1. Iterative Deepening A* search (IDA*)
- Similar to Iterative Deepening DFS
- Difference is that the cutoff (i.e., limit) used here is f(n) rather than depth.
- Key feature is it does not keep track of each visited node=> which helps in
saving memory consumption and can be used when memory is constrained

- Disadvantage: occupies very less memory


- Algorithm
function IDA*(pmblem) returns a solution sequence
root <— MAKE-NODE(lNlTIAL-STATE[problem])
f-limit <—f- cost(root)
solution <-NIL
loop do
solution, f-limit — DFS-CONTOUR(root, f-limit)
if solution is non-null then return solution
if f-limit = ∞ then return failure
end

function DFS-CONTOUR(node, f-limit) returns ( solution f-limit)


next-f<-∞
if f- cost(node] > f-limit then return null, f-cost[node]
else if GOAL(node) then return node, f-limit
else
for each successor S of node do
solution, new-f— DFS-CONTOUR(S, f-limit)
if solution is non-null then return solution, f-limit
next-f<— min(next-f, new-f)
end
return null, next-f

- Example : Route finding from A to B

CSE – Panimalar Engineering College 13


CS8691 – Artificial Intelligence

CSE – Panimalar Engineering College 14


CS8691 – Artificial Intelligence

2. Recursive Best First Search (RBFS)


- Mimic the operation of best first search technique => uses only linear space.
- It is similar to recursive depth first search with an inclusion => uses the f-
limit variable to keep track of the f-value of the best alternative path

available from any ancestor of the current node.


- If the current node exceeds this limit, the recursion unwinds back to the
alternative path
- As the recursion unwinds RBFS replaces the f-value of each node along the
path with the best f-value of its children.
- main idea => remembers the second best alternate node (forgotten node)
and decides whether it's worth to re-expand the subtree at some later time.
- Algorithm

- Example: Stages in an RBFS search for the shortest route to A-B.

CSE – Panimalar Engineering College 15


CS8691 – Artificial Intelligence

Time and space complexity


 RBFS is an optimal algorithm if the heuristic function h(n) is admissible.
 Its time complexity depends both on the accuracy of the heuristic function
 IDA* and RBFS suffer from using too little memory.
 Between iterations, IDA* retains only a single number: the current f-cost
limit. RBFS retains more information in memory, but it uses only linear
space: even if more memory were available,

CSE – Panimalar Engineering College 16


CS8691 – Artificial Intelligence

 Because they forget most of what they have done, both algorithms may
end up re-expanding the same states many times over.

3. MA* (Memory - bounded A*) & SMA* (Simplified MA*)


 These two algorithm uses all available memory
 SMA*
 Similar to A*, but restricts the queue size to fix into the available memory
 when memory is full it cannot add a new node to the search tree without
dropping an old one
 to add new node it always drops the worst leaf node—the one with the
highest f-value
 SMA* expands the best leaf and deletes the worst leaf.
 Advantage
 SMA* uses only the available memory.
 Remembers a node rather than to regenerate it when needed
 Disadvantage
 If enough memory is not available it leads to unoptimal solution.
 Memory limitations can make a problem intractable with respect to
time
 Space and Time complexity: depends on the available number of node.
 Example

 The values at the nodes are given as per the A* function i.e. g+h=f
 From the Figure the goal states are D,F,J,I because the h value of these nodes
are zero (marked as a square)
 Available memory - 3 nodes of storage space.

 Task: Find a optimal path from A to anyone of the goal state.


Solution:

CSE – Panimalar Engineering College 17


CS8691 – Artificial Intelligence

1.1.3 Local Search Algorithms And Optimization Problems


 Works on single current state (rather than multiple paths) and moves only
to neighbors (i.e., successors).
 paths followed by the search are not retained.
 Termination is based on a time bound or when it finds a solution
 They are not systematic=> disadvantage
 two key advantages:
1. They use very little memory-usually a constant amount=> because they
do not store past history

CSE – Panimalar Engineering College 18


CS8691 – Artificial Intelligence

2. They can often find reasonable solutions in large or infinite (continuous)


state spaces for which systematic algorithms are unsuitable.
 Use to solve pure optimization problem
 Search space of local search algorithm is called as landscape
 State – called as location
 f(n) (Evaluation function or heuristic function)-called as
elevation(evaluation function is called objective function)
 Pictorial representation of landscape

 A complete local search algorithm always finds a goal if one exists, an optimal
algorithm always finds a global minimum/maximum.
 Application of Local Search
1. Job Scheduling
2. Vehicle Routing
3. Telecommunication Network Optimization
 Local search algorithms are

1. Hill Climbing search/Steepest-ascent Hill Climbing/Greedy Local


Search
 moves in the direction of increasing value(uphill) to reach a peak state(goal).
 it terminates when it reaches a "peak" where no neighbor has a higher value.
 Used when a good heuristic is available

CSE – Panimalar Engineering College 19


CS8691 – Artificial Intelligence

 does not maintain a search tree, so the current node data structure need only
to record the state and its objective function value(i.e., f(n)
 At each step the current node is replaced by the best neighbor
 Algorithm

MAX Version
function HILL-CLIMBING(problem) returns a state that is a local maximum
current <- MAKE-NODE(INITIAL-STATE[problem])
loop do
neighbor <- a highest-valued successor of current
if VALUE[neighbor] ≤ VALUE[current] then return STATE[current]
current <- neighbor
MIN Version
function HILL-CLIMBING(problem) returns a state that is a local maximum
current <- MAKE-NODE(INITIAL-STATE[problem])
loop do
neighbor <- a lowest-valued successor of current
if VALUE[neighbor] ≥ VALUE[current] then return STATE[current]
current <- neighbor

 Example

 Drawbacks of hill climbing(pictorial representation)

1. Local maxima/foot hills /no uphills step

CSE – Panimalar Engineering College 20


CS8691 – Artificial Intelligence

 A state that is better(higher) than each of its neighboring states, but not
better(lower) than some other states far away
 Example: consider the following tree. ‘a’ is an initial state and ‘h’ and ‘k’
are final states. The number near the states is the heuristic value

 by applying hill climbing algorithm, we


get a->f->g which is local maxima.
 Hill climbing cannot go back and
choose a new node (i.e. ‘e’ ) since it
keeps no history

 to overcome local maxima , backtrack to one of the previous states and


explore other directions
2. Plateau (flat-plateau whose edges go downhill. or shoulder - a plateau that has
an uphill edge.)
 flat area of the search space in which all the neighboring(successors) states

have same value=> therefore cannot determine the best direction

 Example

 The evaluation function value of B, C, D are same and


at the same time Best successor has the same value
as the current state
 To overcome plateau skip few states or make a jump
in new directions

3. Ridges
 A special kind of local maxima
 Defn-1: An area of the search space which is higher than the surrounding
area and that itself has a slope
 Defn-2: is a sequence of local maxima
 To overcome ridges explore in several directions to find out the correct
path

 Variants of hill-climbing

1. Stochastic hill climbing => choose successor at random


 does not focus on all the nodes
 selects one node at random and decides whether it should be expanded or
search for a better one.

CSE – Panimalar Engineering College 21


CS8691 – Artificial Intelligence

 the probability of selection can vary with the steepness of the uphill move.
 Better than steepest ascent
2. First-choice hill climbing/Simple hill climbing => choose first
successor that is better than current state
 implements stochastic hill climbing by generating successors randomly
until one is generated that is better than the current state
3. Random-restart hill climbing => try with different initial states if
chosen initial state fails
 based on try and try strategy
 It conducts a series of hill-climbing searches from randomly generated
initial state, stopping when a goal is found. (Or) generates different
initial state until it finds a goal state.
2. Simulated annealing
 Annealing: is the process of controlling cooling

 Inspired from the process of annealing in metal work


 Physical process in which physical substances such as metals are melted and
then gradually cooled until some solid state is reached=> goal is to produce a
minimal energy final state.
 The rate at which the system is cooled is called annealing schedule
 Pictorial representation of annealing

 During cooling process, sometimes a worsen state (unaccepted state) can be


made.
 The worsen state can be accepted by some probability(accept this state with
probability less than 1)
 The probability is defined as

 Note: the chance of accepting worst solution is done only when the
temperature is high
 Physical annealing is simulated=> simulated annealing

 Simulated Annealing
 Variants of hill climbing in which at the beginning of the process Some downhill
moves can be made=> helps to avoid local maxima
 Used when the number of moves from a given state is large

CSE – Panimalar Engineering College 22


CS8691 – Artificial Intelligence

 The probability in simulated annealing is defined as

 Annealing schedule consists of 4 components


i) Starting temperature(Ts)
ii) Final temperature(Tf)
iii) Temperature length(TL): criteria used to decide when the temperature
of the system should be reduced)
iv) Cooling criteria/temperature decrement(f(t)): amount by which the
temperature will be reduced each time it is changed
 Algorithm in simple words
 Generate a random new neighbor from current state.
 If it’s better take it.
 If it’s worse then take it with some probability proportional to the
temperature and the delta between the new and old states
 Algorithm

 Property of simulated annealing search :T decreases slowly enough then


simulated annealing search will find a global optimum with probability one
 Applications
a. VLSI layout
b. Airline scheduling
 Difference between simulated annealing and hill climbing
1. Annealing schedule must be maintained
2. Moves to the worst state is accepted
3. Maintain best state found so far
3. Local beam search => search with multiple(k) hill climbers(initial
states) in parallel
 Keep track of K states rather than just one
 The sequence of steps performed by local beam search is
 Start with K randomly generated states (i.e. select k different initial
states).
 K is called as beam width

CSE – Panimalar Engineering College 23


CS8691 – Artificial Intelligence

 At each iteration, all the successors of all K states are generated.


 If anyone is a goal state stop; else select the K best successors from the
complete list and repeat. (picks randomly in the case of ties.)
 a local beam search with k states looks similar to running k random restarts
 the local beam search run in parallel and random restarts run in sequence.
(i.e. each search process runs independently of the others.)
 In a local beam search, useful information is passed among the parallel
search threads(i.e., communication happens between all parallel threads since

they share common memory)


 Terminate the thread if state is already visited by another thread=> to

eliminate duplication in search =>i.e. algorithm quickly abandons unfruitful


searches and moves its resources to where the most progress is being made.
 Pictorial representation

 Algorithm
function beam-search(problem, k) returns a solution state
start with k randomly generated states
loop
generate all successors of all k states
if any of them is a solution then return it
else select the k best successors

 local beam search suffer from a lack of diversity among K states=> they
quickly become concentrated in a small region of the state space, making the
search little more than an expensive version of hill climbing
 variant called stochastic beam search
Instead of choosing the best k successors, stochastic beam search
chooses k successors at random, with the probability of choosing a given

successor being an increasing function of its value.

CSE – Panimalar Engineering College 24


CS8691 – Artificial Intelligence

4. Genetic Algorithms (GA)


Introduction
 Genetic Algorithms(GAs) are adaptive heuristic search algorithms that are
part of evolutionary algorithms which is a rapidly growing area of artificial
intelligence
 GA’s are based on Darwin’s theory of evolution – the survival of the fittest
 GA’s are the ways of solving problems by mimicking processes nature and
genetics uses: i.e., Selection, crossover, mutation, to evolve a solution to a
problem
GA components based on biology and computer science
Biology GA component Algorithm
Collection of individuals Initialize population Collection of states
More healthy less prone to Fitness function Closest to the final solution
diseases
Selecting parents Selection Selecting states that are closest to
the solution(fittest)
Mating or reproduction Crossover a genetic operator that
Selects genes from parents combines(mates) two
chromosomes and creates states(parents) to produce new
new offspring(child) state(successor) => done by
Interchanging values between
selected states
Change or variation Mutation Alteration=> when done it is able
(Alters one or more gene to arrive a better solution than its
values in a chromosome that initial states.
result in new gene values)
 A genetic algorithm (or GA) is a variant of stochastic beam search in which
successor states are generated by combining two parent states, rather than

by modifying a single state


 GA begins
 with a set of k randomly generated states, called the population. Each
state, or individual, is represented as a string over a finite alphabet.
 Evaluation function (or) Fitness functions: A function that returns
higher values for better State
 Selection: A random choice of two pairs is selected for reproduction, by
considering the probability of fitness function of each state
 Cross over: Each pair to be mated, a crossover point is randomly chosen
 Mutation: Each location is subject to random mutation

CSE – Panimalar Engineering College 25


CS8691 – Artificial Intelligence

 Algorithm

 Example: solving 8 Queen Problem using GA


 Steps are
1. Representing individuals : Formulate an appropriate method
 Uses array
Index: column
Value : row
 Example

2. Generate an initial population : K randomly generated states of 8 queen


problem
The Initial Population (four randomly selected States) is:

3. Applying a fitness function


 f(n)=the number of non attacking pairs of queens
 Minimum fitness value is 0
 Maximum fitness value is: 8*7/2 = 28 for a solution

f(n) for 24748552 : Q1:6 Q2:5 Q3:4 Q4:4 Q5:3 Q6:1 Q7:0 Q8:0 24

 The values of the four states are 24, 23, 20, and 11.
 The probability of being chosen for reproduction is directly proportional to the
fitness score, which is denoted as percentage.

CSE – Panimalar Engineering College 26


CS8691 – Artificial Intelligence

24 / (24+23+20+11) = 31%
23 / (24+23+20+11) = 29%
20 / (24+23+20+11) = 26%
11 / (24+23+20+11) = 14%
4. Selecting parents for mating in accordance to their fitness
 There are various methods for selection
 E.g., Roulette Wheel, Tournament, Rank etc.,
5. Crossover of parents to produce new generation
 Types of crossover are One Point Crossover, Multi Point Crossover Uniform
Crossover, etc. In this example one point crossover is
used
 a crossover point is randomly chosen. For the first pair
the crossover point is chosen after 3 digits and after 5
digits for the second pair.
 In the picture the crossover is specified by lines
6. Mutation of new generation to bring diversity
 One digit was mutated in the first, third, and fourth
offspring

 Production of Next Generation of States

The initial population in (a) is ranked by the fitness function in (b), resulting in
pairs for mating in (c). They produce offspring in (d), which are subject to
mutation in (e).
1.1.4 SEARCHING WITH PARTIAL OBSERVATIONS
- In the previous topics we have seen Deterministic, fully observable=>single-
state problem
 agent knows exactly which state it will be in
 solution is a sequence

CSE – Panimalar Engineering College 27


CS8691 – Artificial Intelligence

- The problem of partial observability => agent percept is not sufficient to pin
down the exact state
- Different types of incompleteness lead to three distinct problem types:
 Sensorless problems(conformant): If the agent has no sensors at all
 Deterministic, non-observable=>multi-state problem
 agent may have no idea where it is
 solution is a sequence
 Contingency problem: if the environment if partially observable or if
action are uncertain (adversarial)
 Nondeterministic and/or partially observable
 percepts provide new information about current state

 often inter leave search, executionsolution is a tree or policy

 Exploration problems/ Unknown state space: where the states and


actions of the environment are unknown.
- The key concept required for solving partially observable problem is the belief
state
1. Searching with no observations/sensorless problem/conformant
problem
 whose percepts provide no information at all
 can still perform successful and actually be advantageous since they don’t
rely on costly and potentially unreliable sensor information
 As example , assume a sensorless vacuum world where the agent knows
the geography of its world(knows all the effects of its actions) but not its

position or the distribution of dirt ,

 The initial state then can be any element of the set


{1,2,3,4,5,6,7,8}

 A
c
tion
i) move Right => Result = {2, 4, 6, 8}
ii) Suck => Result = {4, 8}
iii) Move Left => Result={3,7}
iv) Suck => Result = {7} guaranteed! => the agent coerce into
world state
 Solve sensorless problems by searching space of belief states, which is
fully observable to agent.

CSE – Panimalar Engineering College 28


CS8691 – Artificial Intelligence

 Suppose the underlying physical problem P is defined by ACTIONS P,


RESULTP, GOAL-TESTP, and STEP-COSTP . Then we can define the
corresponding sensorless problem as follows:
1. Belief states: every possible set of physical states. If P has n states,
the sensorless problem as 2N states, although many may be
unreachable from the initial state.
2. Initial state: Typically the set of all states in P
3. Actions: Suppose the agent is in belief state b={s1, s2}, but ACTIONS P
(s1) = ACTIONSP (s2); then the agent is unsure of which actions are
legal.
 Union if the states are legal and intersection if it is illegal

4. Goal test: b satisfies the goal test if all physical states in b satisfies
GOAL-TESTP
5. Path cost : the cost of an action is the same in all states
 Example

1.1.5 CONSTRAINT SATISFACTION PROBLEMS(CSP)


 Defn-1: is defined by 3 components R={X,D,C}, where
i) a set of variables X={x1,x2,x3……..xn}
ii) a set of domains D={d1,d2,d3……..dn}
iii) a set of constraints C={c1,c2,c3………cm}
The solution is complete (values are assigned to all variables) and consistent
assignment (assignment does not violate the constraints)
 Defn-2: in which the goal is to discover some problem state that satisfies a
given set of constraints
 Defn-3: are mathematical problems where one must find states or objects
that satisfy a number of constraints or criteria.

 Popular problems of CSP's are:

CSE – Panimalar Engineering College 29


CS8691 – Artificial Intelligence

a. The n-queens problem


b. A crossword puzzle
c. A map coloring problem
d. A crypt arithmetic problem
e. real life problems like time table scheduling, transport scheduling, floor
planning etc

 Example for Constraint Satisfaction Problem : Map coloring problem


Description of Map coloring
 The task is coloring each region in such a way that no neighboring regions
have the same color.
 Map of Australia showing each of its states and territories

 CSP can be visualized using Constraint graph for better understand


 Constraint Graph(Binary Constraint): A CSP is usually represented as an
undirected graph, called constraint graph where the nodes are the
variables and the edges(i.e., arcs) are constraints
 Constraint graph for map-coloring problem

 CSP can be viewed as a standard search problem as follows :


 Initial state: the empty assignment {},in which all variables are
unassigned.
 Successor function: a value can be assigned to any unassigned variable,
provided that it does not conflict with previously assigned variables.
 Goal test: the current assignment is complete.
 Path cost: a constant cost (E.g., 1) for every step.
 Varieties of CSPs
a) Variables: variables are discrete

CSE – Panimalar Engineering College 30


CS8691 – Artificial Intelligence

b) Domains: Discrete variables can have


 Finite Domains
 Domain values are finite set
 Example : N-Queens with domain values(D1,D2……….Dn), Map coloring
with limited number of colors
 Finite domain CSPs include Boolean CSPs, whose variables can be
either true or false.
 Infinite domains
 Domain values can be set of integers or strings
 Example : Job(Task) Scheduling, variables with start/end days of task
 This type of domain are represented using constraint language
 E.g., assume task T2 should start after task T1. Constraint language
of this is T1(start date of T1)+d1(duration to finish T1)≤T2(start date
of T2)
c) constraints
i. Unary constraints – involves a single variable.
 Example : in map coloring problem if south Australian does not like
green color, then the domain value of SA is restrict to {R, B).
 Such constraint is called as unary constraints represented as SA 
green
ii. Binary constraints – involves s pairs of variables.
Example: SA  WA

iii. Higher order constraints/n-ary /global constraints: involve 3 or


more variables.(arbitrary number of variables)
 Example: crypt arithmetic puzzles. Each letter is assigned with a
distinct (unique)digit.
 Global constraints are represent by constraint hypergraph.
 Hypegraph consists of nodes(circle) which represents variables and
hypernodes[square] that represents n-ary constraints
 Constraint hyper graph for crypt arithmetic Problem

CSE – Panimalar Engineering College 31


CS8691 – Artificial Intelligence

- CSP’s are usually NP hard problems


- Can be solved using
1. Constraint Propagation or inference
2. Search=> Backtracking[DFS style search]
1. Constraint propagation or inference in CSP’s
 Defn: using constraints, it reduces the number of legal values for a variable,
which in turn can reduce the legal values for another variable and so on.
 Constraint propagation can act as preprocessing step before search starts=>
can solve the whole problem, without the need for searching
 Constraint propagation can be obtained by local consistency
 Enforcing local consistency in each part of the graph reduces inconsistent values
throughout the graph
 Different types of local consistency are
a) Node consistency : Every value in the domain satisfies the variables
Unary constraint
b) Arc consistency
 Denf-1: Every value in the domain satisfies the variables binary constraints
 Defn-2: X-Y is said to be arc consistent iff for every value of x in X , there is some
allowed value y in Y.
 Example
 Consider the constraint Y=X2, where the domain of X and Y is the set of
integers.
 To make X arc-consistent with respect to Y, X’s domain is reduce to
{0,1,2,3….} and Y arc-consistent with respect to X, then Y domain becomes
{0,1,4,9…}
 The concept of arc consistency is direction.(i.e., if an arc (Vi,Vj) is
consistent, then it does not mean that (Vj,Vi) is arc consistent)
 Pictorial representation of map coloring

In the above picture (V1, V2) is arc consistent, because b is the only value
in the domain of V1 and there exists a value g in the domain of V2(i.e.,
V1=b and V2=g are compatible(i.e., satisfies the not-same constraint),
but (V3,V1) is not arc consistent because V3=b and V1=b is not compatible
with it and there is no other value in the domain of V1

CSE – Panimalar Engineering College 32


CS8691 – Artificial Intelligence

 AC-3 Algorithm
 is the most popular arc-consistent algorithm.
 Maintains a queue of arcs. Initially the queue contains all the arcs
in the problem.
 This algorithm pops an arc (Xi,Xj) from the queue and makes Xi arc-
consistent with respect to Xj.
 If Domain (Di) is unchanged , the algorithm chooses the next arc
 Otherwise ,Domain is revised( changed/made smaller), add all the arcs
(Xk,Xi) to the queue where Xk is the neighbor of Xi
 If Di is changed to nothing(i.e., there is no value in the domain), the
algorithm returns failure=> means CSP has no consistent solution

c) Path consistency
- Compares 3 variables and 2 constraints
- For each assignment of 2 variables , ensure that the third variable has
legal values
{R, B}
- Example
V1

{R, B} {R, B}
V2 V3
 The above CSP is arc-consistent. But there is no solution, because
there are only two colors in three variable domains. In order to
solve it the path consistency takes place
 One of the relationship between x1(V1) and x2(v2) is x1="Red"
and x2="Blue". For this pair there is no legal value in V3. Therefore
Red and blue is removed from V1 and V2.

CSE – Panimalar Engineering College 33


CS8691 – Artificial Intelligence

- The path consistency algorithm reduces the variable domain after the arc-
consistency is performed.
- Algorithm

d) K-consistency
- A CSP is k-consistent, for any set of k-1 variables and for any consistent
assignment (i.e., assigned values that satisfy all the constraints among K-

1 variables) , there exists a legal value(i.e., consistent assignment) for the


kth variable that satisfies all the constraints among these k variables.
- A graph is strongly k-consistent if it is J-consistent for all J≤K.
e) Global Consistency
A constraint graph with n variable is globally consistent, if it is strongly n-
consistent (can be solved using searching technique)

2. Backtracking Search for CSPs


- backtracking search is used for depth-first search that chooses values for
one variable at a time and backtracks when a variable has no legal values left
to assign.
- Algorithm

- Part of search tree generated by simple backtracking for the map


coloring problem

CSE – Panimalar Engineering College 34


CS8691 – Artificial Intelligence

- Improving backtracking efficiency


1. Which variable should be assigned next(SELECT-UNASSIGNED-VARIABLE) and
what order should its values be tried(ORDER-DOMAIN-VARIABLES)?
2. What are the implications of the current variable assignments for the other
unassigned variables?
Solutions
1. Variable & value ordering
- In the backtracking algorithm each unassigned variable is chosen from
Minimum Remaining Values (MRV) heuristic, that is choosing the variable
with the fewest legal values. It also has been called the "most constrained
variable" or "fail-first" heuristic.
- For example , after the assignment for WA=red and NT=green, choose SA
rather than Q since SA as only one possible value i.e., blue .=> called as

Minimum Remaining Values heuristics


2. Propagating information through constraints
- One of the simplest form of propagation is Forward checking
- Forward checking
 a better use of constraints during search
 Whenever a variable X is assigned, the forward checking process looks at
each unassigned variable Y that is connected to X by a constraint and
deletes from Y ’s domain any value that is inconsistent with the value
chosen for X.
 Example: map-coloring search with forward checking.

In forward checking WA = red is assigned first; then forward checking


deletes red from the domains of the neighboring variables NT and SA.
After Q = green, green is deleted from the domains of NT, SA, and NSW.
After V = blue, blue is deleted from the domains of NSW and SA, leaving
SA with no legal values. NT and SA cannot be blue
- Intelligent backtracking
a) Chronological backtracking: When a branch of the search fails, back up
to the preceding variable and try a different value for it (i.e.) the most
recent decision point is revisited.

CSE – Panimalar Engineering College 35


CS8691 – Artificial Intelligence

b) Conflict directed backtracking: When a branch of the search fails,


backtrack to one of the set of variables that caused the failure-conflict set.
- Handling special constraints
a) Alldiff constraint - All the variables involved must have distinct values.
1.1.6 Game Playing
- is called as adversarial search (mixture of reasoning and creativity)
- game theory is a branch of economics => viewed as multi-agent environment
as a game=> regardless the agent is cooperative or competitive.
- In AI games are specialized kind=> looks like deterministic, fully-observable,
two-agent act alternatively
- A game can be formally a kind of search problem, the components are
1. initial state(S0): board position which specifies how the game is set up to
start
2. PLAYER(S): which player has to move the state
3. SUCCESSOR FUNCTION/ACTION(S): set of legal moves for the state
4. RESEULT(S,G): defines the result of the move
5. goal test/TERMINAL-TEST(S): whether the game is over – terminal
states(true when the game is over or false otherwise)
6. UTILITY(S,P) /evaluation /payoff/objective: gives a numeric value for the
terminal state
- Note: zero-sum/constant game: the total payoff to all players is the same for
every instance of the game. E.g., Chess. 0+1, 1+0, ½+½
- Game tree(initial state+ legal moves)
 While solving game problem a tree/graph is drawn to show all the possible
states
 The nodes are game states and the edges are moves
 E.g.,

- Optimal Decision in Games


 In normal search problem, optimal solution is the sequence of
actions(operators) that leads to goal state
 In adversarial search , MAX must find a contingent(meaning is chance)
strategy, specifying MAX’s move in:

 the initial state


 the states resulting from every possible response by MIN
- MINMAX Procedure
1. Generate the whole game tree till leaves(terminal nodes)

CSE – Panimalar Engineering College 36


CS8691 – Artificial Intelligence

2. Apply utility to evaluate the leaves


3. Back-up values from leaves toward its root
i. A max node computes the maximum of its child values
ii. A min node computes the minimum of its child values
4. When the values reaches the root: choose the max value and the
corresponding move
- 2-ply game (Each layer in the search is called a ply)

 - Moves by Max Player


 - Moves by Min Player
 The possible moves for MAX at the root node are labeled a l, a2, and a3.
The possible replies to a1 for MIN are b1, b2, b3, and so on.
 The terminal nodes show the utility values for MAX;
 The other nodes are labeled with their minimax values.
 MAX'S best move at the root is al, because it leads to the successor
with the highest minimax value
 MIN'S best reply is bl, because it leads to the successor with the lowest
minimax value.
 The root node is a MAX node; its successors have minimax values 3, 2,
and 2; so it has a minimax value of 3.
 The first MIN node, labeled B, has three successors with values 3, 12,
and 8, so its minimax value is 3

- Given a game tree, the optimal strategy can be determined by examining the
minimax value of each node, which is writtern as MINIMAX- VALUE (n).
MINIMAX- VALUE(n) =
UTILITY(n) if n is a terminal state
Maxs  successors(n) MAX-VALUE(s) if n is a MAX node
Mins  Successors(n) MIN-VALUE(s) if n is a MIN node

- Algorithm MINMAX

CSE – Panimalar Engineering College 37


CS8691 – Artificial Intelligence

Example : TIC-TAC-TOE

- Performance of Minimax
 Complete? Yes (if tree is finite)
 Optimal? Yes (against an optimal opponent)
 Time complexity? O(bm)
 Space complexity? O(bm) (depth-first exploration)
- Alpha-Beta pruning
 In MINMAX search, the number of nodes explored increase exponentially,
because MINMAx is DFS
 is a modified version of MINMAX
 reduces number of nodes exploring=> Pruning

 to Prune use branh and bound techniques which involes upperbound and
lowerbound
 to maintain upperbound and lowerbound two parameters are represented
called as alpha and beta => called alpha-beta pruning
 Alpha(∞)[lower bound]=> the value of the best(highest value) choice so far for
the player MAX
 Beta(β)[Upper bound]=> the value of the best(lowest value) choice so far for the
player MIN

CSE – Panimalar Engineering College 38


CS8691 – Artificial Intelligence

 Algorithm

 Example

1.1.7 Stochastic Games


- In real life, many unpredictable external events can put us into unforeseen
situations.
 Many games mirror this unpredictability by including a random element
=> Uncertainty in the result of an action.

- We call these stochastic games.

 Examples:
 In solitaire, next card is unknown
 Dice are rolled at the beginning of a player’

CSE – Panimalar Engineering College 39


CS8691 – Artificial Intelligence

 In stochastic games, there are 4 nodes min, mix, chance and terminal
nodes
 Can do expectimax search for games with chance node
 Terminal nodes and MAX , MIN nodes work similar to MINMAX
 Chance nodes=> the expected value, which is the sum of the value
over all outcomes, weighted by the probability of each chance action
def exp-value(state):
initialize v = 0
for each successor of state:
p = probability(successor)
v += p * value(successor)
return v

v = (1/2) (8) + (1/3) (24) + (1/6) (-12) = 10


 Pictorial representation of game tree of stochastic game

 Algorithm

Students Please Note:

Step by Step Procedure for Solving the problem is described in


handwritten.

CSE – Panimalar Engineering College 40

You might also like