machine_learning.astar ====================== .. py:module:: machine_learning.astar .. autoapi-nested-parse:: The A* algorithm combines features of uniform-cost search and pure heuristic search to efficiently compute optimal solutions. The A* algorithm is a best-first search algorithm in which the cost associated with a node is f(n) = g(n) + h(n), where g(n) is the cost of the path from the initial state to node n and h(n) is the heuristic estimate or the cost or a path from node n to a goal. The A* algorithm introduces a heuristic into a regular graph-searching algorithm, essentially planning ahead at each step so a more optimal decision is made. For this reason, A* is known as an algorithm with brains. https://en.wikipedia.org/wiki/A*_search_algorithm Attributes ---------- .. autoapisummary:: machine_learning.astar.world Classes ------- .. autoapisummary:: machine_learning.astar.Cell machine_learning.astar.Gridworld Functions --------- .. autoapisummary:: machine_learning.astar.astar Module Contents --------------- .. py:class:: Cell Class cell represents a cell in the world which have the properties: position: represented by tuple of x and y coordinates initially set to (0,0). parent: Contains the parent cell object visited before we arrived at this cell. g, h, f: Parameters used when calling our heuristic function. .. py:method:: __eq__(cell) .. py:method:: showcell() .. py:attribute:: f :value: 0 .. py:attribute:: g :value: 0 .. py:attribute:: h :value: 0 .. py:attribute:: parent :value: None .. py:attribute:: position :value: (0, 0) .. py:class:: Gridworld(world_size=(5, 5)) Gridworld class represents the external world here a grid M*M matrix. world_size: create a numpy array with the given world_size default is 5. .. py:method:: get_neighbours(cell) Return the neighbours of cell .. py:method:: show() .. py:attribute:: w .. py:attribute:: world_x_limit :value: 5 .. py:attribute:: world_y_limit :value: 5 .. py:function:: astar(world, start, goal) Implementation of a start algorithm. world : Object of the world object. start : Object of the cell as start position. stop : Object of the cell as goal position. >>> p = Gridworld() >>> start = Cell() >>> start.position = (0,0) >>> goal = Cell() >>> goal.position = (4,4) >>> astar(p, start, goal) [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4)] .. py:data:: world