rectangle-packing-solver
A solver to find a solution of the 2D rectangle packing problem by simulated annealing (SA) optimization. Sequence-pair [1] is used to represent a rectangle placement (floorplan).
Features
- Solution quality and execution time are tunable, since the solver is SA-based.
- Not only integers but also real numbers can be set as a rectangle width and height.
- A rectangle can rotate while optimizing.
- The built-in visualizer visualizes a floorplan solution.
Installation
pip install rectangle-packing-solver
Example Usage
Sample code:
import rectangle_packing_solver as rps
# Define a problem
problem = rps.Problem(rectangles=[
[4, 6], # Format: [width, height] as list. Default rotatable: False
(4, 4), # Format: (width, height) as tuple. Default rotatable: False
{"width": 2.1, "height": 3.2, "rotatable": False}, # Or can be defined as dict.
{"width": 1, "height": 5, "rotatable": True},
])
print("problem:", problem)
# Find a solution
print("\n=== Solving without width/height constraints ===")
solution = rpm.Solver().solve(problem=problem)
print("solution:", solution)
# Visualization (to floorplan.png)
rps.Visualizer().visualize(solution=solution, path="./floorplan.png")
# [Other Usages]
# We can also give a solution width (and/or height) limit, as well as progress bar and random seed
print("\n=== Solving with width/height constraints ===")
solution = rps.Solver().solve(problem=problem, height_limit=6.5, show_progress=True, seed=1111)
print("solution:", solution)
rps.Visualizer().visualize(solution=solution, path="./figs/floorplan_limit.png")
Output:
problem: 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}]})
=== Solving without width/height constraints ===
solution: 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})})
=== Solving with width/height constraints ===
Progress: 100%|█████████████████████████████████████████████████████████████| 10000/10000 [00:05<00:00, 1764.33it/s]
solution: 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})})
Floorplan (example):
Floorplan (larger example):
References
[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.
License
Metadata
Release files for rectangle-packing-solver 0.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| rectangle-packing-solver-0.0.5.tar.gz | 19.2 kB | Without provenance | Details for rectangle-packing-solver-0.0.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| rectangle_packing_solver-0.0.5-py3-none-any.whl | Python 3 | none | any | Details for rectangle_packing_solver-0.0.5-py3-none-any.whl |
Total release size: 46.5 kB
Release files / rectangle-packing-solver-0.0.5.tar.gz
| Download URL | rectangle-packing-solver-0.0.5.tar.gz |
|---|---|
| Size | 19.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cf23494fce5626e5285d5ebcbfc7d160944549c060b24b3f6e27ed8248bd01f3
|
|
BLAKE2b-256 checksum How to use checksums |
614974a5394c0d8317cf2273a0898ff259608524dfd6f47b2b8be409efc26c50
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.6
|
Release files / rectangle_packing_solver-0.0.5-py3-none-any.whl
| Download URL | rectangle_packing_solver-0.0.5-py3-none-any.whl |
|---|---|
| Size | 27.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8e248815a2a6572b6ae71110363d9fd524fdc37b3648219994edb90ff6724fd7
|
|
BLAKE2b-256 checksum How to use checksums |
67e2f44e608a90032154486bdc3156c1c3d4b9234b5db122e87489a8b13b61c8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.6
|
Security for rectangle-packing-solver 0.0.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.