No project description provided
Project description
pymoors
Overview
pymoors is the python implementation of the moo-rs project. It's an extension crate (via pyo3) exposing moors algorithms with a Pythonic API
Inspired by the amazing Python project pymoo, pymoors delivers both the speed of Rust and the ease-of-use of Python.
Installation
pip install pymoors
Quickstart
import numpy as np
from pymoors import (
Nsga2,
RandomSamplingBinary,
BitFlipMutation,
SinglePointBinaryCrossover,
ExactDuplicatesCleaner,
)
from pymoors.typing import TwoDArray
PROFITS = np.array([2, 3, 6, 1, 4])
QUALITIES = np.array([5, 2, 1, 6, 4])
WEIGHTS = np.array([2, 3, 6, 2, 3])
CAPACITY = 7
def knapsack_fitness(genes: TwoDArray) -> TwoDArray:
# Calculate total profit
profit_sum = np.sum(PROFITS * genes, axis=1, keepdims=True)
# Calculate total quality
quality_sum = np.sum(QUALITIES * genes, axis=1, keepdims=True)
# We want to maximize profit and quality,
# so in pymoors we minimize the negative values
f1 = -profit_sum
f2 = -quality_sum
return np.column_stack([f1, f2])
def knapsack_constraint(genes: TwoDArray) -> TwoDArray:
# Calculate total weight
weight_sum = np.sum(WEIGHTS * genes, axis=1, keepdims=True)
# Inequality constraint: weight_sum <= capacity
return weight_sum - CAPACITY
algorithm = Nsga2(
sampler=RandomSamplingBinary(),
crossover=SinglePointBinaryCrossover(),
mutation=BitFlipMutation(gene_mutation_rate=0.5),
fitness=knapsack_fitness,
constraints_fn=knapsack_constraint,
duplicates_cleaner=ExactDuplicatesCleaner(),
num_vars=5,
num_objectives=1,
num_constraints=1,
population_size=32,
num_offsprings=32,
num_iterations=10,
mutation_rate=0.1,
crossover_rate=0.9,
keep_infeasible=False,
)
algorithm.run()
pop = algorithm.population
# Get genes
>>> pop.genes
array([[1., 0., 0., 1., 1.],
[0., 1., 0., 0., 1.],
[1., 1., 0., 1., 0.],
...])
# Get fitness
>>> pop.fitness
array([[ -7., -15.],
[ -7., -6.],
[ -6., -13.],
...])
# Get constraints_fn evaluation
>>> pop.constraints_fn
array([[ 0.],
[-1.],
[ 0.],
...])
# Get rank
>>> pop.rank
array([0, 1, 1, 2, ...], dtype=uint64)
# Get best individuals
>>> pop.best
[<pymoors.schemas.Individual object at 0x...>]
>>> pop.best[0].genes
array([1., 0., 0., 1., 1.])
>>> pop.best[0].fitness
array([ -7., -15.])
>>> pop.best[0].constraints_fn
array([0.])
In this small example, the algorithm finds a single solution on the Pareto front: selecting the items (A, D, E), with a profit of 7 and a quality of 15. This means there is no other combination that can match or exceed both objectives without exceeding the knapsack capacity (7).
Once the algorithm finishes, it stores a population attribute that contains all the individuals evaluated during the search.
Contributing
Contributions welcome! Please read the contribution guide and open issues or PRs in the relevant crate’s repository
License
This project is licensed under the MIT License.
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 Distributions
Built Distributions
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 pymoors-0.2.6-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: pymoors-0.2.6-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 812.5 kB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ab1941c2210ec75bf4cd8605af7415ea1841a30bb9a2d583e7d1de720e9369a2
|
|
| MD5 |
fecd400c294eadcac1ef5748f35944e8
|
|
| BLAKE2b-256 |
21bc1bd26a6349e5d9a18ebdc038956a36014118ef1a5b92236151c714913235
|
File details
Details for the file pymoors-0.2.6-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: pymoors-0.2.6-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.13, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c98e0631571d79f43bfd3d0bb01aceea553f240e2a4dcf261e818596e587032
|
|
| MD5 |
ae04d8c51a5caad6a0ed44b0f79ba31f
|
|
| BLAKE2b-256 |
2b8f72ffdb397b7cd5252418529399f0dd4000cfcdbb137972648929adb41d38
|
File details
Details for the file pymoors-0.2.6-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: pymoors-0.2.6-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 999.2 kB
- Tags: CPython 3.13, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
307175a21c62f1fd407092e83e8e2f142de406ed4a382e9afa3b1e42c0e9bcf6
|
|
| MD5 |
597921e3646caa201686d1cc1a33c92e
|
|
| BLAKE2b-256 |
37c4bd6e142811cfafe33ec59a1b643e0a53f883cc0a1b758d84ec0e718fd42c
|
File details
Details for the file pymoors-0.2.6-cp313-cp313-macosx_11_0_arm64.whl.
File metadata
- Download URL: pymoors-0.2.6-cp313-cp313-macosx_11_0_arm64.whl
- Upload date:
- Size: 842.5 kB
- Tags: CPython 3.13, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4124d0d5d7f7817587ee3a9b8990ed0e7eed7ffefb2e921cd356d79f18738117
|
|
| MD5 |
10aa2f17d9d2b69499bead85361954f2
|
|
| BLAKE2b-256 |
8b5e03e6b80d797fc5c5d5f50b6f962c8d518723b620ff505bc8c79017e00be4
|
File details
Details for the file pymoors-0.2.6-cp313-cp313-macosx_10_12_x86_64.whl.
File metadata
- Download URL: pymoors-0.2.6-cp313-cp313-macosx_10_12_x86_64.whl
- Upload date:
- Size: 973.7 kB
- Tags: CPython 3.13, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
171e4d689bb8ceca08daf283cadea7f4ef742761142f7b59230d8f13158d6828
|
|
| MD5 |
ec824141e81b164b6728d1aa6f82ac18
|
|
| BLAKE2b-256 |
bf4efe97e727f6cd7865819a0fff58072225fdb376845ae3380bfff45db101ea
|
File details
Details for the file pymoors-0.2.6-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: pymoors-0.2.6-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 812.9 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b793656e7aea939aa832b01ec512b67a371b3b819f086e9fff6c2a529dc90c1f
|
|
| MD5 |
92a1c713d663f42e24bf6758ed5d9510
|
|
| BLAKE2b-256 |
11fc926969fc067db98e270c2b5e8401f7bc0530499db4227f0ea15b838c4cd5
|
File details
Details for the file pymoors-0.2.6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: pymoors-0.2.6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
34bf18812672c0ac6af3ef570d2901b16a0a80f7a8b57e24089cc3bae424735c
|
|
| MD5 |
4734e08f5a6de2979df15035fe21d462
|
|
| BLAKE2b-256 |
b5f8bb54c27a02020ed24695381fd0e75369866085ea951872a436ffbcc8a927
|
File details
Details for the file pymoors-0.2.6-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: pymoors-0.2.6-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 999.9 kB
- Tags: CPython 3.12, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ec9a33fdbfb4c8ada75ef9bbf27e4dc8bd288c63dd50460e829a25a4ae3880d
|
|
| MD5 |
5e17504ec35e7fce291c15a0a82f8028
|
|
| BLAKE2b-256 |
3942123115704eb8e867bfb32b7c43eb10de1c9b5b975e9668b4a70ee1e1822f
|
File details
Details for the file pymoors-0.2.6-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: pymoors-0.2.6-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 842.7 kB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5445893cd4f97e066c0cdcbfd92be4b002508a367b0abb6dbe1900e39f30496c
|
|
| MD5 |
f153a3609e66b8aeea196dcf7c5af452
|
|
| BLAKE2b-256 |
b691ab644bb4f985cfe855e9bfbfa65e409da80d4861f0ccaca2622301d945c3
|
File details
Details for the file pymoors-0.2.6-cp312-cp312-macosx_10_12_x86_64.whl.
File metadata
- Download URL: pymoors-0.2.6-cp312-cp312-macosx_10_12_x86_64.whl
- Upload date:
- Size: 974.2 kB
- Tags: CPython 3.12, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8c3b38c4b6ebacc0086e5348b61290cf6c43bcd36c7bbdb9babd626046492d33
|
|
| MD5 |
3a314fcd0e9e4212fa24c969f0a2a5ee
|
|
| BLAKE2b-256 |
0509c158bd73846c6b3184dd346dc3e8e0227e3a44c2be1f1302f80a245500ff
|
File details
Details for the file pymoors-0.2.6-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: pymoors-0.2.6-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 811.6 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aa04bbd242b97ff509d20cb6e01cebe8434584fcbfd82ab7ec4fbc10441a92e2
|
|
| MD5 |
4ef354893cc1bbd6e47d9d4beee43b0d
|
|
| BLAKE2b-256 |
f1d020aea0ef7554d087f04e2fb3e42dc9440b50cf82a9a4972f85410fe38361
|
File details
Details for the file pymoors-0.2.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: pymoors-0.2.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e7e6a84e88e89b793876f5efa5cbe5ca1b9372bbde045dd238a5d4218435d397
|
|
| MD5 |
b260396b9d5371f2124aae576af520fe
|
|
| BLAKE2b-256 |
2cba0210840044d460e7065e74be7ac9b37602820736480849cdebef1b2f9c46
|
File details
Details for the file pymoors-0.2.6-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: pymoors-0.2.6-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 1.0 MB
- Tags: CPython 3.11, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1b60a968bb7d0938529f245a1c94623ec1cdcfde92667958528aaa1cd3eca52d
|
|
| MD5 |
6da54bf766b1c578719fda26ddb1bdc7
|
|
| BLAKE2b-256 |
5e6074d66a3fade7b2a35836bd04800aef66947c19937315ca1d9b247473f14c
|
File details
Details for the file pymoors-0.2.6-cp311-cp311-macosx_11_0_arm64.whl.
File metadata
- Download URL: pymoors-0.2.6-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 854.6 kB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a2fac4f8f02a4502de77b21a9ab75ca7d22c020053fd857883132f574881774d
|
|
| MD5 |
72f08762c8d08391fe75229dd825c560
|
|
| BLAKE2b-256 |
9ca45f682961868d864087726a247faeafb33beccf3931da2e5cbca77cc99074
|
File details
Details for the file pymoors-0.2.6-cp311-cp311-macosx_10_12_x86_64.whl.
File metadata
- Download URL: pymoors-0.2.6-cp311-cp311-macosx_10_12_x86_64.whl
- Upload date:
- Size: 978.0 kB
- Tags: CPython 3.11, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e2b8aed724607df86f88c6fb9cad3c8cf441aa34f89293add8b98881e15de0ae
|
|
| MD5 |
b1802e2eb2f52069d7ba2eb01986be39
|
|
| BLAKE2b-256 |
c30a6a0decfcd87043986ea71b43c9eb7c271fd2d82d0734add406c0f9b0cb0e
|
File details
Details for the file pymoors-0.2.6-cp310-cp310-win_amd64.whl.
File metadata
- Download URL: pymoors-0.2.6-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 812.7 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
61731806fe24be5d65edcc44bc888787bd3e3c01e30069279cda83a01b1ac3db
|
|
| MD5 |
09f72cf2fa1064a952eb81c764a8e6ad
|
|
| BLAKE2b-256 |
e717a3b93a2e3dc286afbab9d4c7dca3a96430feb9c60018be003ef43a78d7a7
|
File details
Details for the file pymoors-0.2.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: pymoors-0.2.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4fc98fe86952aaa24c49322c9a8150d5563e1176dcea206cf16262579eaf74b5
|
|
| MD5 |
64aa17c99444adde21fa7ffd49ada840
|
|
| BLAKE2b-256 |
ff00878f393a71449e5962043e6a4e448cbb74fc61e07af7bf150fb8efc0c4df
|
File details
Details for the file pymoors-0.2.6-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: pymoors-0.2.6-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 1.0 MB
- Tags: CPython 3.10, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ef5067cf9287d16cae2da20c74279c3f7f6075fb6676b937a0f521f1bc7d886
|
|
| MD5 |
dfb19712ecf6759137f2a2c2cf574f33
|
|
| BLAKE2b-256 |
1bf468749dcba2b60431cb869f3b6a9329ca18113155e1a7718f41adc86673f2
|
File details
Details for the file pymoors-0.2.6-cp310-cp310-macosx_11_0_arm64.whl.
File metadata
- Download URL: pymoors-0.2.6-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 854.8 kB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b9300f76748570e2661a10664e0f4443f3594bd65d8f020aca66d2d38e1cf79a
|
|
| MD5 |
a4909ced1288bda755e793171733b867
|
|
| BLAKE2b-256 |
b753fe116e37100f85e95e257fa55979519d6dc83fb6282dc81acb668652f7e6
|
File details
Details for the file pymoors-0.2.6-cp310-cp310-macosx_10_12_x86_64.whl.
File metadata
- Download URL: pymoors-0.2.6-cp310-cp310-macosx_10_12_x86_64.whl
- Upload date:
- Size: 978.3 kB
- Tags: CPython 3.10, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a3d2ad963bb9dfdcd55f2171d522b83ff3a3764c4ed08194680c006258c3084
|
|
| MD5 |
9ce6990bd041970fe7b217119ae37318
|
|
| BLAKE2b-256 |
adf09fa17cb1f1f695071338bdf7ee1c1c898ecb3d6de70b74785576704acda9
|