Skip to main content

A high-performance genetic algorithm library implemented in Rust with Python bindings

Project description

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

pip install genealgolib

Quick Start

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

genealgolib-0.1.0.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

genealgolib-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl (261.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

File details

Details for the file genealgolib-0.1.0.tar.gz.

File metadata

  • Download URL: genealgolib-0.1.0.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.13.1

File hashes

Hashes for genealgolib-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6108fe5cce4bcd119d23ef2dbbcf3a8794c3328f00c528495d7f92dd0d30f37d
MD5 b2b0bad26a3cdd8a57f83e3efe8cd5a5
BLAKE2b-256 6e6267421930dd4acaa3d855667e034eedbdd31d89cca69462affffb628d74cb

See more details on using hashes here.

File details

Details for the file genealgolib-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for genealgolib-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 8973348d9eab298b50d40a3dd1d2d1600c46732e4d0d36edbdb3c4002570c9de
MD5 a19e357429c2f43e75131f99dda4f8c3
BLAKE2b-256 dabdbb3df3ff6a6d4aadfaac49d824f5470f6ca9a0a7868a9c8a689a4b677ae4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page