pathfinding3d.core.heap module

Simple heap with ordering and removal. Inspired from https://github.com/brean/python-pathfinding/pull/54 Original author: https://github.com/peterchenadded

class pathfinding3d.core.heap.SimpleHeap(node, grid)[source]

Bases: object

A simple implementation of a heap data structure optimized for pathfinding. It maintains an open list of nodes, a status for each node, and a function to retrieve nodes.

Parameters:
__init__(node, grid)[source]

Initializes the SimpleHeap with a given node and grid.

Parameters:
  • node (GridNode) – The initial node to be added to the heap. This node should have an ‘f’ attribute representing its cost.

  • grid (Union[Grid, World]) – The grid in which the nodes are located.

_determine_node_retrieval_function()[source]

Determines the node retrieval function based on the type of grid.

Returns:

A function that takes a node tuple and returns the corresponding node.

Return type:

function

Raises:

ValueError – If the grid is not of type Grid or World.

_determine_node_function()[source]

Determines the node function based on the type of grid.

Returns:

A function that takes a node tuple and returns the corresponding node.

Return type:

function

Raises:

ValueError – If the grid is not of type Grid or World.

pop_node()[source]

Pops the node with the lowest cost from the heap.

Returns:

The node with the lowest cost.

Return type:

GridNode

push_node(node)[source]

Pushes a node to the heap.

Parameters:

node (GridNode) – The node to be pushed to the heap.

remove_node(node, old_f)[source]

Remove the node from the heap.

This just stores it in a set and we just ignore the node if it does get popped from the heap.

Parameters:
  • node (GridNode) – The node to be removed from the heap.

  • old_f (float) – The old cost of the node.