# Search in AI Dr.Yodthong Rodkaew. Why Search? Looking for solution(s) Problem Solving.

## Presentation on theme: "Search in AI Dr.Yodthong Rodkaew. Why Search? Looking for solution(s) Problem Solving."— Presentation transcript:

Search in AI Dr.Yodthong Rodkaew

Why Search? Looking for solution(s) Problem Solving

Type of Search Uninformed Search –does not take into account the specific nature of the problem –can be implemented in general –consume space and time Informed Search –specific to the problem is used as a guide –dramatically out-perform –use heuristic

Uninformed Search #Brute-Force Search / Exhaustive Search #Depth-First Search (DFS) Depth-Limited Search (DLS) #Breadth-First Search (BFS) Iterative Deepening Search (IDS) Bidirection Search (BS)

Informed Search #Best-First Search (Best-FS) #A* Search Hill-Climbing Search  (CH11) Simulated Annealing (SA)  (CH11) TABU Search  (CH11)

Brute-Force Search / Exhaustive Search http://en.wikipedia.org/wiki/Brute-force_search candidate = ผู้ท้าชิง ผู้แข่งขัน ; solution = วิธีปัญหา brute = สัตว์ป่า ; exhaustive = ละเอียดถี่ถ้วน

Brute-Force Search / Exhaustive Search AI M Tim Jones A B C D E F G H I J K

Depth-First Search (DFS) http://www.cse.unsw.edu.au/~billw/Justsearch.html A BC DE FG HIJ K depth0 depth1 depth2 depth3 *(pre-order traversal): a b d h e i j c f k g visiting the node first, then its children *(post-order traversal): h d i j e b k f g c a visiting the children first, then the node *(in-order traversal): h d b i e j a k f c g visiting some of the children, then the node, then the other children Depth = ความลึก

Code preorder(node) begin if node is null, return; print(node); preorder(node.children); end inorder(node) begin if node is null, return; inorder(node.children#1); print(node); inorder(node.children#2-n); end postorder(node) begin if node is null, return; postorder(node.children); print(node); end http://www.nist.gov/dads/HTML/postorderTraversal.html depthfirst_preorder(node) begin if node is null, return; print(node); if node=goal then return found; depthfirst_preorder(node.children); end

ข้อ 1.เติมคำตอบให้ถูกต้อง + เช็คชื่อ (15 นาที) *(pre-order traversal): __________________ ? visiting the node first, then its children *(post-order traversal): __________________ ? visiting the children first, then the node *(in-order traversal): __________________ ? visiting some of the children, then the node, then the other children DFS - Test + -* 10/ +4 -82 3 56

Depth-Limited Search (DLS) A BC DE FG HIJ K depth0 depth1 depth2 depth3 *(pre-order traversal): visiting the node first, then its children *(post-order traversal): visiting the children first, then the node *(in-order traversal): visiting some of the children, then the node, then the other children Depth = ความลึก AI M Tim Jones

Breadth-First Search (BFS) http://www.cse.unsw.edu.au/~billw/Justsearch.html A BC DE FG HIJ K depth0 depth1 depth2 depth3 (level-by-level traversal) a b c d e f g h i j k. Breadth-first search traverses the tree or graph level-by-level, visiting the nodes of the tree above in the order breadth = ความกว้าง

Code breadthfirst(tree, level) begin if tree=empty, return; for each node in tree begin if node.level = level, begin print(node); if node=goal then return found; opennode(tree, node.children); closenode(tree, node); end; end breadthfirst(tree, level+1); end tree = empty; opennode(tree, root_node); breadthfirst(tree, 0); http://www.nist.gov/dads/HTML/postorderTraversal.html A BC E D GF tree = { } tree = { A.0 } #bf(0) A tree = { B.1, C.1 } closenode = {A.0} #bf(1) B C tree = {D.2, E.2 } closenode = {A.0, B.1, C.1} #bf(2) D E tree = {F.3, G.3 } closenode = {A.0, B.1, C.1, D.2, E.2} #bf(3) F G tree = { } closenode = {A.0, B.1, C.1, D.2, E.2, F.3, G.3 } #bf(4) #return

BFS - Test A CW XY Z K M Q ข้อ 2.เติมคำตอบให้ถูกต้อง + เช็คชื่อ จงแสดงการทำงานของ BFS จาก tree ที่ กำหนดให้ (20 นาที)…………………………… ……………………………

Iterative Deepening Search (IDS) AI M Tim Jones 1 2 3 DE FG H IJ K depth0 depth1 depth2 depth3 1 2 5 34 67 H IJ K depth0 depth1 depth2 depth3 1 2 8 35 911 4 67 10 depth0 depth1 depth2 depth3 iterative 1iterative 2 iterative 3 IDS combines the features of depth-first search with beadth-first search

Bidirection Search (BS) AI M Tim Jones A B C DE FG H IJ K depth0 depth1 depth2 depth3 Z U T Y V R X W QS depth = n goal depth n-1 depth n-2 two breadth-first search from root and goal simultaneously, require known solution

Best-First Search (BestFS) Evaluation Function f(n) Heuristic Function h(n) Estimated cost g(n) or actual distance from n to start state f(n) = h(n) + g(n)

Code bestfirst(tree) begin if tree=empty, return; for each node in tree, eval_fn(node); mincostnode=findmincostnode(tree); for each node in mincostnode begin print(node); if node=goal then return found; opennode(tree, node.children); closenode(tree, node); end; bestfirst(tree); end tree = empty; opennode(tree, root_node); bestfirst(tree); A CW XY Z K M Q 1 2 1 1 1 2 2 1 h=1 h=2 h=1

Example A CW XY Z K M Q g=1 2 1 1 1 2 2 1 h=1 h=2 h=1 A CW XY Z K M Q 1 1 2 2 f=1 f=1+1 f=2+1+2 f=2+1+1 f=2+2 f=2+1+1+2 f=1+1+1+1+2 f=1+3 f=1+4

Example A CW XY Z K M Q 1 1 2 2 f=1 f=1+1 f=2+1+2 f=2+1+1 f=2+2 f=2+1+1+2 f=1+1+1+1+2 f=1+3 f=1+4 A CW XY Z K M Q 1 2 4 5 4 6 6 5 4

Example A CW XY Z K M Q 1 2 4 5 4 6 6 5 4 1 23 53 4 6 7 5 order node traversed

Code A CW XY Z K M Q 1 1 3 1 1 2 1 1 h=1 h=3 h=1 h=3 h=1 ข้อ 3.เติมคำตอบให้ถูกต้อง + เช็คชื่อ จงแสดงการทำงานของ BestFS จาก tree ที่กำหนดให้ (20 นาที)…………………………… ……………………………

Download ppt "Search in AI Dr.Yodthong Rodkaew. Why Search? Looking for solution(s) Problem Solving."

Similar presentations