Skip to main content
. 2022 Jul 26;22(15):5569. doi: 10.3390/s22155569
Algorithm 1: A* shortest path Algorithm with Greedy heuristic
  • Require: 

    maze, start and goal

  • Ensure: 

    startgoal

  • 1:

    procedureA_Star(maze,start,goal)                                                                                                   ▷ returns path

  • 2:

        Add start to priorityQueue

  • 3:

        searchedNodesϕ

  • 4:

     

  • 5:

        while priorityQueueϕ do

  • 6:

            if currentNodegoal then

  • 7:

               return path

  • 8:

            end if

  • 9:

            Remove currentNode from priorityQueue

  • 10:

          Add currentNode to searchedNodes

  • 11:

     

  • 12:

          childneighbor.currentNode

  • 13:

     

  • 14:

          for each child in neighbor do

  • 15:

               if child is in searchedNodes then

  • 16:

                   continue

  • 17:

               end if

  • 18:

               child.gcurrentNode.g+d    ▷d is distance between currentNode and child, which is 1 in this case

  • 19:

     

  • 20:

               child.h distance from child to goal

  • 21:

     

  • 22:

               child.fchild.g+child.h       ▷h is calculated using heuristic function, Euclidean distance in this case

  • 23:

     

  • 24:

               if child.position is in priorityQueue then

  • 25:

                   if child.g>priorityqueue.child.position.g then

  • 26:

                       continue

  • 27:

                   end if

  • 28:

               end if

  • 29:

     

  • 30:

               Add child to priorityQueue

  • 31:

            end for

  • 32:

        end while

  • 33:

     

  • 34:

        return failure                              ▷ If priorityQueue is ϕ

  • 35:

    end procedure