https://github.com/phoenixsmaug/perfectpacking.jl
PerfectPacking.jl - Different exhaustive algorithms for perfect rectangle packing implemented in Julia
https://github.com/phoenixsmaug/perfectpacking.jl
backtracking dancing-links dancing-links-algorithms integer-linear-programming integer-programming packing-algorithm rectangle-packer rectangle-packing
Last synced: 30 days ago
JSON representation
PerfectPacking.jl - Different exhaustive algorithms for perfect rectangle packing implemented in Julia
- Host: GitHub
- URL: https://github.com/phoenixsmaug/perfectpacking.jl
- Owner: PhoenixSmaug
- License: mit
- Created: 2023-06-21T17:12:08.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-11-29T11:27:57.000Z (almost 2 years ago)
- Last Synced: 2025-10-11T05:08:24.049Z (about 1 month ago)
- Topics: backtracking, dancing-links, dancing-links-algorithms, integer-linear-programming, integer-programming, packing-algorithm, rectangle-packer, rectangle-packing
- Language: Julia
- Homepage:
- Size: 16.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PerfectPacking.jl
This library solves the NP-complete perfect rectangle packing problem, where smaller rectangles must be placed in a bounding rectangle without overlapping or leaving tiles uncovered. It can also solve the perfect rectangle packing problem with orthogonal rotation, where the smaller rectangles are allowed to be rotated. The common solving algorithms from literature are implemented.
### Backtracking
```julia
feasibility, solution = rectanglePacking(height, width, rectangles, rotAllowed, backtracking)
```
The most popular and generally the fastest algorithm is backtracking with the top-left heuristic. In each step, an attempt is made to place a new rectangle in the first free tile, proceeding first by rows and then by columns. To further reduce the search space, the rectangles are sorted by descending width.
### Integer Programming
```julia
feasibility, solution = rectanglePacking(height, width, rectangles, rotAllowed, integerProgramming)
```
The perfect rectangle packing problem is translated into an Integer Programming feasibility problem using a model from [this article](https://link.springer.com/chapter/10.1007/978-3-642-00142-0_69). Then it is solved with the open source ILP solver HiGHS. In many cases, it provides the quickest way to prove non-feasibility of the packing problem.
### Dancing Links
```julia
feasibility, solution = rectanglePacking(height, width, rectangles, rotAllowed, dancingLinks)
```
Knuth's famous dancing links algorithm can be used to solve the perfect rectangle packing problem, since it can be reduced to an exact cover problem. When the problem is feasible, it often outperforms the Integer Programming model, but can rarely compete with the classical backtracking approach.
(c) Christoph Muessig