Skip to content

NoolAngelo/Python_AI

Repository files navigation

Python AI & Algorithms Collection

A comprehensive collection of Python implementations for classic algorithms, AI techniques, and programming utilities.

🚀 Features

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

📋 Table of Contents

🔧 Installation

Clone this repository:

git clone https://github.com/yourusername/Python_AI.git
cd Python_AI

Install dependencies:

pip install pillow  # For maze visualization

💻 Usage

Maze Solver

The maze solver accepts text files where:

  • # represents walls
  • A represents the starting point
  • B 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.

Sorting Algorithms

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]

Knapsack Problem

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}")

File Processing

Process CSV files:

python "Python read from file/readfile.py" "Python read from file/cereal.csv"

📁 Project Structure

.
├── 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

👥 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

📝 Changelog

[1.0.2] - 2024-11-4

  • Added a changelog

[1.0.3] - Current

Added

  • 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

Technical

  • 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

[1.0.4] - Current

Added

  • Added proper cost tracking for A* algorithm
  • Added comprehensive docstrings
  • Added color configuration dictionary

Changed

  • Optimized PriorityQueueFrontier using heapq
  • Improved maze visualization configuration
  • Enhanced error handling and messages

Fixed

  • Removed duplicate main block
  • Improved state tracking in frontier

About

Python implementations for classic algorithms,AI techniques

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages