1 / 17

MOI 培訓班提高組 搜索 2

MOI 培訓班提高組 搜索 2. 澳門電腦學會. 搜索樹. 初始狀態. 搜索路徑. 可能性結點. 目標結點. a. a. b. c. b. c. d. d. d. e. f. e. f. e. f. g. g. g. g. g. h. i. h. i. h. i. h. i. h. i. 搜索圖與搜索樹. 搜索圖. 搜索樹. 搜索狀態. 若搜索狀態是有限的,則要記下所有曾經搜索過的狀態,以免出現重複搜索 這種搜索變為圖搜索 openset=set of all unsearched node

Download Presentation

MOI 培訓班提高組 搜索 2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. MOI 培訓班提高組搜索 2 澳門電腦學會

  2. 搜索樹 初始狀態 搜索路徑 可能性結點 目標結點

  3. a a b c b c d d d e f e f e f g g g g g h i h i h i h i h i 搜索圖與搜索樹 搜索圖 搜索樹

  4. 搜索狀態 • 若搜索狀態是有限的,則要記下所有曾經搜索過的狀態,以免出現重複搜索 • 這種搜索變為圖搜索 openset=set of all unsearched node closeset={} WHILE openset<>{} DO Select and remove E from openset Put E in closeset Expend E END • 例子:走迷宮(曾經到訪的每格都被放進closeset中)

  5. 搜索狀態 • 但有部份搜索問題狀態太多,不能完全記錄 • 例如:16-puzzle problem,它的狀態共有16! = 20,922,789,888,000 種 • 這時候就不可以用純圖搜索法因為沒辦法實現openset/closeset 的完全數據結構

  6. 解決方法 • 只存放部份 closeset 數據 • 盡用有限的記憶空間 • 利用 hashing function 及 hashing table • 將一個狀態轉變為一個數值然然存放在一個表中(或二叉樹中) • 利用函數引導搜索

  7. Heuristic Search • 下一個搜索的狀態取決於一個函數 h(S) 的值 SS = Set of Child of Current State Select So such that h(So) = Min(h(SS)) Expend So • 決定 h() 是相對困難的事情

  8. 8-Puzzle Problem • 在一個 3x3 的遊戲板上有 8 塊數字板及一個空格,數字板可以從四個方向推入空格中(令空格變位) • 可能的狀態 9! = 362880 目標狀態 最始狀態(例)

  9. 兩個 h() 的例子 • h1(S) = 錯位格的數目 • h2(S) = 各自回到本位格的移動總數 h1(S) = 6 h2(S) = 0 + 1 + 2 + 1 + 1 + 2 + 3 + 0 + 0 = 10

  10. h1(S) 6 1 3 5 7 2 4 6 8 7 1 3 5 8 1 3 5 7 2 7 2 4 6 8 4 6 8 7 1 3 7 1 3 5 7 2 5 7 2 6 8 4 6 8 4 6 1 3 7 2 5 6 8 4 5 1 2 3 7 1 3 7 5 7 2 5 6 8 4 6 8 4 5 1 2 3 4 1 2 3 6 1 2 3 7 5 7 5 7 8 5 6 8 4 6 8 4 6 4

  11. Admissible Heuristics • 對於所有 S, h(S)  h*(S) • h*(S) 為由 S 到 G (目標狀態) 的真實距離 • h(G) = 0

  12. A* Search • f(S) = g(S) + h(S) • g(S) 為到達狀態 S 的代價(如步數)

  13. f(S) 6 1 3 5 7 2 4 6 8 1+7 1 3 5 1+8 1 3 5 7 2 7 2 4 6 8 4 6 8 2+7 1 3 2+7 1 3 5 7 2 5 7 2 6 8 4 6 8 4 3+6 1 3 7 2 5 6 8 4 4+5 1 2 3 4+7 1 3 7 5 7 2 5 6 8 4 6 8 4 5+5 1 2 3 5+4 1 2 3 5+6 1 2 3 7 5 7 5 7 8 5 6 8 4 6 8 4 6 4

  14. Hash Function • 8-Puzzle 的可能狀態為 9! = 362880 • 若我們只想存放其中一部份(Closeset),則可嘗試使用 hash function • H(S) -> Table index • 例: 8-Puzzle 將每格內的數值轉變成一個9位數,空格為0

  15. Hash function 例: 8-Puzzle • 將每格內的數值轉變成一個9位數,空格為0 • 再除以一個大的質數如7901 ,取其餘數(這裡,我們最多只可以存放 7901 個狀態資料) • 其這個狀態資料存於該索引內 1 3 5 7 2 4 6 8 135724680 MOD 7901 = 1302 HashTable[1302] = State

  16. 相重索引 • 有可能出現 H(S1)=H(S2) 但 S1<>S2的情況 • 這時有兩個解決方法 S1 H(S1) S1 S2 H(S1) S2

  17. Hash table 的內容 • Hash table 的內容可以是 S 或 F(S) • 如 S MOD 7907 (另一個質數)

More Related