Searching Techniques
Searching Techniques
Searching Techniques
Searching
Example 1: Water Jug Problem
Consider the following problem:
A Water Jug Problem: You are given two jugs, a 4-gallon one and a 3-gallon one, a
pump which has unlimited water which you can use to fill the jug, and the ground on
which water may be poured. Neither jug has any measuring markings on it. How can
you get exactly 2 gallons of water in the 4-gallon jug?
• State Representation and Initial State – we will represent a state of the problem as a
tuple (x, y) where x represents the amount of water in the 4-gallon jug and y
represents the amount of water in the 3-gallon jug. Note 0 ≤ x ≤ 4, and 0 ≤ y ≤ 3.
• Our initial state: (0,0)
• Goal Predicate – state = (2,y) where 0 ≤ y ≤ 3.
• Operators – we must define a set of operators that will take us from one state to
another:
Example: Water jug problem
Given a 3-gallon and a 4-gallon water jug, how can we measure exactly 2 gallons in the 4-g jug in the
minimum number of moves?
0 0
Problem solving agents
• Goal Formulation
Desired state of the world.
Organize behavior by limiting the objectives
• Problem Formulation
(successor function).
Process of deciding what action and state to consider, given a goal
• Search
Determine a sequence of actions that lead to a goal state.
• Execute
Perform the actions.
• Assumptions:
Environment is fully observable and deterministic
In order to provide a formal description of a problem, it is necessary to do the following:
-Completeness
-Time Complexity
-Space Complexity
-Optimality
Complexity:
branching factor: maximum number of successor of any node.
depth: shallowest goal node.
m:maximum length of any path in a state space.
Uninformed search
• Given a state, we only know whether it is a goal state or not
• Cannot say one non goal state looks better than another non
goal state
• Can only traverse state space blindly in hope of somehow
hitting a goal state at some point
Algorithm
1. Generate a possible solution.
2. Test to see if this is actually a solution.
3. Quit if a solution has been found.
Otherwise, return to step 1.
38
Generate-and-Test
39
Generate-and-Test
• Exhaustive generate-and-test.
• Heuristic generate-and-test: not consider paths that seem unlikely to
lead to a solution.
• Plan generate-test:
- Create a list of candidates.
- Apply generate-and-test to that list.
40
Generate-and-Test
41
Generate-and-Test
42
Hill Climbing
43
Hill Climbing
44
Simple Hill Climbing
Algorithm
1. Evaluate the initial state.
2. Loop until a solution is found or there are no new
operators left to be applied:
- Select and apply a new operator
- Evaluate the new state:
goal quit
better than current state new current state
45
Simple Hill Climbing
• Evaluation function as a way to inject task-specific knowledge into the
control process.
46
Simple Hill Climbing
47
Steepest-Ascent Hill Climbing (Gradient
Search)
• Considers all the moves from the current state.
• Selects the best one as the next state.
48
Steepest-Ascent Hill Climbing (Gradient
Search)
Algorithm
1. Evaluate the initial state.
2. Loop until a solution is found or a complete
iteration produces no change to current state:
- SUCC = a state such that any possible successor of the
current state will be better than SUCC (the worst state).
- For each operator that applies to the current state, evaluate
the new state:
goal quit
better than SUCC set SUCC to this state
- SUCC is better than the current state set the current
state to SUCC.
49
Hill Climbing: Disadvantages
Local maximum
A state that is better than all of its neighbours, but not
better than some other states far away.
50
Hill Climbing: Disadvantages
Plateau
A flat area of the search space in which all neighbouring
states have the same value.
51
Hill Climbing: Disadvantages
Ridge
The orientation of the high region, compared to the set
of available moves, makes it impossible to climb up.
However, two moves executed serially may increase
the height.
52
Hill Climbing: Disadvantages
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.
53
Hill Climbing: Disadvantages
• Hill climbing is a local method:
Decides what to do next by looking only at the “immediate”
consequences of its choices.
• Global information might be encoded in heuristic functions.
54
Hill Climbing: Disadvantages
Start Goal
A D
D C
C B
B A
Blocks World
55
Hill Climbing: Disadvantages
Start Goal
A D
0 4
D C
C B
B A
Blocks World
Local heuristic:
+1 for each block that is resting on the thing it is supposed to be
resting on.
-1 for each block that is resting on a wrong thing.
56
Hill Climbing: Disadvantages
0 A 2
D D
C C
B B A
57
Hill Climbing: Disadvantages
D 2
C
B A
A 0
0
D
C C D C 0
B B A B A D
58
Hill Climbing: Disadvantages
Start Goal
A D
-6 6
D C
C B
B A
Blocks World
Global heuristic:
For each block that has the correct support structure: +1 to
every block in the support structure.
For each block that has a wrong support structure: -1 to
every block in the support structure.
59
Hill Climbing: Disadvantages
D -3
C
B A
A -6
-2
D
C C D C -1
B B A B A D
60
Hill Climbing: Conclusion
• Can be very inefficient in a large, rough problem space.
• Global heuristic may have to pay for computational complexity.
• Often useful when combined with other methods, getting it started
right in the right general neighbourhood.
61
Simulated Annealing
• A variation of hill climbing in which, at the beginning of the process,
some downhill moves may be made.
62
Temperature reduction Rules
Simulated Annealing
Physical Annealing
• Physical substances are melted and then gradually cooled until some
solid state is reached.
• The goal is to produce a minimal-energy state.
• Annealing schedule: if the temperature is lowered sufficiently slowly,
then the goal will be attained.
• Nevertheless, there is some probability for a transition to a higher
energy state: e-E/kT.
64
Simulated Annealing
Algorithm
1. Evaluate the initial state.
2. Loop until a solution is found or there are no new
operators left to be applied:
- Set T according to an annealing schedule
- Selects and applies a new operator
- Evaluate the new state:
goal quit
E = Val(current state) - Val(new state)
E < 0 new current state
else new current state with probability e-E/kT.
65
Best-First Search
• Depth-first search: not all competing branches having to be expanded.
• Breadth-first search: not getting trapped on dead-end paths.
Combining the two is to follow a single path at a time, but
switch paths whenever some competing path look more
promising than the current one.
66
Best-First Search
A A A
B C D B C D
3 5 1 3 5
E F
4 6
A A
B C D B C D
5 5
G H E F G H E F
6 5 4 6 6 5 6
I J
2 1
67
Best-First Search
• OPEN: nodes that have been generated, but have not examined.
This is organized as a priority queue.
68
Best-First Search
Algorithm
1. OPEN = {initial state}.
2. Loop until a goal is found or there are no nodes left
in OPEN:
- Pick the best node in OPEN
- Generate its successors
- For each successor:
new evaluate it, add it to OPEN, record its parent
generated before change parent, update successors
69
Best-First Search
• Greedy search:
h(n) = estimated cost of the cheapest path from node n to a goal
state.
70
Best-First Search
• Uniform-cost search:
g(n) = cost of the cheapest path from the initial state to node
n.
71
Best-First Search
• Greedy search:
h(n) = estimated cost of the cheapest path from node n to a
goal state.
Neither optimal nor complete
72
Best-First Search
• Greedy search:
h(n) = estimated cost of the cheapest path from node n to a
goal state.
Neither optimal nor complete
• Uniform-cost search:
g(n) = cost of the cheapest path from the initial state to node
n.
Optimal and complete, but very inefficient
73
AND/OR graphs
• Some problems are best represented as achieving subgoals, some
of which achieved simultaneously and independently (AND)
• Up to now, only dealt with OR options
Possess TV set
A
(9) A
(3) B D (5)
(4) C 38
B C D
17 9 27
E F G H I J
(5) (10) (3) (4) (15) (10)
AND/OR Best-First-Search
• Traverse the graph (from the initial node) following
the best current path.
• Pick one of the unexpanded nodes on that path and
expand it. Add its successors to the graph and
compute f for each of them
• Change the expanded node’s f value to reflect its
successors. Propagate the change up the graph.
• Reconsider the current best solution and repeat until
a solution is found
AND/OR Best-First-Search example
1. 2.
A A
(5) (9)
(3) B D (5)
(4) C
3. A
(9) D (10)
B (3) C (4)
(10)
E (4) F (4)
AND/OR Best-First-Search example
4.
A
(12)
B (6) C (4) D (10)
(10)
G (5) H (7) E (4) F (4)
A Longer path may be better
A
B C D A
G H E F Unsolvable B C D
I J G H E F Unsolvable
I J
Means-ends analysis
• All the above search strategies reason either forward or backward.
• However, often a mixture of forward and backward is needed.
• --So solve major parts of the problem first. And then go back and solve these
small problems to glue by pieces together.
• --centers around detection of differences between the current and goal state.
• --When detected reduce the difference by choosing the appropriate
operator.
• --But operator may not be applicable on current state.
• --So setup a sub problem of getting on to a state in which it can be applied.
MEA
• This backward chaining in which operators are selected and subgoals are
set up to establish precondition of operators is called operator
subgoaling.
• MEA process applied recursively
• Each rule (operator) has
• LHS preconditions and RHS aspects of problem state changed.
• Difference table of rules and differences they can reduce.
• Problem for household robot: moving desk with 2 things on it from one room to
another.
• Main difference between start and goal state is location.
• Choose PUSH and CARRY
Move desk with 2 things on it to new room
Move * *
object
Move *
robot
Clear *
object
Get object *
on object
Get arm
empty * *
Be holding
object *
Operator Preconditions Results