# Problems _ Search

Document Sample

```					Problems & Search

Ref: Chapter 2

1
Building a System to Solve a
Problem
• Define the problem precisely.
• Determine what kind of knowledge is
necessary to solve the problem.
• Create a representation scheme for such
knowledge.
• Choose (or develop) problem solving
techniques that are applicable to the
problem.
2
Problem Definition
• Some things we need to consider:
–   Environment (including encoding methods)
–   Goal (what we hope to achieve)
–   Where to start
–   How to make changes
–   How to tell when a change is beneficial

3
Example
• Tic-Tac-Toe:
– Environment includes the board and input from
opponent (moves).
– Goal is “three in a row, column or diagonal”.
– Start at a given board.
– Make changes by making a legal move.
– Moves are good if we win or don’t lose (and
perhaps other criteria).

4
Harder problems
• A precise definition is not always easy:
–   Understand English language.
–   Write script for hit sitcom.
–   Predict the weather.
–   Predict stock market changes

5
Problem Generalization
• It is useful to develop general methods for
describing problems.
• This makes it easy to compare problems
(specifically the size of problems).
• We can develop a set of problem solving
strategies, any one can be applied to any
problem.
• Hopefully lots of problems will fit our
methodology.                                  6
State Space Problem Definition
• One widely used way to describe problems
is by listing or describing all possible states.
• Solving a problem means moving through
the state space from a start state to a goal
state.
• Need to devise a set of operators that move
from one state to another.

7
State Space Problem Definition
• Set of possible states.
• Set of possible operations that change the
state.
• Specification of a starting state(s).
• Specification of a goal state(s).

8
State Space
• It is usually not possible to list all possible
states:
– use abstractions to describe legal states.
– It may be easier to describe the illegal states.
– Sometimes it is useful to provide a general
description of the state space and a set of
constraints.

9
Operations
• The problem solving system moves from
one state to another according to well
defined operations.
• Typically these operations are described as
rules.
• A control system decides which rules are
applicable at any state, and resolves
conflicts and/or ambiguities.
10
Example: Water Jug Problem

4 Gal    Unlimited
3 Gal
Water

Goal: 2 Gallons in the 4 Gal. Jug
11
Water Jug State Space
• The state can be represented by 2 integers x
and y:
• x = gallons in the 4 gallon jug
• y = gallons in the 3 gallon jug

State Space = (x,y)
such that x  {0,1,2,3,4}, y  {0,1,2,3}

12
Water Jug Start and Goal States
• The start state is when both jugs are empty:
(0,0)

• The goal state is any state that has 2 gallons
in the 4 gallon jug:
(2,n) for any n

13
Water Jug States

(0,0)   (1,0)   (2,0)   (3,0)   (4,0)

(0,1)   (1,1)   (2,1)   (3,1)   (4,1)

(0,2)   (1,2)   (2,2)   (3,2)   (4,2)

(0,3)   (1,3)   (2,3)   (3,3)   (4,3)

14
Water Jug Operations
• Fill 3 gal. jug from pump     (x,y) -> (x,3)
• Fill 4 gal. jug from pump     (x,y) -> (4,y)
• Empty 3 gal. jug              (x,y) -> (x,0)
• Empty 4 gal. jug              (x,y) -> (0,y)
• Pour contents of 3 gal. jug   (0,y) -> (y,0)
into 4 gal. Jug
• Others ???

15
Constraints
• It doesn’t make sense to fill a jug if it is
• We often associate some constraints on the
state an operation should be applied to.
(x,y), x<4 -> (x,0)
(x,y), y<3 -> (0,y)
(x,y), x>0,y=0 -> (y,0)

16
Production Rules
• An operation and the conditions that must
be met (constraints) before the operation
can be applied is called a rule.
• Typically we need a mix of general rules
and specific rules.
• Domain specific information can often lead
to specific rules that speed up a search

17
Domain Specific Rules
• For the water jug problem:
(0,2) -> (2,0)
(x,2) -> (0,2)

• Using these rules can speed things up!

18
Production System
• A Production System:
– A set of rules.
– Some mechanism for representing the state of
the system (a database).
– A control strategy that controls the order in
which rules are compared to the database and
resolves conflicts.
– A rule applier.

19
Control Strategies
• General Requirements:
– Motion:
• application of the same rule over and over again is
probably not useful.
• We need to change the state to make any progress.
– Systematic
• operates in a manner that explores new regions in
the state space.
• Avoids getting stuck in loops.

20
Control Strategies for Water Jug
• Ordered list of rules - apply the first one
that applies to current situation.
• Pick any rule (randomly) that applies to the
current situation.
• Try all applicable rules, and keep track of
all resulting states. At next step do the same
to all states.

21
Water Jug Tree
(0,0)

(4,0)                             (0,3)

(4,3)   (0,0)     (1,3)           (4,3)   (0,0)   (3,0)

22
• The tree strategy for the water jug problem is an
• General Algorithm for BFS:
create nodelist and initialize to the start state.
repeat until a goal state is found or nodelist = {}
remove the first element from nodelist:
apply all possible rules and add resulting
states to nodelist.

23
Characteristics
• If there is a solution, BFS will find it.
• BFS will find the minimal solution (shortest
path length to the solution).
• BFS will not get caught in state space
cycles.
• Require space available to store the
nodelist. This can be very large!!!

24
Depth-First Search
Establish some ordering to rules.
While applicable rules exist
apply the next rule and generate a new state.
do a depth-first search on the new state.

25
Depth-First Search
Characteristics
• Don’t need to keep track of a large list of
states.
• May find a solution very fast.
• “Pruning” is possible
– example: branch-and-bound
• Can easily get caught in loops.

26
Water Jug Problem Revisited
Rules
(x,y), y<3     ->   (x,3)   Exercises:
(x,y), x<4     ->   (4,y)   1. Draw the BFS search
(x,y), y0     ->   (x,0)
2. Draw the DFS search
(x,y), x0     ->   (0,y)
(0,y), y0     ->   (y,0)
(0,2)          ->   (2,0)
(x,2)          ->   (0,2)
27
Another Problem
• Traveling Salesman Problem
–   List of cites to visit.
–   List of distances between cities.
–   Visit each city exactly once.
–   Find the minimum tour
• Describe BFS and DFS search strategies
that could be used for this problem.

28
Heuristic Search
• Many problems have search spaces that are
too large to examine completely.
• We can construct control strategies that
don’t promise the best answer, but that find
a “good” answer and finish within our
• Heuristic Search strategies use domain
specific information to limit a search to
(hopefully) the most promising areas.
29
Heuristic
• A heuristic is:
– educated guess.
– hint.
– evaluation based on less than complete
information.
– prediction.
• A heuristic is used to guide the search
process.

30
Exercise
• Come up with heuristics for the following:
– what to study for a test
– how long it will take for the registrar to fix your
scheduling problems
– what the weather will be tomorrow
– how to win at tic-tac-toe.

31
TSP Heuristic
• Nearest neighbor heuristic (greedy):

1. Select any starting city

2. While cities remain
pick the city nearest to the current
city.

32
Heuristic Search Usage
• Don’t need the optimal solution (any
solution is a good solution).
• The worst case is rare.
• Understanding when and how a heuristic
works can lead to better understanding of
the problem.

33
Using heuristic knowledge in a
rule based system
• Heuristic knowledge can be encoded
directly in to the rules.
– Water jug problem - don’t fill a jug if it is
• As a heuristic function that evaluates
problem states and imposes an ordering.
– Chess - which moves should be explored first.

34
Problem Characteristics
• It is useful to itemize characteristics so that
can select the best strategies for new
problems by looking at other problems that
share characteristics.

35
1. Decomposition
• Can the problem be broken down
(decomposed) in to several independent
problems of smaller size ?
• Yes - recursion can be used, only the small
problems are attacked directly.

36
2. Can steps be ignored or undone?
• What if the search makes a silly mistake?:
– Ignorable - solution steps can be ignored (don’t
change the search strategy).
– Recoverable - steps can be undone (we can
backtrack).
– Irrecoverable - steps can’t be undone.

37
3. Is the universe predictable ?
• Sometimes the system is in complete
control of the state and knows exactly the
outcome of each operation.
• Other times the outcome is not completely
predictable.

38
4. Is a good solution relative or
absolute?
• Single vs. multiple paths to a single
solution.
• Absolute probably means we can’t use a
heuristic (we need to look at all
possibilities).

39
5. Is the solution a state or a path?
• Sometime the result is just an answer.

• Sometimes the path to the solution is the

• We can often reformulate the problem so
that the result is not the path.

40
6. What is the role of knowledge?
• Some problems use knowledge to constrain
the search (the search strategy makes use of
knowledge).

• Other problem require knowledge to
evaluate states (to recognize success).

41
7. Are humans involved?
• Sometimes humans can provide help.

• Humans are not likely to trust systems if the
humans cannot understand the logic behind

42
Types of Problems
• The 7 characteristics can be used to classify
problems.
• Some techniques work well on some kinds
of problems.
– classification
– Propose and refine

43
Search Programs

• Search can be viewed as traversal of a tree.
• Tree is defined by the rules.
• Implicit vs. Explicit representation.
• Sometimes it is better to think of the search
as a directed graph.

44

```
DOCUMENT INFO
Shared By:
Categories:
Stats:
 views: 6 posted: 12/26/2010 language: English pages: 44