430 likes | 737 Views
CS1103 電機資訊工程實習. Problem Solving. 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 m ethodologies.pdf ). 假設我們要到澎湖玩. 由松山機場搭機前往.
E N D
CS1103 電機資訊工程實習 Problem Solving 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/Topic3.Search methodologies.pdf)
清大 松山機場 三重/新竹/豪泰客運 清大校門 台北火車站 台北捷運 225路公車 松山機場 台北捷運中山國中站
How Did We Derive the Solution? • Problem solving as state space search • What is “state”? • States: location of you • Transitions: transportation (客運、高鐵、台鐵、捷運、公車、計程車、走路) 客運 台北火車站 清大校門 計程車 台北捷運 公車 松山機場 台北捷運中山國中站
Consider 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
Problem 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), . . .
Initial State Goal State
Representing 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
The 8-Puzzle Problem • Operator: “move blank”
目前為止我們只到一個解答 • 但做為資工系的學生,我們不但要知道一個解答,我們更想知道一個更好的解答,甚至 最佳解 (optimal solution) • 例如:sorting • Bubble sort, selection sort, insertion sort, merge sort, heapsort, quicksort, ...
問題是... • 何謂「最佳」? • 時間最短 • 記憶體用最少 • 最便宜 • 耗電最低 • 最環保 • 最容易使用 • 最漂亮 • 還有更複雜的目標 ... • 又快又便宜 • 功能又強又省電 Optimization goal 不同目標如何協調?
如何計算目標值? • 時間: • 其他方法: • 步數、運算數 客運 (1.5小時) 清大校門 台北火車站 捷運 (0.5小時) 公車 (15分鐘) 松山機場 台北捷運中山國中站
如何計算目標值? • 成本: • 其他方法: • 元件成本、售價 客運 ($100) 清大校門 台北火車站 捷運 ($40) 公車 ($15) 松山機場 台北捷運中山國中站
如何計算目標值? • 路上風景最好: • 常用方法:專家評分、民意調查 客運 (???) 清大校門 台北火車站 捷運 (???) 公車 (???) 松山機場 台北捷運中山國中站
Cost-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
State Space of TSP (arc label = cost from root)
Nearest Neighbor Path Nearest neighbor path = AEDBCA (550) Minimal cost path = ABCDEA (375)
Finding 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?
Search 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
Search 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)
Search 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
Depth-first Search Depth bound = 5
“Blind 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 can’t expect too much from these, but they provide • Worst-case scenarios
Heuristic 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
Tic-tac-toe • # of states in an exhaustive search is 9!
Tic-tac-toe • A heuristic is moving to the board in which X has the most winning lines
Hill-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
Hill-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
Best-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
Heuristic 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
Heuristic 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
Iterative Improvement • Start with one solution and make modifications to improve its quality
Find Initial Solution • Traverse the state space and find one solution 客運 (1.5小時) 清大校門 台北火車站 捷運 (0.5小時) 公車 (15分鐘) 松山機場 台北捷運中山國中站
Refinement • Modify the solution to make it better 重慶北路交流道 客運 (1.2小時) 公車 (45分鐘) 客運 (1.5小時) 清大校門 台北火車站 捷運 (0.5小時) 公車 (15分鐘) 松山機場 台北捷運中山國中站
Example 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, …
Importance 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
Quiz • 假設我們要以最小的成本設計一台掌上型DVD播放機。我們能夠調整的參數包含CPU的種類、記憶體的大小 • 請列出本設計的state space • 如何評估某一組參數 (path)可以達成目標?