Skip to main content

Librería de algoritmos genéticos adaptativos para problemas de optimización

Project description

Genetic Algorithm Library

PyPI version Python 3.6+ License: MIT

Overview

Genetic Algorithm Library is a robust Python library implementing adaptive genetic algorithms for optimization problems. It provides a flexible framework for solving complex problems through evolutionary computing techniques.

Features

  • Population Initialization: Create diverse initial populations with various strategies
  • Multiple Selection Methods: Tournament, Roulette Wheel, and Rank-based selection
  • Diverse Crossover Operations: Single-point, Two-point, and Uniform crossover
  • Adaptive Mutation: Automatically adjusts mutation rates for better convergence
  • Visualization Tools: Plot evolution and convergence metrics
  • Easy-to-use API: Simple interface for quick integration

Installation

pip install genetic-algorithm-library

Quick Start

from genetic_algorithm import run_genetic_algorithm

# Define a simple objective function (maximizing)
def objective_function(x):
    return -(x[0]**2 + x[1]**2)  # Maximize negative of sum of squares

# Run the genetic algorithm
result = run_genetic_algorithm(
    objective_function=objective_function,
    gene_length=2,               # 2 parameters to optimize
    bounds=(-10, 10),            # Search bounds
    pop_size=100,                # Population size
    num_generations=50,          # Number of generations
    selection_type="tournament", # Selection method
    adaptive=True                # Enable adaptive mutation
)

# Display results
print(f"Best solution: {result['best_individual']}")
print(f"Best fitness: {result['best_fitness']}")

# Plot the evolution
from genetic_algorithm import plot_evolution
plot_evolution(result['history'])

Advanced Usage

import numpy as np
from genetic_algorithm import (
    create_population,
    fitness_function,
    selection,
    crossover,
    mutation
)

# Create initial population
population = create_population(size=50, gene_length=5, min_val=-5, max_val=5)

# Custom fitness function
def my_objective(x):
    return np.sin(x[0]) + np.cos(x[1]) + x[2]**2 - x[3] + x[4]

# Manual iteration
for generation in range(100):
    # Evaluate fitness
    fitness_values = np.array([fitness_function(ind, my_objective) for ind in population])
    
    # Select parents
    parents = selection(population, fitness_values, num_parents=25, selection_type="rank")
    
    # Create offspring through crossover
    offspring = crossover(parents, offspring_size=(25, 5), crossover_type="two_point")
    
    # Apply mutation
    offspring = mutation(offspring, mutation_rate=0.05, mutation_type="gaussian", min_val=-5, max_val=5)
    
    # Create new population with elitism (keeping the best individual)
    best_idx = np.argmax(fitness_values)
    population = np.vstack([population[best_idx:best_idx+1], parents[:-1], offspring])

Documentation

For complete documentation, visit our GitHub Wiki.

Contributors

  • Julian Lara
  • Johan Rojas

License

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

Citation

If you use this library in your research, please cite:

@software{genetic_algorithm_library,
  author = {Lara, Julian and Rojas, Johan},
  title = {Genetic Algorithm Library},
  url = {https://github.com/Zaxazgames1/genetic-algorithm-library},
  version = {0.1.0},
  year = {2025},
}

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

genetic_algorithm_library-0.1.0.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

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

genetic_algorithm_library-0.1.0-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for genetic_algorithm_library-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5149ba716294351e267eed92511e8f8b06fd5c7301088face275117210286ae8
MD5 bae9e9ccbb5f2d661b8bd8a04bdc31fa
BLAKE2b-256 23e959091840d76b1a96f999ff16bc65ffaaab855869cb3ddc41165c34574c1e

See more details on using hashes here.

File details

Details for the file genetic_algorithm_library-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for genetic_algorithm_library-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4ff5638bfcec4271a45e27750321dc82800aa2869dbba452eb4340b65c7d0634
MD5 8c532eb70eac3b8b2f93c3b0586f89bf
BLAKE2b-256 d4c1ecdc5d07382e40a5e9119d7c8c59c82b35ea4c8278b90547823a7e4ba4b0

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