480 likes | 490 Views
問題解決:木とグラフの探索. 白井 良明 立命館大学情報理工学部 知能情報学科 shirai@ci.ritsumei.ac.jp. ON (B, C) ON (C, A). ON (B, C) ON (C, A). 問題の記述:初期状態と目標状態. A. B. C. B. A. C. ONTABLE (A) ONTABLE (C). x. y. 問題の記述: オペレータ.
E N D
問題解決:木とグラフの探索 白井 良明 立命館大学情報理工学部 知能情報学科 shirai@ci.ritsumei.ac.jp
ON (B, C) ON (C, A) ON (B, C) ON (C, A) 問題の記述:初期状態と目標状態 A B C B A C ONTABLE (A) ONTABLE (C)
x y 問題の記述:オペレータ PICKUP(x);テーブルの上のxをつかむ 前提条件: ONTABLE(x),CLEAR(x),EMPTY 削除リスト:ONTABLE(x),CLEAR(x),EMPTY 追加リスト:HOLD(x);手はxをつかんでいる PUTDOWN(x);xをテーブルの上に置く 前提条件: HOLD(x) 削除リスト:HOLD(x) 追加リスト: ONTABLE(x),CLEAR(x),EMPTYTAKEOFF(x,y);yの上にあるxをつかむ 前提条件:ON(x,y),CLEAR(x),EMPTY 削除リスト: ON(x,y),CLEAR(x),EMPTY 追加リスト:CLEAR(y),HOLD(x) PUTON(x,y);xをyの上へ置く 前提条件: HOLD(x),CLEAR(y) 削除リスト:HOLD(x),CLEAR(y) 追加リスト: ON(x,y),CLEAR(x),EMPTY x x
木の探索 S A B C D E F H G
width-first procedure depth-first tree search • add (s, open); • LOOP: if open = null then exit(fail); • n:= first(open); • If goal(n) then exit (success); • Remove(n, open); • Expand(n); • Put all child nodes into the top of open and attach pointers to n; • Go to LOOP. last
グラフの探索 D B E G H A C F S I
procedure depth-first tree search • add (s, open); • LOOP: if open = null then exit(fail); • n:= first(open); • If goal(n) then exit (success); • Remove(n, open); • Expand(n); • Put all child nodes into the top of open and attach pointers to n; • Go to LOOP. add(n, closed)
procedure depth-first tree search • add (s, open); • LOOP: if open = null then exit(fail); • n:= first(open); • If goal(n) then exit (success); • Remove(n, open); add(n, closed) • Expand(n); • Put all child nodes into the top of open and attach pointers to n; • Go to LOOP. which are not in open nor closed
4 1 6 5 4 3 5 7 6 7 最適経路の探索 S 4 1 B A 2 3 1 2 E C F D 4 3 2 1 H G1 I G2
procedure optimal tree search • add (s, open); g^(s):= 0; • LOOP: if open = null then exit(fail); • n:= first(open); • If goal(n) then exit (success); • Remove(n, open); • Expand(n); • Put all child nodes into open and attach pointers to n; • Sort nodes in open in increasing order of g^; • Go to LOOP.
4 1 6 5 4 3 5 7 6 7 最適経路の探索 S 4 1 B A 2 3 1 2 E C F D 4 3 2 1 H G1 I G2
グラフ最適経路の探索 D B E G 6 5 4 5 3 6 H A 4 5 C F 6 S I
procedure optimal tree search • add (s, open); g^(s):= 0; • LOOP: if open = null then exit(fail); • n:= first(open); • If goal(n) then exit (success); • Remove(n, open); • Expand(n); • Put all child nodes into open and attach pointers to n; • Sort nodes in open in increasing order of g^; • Go to LOOP.
procedure optimal tree search • add (s, open); g^(s):= 0; • LOOP: if open = null then exit(fail); • n:= first(open); • If goal(n) then exit (success); • Remove(n, open); • Expand(n); • Put all child nodes into open, and attach pointers to n; • Sort nodes in open in increasing order of g^; • Go to LOOP. add(n, closed)
procedure optimal tree search • add (s, open); g^(s):= 0; • LOOP: if open = null then exit(fail); • n:= first(open); • If goal(n) then exit (success); • Remove(n, open); add(n, closed) • Expand(n); • Put all child nodes into open, and attach pointers to n; • Sort nodes in open in increasing order of g^; • Go to LOOP. which are not in open nor closed. If child node j was in open and g^(n, j) < g^(j), then attach pointers to n;
グラフ最適経路の探索 D B E G 6 5 4 5 3 6 H A 4 5 C F 6 S I
グラフ最適経路の探索 4 B G 3 C A 2 H D E 4 S F
グラフ最適経路の探索 4 B G 3 C A 2 7 H D E 4 S F
グラフ最適経路の探索 4 B G 3 C A 2 / 5 7 H D E 4 S F
グラフ最適経路の探索 4 B G 8 3 C A 2 6 5 H D E 4 6 S F
2 1 3 0 D B E G 2 3 A H 4 3 C F 4 6 S I グラフの最良優先探索
2 2 1 3 0 D B E G 2 3 A H 4 4 3 C F 4 6 S I グラフの最良優先探索 3 6
2 1 2 1 3 3 0 D B E G 2 3 A H 4 4 3 C F 4 6 S I グラフの最良優先探索 3 6
2 1 2 1 3 0 3 0 D B E G 2 2 3 A H 4 4 3 C F 4 6 S I グラフの最良優先探索 3 6
procedure best-first search • add (s, open); • LOOP: if open = null then exit(fail); • n:= first(open); • If goal(n) then exit (success); • Remove(n, open); add(n, closed) • Expand(n); • Put all child nodes except in open or closed into open, Sort nodes in open in increasing order of h^ ; • Go to LOOP;
2 0 B G 4 3 A C 3 4 2 H D E 6 4 S F グラフの最良優先探索
2 2 0 B G 4 4 3 3 A C 3 4 2 H D E 6 6 4 S F グラフの最良優先探索 3
2 2 0 B G 4 4 3 3 A C 3 4 4 2 2 H D E 6 6 4 S F グラフの最良優先探索 3
2 2 0 0 B G 4 4 3 3 A C 3 4 4 2 2 H D E 6 6 4 4 S F グラフの最良優先探索 3
A*アルゴリズム f^(n):= g^(n) + h^(n) 2 1 3 0 D B E G 6 3 2 A H 4 3 C F 4 6 6 S I
6 8 A*アルゴリズム 2 1 3 0 D B E G 6 3 2 A H 4 3 C F 4 6 6 S I
6 6 8 8 A*アルゴリズム 2 1 3 0 D B E G 6 3 2 A H 4 3 C F 4 6 6 S I
6 6 8 6 8 8 A*アルゴリズム 2 1 3 0 D B E G 6 3 2 A H 4 3 C F 4 6 6 S I
procedure optimal tree search • add (s, open); g^(s):= 0; • LOOP: if open = null then exit(fail); • n:= first(open); • If goal(n) then exit (success); • Remove(n, open); add(n, closed) • Expand(n); • Put all child nodes into open, and attach pointers to n; • Sort nodes in open in increasing order of g^; • Go to LOOP. which are not in open nor closed. If child node j was in open,select min{g^(j), g^(n, j)},
procedure optimal tree search • add (s, open); g^(s):= 0; • LOOP: if open = null then exit(fail); • n:= first(open); • If goal(n) then exit (success); • Remove(n, open); add(n, closed) • Expand(n); • Put all child nodes into open, and attach pointers to n; • Sort nodes in open in increasing order of g^; • Go to LOOP. which are not in open nor closed. If child node j was in open,select min{g^(j), g^(n, j)},
procedure optimal search • add (s, open); g^(s):= 0; • LOOP: if open = null then exit(fail); • n:= first(open); • If goal(n) then exit (success); • Remove(n, open); add(n, closed) • Expand(n); • Put all child nodes except in open or closed into open, compute g, and attach pointers to n; and attach pointers to n; • Sort nodes in open in increasing order of g^; • Go to LOOP. If child node j was in open,select min{g^(j), g^(n, j)},
A-algorithm procedure optimal search f^(s):=h^(s); • add (s, open); g^(s):= 0; • LOOP: if open = null then exit(fail); • n:= first(open); • If goal(n) then exit (success); • Remove(n, open); add(n, closed) • Expand(n); • Put all child nodes except in open or closed into open, compute g, and attach pointers to n; • Sort nodes in open in increasing order of g^; • Go to LOOP. f^(n, j):= g^(n, j) + h^(n); If child node j was in open,select min{g^(j), g^(n, j)},
procedure A-algorithm • add (s, open);f^(s):=h^(s); • LOOP: if open = null then exit(fail); • n:= first(open); • If goal(n) then exit (success); • Remove(n, open); add(n, closed) • Expand(n); • Put all child nodes except in open or closed into open, compute g; f^(n, j):= g^(n, j) + h^(n); and attach pointers to n; • Sort nodes in open in increasing order of g^; • Go to LOOP. If child node j was in open,select min{g^(j), g^(n, j)}, min{f^(j), f^(n, j)}; f^;
procedure optimal search procedure A-algorithm search procedure A-algorithm search • add (s, open); f^(s):= h^(s); • LOOP: if open = null then exit(fail); • n:= first(open); • If goal(n) then exit (success); • Remove(n, open); add(n, closed) • Expand(n); • Put all child nodes except in open or closed into open, compute g; f^(n, j):= g^(n, j) + h^(n); if node j is in open or closed, select min{f^(j), f^(n, j)} and put into open; Sort nodes in open in increasing order of f^; • Go to LOOP;
A*アルゴリズム 2 0 6 B G 4 3 6 6 A C 3 4 2 D E H 6 6 4 S F
A*アルゴリズム 2 0 6 B G 4 3 6 6 A C 3 4 2 8 10 D E H 6 6 4 S F
A*アルゴリズム 2 0 6 B G 4 3 6 6 A C 8 3 4 2 8 D E H 6 6 10 4 S F
A*アルゴリズム 2 8 0 6 B G 4 3 6 6 A C 8 3 4 2 8 10 8 D E H 6 6 10 4 S F
CLOSED, OPEN を用いる例 10 S 3 1 9 9 6 10 A B 1 6 4 5 8 7 14 7 15 E D C
CLOSED, OPEN を用いる例 10 S 3 1 8 9 6 10 A B 1 6 4 5 8 7 14 15 7 15 E D C
CLOSED, OPEN を用いる例 10 S 3 1 8 9 6 10 A B 1 6 4 5 8 7 14 15 13 7 14 15 E D C
A*アルゴリズムが有効な例 S (7) 4 5 6 9 9 8 (5) (4) (2) A B C 3 3 3 2 2 2 1 1 1 10 8 9 (2) (3) (3) (3) (3) (3) (1) D E K F H I J 4 4 4 4 4 4 4 2 1 3 3 4 4 4 9 8 G2 G1 G3 G4 G5 G6 G7 G8
A*アルゴリズムとならない例 S 5 2 3 5 3 4 7 A B 4 2 G 6