next up previous
Next: 3.3 ヒューリスティック関数 Up: 3 ヒューリスティックな探索法 Previous: 3.1 頂点の座標空間

3.2 頂点間の距離とパスの長さ

頂点間の距離は頂点を引数として以下の関数で求めることができます.

(defun coordinates (v) (get v 'coordinates))

(defun straight-distance (node-1 node-2)
  (distance (coordinates node-1) (coordinates node-2)))

> (straight-distance 's 'd)
3.4641016151377544

> (straight-distance 's 'a)
4.358898943540674
という具合に求められます. パスの長さは,

(defun path-length (path)
  (if (null (rest path)) 0
    (+ (straight-distance (first path) (second path))
       (path-length (rest path)))))
と定義できます.

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