28This module provides bin packing utilities.
32__author__ =
"Kipp Cannon <kipp.cannon@ligo.org>"
33from .git_version
import date
as __date__
34from .git_version
import version
as __version__
52 Bin object for use in packing algorithm implementations. A Bin
53 instance has two attributes: size, which is the total
"size" of
54 the contents of the Bin,
and objects, which
is a list of the Bins
61 >>> strings.add(s, len(s))
69 Initialize a new Bin instance.
74 def add(self, obj, size):
76 Add the object, whose size is as given, to the bin.
84 Add the contents of another Bin object to this one.
86 self.objects.extend(other.objects)
87 self.size += other.size
95 return self.
size < other.size
98 return self.
size <= other.size
101 return self.
size == other.size
104 return self.
size != other.size
107 return self.
size >= other.size
110 return self.
size > other.size
114 A representation of the Bin object.
116 return "Bin(size=%s, %s)" % (str(self.
size), str(self.
objects))
134 Parent class for packing algorithms. Specific packing algorithms
135 should sub-class this, providing implementations of the pack() and
138 def __init__(self, bins):
140 Set the list of bins on which we shall operate
144 def pack(self, size, obj):
146 Pack an object of given size into the bins.
148 raise NotImplementedError
150 def packlist(self, size_object_pairs):
152 Pack a list of (size, object) tuples into the bins.
154 Default implementation invokes self.pack() on each pair in
157 for size, obj
in size_object_pairs:
163 Packs the biggest object into the emptiest bin.
169 for size, obj
in sorted(size_object_pairs, reverse =
True):
static double min(double a, double b)
Packs the biggest object into the emptiest bin.
def pack(self, size, obj)
Pack an object of given size into the bins.
def packlist(self, size_object_pairs)
Pack a list of (size, object) tuples into the bins.
Bin object for use in packing algorithm implementations.
def add(self, obj, size)
Add the object, whose size is as given, to the bin.
def __iadd__(self, other)
Add the contents of another Bin object to this one.
def __repr__(self)
A representation of the Bin object.
Parent class for packing algorithms.
def pack(self, size, obj)
Pack an object of given size into the bins.
def packlist(self, size_object_pairs)
Pack a list of (size, object) tuples into the bins.