Libreria de algoritmos geneticos flexible y extensible
Project description
EvoCore
Librería Python para construir y experimentar con algoritmos genéticos mediante un núcleo fijo y operadores intercambiables.
¿Qué es EvoCore?
EvoCore permite ejecutar algoritmos genéticos sin tocar el núcleo evolutivo. Los operadores de selección, cruce, mutación e inicialización se inyectan como dependencias, lo que hace que la librería sea fácil de extender y adaptar a cualquier problema.
¿Por que EvoCore?
Aqui Sergio explicara en el futuro que diferencia esta libreria del resto.
Instalación
Puede ser instalada desde pip.
En caso de querer instalar desde el repositorio:
- Python 3.10 or higher
- NumPy >= 1.26
Optional development dependencies (tests, documentation):
- pytest >= 8.0
- sphinx >= 7.0
- furo >= 2024.1.0
- numpydoc >= 1.8.0
- myst-parser >= 3.0.0
- build >= 1.2.0
git clone https://github.com/tu-usuario/evocore.git
cd evocore
python3 -m venv .venv
source .venv/bin/activate # Linux / macOS
.venv\Scripts\activate # Windows
pip install -e .[dev]
Uso rápido
El siguiente ejemplo resuelve el problema OneMax: maximizar el número de unos en un cromosoma binario.
import random
from evocore import GeneticAlgorithm, GeneticAlgorithmConfig, Individual
from evocore import TournamentSelection
from evocore import OnePointCrossover
from evocore import BitFlipMutation
from evocore import RandomBinaryInitializer
# Función de fitness: cuenta el número de unos
def onemax(solution, data=None):
return float(sum(solution))
# Configuración del algoritmo
config = GeneticAlgorithmConfig(
population_size=50,
generations=100,
crossover_rate=0.8,
mutation_rate=0.01,
elitism=2,
seed=42,
)
# Construcción del algoritmo con operadores intercambiables
ga = GeneticAlgorithm(
config=config,
initializer=RandomBinaryInitializer(chromosome_length=20),
selection=TournamentSelection(tournament_size=3),
crossover=OnePointCrossover(),
mutation=BitFlipMutation(mute_probability=0.1),
fitness_function=onemax,
)
# Ejecución
best, history = ga.run()
print(f"Mejor solución: {best.solution}")
print(f"Fitness: {best.fitness}")
print(f"Generaciones: {len(history.records)}")
Operadores disponibles
| Familia | Operador | Codificación |
|---|---|---|
| Selección | TournamentSelection |
Cualquiera |
| Selección | RouletteWheelSelection |
Cualquiera |
| Cruce | OnePointCrossover |
Binaria |
| Cruce | UniformCrossover |
Binaria |
| Mutación | BitFlipMutation |
Binaria |
| Inicialización | RandomBinaryInitializer |
Binaria |
Estructura del proyecto
src/evocore/
├── __init__.py ← public API
├── core/
│ ├── algorithm.py ← GeneticAlgorithm (evolutionary loop)
│ ├── config.py ← GeneticAlgorithmConfig
│ ├── individual.py ← Individual
│ ├── history.py ← History, GenerationRecord
│ └── population.py ← population utilities
├── operators/
│ ├── base.py ← GeneticOperator (abstract)
│ ├── selection/ ← 5 selection operators
│ ├── crossover/ ← 7 crossover operators
│ ├── mutation/ ← 5 mutation operators
│ └── initialization/ ← 3 initializers
├── encodings/
│ ├── base.py ← Encoding (abstract)
│ ├── binary.py
│ ├── real.py
│ └── permutation.py
├── metrics/
│ ├── base.py ← Metric (abstract)
│ ├── fitness_variance.py
│ ├── diversity.py
│ ├── stagnation.py
│ ├── mean_fitness.py
│ └── selection_pressure.py
├── gp/ ← Genetic Programming module
│ ├── node.py
│ ├── primitives.py
│ ├── adf.py
│ ├── individual.py
│ ├── evaluation.py
│ └── operators/
└── utils/
├── validation.py ← shared validation functions
└── random.py ← random chromosome generators
Tests
pytest -v
Documentación
file:///home/sergio/Escritorio/Uni/TFG/GA/docs/build/html/index.html
Estado del proyecto
Finalización de la etapa 1.0, en futuras versiones se planea apliar el modulo de programación genetica.
Licencia
MIT
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
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
File details
Details for the file evocore-0.1.0.tar.gz.
File metadata
- Download URL: evocore-0.1.0.tar.gz
- Upload date:
- Size: 49.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d47b5a173e281451f8252487c60b8490bb6242d27ebfced5ac181fe0d78e438a
|
|
| MD5 |
cdbdbae83aa9b643bca08246ba8da9fb
|
|
| BLAKE2b-256 |
134231d9c97f9e37cda0aaa6e12ec70d9950475fbc16241e42e75a916bcc3c21
|
File details
Details for the file evocore-0.1.0-py3-none-any.whl.
File metadata
- Download URL: evocore-0.1.0-py3-none-any.whl
- Upload date:
- Size: 72.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b0a6a2516d1e78ec02bc2209e06c36e51dcc24225cd2ec69a18c455d5850f5a
|
|
| MD5 |
785edf8902ea223ab060c331c2a5b972
|
|
| BLAKE2b-256 |
ca9d18c737270886ff0854f85c10233bb0b05f3a7f13ccb7d9240299773990de
|