{"id":16568690,"url":"https://github.com/drupol/phpartition","last_synced_at":"2025-10-29T00:31:47.523Z","repository":{"id":56972711,"uuid":"76719043","full_name":"drupol/phpartition","owner":"drupol","description":"Partition problem for balanced arrays splitting made easy.","archived":false,"fork":false,"pushed_at":"2019-09-11T09:14:13.000Z","size":54,"stargazers_count":8,"open_issues_count":1,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-02-01T20:44:59.731Z","etag":null,"topics":["karmarkar","partition","partition-problem","php","subsets"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/drupol.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":null,"code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null},"funding":{"github":"drupol"}},"created_at":"2016-12-17T10:58:46.000Z","updated_at":"2021-04-29T06:31:02.000Z","dependencies_parsed_at":"2022-08-21T10:20:21.849Z","dependency_job_id":null,"html_url":"https://github.com/drupol/phpartition","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drupol%2Fphpartition","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drupol%2Fphpartition/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drupol%2Fphpartition/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drupol%2Fphpartition/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drupol","download_url":"https://codeload.github.com/drupol/phpartition/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238751200,"owners_count":19524536,"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":["karmarkar","partition","partition-problem","php","subsets"],"created_at":"2024-10-11T21:11:24.653Z","updated_at":"2025-10-29T00:31:47.157Z","avatar_url":"https://github.com/drupol.png","language":"PHP","funding_links":["https://github.com/sponsors/drupol"],"categories":[],"sub_categories":[],"readme":"## PHPartition\n[![Build Status](https://travis-ci.org/drupol/phpartition.svg?branch=master)](https://travis-ci.org/drupol/phpartition) [![Code Coverage](https://scrutinizer-ci.com/g/drupol/phpartition/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/drupol/phpartition/?branch=master) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/drupol/phpartition/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/drupol/phpartition/?branch=master) [![Dependency Status](https://www.versioneye.com/user/projects/58551f4d4d6466004c28cc8f/badge.svg?style=flat-square)](https://www.versioneye.com/user/projects/58551f4d4d6466004c28cc8f)\n\nIn number theory and computer science, the partition problem is the task of deciding whether a given multiset of items can be partitioned into multiple balanced subsets.\n\n## Requirements\n\n* PHP \u003e= 5.6,\n* (optional) [PHPUnit](https://phpunit.de/) to run tests.\n\n## Examples\n\n```php\n\u003c?php\n\ninclude \"./vendor/autoload.php\";\n\n$data = array(1, 5, 5, 11, 6, 7, 9, 3);\n\n$greedy = new \\drupol\\phpartition\\Algorithm\\Greedy();\n$greedy-\u003esetData($data);\n$greedy-\u003esetSize(3);\n$result = $greedy-\u003egetResult();\n\n// $result is:\n/*\n * Array\n   (\n       [0] =\u003e Array\n           (\n               [0] =\u003e 9\n               [1] =\u003e 5\n               [2] =\u003e 1\n           )\n   \n       [1] =\u003e Array\n           (\n               [0] =\u003e 7\n               [1] =\u003e 6\n               [2] =\u003e 3\n           )\n   \n       [2] =\u003e Array\n           (\n               [0] =\u003e 11\n               [1] =\u003e 5\n           )\n   )\n */\n\n$simple = new \\drupol\\phpartition\\Algorithm\\Simple();\n$simple-\u003esetData($data);\n$simple-\u003esetSize(3);\n$result = $simple-\u003egetResult();\n\n// $result is:\n/*\n * Array\n(\n    [0] =\u003e Array\n        (\n            [0] =\u003e 5\n            [1] =\u003e 11\n        )\n\n    [1] =\u003e Array\n        (\n            [0] =\u003e 1\n            [1] =\u003e 7\n            [2] =\u003e 3\n        )\n\n    [2] =\u003e Array\n        (\n            [0] =\u003e 5\n            [1] =\u003e 6\n            [2] =\u003e 9\n        )\n)\n */\n```\nYou may also pass objects or array but then, you'll have to define how to access their value.\n\n```php\n\u003c?php\n\ninclude \"./vendor/autoload.php\";\n\n$data = array(\n  array(\n    'item' =\u003e 'anything A',\n    'weight' =\u003e 1,\n  ),\n  array(\n    'item' =\u003e 'anything B',\n    'weight' =\u003e 2,\n  ),\n  array(\n    'item' =\u003e 'anything C',\n    'weight' =\u003e 3,\n  ),\n  array(\n    'item' =\u003e 'anything D',\n    'weight' =\u003e 4,\n  ),\n);\n\n$greedy = new \\drupol\\phpartition\\Algorithm\\Greedy();\n$greedy-\u003esetData($data);\n$greedy-\u003esetSize(2);\n$greedy-\u003esetItemAccessCallback(function($item) {\n  return $item['weight'];\n});\n$result = $greedy-\u003egetResult();\n\n// $result is\n/*\n * Array\n   (\n       [0] =\u003e Array\n           (\n               [0] =\u003e Array\n                   (\n                       [item] =\u003e anything C\n                       [weight] =\u003e 3\n                   )\n   \n               [1] =\u003e Array\n                   (\n                       [item] =\u003e anything B\n                       [weight] =\u003e 2\n                   )\n   \n           )\n   \n       [1] =\u003e Array\n           (\n               [0] =\u003e Array\n                   (\n                       [item] =\u003e anything D\n                       [weight] =\u003e 4\n                   )\n   \n               [1] =\u003e Array\n                   (\n                       [item] =\u003e anything A\n                       [weight] =\u003e 1\n                   )\n   \n           )\n   \n   )\n */\n```\n\nIt's also possible to mix the type of object to partition.\n\n## TODO\n\n- Implement Complete Karmarkar-Karp (CKK) algorithm,\n- Documentation.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrupol%2Fphpartition","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrupol%2Fphpartition","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrupol%2Fphpartition/lists"}