2016-12-07 18 views
0

に擬似コードを変換します。CLISP - 私は擬似コードが<a href="https://en.wikipedia.org/wiki/A*_search_algorithm" rel="nofollow noreferrer">here</a>を見つけることができますlispの</p> <p>にA *検索アルゴリズムを定義しようとしている実際のLispコード

これは私がこれまで持っているものです。

;;; A* 
(defun a* (problem) 
;;;;;;;;;;;;;;;;;;;;;;;;;;; cameFrom -> Parent do node 
;;;;;;;;;;;;;;;;;;;;;;;;;;; gScore -> node-g 
;;;;;;;;;;;;;;;;;;;;;;;;;;; fScore -> node-g + node-h   
    (setq closedSet '()) 
    (setq openSet (list (make-node :state (problem-initial-state problem)))) 
    (setq listaVizinhos '()) 

    (loop while(not(eq openSet nil)) 

     (setq tamanho_openS (list-length (openSet)))               ;        
     (setq current (nth 0 openSet))                   ; 
     (dotimes (i tamanho_openS)                    ;PARA ENCONTRAR O NODE COM MENOR FSCORE 
      (if (< (+ (node-g (nth i openSet)) (node-h (nth i openSet))) (+ (node-g current) (node-h current))) ;    CURRENT 
      (setq current (nth i openSet))))                 ; 

     (if (funcall (problem-fn-isGoal problem) (node-state current)) (return-from a* (solucao current)))  ; caso current seja solucao -> retorna-o para a funcao solucao (que cria a solucao pedida) 

     (remove current openSet) ; retira o curretn da lista dos abertos 
     (append (list(current)) closedSet) ; introduz curretn na lista dos fechados 

     (setf estadosVisinhos (nextStates (node-state current))) ; nextestates de current-state 
     (setf tamanho_estadosVizinhos (list-length (estadosVisinhos))) 

     (dotimes (i tamanho_estadosVizinhos)            ; 
      (setf visinho (make-node :parent current :state (nth i estadosVisinhos)))  ;PARA CRIAR LISTA COM TODOS NODES VIZINHOS DE CURRENT 
      (append (list(visinho)) listaVizinhos))           ;     LISTAVIZINHOS 

     (loop for vizinho in listaVizinhos do 
      (if (member vizinho closedSet) (continue)) 

      (setq tentative_gScore (+ (node-g current) (dist_between current vizinho))) 

      (if (not(member vizinho closedSet)) (append (list(vizinho)) openSet))   ; 
      (if (>= (tentative_gScore) (node-g vizinho)) (continue))      ; MAYBE CONDS AQUI 

      (setq (node-g vizinho) tentative_gScore) 
      (setq (node-f vizinho) (+ (node-g vizinho) (compute-heuristic (node-state vizinho)))) 
) 
) 

(return-from a* nil)) 

と私のノード構造は次のとおりです。私は他の機能を使用しますが、私はすでにテストされ、正しいきたものを、私の訳

;;; Definition of a search node 
;;; * parent - the parent node 
;;; * state - the state of the node 
;;; * f - estimate of the cost 
;;; * g - cost from the initial node to the current node 
;;; * h - estimate of the cost from the current node to the nearest goal 
(defstruct node 
    parent 
    state 
    f 
    g 
    h) 

私は構文エラーを取得しますが、私はどこかわからない私のコードをコンパイルしよう

...

EDIT: エラーメッセージ:

LOOP: illegal syntax near (setq tamanho_openS (list-length (openSet))) in loop (and then the terminal prints the entire loop) 
+0

1.インデントを修正してください(例:emacsを使用してコードを編集してください)。 2.エラーメッセージテキストを正確に貼り付けてください。 3.ローカル変数に 'setq'の代わりに' let'を使用してください。 – sds

答えて

2

あなたは「拡張」loopフォームを使用していますので、あなたは

(loop while ... 
    do ...) 

代わりの

0123を実行する必要があります

エラーが表示されます:whileの後にキーワードが必要です。本文の最初の文が見つかりました。

The LOOP Facilityをさらに詳しくチェックすることをおすすめします。

PS。 setqに設定する前に、letまたはloop,withを使用してローカル変数をバインドしてください。さもなければあなたの変数はグローバルスペシャルです。

PPS。コードを適切にインデントしてください。そのためにEmacsを使うことができます。

+0

は既に私の質問を編集しました!私はその感謝を試みます! – xicocana

+0

うん、おかげで、あなたのエラーで私の推測は正しかった、あなたはボディの前に 'do'が欠けている。 – sds

関連する問題

 関連する問題