{"id":21810673,"url":"https://github.com/samdark/sack","last_synced_at":"2025-04-13T22:11:22.326Z","repository":{"id":58713915,"uuid":"533296734","full_name":"samdark/sack","owner":"samdark","description":"This package implements \"0-1 Knapsack Problem\" algorithm i.e. allows to find the best way to fill a knapsack of a specified volume with items of a certain volume and value.","archived":false,"fork":false,"pushed_at":"2025-02-21T15:19:19.000Z","size":21,"stargazers_count":9,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-27T12:38:11.379Z","etag":null,"topics":["knapsack-problem"],"latest_commit_sha":null,"homepage":"","language":"PHP","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/samdark.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"patreon":"samdark"}},"created_at":"2022-09-06T11:38:27.000Z","updated_at":"2025-02-21T15:18:56.000Z","dependencies_parsed_at":"2024-11-27T13:47:46.971Z","dependency_job_id":null,"html_url":"https://github.com/samdark/sack","commit_stats":{"total_commits":5,"total_committers":1,"mean_commits":5.0,"dds":0.0,"last_synced_commit":"89ae2243d0f4e5aca5a78edebf32d6afca61a752"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samdark%2Fsack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samdark%2Fsack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samdark%2Fsack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samdark%2Fsack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/samdark","download_url":"https://codeload.github.com/samdark/sack/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248788925,"owners_count":21161727,"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":["knapsack-problem"],"created_at":"2024-11-27T13:37:06.431Z","updated_at":"2025-04-13T22:11:22.318Z","avatar_url":"https://github.com/samdark.png","language":"PHP","readme":"\u003ch1 align=\"center\"\u003eSack\u003c/h1\u003e\n\n[![Latest Stable Version](https://poser.pugx.org/samdark/sack/v)](https://packagist.org/packages/samdark/sack)\n[![Total Downloads](https://poser.pugx.org/samdark/sack/downloads)](https://packagist.org/packages/samdark/sack)\n[![Build status](https://github.com/samdark/sack/workflows/build/badge.svg)](https://github.com/samdark/sack/actions?query=workflow%3Abuild)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/samdark/sack/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/samdark/sack/?branch=master)\n[![Code Coverage](https://scrutinizer-ci.com/g/samdark/sack/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/samdark/sack/?branch=master)\n[![Mutation testing badge](https://img.shields.io/endpoint?style=flat\u0026url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Frbac%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/samdark/sack/master)\n[![static analysis](https://github.com/samdark/sack/workflows/static%20analysis/badge.svg)](https://github.com/samdark/sack/actions?query=workflow%3A%22static+analysis%22)\n[![type-coverage](https://shepherd.dev/github/samdark/sack/coverage.svg)](https://shepherd.dev/github/samdark/sack)\n\nThis package implements \"0-1 Knapsack Problem\" algorithm i.e. allows to find the best way to fill\na knapsack of a specified volume with items of a certain volume and value.\n\nIt could be applied to:\n\n- Filling a box with most valued items.\n- Selecting best tasks for a week knowing each task value and effort in days.\n- Selecting attractions to visit in a limited time knowing how much one wants to visit an attraction and time \n  required for a visit.\n- etc. \n\n\n## Installation\n\nThe package could be installed with composer:\n\n```shell\ncomposer require samdark/sack --prefer-dist\n```\n\n## General usage\n\n```php\ndeclare(strict_types=1);\n\nuse Samdark\\Sack\\Item;\nuse Samdark\\Sack\\SackFiller;\n\nrequire __DIR__ . '/vendor/autoload.php';\n\n// Items to select from\n$items = [\n    new Item('Guitar', 1, 1500),\n    new Item('Player', 4, 3000),\n    new Item('Laptop', 3, 2000),\n];\n\n$sackVolume = 7;\n$filler = new SackFiller($sackVolume);\n$result = $filler-\u003efill($items);\n\necho \"Possible items:\\n\\n\";\necho \"Name\\tVolume\\tValue\\n\";\nforeach ($items as $item) {\n    echo \"{$item-\u003egetName()}\\t{$item-\u003egetVolume()}\\t{$item-\u003egetValue()}\\n\";\n}\n\necho \"\\n\\nMaximum value for sack of $sackVolume is {$result-\u003egetValue()}:\\n\\n\";\necho \"Name\\tVolume\\tValue\\n\";\nforeach ($result-\u003egetItems() as $item) {\n    echo \"{$item-\u003egetName()}\\t{$item-\u003egetVolume()}\\t{$item-\u003egetValue()}\\n\";\n}\n```\n\n\n## Testing\n\n### Unit testing\n\nThe package is tested with [PHPUnit](https://phpunit.de/). To run tests:\n\n```shell\n./vendor/bin/phpunit\n```\n\n### Mutation testing\n\nThe package tests are checked with [Infection](https://infection.github.io/) mutation framework with\n[Infection Static Analysis Plugin](https://github.com/Roave/infection-static-analysis-plugin). To run it:\n\n```shell\n./vendor/bin/roave-infection-static-analysis-plugin\n```\n\n### Static analysis\n\nThe code is statically analyzed with [Psalm](https://psalm.dev/). To run static analysis:\n\n```shell\n./vendor/bin/psalm\n```\n","funding_links":["https://patreon.com/samdark"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamdark%2Fsack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamdark%2Fsack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamdark%2Fsack/lists"}