By default, a partition algorithm returns an entire partition.
import prtpy
greedy = prtpy.partitioning.greedy
values = [4, 5, 5, 6, 7, 8, 8]
print(prtpy.partition(algorithm=greedy, numbins=2, items=values))
[[8, 7, 5], [8, 6, 5, 4]]
You can tell it to return only the sums of the bins. This makes the computation more efficient, as it does not need to track the bin contents.
print(prtpy.partition(algorithm=greedy, numbins=2, items=values, outputtype=prtpy.out.Sums))
[20.0, 23.0]
Other options are: Return only the largest sum:
print(prtpy.partition(algorithm=greedy, numbins=2, items=values, outputtype=prtpy.out.LargestSum))
23.0
Return only the smallest sum:
print(prtpy.partition(algorithm=greedy, numbins=2, items=values, outputtype=prtpy.out.SmallestSum))
20.0
Return both the partition and the sum of each bin:
prtpy.partition(algorithm=greedy, numbins=2, items=values, outputtype=prtpy.out.PartitionAndSums)
(array([20., 23.]), [[8, 7, 5], [8, 6, 5, 4]])
Markdown generated automatically from output_formats.py using Pweave 0.30.3 on 2022-07-11.