Metadata-Version: 2.4
Name: genealgolib
Version: 0.1.0
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Rust
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Dist: numpy ; extra == 'dev'
Requires-Dist: pytest ; extra == 'dev'
Provides-Extra: dev
License-File: LICENSE
Summary: A high-performance genetic algorithm library implemented in Rust with Python bindings
Keywords: genetic-algorithm,optimization,rust,performance
Author-email: Arun Hariharan <r.arunhariharan@gmail.com>
License: MIT
Requires-Python: >=3.8
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Homepage, https://github.com/SunOrangeBurger/genealgolib
Project-URL: Issues, https://github.com/SunOrangeBurger/genealgolib/issues
Project-URL: Repository, https://github.com/SunOrangeBurger/genealgolib

# GeneAlgoLib

A blazingly fast genetic algorithm library implemented in Rust with Python bindings via PyO3.

## Features

- **High Performance**: Rust implementation provides significant speedup over pure Python/NumPy implementations
- **Simple API**: Easy-to-use Python interface
- **Tournament Selection**: Efficient selection mechanism with configurable tournament size
- **Elitism**: Preserves best individuals across generations
- **Configurable**: Adjustable population size, mutation rate, and gene count

## Installation

```bash
pip install genealgolib
```

## Quick Start

```python
import numpy as np
from fast_ga import GeneticAlgorithm

# Initialize GA
ga = GeneticAlgorithm(
    pop_size=1000,      # Population size
    num_genes=10,       # Number of genes per individual
    mutation_rate=0.05  # Mutation probability
)

# Evolution loop
for generation in range(100):
    # Get current population
    population = ga.get_population()
    
    # Calculate fitness scores (example: sum to 10.0)
    sums = np.sum(population, axis=1)
    fitness_scores = 1.0 / (np.abs(10.0 - sums) + 1e-6)
    
    # Evolve to next generation
    ga.evolve(fitness_scores)

# Get final population
final_pop = ga.get_population()
```

## Performance

GeneAlgoLib significantly outperforms highly optimized NumPy implementations:

- **Average Speedup**: 2-5x faster than vectorized NumPy
- **Scales Well**: Better performance with larger populations
- **Memory Efficient**: Optimized memory usage in Rust

## API Reference

### `GeneticAlgorithm(pop_size, num_genes, mutation_rate)`

Initialize a genetic algorithm instance.

**Parameters:**
- `pop_size` (int): Number of individuals in the population
- `num_genes` (int): Number of genes per individual
- `mutation_rate` (float): Probability of mutation (0.0 to 1.0)

### `get_population()`

Returns the current population as a NumPy array of shape `(pop_size, num_genes)`.

### `evolve(fitness_scores)`

Evolve the population to the next generation.

**Parameters:**
- `fitness_scores` (np.ndarray): 1D array of fitness scores for each individual

## License

MIT License

## Contributing

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

