Beginner-friendly AI search algorithms: BFS, DFS, A*, Minimax, CSP, ANN and more
Project description
aialgos 🤖
A beginner-friendly Python library covering the core AI algorithms taught in university courses.
Zero dependencies — pure Python, works everywhere.
pip install aialgos
What's inside?
| Module | Algorithms |
|---|---|
uninformed |
BFS, DFS, DLS, UCS, Bidirectional BFS |
informed |
Greedy Best-First, A* |
adversarial |
Minimax, Alpha-Beta Pruning |
beyond_classical |
Hill Climbing, Steepest-Ascent HC, Simulated Annealing, Local Beam Search |
csp |
Backtracking, Forward Checking, MRV, LCV, Degree Heuristic |
ann |
Feedforward Neural Network (from scratch) |
Quick Start
Uninformed Search (BFS)
from aialgos import bfs
graph = {
'A': ['B', 'C'],
'B': ['D', 'E'],
'C': ['F'],
'D': [], 'E': [], 'F': []
}
path = bfs(graph, start='A', goal='E')
print(path) # ['A', 'B', 'E']
Informed Search (A*)
from aialgos import a_star
graph = {
'A': [('B', 1), ('C', 4)],
'B': [('D', 5)],
'C': [('D', 1)],
'D': []
}
heuristic = {'A': 4, 'B': 3, 'C': 1, 'D': 0}
path, cost = a_star(graph, 'A', 'D', heuristic)
print(path, cost) # ['A', 'C', 'D'] 5
Adversarial Search (Minimax)
from aialgos import minimax
# Game tree as nested lists (leaf values: positive=MAX wins)
tree = {'A': ['B', 'C'], 'B': ['D', 'E'], 'C': ['F', 'G'],
'D': 3, 'E': 5, 'F': 2, 'G': 9}
def get_children(node):
v = tree[node]
return v if isinstance(v, list) else []
def evaluate(node):
v = tree[node]
return v if isinstance(v, int) else 0
score = minimax('A', depth=0, is_maximizing=True,
get_children=get_children, evaluate=evaluate, max_depth=2)
print(score) # 5
Neural Network (ANN)
from aialgos import NeuralNetwork
# Solve XOR problem
nn = NeuralNetwork([2, 4, 1], learning_rate=0.1)
X = [[0,0], [0,1], [1,0], [1,1]]
y = [[0], [1], [1], [0]]
nn.train(X, y, epochs=2000, print_every=500)
print(nn.predict([0, 1])) # ≈ [0.95]
print(nn.predict([0, 0])) # ≈ [0.05]
CSP (Map Coloring)
from aialgos import forward_checking
variables = ['WA', 'NT', 'SA', 'Q', 'NSW', 'V']
domains = {v: ['Red', 'Green', 'Blue'] for v in variables}
def diff(a, b): return a != b
constraints_map = {
'WA': [('NT', diff), ('SA', diff)],
'NT': [('WA', diff), ('SA', diff), ('Q', diff)],
'SA': [('WA', diff), ('NT', diff), ('Q', diff), ('NSW', diff), ('V', diff)],
'Q': [('NT', diff), ('SA', diff), ('NSW', diff)],
'NSW': [('Q', diff), ('SA', diff), ('V', diff)],
'V': [('SA', diff), ('NSW', diff)],
}
result = forward_checking(variables, domains, constraints_map)
print(result) # {'WA': 'Red', 'NT': 'Green', 'SA': 'Blue', ...}
Installation
pip install aialgos
Or install from source:
git clone https://github.com/mQasim04/aialgos
cd aialgos
pip install -e .
Similar Libraries
| Library | Focus |
|---|---|
aima3 |
Textbook algorithms (Russell & Norvig) - less beginner-friendly |
networkx |
Graph algorithms only |
python-constraint |
CSP only |
scikit-learn |
ML — no search algorithms |
| aialgos | All-in-one, beginner-focused, zero dependencies |
License
MIT — free to use in education and projects.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
aialgos-0.1.0.tar.gz
(15.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
aialgos-0.1.0-py3-none-any.whl
(16.1 kB
view details)
File details
Details for the file aialgos-0.1.0.tar.gz.
File metadata
- Download URL: aialgos-0.1.0.tar.gz
- Upload date:
- Size: 15.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6baf1863eb9b67ead0a4c12fa6d41c595ceae9dc7e389aabb8da295678c5a2c8
|
|
| MD5 |
024a8950233aba005a57a694c1d1542a
|
|
| BLAKE2b-256 |
5f7d4f185cef8848871b6175d07616eee8a4ca6070e5a0b2f18b87712c6ed534
|
File details
Details for the file aialgos-0.1.0-py3-none-any.whl.
File metadata
- Download URL: aialgos-0.1.0-py3-none-any.whl
- Upload date:
- Size: 16.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
73b46d1d85be9f457b8ffb4bb4c127202022be5e9dcb31874d0bd438c74574d3
|
|
| MD5 |
b1388c660956f7a034d02fa2e9181845
|
|
| BLAKE2b-256 |
f4cb484f91cf9e716b52343aef0537794ffede38e86b1bce48bd2a7170edf923
|