spyrrow documentation

spyrrow is a Python wrapper on the Rust project sparrow. It enables to solve 2D Strip packing problems.

Installation

Spyrrow is hosted on PyPI.

You can install with the package manager of your choice, using the PyPI package index.

For example, with pip, the default Python package:

pip install spyrrow

Examples

import spyrrow

rectangle1 = spyrrow.Item(
   "rectangle", [(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)], demand=4, allowed_orientations=[0]
)
triangle1 = spyrrow.Item(
   "triangle",
   [(0, 0), (1, 0), (1, 1), (0, 0)],
   demand=6,
   allowed_orientations=[0, 90, 180, -90],
)

instance = spyrrow.StripPackingInstance(
   "test", strip_height=2.001, items=[rectangle1, triangle1]
)
config = spyrrow.StripPackingConfig(early_termination=False,total_computation_time=60,num_wokers=3,seed=0)
sol = instance.solve(config)
print(sol.width) # 4.0 +/- 5%
print(sol.density)

print("\n")
for pi in sol.placed_items:
   print(pi.id)
   print(pi.rotation)
   print(pi.translation)
   print("\n")

In order to express that an Item can rotate freely, its allowed_orientations attributes should be set to None.

import spyrrow

triangle1 = spyrrow.Item(
      "triangle",
      [(0, 0), (1, 0), (1, 1), (0, 0)],
      demand=6,
      allowed_orientations=None,
   )

One can enable early_termination, by setting its value to true inside the configuration object. It will use internal mechanism to detect when the solution can not be improved by the current algorithm.

Further configuration options are available through the configuration object. You may refer to sparrow for more precise explanations.