prtpy is a Python library for number partitioning. It provides various algorithms to divide a list of numbers into a specified number of subsets, typically aiming to minimize the largest sum of a subset. It is actively maintained, with the current version being 0.8.3, and releases occur as new algorithms, improvements, or bug fixes are introduced.
pip install prtpyVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `prtpy` to partition a list of numbers into a specified number of bins using the greedy algorithm. The `partition` function acts as a general interface, accepting the algorithm as a parameter.
Install `pulp` via `pip install pulp` and ensure a compatible solver (e.g., `cbc` is often included with `pulp` or can be installed separately) is available in your system's PATH.
For large datasets or performance-critical applications, prefer polynomial-time algorithms like `greedy`, `balancer`, or `complete_greedy`. Consult the documentation for the complexity characteristics of each algorithm.
Always ensure that the list of items you pass to `prtpy` algorithms contains only numbers. Validate or sanitize your input data if it originates from external sources.
Install the `pulp` library using `pip install pulp`.
Ensure all items in the list passed to `prtpy` algorithms are numerical (integers or floats).
Switch to a polynomial-time complexity algorithm for large inputs, such as `greedy`, `balancer`, or `complete_greedy`, which are much more performant.