PythonRobotics
PythonRobotics copied to clipboard
Optimize D* Lite with heapq for O(log n) performance
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_finderdictionary - 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)