Skip to main content

Basic implementation of a genetic algorithm (GA).

Project description

galgopy

PyPI - Status PyPI - Version PyPI - Python Version

galgopy title image.

A lightweight Python package providing a basic but flexible implementation of the Genetic Algorithm (GA) for optimization tasks. It can be easily integrated into other projects or extended with custom selection, crossover, and mutation strategies.

Installation

galgopy is available on PyPI:

pip install galgopy

Usage

Sphere Function Optimization example

import numpy as np

from galgopy.crossover import IntermediateRecombination
from galgopy.ga import GA
from galgopy.mutation import UniformMutation
from galgopy.selection import TournamentSelection

ga = GA(
    population_size=100,
    chromosome_size=2,
    gene_bounds=(-5.12, 5.12),
    fitness_func=lambda x: -np.sum(np.square(x)),
    mutation=UniformMutation(individual_rate=0.1, gene_bounds=(-5.12, 5.12)),
    crossover=IntermediateRecombination(),
    selection=TournamentSelection(),
)

# The course of 50 generations.
for _ in range(50):
    next(ga)

# Result
best_chromosome, _ = ga.best_chromosome()
print(
    f"Result:\t{best_chromosome}",
    "Global minimum:\t[0. 0.]",
    sep="\n",
)

More examples

More examples can be found in the examples directory.

License

This project is licensed under the MIT License.

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

galgopy-0.1.1.tar.gz (109.1 kB view details)

Uploaded Source

Built Distribution

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

galgopy-0.1.1-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file galgopy-0.1.1.tar.gz.

File metadata

  • Download URL: galgopy-0.1.1.tar.gz
  • Upload date:
  • Size: 109.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for galgopy-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8d25045e6556f3fea4e2129352bdde1ed2ad8e3a4d70233142bc21774e25fdcf
MD5 10385d9cceddd7125e060a7d0dfa735d
BLAKE2b-256 d54775fed9b612a2b1f4b4ead73f8838bb274bfea6c08128039d404211c58013

See more details on using hashes here.

Provenance

The following attestation bundles were made for galgopy-0.1.1.tar.gz:

Publisher: python-publish.yml on vec2pt/galgopy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file galgopy-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: galgopy-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 12.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for galgopy-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 64e8d0d3f82570e044c7580536882c051c8ab5f418e31ece20122245a102b847
MD5 29956657065aa17d7bffbebb0f81e7ba
BLAKE2b-256 a595b83e788301b521a1a3216826e5972c587584986ed7b65f62f6c4edf13c1b

See more details on using hashes here.

Provenance

The following attestation bundles were made for galgopy-0.1.1-py3-none-any.whl:

Publisher: python-publish.yml on vec2pt/galgopy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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