{"id":20949980,"url":"https://github.com/kotarot/rectangle-packing-solver","last_synced_at":"2025-05-14T03:32:20.628Z","repository":{"id":41269220,"uuid":"364480384","full_name":"kotarot/rectangle-packing-solver","owner":"kotarot","description":"A solver to find a solution of the 2D rectangle packing problem by simulated annealing (SA) optimization.","archived":false,"fork":false,"pushed_at":"2022-02-12T12:00:35.000Z","size":483,"stargazers_count":85,"open_issues_count":4,"forks_count":17,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-03T06:55:25.462Z","etag":null,"topics":["floorplan","optimization","placement","python","rectangle-packing","sequence-pair","simulated-annealing","solver"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kotarot.png","metadata":{"files":{"readme":"README.md","changelog":null,"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-05-05T06:22:26.000Z","updated_at":"2024-09-21T12:45:19.000Z","dependencies_parsed_at":"2022-07-13T15:29:49.530Z","dependency_job_id":null,"html_url":"https://github.com/kotarot/rectangle-packing-solver","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kotarot%2Frectangle-packing-solver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kotarot%2Frectangle-packing-solver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kotarot%2Frectangle-packing-solver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kotarot%2Frectangle-packing-solver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kotarot","download_url":"https://codeload.github.com/kotarot/rectangle-packing-solver/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225275225,"owners_count":17448384,"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":["floorplan","optimization","placement","python","rectangle-packing","sequence-pair","simulated-annealing","solver"],"created_at":"2024-11-19T00:44:48.554Z","updated_at":"2024-11-19T00:44:49.207Z","avatar_url":"https://github.com/kotarot.png","language":"Python","readme":"# rectangle-packing-solver\n\n[![PyPI](https://img.shields.io/pypi/v/rectangle-packing-solver)](https://pypi.org/project/rectangle-packing-solver/)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/rectangle-packing-solver)](https://pypi.org/project/rectangle-packing-solver/)\n[![GitHub Repo Size](https://img.shields.io/github/repo-size/kotarot/rectangle-packing-solver)](https://github.com/kotarot/rectangle-packing-solver)\n[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/kotarot/rectangle-packing-solver/Continuous%20Integration)](https://github.com/kotarot/rectangle-packing-solver/actions?query=workflow%3AContinuous%20Integration)\n[![Codecov branch](https://img.shields.io/codecov/c/gh/kotarot/rectangle-packing-solver/main?flag=unittests)](https://codecov.io/gh/kotarot/rectangle-packing-solver)\n[![GitHub License](https://img.shields.io/github/license/kotarot/rectangle-packing-solver)](https://github.com/kotarot/rectangle-packing-solver/blob/main/LICENSE)\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fkotarot%2Frectangle-packing-solver.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fkotarot%2Frectangle-packing-solver?ref=badge_shield)\n\nA solver to find a solution of the 2D rectangle packing problem by simulated annealing (SA) optimization.\nSequence-pair [1] is used to represent a rectangle placement (floorplan).\n\n\n## Features\n\n- Solution quality and execution time are tunable, since the solver is SA-based.\n- Not only integers but also real numbers can be set as a rectangle width and height.\n- A rectangle can rotate while optimizing.\n- The built-in visualizer visualizes a floorplan solution.\n\n\n## Installation\n\n```bash\npip install rectangle-packing-solver\n```\n\n\n## Example Usage\n\n### Sample code:\n\n```python\nimport rectangle_packing_solver as rps\n\n# Define a problem\nproblem = rps.Problem(rectangles=[\n    [4, 6],  # Format: [width, height] as list. Default rotatable: False\n    (4, 4),  # Format: (width, height) as tuple. Default rotatable: False\n    {\"width\": 2.1, \"height\": 3.2, \"rotatable\": False},  # Or can be defined as dict.\n    {\"width\": 1, \"height\": 5, \"rotatable\": True},\n])\nprint(\"problem:\", problem)\n\n# Find a solution\nprint(\"\\n=== Solving without width/height constraints ===\")\nsolution = rpm.Solver().solve(problem=problem)\nprint(\"solution:\", solution)\n\n# Visualization (to floorplan.png)\nrps.Visualizer().visualize(solution=solution, path=\"./floorplan.png\")\n\n# [Other Usages]\n# We can also give a solution width (and/or height) limit, as well as progress bar and random seed\nprint(\"\\n=== Solving with width/height constraints ===\")\nsolution = rps.Solver().solve(problem=problem, height_limit=6.5, show_progress=True, seed=1111)\nprint(\"solution:\", solution)\nrps.Visualizer().visualize(solution=solution, path=\"./figs/floorplan_limit.png\")\n```\n\n### Output:\n\n```plaintext\nproblem: Problem({'n': 4, 'rectangles': [{'id': 0, 'width': 4, 'height': 6, 'rotatable': False}, {'id': 1, 'width': 4, 'height': 4, 'rotatable': False}, {'id': 2, 'width': 2.1, 'height': 3.2, 'rotatable': False}, {'id': 3, 'width': 1, 'height': 5, 'rotatable': True}]})\n\n=== Solving without width/height constraints ===\nsolution: Solution({'sequence_pair': SequencePair(([3, 0, 2, 1], [0, 1, 3, 2])), 'floorplan': Floorplan({'positions': [{'id': 0, 'x': 0, 'y': 0, 'width': 4, 'height': 6}, {'id': 1, 'x': 4, 'y': 0, 'width': 4, 'height': 4}, {'id': 2, 'x': 5.0, 'y': 4.0, 'width': 2.1, 'height': 3.2}, {'id': 3, 'x': 0, 'y': 6, 'width': 5, 'height': 1}], 'bounding_box': (8, 7.2), 'area': 57.6})})\n\n=== Solving with width/height constraints ===\nProgress: 100%|█████████████████████████████████████████████████████████████| 10000/10000 [00:05\u003c00:00, 1764.33it/s]\nsolution: Solution({'sequence_pair': SequencePair(([0, 1, 2, 3], [0, 3, 1, 2])), 'floorplan': Floorplan({'positions': [{'id': 0, 'x': 0, 'y': 0, 'width': 4, 'height': 6}, {'id': 1, 'x': 4, 'y': 1, 'width': 4, 'height': 4}, {'id': 2, 'x': 8.0, 'y': 1.0, 'width': 2.1, 'height': 3.2}, {'id': 3, 'x': 4, 'y': 0, 'width': 5, 'height': 1}], 'bounding_box': (10.1, 6), 'area': 60.599999999999994})})\n```\n\n### Floorplan (example):\n\n![floorplan_example](https://raw.githubusercontent.com/kotarot/rectangle-packing-solver/main/figs/floorplan_example.png)\n\n### Floorplan (larger example):\n\n![floorplan_large](https://raw.githubusercontent.com/kotarot/rectangle-packing-solver/main/figs/floorplan_large_limit.png)\n\n\n## References\n\n[1] H. Murata, K. Fujiyoshi, S. Nakatake, and Y. Kajitani, \"VLSI module placement based on rectangle-packing by the sequence-pair,\" *IEEE Trans. on Computer-Aided Design of Integrated Circuits and Systems*, vol. 15, no. 12, pp. 1518--1524, Dec 1996.\n\n\n## License\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fkotarot%2Frectangle-packing-solver.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fkotarot%2Frectangle-packing-solver?ref=badge_large)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkotarot%2Frectangle-packing-solver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkotarot%2Frectangle-packing-solver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkotarot%2Frectangle-packing-solver/lists"}