Skip to content

Commit 56bc007

Browse files
committed
expose 2 function crossover and mutation , design for lib usable and make pypi export as pip , building wheel
1 parent afde0f0 commit 56bc007

14 files changed

Lines changed: 1081 additions & 226 deletions

File tree

.github/workflows/publish.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Publish to PyPI
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
release:
8+
types: [published]
9+
workflow_dispatch:
10+
11+
jobs:
12+
build_wheels:
13+
name: Build wheels (${{ matrix.os }})
14+
runs-on: ${{ matrix.os }}
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
os: [ubuntu-latest, macos-latest, windows-latest]
19+
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
24+
- name: Set up Python
25+
uses: actions/setup-python@v5
26+
with:
27+
python-version: "3.12"
28+
29+
- name: Build wheels
30+
uses: pypa/cibuildwheel@v2.19.2
31+
env:
32+
CIBW_BUILD: "cp38-* cp39-* cp310-* cp311-* cp312-*"
33+
CIBW_SKIP: "pp* *-musllinux_*"
34+
CIBW_TEST_COMMAND: >-
35+
python -c "import genetic_algorithm_lib as ga; cfg = ga.Config(); print(cfg)"
36+
37+
- name: Upload wheels
38+
uses: actions/upload-artifact@v4
39+
with:
40+
name: wheels-${{ matrix.os }}
41+
path: wheelhouse/*.whl
42+
43+
build_sdist:
44+
name: Build sdist
45+
runs-on: ubuntu-latest
46+
47+
steps:
48+
- name: Checkout
49+
uses: actions/checkout@v4
50+
51+
- name: Set up Python
52+
uses: actions/setup-python@v5
53+
with:
54+
python-version: "3.12"
55+
56+
- name: Build sdist
57+
run: |
58+
python -m pip install --upgrade pip
59+
python -m pip install build
60+
python -m build --sdist
61+
62+
- name: Upload sdist
63+
uses: actions/upload-artifact@v4
64+
with:
65+
name: sdist
66+
path: dist/*.tar.gz
67+
68+
publish:
69+
name: Publish
70+
needs: [build_wheels, build_sdist]
71+
runs-on: ubuntu-latest
72+
permissions:
73+
id-token: write
74+
contents: read
75+
76+
steps:
77+
- name: Download artifacts
78+
uses: actions/download-artifact@v4
79+
with:
80+
path: dist
81+
merge-multiple: true
82+
83+
- name: Publish to PyPI
84+
uses: pypa/gh-action-pypi-publish@release/v1
85+
with:
86+
packages-dir: dist

.github/workflows/wheels.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Build wheels
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: ["main"]
7+
workflow_dispatch:
8+
9+
jobs:
10+
build_wheels:
11+
name: Build wheels (${{ matrix.os }})
12+
runs-on: ${{ matrix.os }}
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
os: [ubuntu-latest, macos-latest, windows-latest]
17+
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
22+
- name: Set up Python
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: "3.12"
26+
27+
- name: Build wheels
28+
uses: pypa/cibuildwheel@v2.19.2
29+
env:
30+
# Keep the matrix explicit and predictable.
31+
CIBW_BUILD: "cp38-* cp39-* cp310-* cp311-* cp312-*"
32+
CIBW_SKIP: "pp* *-musllinux_*"
33+
CIBW_TEST_COMMAND: >-
34+
python -c "import genetic_algorithm_lib as ga; cfg = ga.Config(); print(cfg)"
35+
36+
- name: Upload wheels
37+
uses: actions/upload-artifact@v4
38+
with:
39+
name: wheels-${{ matrix.os }}
40+
path: wheelhouse/*.whl

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
build/
2+
.scikit-build/
3+
_skbuild/
4+
.venv/
25
__pycache__/
36
*.pyc
47
*.pyo
58
*.so
69
*.egg-info/
710
dist/
811
.eggs/
12+
.pytest_cache/
913
# Benchmark and test result files
1014
benchmark_results.*
1115
ga_results.txt

ARCHITECTURE.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,29 +117,27 @@ g++ myapp.cpp -o myapp -Ibuild/_deps/genetic_algorithm/include -Lbuild/lib -lgen
117117
### Python Usage (via pybind11)
118118

119119
```python
120-
import ga
120+
import genetic_algorithm_lib as ga
121121

122122
def sphere(x):
123123
return 1000.0 / (1.0 + sum(xi**2 for xi in x))
124124

125125
cfg = ga.Config()
126-
cfg.populationSize = 50
126+
cfg.population_size = 50
127127
cfg.generations = 100
128128
cfg.dimension = 10
129129
cfg.bounds = ga.Bounds(-5.12, 5.12)
130130

131131
alg = ga.GeneticAlgorithm(cfg)
132132
result = alg.run(sphere)
133133

134-
print(f"Best fitness: {result.bestFitness}")
135-
print(f"Best solution: {result.bestGenes}")
134+
print(f"Best fitness: {result.best_fitness}")
135+
print(f"Best solution: {result.best_genes}")
136136
```
137137

138138
**Setup:**
139139
```bash
140-
pip install pybind11
141-
cmake --build build
142-
export PYTHONPATH=$PWD/build/python:$PYTHONPATH
140+
pip install .
143141
python my_script.py
144142
```
145143

0 commit comments

Comments
 (0)