PythonRobotics icon indicating copy to clipboard operation
PythonRobotics copied to clipboard

Optimize D* Lite with heapq for O(log n) performance

Open TahaZahid05 opened this issue 11 months ago • 0 comments

Reference issue

Fixes #1333

What does this implement/fix?

This PR optimizes the D* Lite algorithm by replacing the list-based priority queue with a heapq-based implementation using lazy deletion.

Performance improvements:

  • Priority queue operations: O(n log n) → O(log n)
  • Node lookup: O(n) → O(1)

Changes:

  • Implement min-heap priority queue using heapq
  • Add lazy deletion pattern with entry_finder dictionary
  • Add __eq__ and __hash__ methods to Node class for proper dictionary operations
  • Add comprehensive docstrings to new priority queue methods
  • Update unit tests to verify path finding with dynamic obstacles

Compatibility:

  • Uses only standard library (heapq) - no new dependencies
  • Maintains identical algorithm behavior and visualization
  • All existing functionality preserved

Additional information

The optimization significantly improves scalability for larger grids and scenarios with frequent obstacle updates, while maintaining the exact same algorithm behavior and API.

CheckList

  • [x] Did you add an unittest for your new example or defect fix?
  • [ ] Did you add documents for your new example?
  • [x] All CIs are green? (You can check it after submitting)

TahaZahid05 avatar Dec 27 '25 16:12 TahaZahid05