|
Aqui está o algoritmo para implementar o IDA*.
Procura A* de Aprofundamento Iterativo ( IDA* )
tree-ida*-search function (problem) Iterative Deepening Tree-A* Search.
dfs-contour function (
node problem f-limit) Devolve a solução e o novo limite f-cost.
;;; ida.lisp
;;;; Iterative Deepening A* (IDA*) Search
(defun tree-ida*-search (problem) "Árvore de Procura A* de Aprofunda
mento Iterativo" ;; O loop principal faz uma serie de f-cost-limites depth-first ;; procura até encontrar uma solução. Depois de cada procura o f-cost ;; limite é incrementado para o menor valor de f-cost encontrado &
nbsp; ;; excedendo o limite anterior. Nota que as variaveis aqui são ;; locais, não são estáticas. (setf (problem-iterative? problem) t) (let* ((root (create-start-node pro
blem)) (f-limit (node-f-cost root)) (solution nil)) (loop (multiple-value-setq (solution f-limit) (DFS-contour root problem f-limit)) (dprint "DFS-contour retu
rnado" solution "em" f-limit) (if (not (null solution)) (RETURN solution)) (if (= f-limit infinity) (RETURN nil)))))
(defun DFS-contour (node problem f-limit) "Reto
rna a solução e um novo limite f-cost." (let ((next-f infinity)) (cond ((> (node-f-cost node) f-limit) (values nil (node-f-cost node))) ((go
al-test problem (node-state node)) (values node f-limit)) (t (for each s in (expand node problem) do (multiple-value-bind (solution new-f) (DFS-contour s problem f-limit)
(if (not (null solution)) (RETURN-FROM DFS-contour (values solution f-limit))) (setq next-f (min next-f new-f)))) (values nil next-f)))))
|
|