{"id":24540557,"url":"https://github.com/unit2795/bee-sim-knapsack","last_synced_at":"2025-03-16T05:43:14.728Z","repository":{"id":242336319,"uuid":"809181752","full_name":"Unit2795/bee-sim-knapsack","owner":"Unit2795","description":"0/1 Knapsack problem demonstrated with a recursive and whimsical twist.","archived":false,"fork":false,"pushed_at":"2024-06-04T12:54:02.000Z","size":452,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-22T18:14:02.254Z","etag":null,"topics":["knapsack","knapsack-problem","recursion","recursive-algorithm"],"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/Unit2795.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"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}},"created_at":"2024-06-01T23:58:02.000Z","updated_at":"2024-06-07T11:49:14.000Z","dependencies_parsed_at":"2024-06-02T10:50:38.381Z","dependency_job_id":"55b08aaf-0a32-4891-ade3-fa96b3a0e064","html_url":"https://github.com/Unit2795/bee-sim-knapsack","commit_stats":null,"previous_names":["unit2795/bee-sim-knapsack"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Unit2795%2Fbee-sim-knapsack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Unit2795%2Fbee-sim-knapsack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Unit2795%2Fbee-sim-knapsack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Unit2795%2Fbee-sim-knapsack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Unit2795","download_url":"https://codeload.github.com/Unit2795/bee-sim-knapsack/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243830914,"owners_count":20354850,"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","knapsack-problem","recursion","recursive-algorithm"],"created_at":"2025-01-22T18:14:06.787Z","updated_at":"2025-03-16T05:43:14.677Z","avatar_url":"https://github.com/Unit2795.png","language":"Python","readme":"# Bee Simulator - 0/1 Knapsack Problem \u0026 Recursion Demonstration 🐝🌻\n\n![CLI output from Bee Simulator](example.png \"Title\")\n\nSimple example of the knapsack problem solved with a recursive algorithm, using a fun and whimsical CLI idle game/simulation about a nectar collecting bee!\n\nPolynomial-time **(𝑂(𝑛 × 𝑚)) implementation (n = number of flowers, m = max energy)**\n\n## Objective\nMaximize the amount of nectar a bee can harvest in a day without exceeding its available energy.\n\n## Constraints\n1. Each flower provides a fixed amount of nectar\n2. Each flower requires a fixed amount of energy to visit\n3. The bee has a fixed amount of energy to spend\n4. The bee can only visit each flower once\n5. The bee can only carry a fixed amount of nectar\n6. The bee must collect all nectar from a flower or none at all (0/1)\n\n## Key Concepts\n- Recursion\n- Dynamic Programming\n- Memoization\n- Knapsack Problem\n- Backtracking\n\n## Run In Docker\nFor a quick and easy way to run the simulation, you can use Docker. All you need to do is run the Dockerfile and after building, the simulation will run automatically and output live results to your terminal.\n```bash\ndocker-compose up\n```\nWhen you are done, you can stop the container with:\n```bash\ndocker-compose down\n```\n\n\n## Install \u0026 Dependencies\nYou'll ideally want Python 3.12 or later to run this project.\n\nRun the following to install dependencies:\n```bash \n  pip install -r requirements.txt\n```\n(Or on Windows)\n```bash\n  py -m pip install pip install -r requirements.txt\n```\n\n## Usage\nTo run the simulation, execute the main script file:\n```bash\npy main.py\n```\n\n### Simulation Speed\nThe simulation speed can be adjusted by setting the `SPEED` environment variable. The smallest possible value is 0, which will run the simulation instantaneously. The default value is 1.\n\n### Debugging\nWhen running the main script file, set the DEBUG environment variable to `1` to enable debugging output.\n\n### Tests\nTo run the tests, execute the test script file:\n```bash\npy -m unittest tests/test.py\n```\n**These tests evaluate the DP and traceback matrices against previously stored versions. If you adjust the code in a way so that the matrices have changed shape, the tests will fail. You must run the references file to update these. You should calculate the tiny_meadow flower set using an online knapsack tool or by hand and compare this with the table generated by Bee Simulator to ensure it is safe to regenerate the references. You can see the tiny_meadow DP and Traceback tables in the console by running the tests above**\n```bash\npy tests/references.py\n```\n\n## Directory Structure\n- `tests/` - Test files\n  - `matrices/` - Reference DP and Traceback tables stored as binary .npy files, which are easily restored into 2D arrays and compared in tests\n  - `references.py` - Generates reference DP and Traceback tables and provides helpers for evaluating them in test cases\n- `beesim.py` - Primary simulation logic. Including the recursive algorithm for solving the knapsack problem\n- `flowers.py` - Arrays of flowers for the bee to collect nectar from, try making your own! (Adjusting the tiny_meadows or hundred_meadow will break the tests, be sure to revert changes to these if you plan on committing!)\n- `helpers.py` - Helper functions\n- `main.py` - Main script file, run this to try out Bee Simulator\n\n\n## Uses\nSome real-world applications of the knapsack problem include:\n- Cost benefit analysis\n  - Determining the most cost-effective way to spend a budget\n- Resource allocation\n  - Assigning resources to maximize output\n- Sprint planning\n  - Determining the most valuable tasks to complete in a sprint\n- Investment\n  - Selecting the best stocks to invest in given a set budget \n\n## Next Steps\nThis library could be a small part of a larger simulation or game. Some ideas for expanding the project include:\n- Adding in pollen as a secondary resource to collect and balance\n- Adding in distance between flowers that takes energy to traverse (Traveling Salesman Problem)\n- Adding more bees, specialized roles, and other colony management mechanics\n- Adding in predators, disease, weather, seasons, etc.\n\nI'm sure the algorithm could be optimized further too. Such as possibly using a one dimensional array instead of a two-dimensional one?\n\n## Contribute \u0026 License\nFeel free to fork this project, open an issue, or submit a pull request. This project is licensed under the MIT License, do with it as you please.\n\nThank you for checking out the Bee Simulator - 0/1 Knapsack Problem \u0026 Recursion Demonstration! 🌷\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funit2795%2Fbee-sim-knapsack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Funit2795%2Fbee-sim-knapsack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funit2795%2Fbee-sim-knapsack/lists"}