{"id":19301267,"url":"https://github.com/fuglede/numberpartitioning","last_synced_at":"2025-04-22T10:32:28.924Z","repository":{"id":45316207,"uuid":"401029709","full_name":"fuglede/numberpartitioning","owner":"fuglede","description":"Pure Python solver for the multi-way partition problem","archived":false,"fork":false,"pushed_at":"2021-12-21T20:02:11.000Z","size":41,"stargazers_count":19,"open_issues_count":4,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-12T23:23:33.098Z","etag":null,"topics":["algorithms","combinatorial-optimization","hacktoberfest","karmarkar-karp","mathematical-optimization","number-partitioning","optimization","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fuglede.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-08-29T11:56:04.000Z","updated_at":"2024-06-04T14:43:48.000Z","dependencies_parsed_at":"2022-07-19T03:02:06.742Z","dependency_job_id":null,"html_url":"https://github.com/fuglede/numberpartitioning","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fuglede%2Fnumberpartitioning","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fuglede%2Fnumberpartitioning/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fuglede%2Fnumberpartitioning/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fuglede%2Fnumberpartitioning/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fuglede","download_url":"https://codeload.github.com/fuglede/numberpartitioning/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223893248,"owners_count":17220862,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithms","combinatorial-optimization","hacktoberfest","karmarkar-karp","mathematical-optimization","number-partitioning","optimization","python"],"created_at":"2024-11-09T23:17:23.178Z","updated_at":"2024-11-09T23:17:23.853Z","avatar_url":"https://github.com/fuglede.png","language":"Python","readme":"# Partition problem solvers in Python\r\n\r\nThis repository includes an implementation of the [Karmarkar--Karp algorithm](https://en.wikipedia.org/wiki/Largest_differencing_method) (also known as the largest differencing method) for the [multiway number partitioning optimization problem](https://en.wikipedia.org/wiki/Multiway_number_partitioning), as well as some greedy algorithms.\r\n\r\n## The problem\r\n\r\nConcretely, the problem we solve is the following: Suppose *S* is some collection of integers, and *k* is some positive integer, find a partition of *S* into *k* parts so that the sums of the integers in each part are as close as possible.\r\n\r\nThe objective function describing \"closeness\" is usually taken to be the difference between the largest and smallest sum among all parts. The optimization version is NP-hard, and the bundled algorithm only aims to provide a good solution in short time. This also means that they can be useful for other objective functions such as, say, the variance of all sums.\r\n\r\n## Installation\r\n\r\nThe package is available from [PyPI](https://pypi.org/project/numberpartitioning/):\r\n\r\n```sh\r\npip install numberpartitioning\r\n```\r\n\r\nIt can also be obtained from [conda-forge](https://anaconda.org/conda-forge/numberpartitioning):\r\n\r\n```sh\r\nmamba install -c conda-forge numberpartitioning\r\n```\r\n\r\n## Examples\r\n\r\nSuppose we want to split the collection `[4, 6, 7, 5, 8]` into three parts. We can achieve that as follows:\r\n\r\n```python\r\nfrom numberpartitioning import karmarkar_karp\r\nnumbers = [4, 6, 7, 5, 8]\r\nresult = karmarkar_karp(numbers, num_parts=3)\r\n```\r\n\r\nHere, `result.partition` becomes `[[8], [4, 7], [5, 6]]`, and `result.sizes` are the sums of each part, `[8, 11, 11]`. This happens to be optimal.\r\n\r\nAs noted [on Wikipedia](https://en.wikipedia.org/wiki/Largest_differencing_method), an example where this approach does not give the optimal result is the following:\r\n\r\n```python\r\nfrom numberpartitioning import karmarkar_karp\r\nnumbers = [5, 5, 5, 4, 4, 3, 3, 1]\r\nresult = karmarkar_karp(numbers, num_parts=3)\r\n```\r\n\r\nHere, `result.sizes` is `[9, 10, 11]` but it is possible to achieve a solution in which the sums of each part is 10.\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffuglede%2Fnumberpartitioning","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffuglede%2Fnumberpartitioning","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffuglede%2Fnumberpartitioning/lists"}