A comprehensive collection of Python implementations for classic algorithms, AI techniques, and programming utilities.
This repository contains:
- Maze Solving Algorithms: Several versions of maze solvers using search algorithms like BFS and DFS
- Sorting Algorithms: Implementations of common sorting techniques
- Bubble Sort
- Insertion Sort
- Merge Sort
- Quick Sort
- Selection Sort
- Dynamic Programming: Knapsack problem solver
- File Processing: Utilities for reading and processing data files
Clone this repository:
git clone https://github.com/yourusername/Python_AI.git
cd Python_AI
Install dependencies:
pip install pillow # For maze visualization
The maze solver accepts text files where:
#
represents wallsA
represents the starting pointB
represents the goal
from maze.maze_solver import Maze
# Load and solve a maze
maze = Maze("maze.txt")
maze.solve(algorithm="dfs") # or "bfs"
maze.print()
maze.output_image("solution.png", show_solution=True)
This will generate a solution visualization as an image.
Run any of the sorting algorithms interactively:
python sorting/bubble_sort.py
# Enter numbers separated by spaces when prompted
Or import and use the algorithms in your own code:
from sorting.bubble_sort import bubble
from sorting.quick_sort import quicksort
sorted_list = bubble([5, 3, 8, 2, 1])
print(sorted_list) # [1, 2, 3, 5, 8]
Solve the classic 0/1 Knapsack problem:
from sorting.Knapsack import knapsack_01
weights = [10, 20, 30]
values = [60, 100, 120]
capacity = 50
total_weight, total_value, num_items, selected = knapsack_01(weights, values, capacity)
print(f"Maximum value: {total_value}")
print(f"Selected items: {selected}")
Process CSV files:
python "Python read from file/readfile.py" "Python read from file/cereal.csv"
.
├── requirements.txt # Project dependencies
├── setup.py # Package setup configuration
├── README.md # This file
├── maze.txt # Sample maze input
├── maze*.png # Generated maze solutions
├── examples/ # Example scripts and demos
│ ├── knapsack_example.py
│ ├── maze_example.py
│ └── sorting_example.py
├── maze/ # Maze solving algorithms
│ ├── __init__.py
│ └── maze_solver.py
├── sorting/ # Sorting algorithms and optimization
│ ├── __init__.py
│ ├── bubble_sort.py # Bubble sort implementation
│ ├── insertion_sort.py # Insertion sort implementation
│ ├── Knapsack.py # Knapsack problem solver
│ ├── merge_sort.py # Merge sort implementation
│ ├── quick_sort.py # Quick sort implementation
│ └── Selection_sort.py # Selection sort implementation
├── tests/ # Unit tests
│ ├── test_file_utils.py
│ ├── test_knapsack.py
│ └── test_sorting.py
├── utils/ # Utility functions
│ ├── __init__.py
│ └── file_utils.py # File reading utilities
└── Python read from file/ # Legacy file utilities
├── cereal.csv # Sample CSV data
└── readfile.py # CSV file processor
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Added a changelog
- Implemented A* pathfinding algorithm for maze solving
- Added PriorityQueueFrontier class for efficient node exploration
- Added maze visualization with PIL
- Implemented Manhattan distance heuristic
- Added support for visual maze solution output as PNG
- Added command-line interface for maze file input
- Type hints added for better code documentation
- Error handling for maze file loading and solving
- Solution path visualization with colored tiles
- Automatic file naming for multiple solution outputs
- Added proper cost tracking for A* algorithm
- Added comprehensive docstrings
- Added color configuration dictionary
- Optimized PriorityQueueFrontier using heapq
- Improved maze visualization configuration
- Enhanced error handling and messages
- Removed duplicate main block
- Improved state tracking in frontier