next up previous
Next: 8.1 3つの積み木の場合の縦型・横型探索 Up: ソフトウェア特論 講義資料 ロボットのソフトウェア Previous: 7 迷路の問題

8 積み木の問題

積み木の世界の問題は同様に以下のように書くことができます. blockworld-nodeのstateを比較する手続きとして :node=メソッドに,集合のexorを使えば 状態記述内の記述子の順番が入れ替わっていても 問題なくなります.

(defclass blockworld-graph
  :super graph
  :slots
  (blocks)
  )

(defclass blockworld-node
  :super node
  :slots (state)
  )

(defun set^ (a b &key (test #'eq))
  (cond
   ((null a) b)
   ((member (car a) b :test test)
    (set^ (cdr a) (remove (car a) b :test test)
          :test test))
   (t (cons (car a) (set^ (cdr a) b :test test)))))

(defun blocks-state= (a b)
  (null (set^ a b :test #'equal)))

(defmethod blockworld-node
  (:init (&rest args &key ((:state s))
      &allow-other-keys)
         (send-super-lexpr :init args)
         (setq state s)
         self)
  (:state () state)
  (:node= (x)
          (blocks-state= state (send x :state)))
  (:distance (n)
             1
             )
  (:all-blocks
   nil
   (mapcar #'car state))
  )




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