Title: Problem Solving
1Problem Solving
CS1103 ????????
- Prof. Chung-Ta King
- Department of Computer Science
- National Tsing Hua University
(Contents from Prof. I. K. Lundqvist, Prof.
Nilufer Onder, Prof. Kun-Yung Lu, 140.121.196.191/
pdf/ai/2007/Topic 3. Search methodologies.pdf)
2?????????
3?????????
4???????????
5?? ? ????
??/??/????
????
?????
????
225???
????
?????????
6How Did We Derive the Solution?
- Problem solving as state space search
- What is state?
- States location of you
- Transitions transportation (?????????????????????
)
??
????
?????
???
????
??
?????????
????
7Consider a More Complex Problem
- Consider the problem
- Astronaut carries Grain, Goose, Fox across river
- Astronaut 1 item allowed in the boat
- Goose alone eats Grain
- Fox alone eats Goose
Astronaut Grain, Goose, Fox
8Problem Solving as State Space Search
- Goal
- Astronaut, Fox, Goose and Grain across river
- Problem representation
- States location of Astronaut, Fox, Goose and
Grain at top or bottom river bank - Operators move boat with astronaut and 1 or 0
items to other bank - Generate solution
- Sequence of states Move(goose,astronaut),
Move(astronaut), . . .
9Initial State
Goal State
10(No Transcript)
11Representing the Problem
- The problem space consists of
- A state space which is a set of states
representing the possible configurations of the
world - A set of operators which can change one state
into another - Initiate state and goal state
- Path sequence of states produced by the valid
application of operators from an old state to a
new state - The problem space can be viewed as a graph where
the states are the nodes and the arcs represent
the operators
12The 8-Puzzle Problem
13State Space of 8-Puzzle
14????????????
- ?????????,???????????,?????????????,??
- ??? (optimal solution)
- ??sorting
- Bubble sort, selection sort, insertion sort,
merge sort, heapsort, quicksort, ...
15???...
- ???????
- ????
- ??????
- ???
- ????
- ???
- ?????
- ???
- ???????? ...
- ?????
- ???????
Optimization goal
?????????
16????????
?? (1.5??)
????
?????
?? (0.5??)
?? (15??)
?????????
????
17????????
?? (100)
????
?????
?? (40)
?? (15)
?????????
????
18????????
?? (???)
????
?????
?? (???)
?? (???)
?????????
????
19Cost-directed Problem Solving
- In many search problem, we are interested not
only in reaching a goal state, but also in
reaching it with the lowest cost (or the maximum
profit) - We can compute a cost as we apply operators and
transit from state to state
20Traveling Salesperson Problem
21State Space of TSP
(arc label cost from root)
22Nearest Neighbor Path
Nearest neighbor path AEDBCA (550) Minimal cost
path ABCDEA (375)
23Finding Solutions
- Some problems have only one solution (goal
state), e.g. 8-puzzle, sorting, Tower of Hanoi
others may have more than one solution, e.g.
???????, traveling salesperson - To find one solution
- We need to find one path from the root to the
leaf in the state space - To find the optimal solution
- We need to traverse all the paths in the state
space - What if the state space is huge?
24Search Algorithms
- Effective search algorithm must
- Cause motion or traversal of the state space
- Do so in a controlled or systematic manner
- The method that never using the information about
the problem to help direct the search is called
brute-force, uninformed, or blind search - Search algorithms which use information about the
problem, such as the cost or distance to the goal
state, are called heuristic, informed, or
directed search
25Search Algorithms
- An algorithm is optimal if it will find the best
solution from among several possible solutions - A strategy is complete if it guarantees that it
will find a solution if one exists. - Complexity of an algorithm
- Time complexity (how long to find a solution)
- Space complexity (how much memory it requires)
26Search Algorithms
- The search problem can be classified to two
classes P and NP - The classes P consists of all problems for which
algorithms with polynomial time behavior have
been found - The class NP is the set of problems for which
algorithms with exponential behavior have been
found - If an optimization of the problem cannot be
solved in polynomial time, it is called NP-hard
27Breadth-first Search
28Depth-first Search
Depth bound 5
29Blind Search
- BFS and DFS are blind in the sense that they have
no knowledge about the problem at all other than
the problem space - Such techniques are also called brute-force
search, uninformed search, or weak methods - Worst case scenarios are equally bad
(exponential) - Obviously, we cant expect too much from these,
but they provide - Worst-case scenarios
30Heuristic State-space Search
- A heuristic algorithm consists of two parts
- The heuristic measure a heuristic evaluation
function measures the goodness of a node - An algorithm that uses the heuristic measure to
search the state space - Heuristics are rules for choosing the branches in
a state space that are most likely to lead to an
acceptable problem solution - A heuristic is only an informed guess of the next
step to be taken in solving the problem - A heuristic is often based on experience or
intuition and can lead to a suboptimal solution
31Tic-tac-toe
- of states in an exhaustive search is 9!
32Tic-tac-toe
- A heuristic is moving to the board in which X has
the most winning lines
33Hill-climbing Search
- Hill-climbing expands the current state and
selects the best child for further expansion - Neither its siblings nor its parent are retained
(without backtracking) - Search halts when it reaches a state that is
better than any of its children - Major problems
- May get stuck at a local optimal
34Hill-climbing Search
- Possible solutions
- Keep a list of plausible move and backtrack when
a dead-end is met - Make a big jump or move the same direction
several times - Try different directions (applying two or more
rules) before test - Hill climbing is basically a local heuristics
35Best-First Search
- Use heuristic function to choose a best move out
of several alternatives - Keep exploring the best path (depth-first search)
until it turns less promising than a previous
path - Return to explore the previous path that has
become most promising
36Heuristic Evaluation Function
- The goal is to use the limited information
available in a single state descriptor to make
intelligent choices - For 8-puzzle, heuristicmay be
- tiles out of place
- Sum of all the distances by which the tiles are
outof pace - 2 x direct tile reversals
37Heuristic Evaluation Function
- The evaluation function may be the sum of two
components f(n)g(n)h(n) - g(n) measures the actual length of the path from
state n to the start state - h(n) is a heuristic estimate of the distance from
state n to a goal - A Algorithm
38Iterative Improvement
- Start with one solution and make modifications to
improve its quality
39Find Initial Solution
- Traverse the state space and find one solution
?? (1.5??)
????
?????
?? (0.5??)
?? (15??)
?????????
????
40Refinement
- Modify the solution to make it better
???????
?? (1.2??)
?? (45??)
?? (1.5??)
????
?????
?? (0.5??)
?? (15??)
?????????
????
41Example Search Problems
- Puzzles missionaries and cannibals, 8-puzzle,
n-queens, Tower of Hanoi, - 2-player games chess, checkers, Chinese Go,
- Proving theorems in logic and geometry
- Path finding
- Industrial problems VLSI layout design,
assembling a complex object - AI problems speech recognition, planning,
42Importance of Problem Space
- The choice of a problem space makes a big
difference - Finding a good abstraction is half of the problem
- Intelligence is needed to figure out what problem
space to use
43Quiz
- ??????????????????DVD???????????????CPU??????????
- ???????state space
- ????????? (path)???????