next up previous
Next: 6.2 状態遷移可能性の判断 Up: 6 状態空間の生成 Previous: 6 状態空間の生成

6.1 状態遷移操作の抽出

図 8: 4つの積木の場合
\includegraphics[width=5cm]{/home/inaba/eps/lecture/fig/blocks4states.eps}
ある状態をすべてのブロックが何の上にあるかという状態の列で与えることに します.たとえば,a,b,c,dの4つのブロックがある場合の1つの状態は, ((a on table) (b on c) (c on table) (d on a)) という形で表します.このような場合に,この状態を与えて, その中に含まれるすべてのブロック名を返す関数 all-blocksと,与えられた状態の中で上に何も載っていないブロッ クを返す関数 top-free-blocksを次のように定義できます.

> (all-blocks '((a on table) (b on a)))
(A B) 
> (top-free-blocks '((a on table) (b on a)))

(B) 
> (top-free-blocks
           '((a on table) (b on table)))

(A B) 

> (setq s
   '((a on table) (b on c) (c on table) (d on a)))
((a on table) (b on c) (c on table) (d on a))

> (all-blocks s)
(b c a d)

> (top-free-blocks s)
(b d)

(defun all-objects (state)
  (cond
   ((null state) nil)
   (t (union (remove 'on (car state))
             (all-objects (cdr state)))))
  )

(defun all-blocks (state)
  (remove 'table (all-objects state)))

(defun top-free-blocks
  (state)
  (let ((blocks (all-blocks state)))
    (dolist
        (x state)
      (if (not (eq 'table (third x)))
          (setq blocks (remove (third x) blocks))))
    blocks))


generated through LaTeX2HTML. M.Inaba 平成18年5月6日