1 Introduction
Let be an input sequence of items such that their sizes are in the interval and the number of distinct item sizes is at most . Our goal is to pack the items in that uses a minimum number of unit capacity bins. This problem is a special case of bin packing where the number of distinct item sizes is restricted to and is often referred to as the 1dimensional cutting stock problem. The study of this problem was initiated by Gilmore and Gomory [4] and has a wide variety of applications [8] including cutting stock applications, packing problems in supply chain management, and resource allocation problems in distributed systems. The bin packing problem for arbitrary number of item types is known to be strongly NPHard [7] and hence the interest in the design of efficient algorithms and approximation schemes for bin packing under the restriction that the number of item types is fixed. For , McCormick et al. [10] presented a polynomial time algorithm for determining an optimal solution. For , Filippi et al. [3] generalized the argument in [10] to find a polynomial time solution that uses at most bins more than an optimal solution. For , Jansen and SolisOba [6] presented an algorithm that uses bins and runs in , where is the reciprocal of the size of the smallest item. More recently, polynomial time solvability of this problem was settled by the time optimal algorithm of Goemans et al. [5]. For arbitrary , the first PTAS was presented by Fernandez de la vega et al [2]
, subsequently Karmarkar and Karp [9] presented an asymptotic FPTAS that uses bins and Rothvob [11] presented an algorithm that uses bins. Both these algorithms run in pseudo polynomial time (polynomial on , where is the number of items of the th size).
Our Results:
In this paper we present an time algorithm to obtain an optimal solution for the bin packing problem under the restriction that the number of item sizes is fixed.
Our main contribution is in the use of elementary ideas in both the design and analysis our algorithm. The recent result of Goemans and Rothvob [5] is theoretically a stronger result than ours, but for moderate to large our algorithm is computationally better.
2 An Optimal Algorithm for dimensional Cutting Stock Problem
In this section, we first present some necessary terms and definitions before presenting an algorithm that given an input sequence consisting of items from at most distinct item sizes determines an optimal bin packing in , where be the reciprocal of the smallest item size in .
2.1 Preliminaries
Definitions 2.1
The sequence with distinct item sizes { } can be viewed as a
dimensional vector
, where for , is the number of items of type (size ); we refer to as the distribution vector corresponding to . Given the distribution vector , we define , the unit neighborhood of with respect to , to be the collection of points in such that each point in this collection is within unit distance ( norm) from some point on , and for , its th component is an integer multiple of .Definitions 2.2
A unit capacity bin with a collection of items from and a free space of at most , for some , can be characterized by a dimensional vector whose th component, , equals sum of items of size in . We refer to such a vector as vector consistent with . An vector that is consistent with is maximal if addition of any item from to the corresponding bin results in the bin exceeding its capacity.
Note: We use the norm to measure distances and sometimes use vectors and points interchangeably.
Definitions 2.3
Let denote the set of all maximal vectors consistent with , for . For a given multiset of vectors from not necessarily distinct and a point , let denote the resulting vector obtained by starting at and then placing the vectors in . Given a point ,

We say that starting at the multiset crosses at point if and dominates (i.e. each of the components of is less than or equal to the corresponding component of ;

We define , the set of points reachable from with respect to , as the collection of points such that each point is in and can be expressed as for some , where ;

For , we define to be a smallest sized multiset for which .
Lemma 1
Let be a sequence with distinct item sizes { }. Let be the multiset consisting of vectors from (i.e. bin configurations) corresponding to an optimal allocation of items in onto unit capacity bins. For some there exists a sized minimal subset such that starting at or any point that dominates and is within a unit distance of , crosses a point on at a distance less than or equal to from the starting point.
Proof We prove this lemma by contradiction. Let us assume that for any there does not exist a multiset of vectors that crosses at any point whose distance from the starting point is in the interval . Then if we partition the vectors in into multisets of vectors, then since none of the sized multiset crosses in the interval the vector sum of all the sized multiset will not dominate and hence will not cross the tip of implying that is missing some item in and hence is not a feasible solution. Hence the result.
2.2 Our Algorithm
Let be a collection of vectors from (configuration of unit capacity bins) used for optimally packing items in . From Lemma 1, we can observe that there is a sized minimal multiset , where , such that starting at the origin (or any point that dominates and is within unit distance from ) the vector crosses at a point which is at a distance from and ends up at a point within an unit distance of . This implies, we can obtain an optimal solution by (i) determining the minimum sized multiset from that starts at the origin, crosses at whose distance from the origin is less than or equal to and ends up at some point that is within an unit distance of ; and (ii) determine the minimum sized multiset from that starts at the point where the first subproblem ends, crosses the tip of , and ends up at a point within a unit distance of the tip of . Solving these two subproblems essentially involves solving the following problem:
Given the start and end points and respectively both in , determine a minimum sized collection of vectors from such that .
We now present a recursive algorithm for solving the above problem that can be easily converted into a dynamic
program.
ALGORITHM A(, , )
Input(s):
(1)
= be the sequence of
items with distinct item
sizes { };
(2)
= be the coordinate of the beginning point
(3)
= be the the coordinate of end point
Output(s):
The collection of vectors consistent with for some
(i.e.
(configuration of unit capacity bins) of an optimal bin packing of items in ;
Pre
processing:
(1)
Construct the unit neighborhood of with respect to ;
(2)
For
an integer
Begin
(2a)
Construct the collection containing all possible sized multisets of
vectors consistent with ;
(2b)
For
each point and for each
Begin
If
then
;
If
then
;
End
End
Recursion:
Beg
in
If
then
return ;
else
return ;
End
Observation : The size of the unit neighborhood of the distribution vector consistent with is and can be computed in time;
Observation : The size of the number of vectors consistent with , for
, is upper bounded by , and the size of , for is
upper bounded by = ;
Observation : The number of distinct subproblems solved by ALGORITHM A(, , )
is upper bounded by .
Theorem 2
Let be a sequence with distinct item sizes { } and be the collection of points in the neighborhood of consistent with , where is the distribution vector of , then the minimum number of bins used to pack the items in using unit capacity bins is and can be determined in time.
Proof
Let be a collection of vectors from used for optimally packing items
in . From Lemma 1, we can observe that there is a sized minimal multiset , where , such that starting at the origin, the vector crosses at a point whose distance from the origin and ends up
at a point within an unit distance from that crossing point. Hence, we can obtain an optimal solution by
(i) determining the minimum sized multiset from that starts at the origin, crosses
at whose distance from the origin is less than or equal to and ends up at some point that
is within an unit distance of ; and (ii) determine the minimum sized multiset from that starts at the point where the first subproblem ends, crosses the tip of , and ends up at a point within a unit distance of the tip of . This essentially
reduces to solving the following problem recursively:
Given the start and end points and respectively both in , determine a minimum sized collection of vectors from such that . For this recursive formulation, using a cut and paste argument we can easily
see that the substructure property is true.
Now, we establish the computational complexity of our algorithm. From Observations and , we can notice that the runtime for the preprocessing steps and is dominated by Step and is . From Observation , we can observe the number of distinct subproblems is and each subproblem depends on at most
subproblems, hence the runtime for the recursion is . Combining the
preprocessing time and the time for recursion, we get the runtime of our algorithm is .
3 Conclusions
We have designed a psudopolynomial time algorithm for the Bin Packing problem under the restriction that the number of item types is at most . For large
, our result is stronger than the currently best known theoeretical result of Goemans et al [GR14]. We are in the process of analyzing heuristics that are relaxed version of this algorithm that consider only a small fraction of the bin configurations (please see Divakaran
[1]) that in practice provide good approximations and scale well computationally.References
 [1] S. Divakaran. A Fast Scalable Heuristic for Bin Packing. CORR 1904.12467, 2019.
 [2] W. Fernandez de la Vega and G.S. Leuker. Bin packing can be solved within in linear time. Combinatorica, Volume 1, Issue 4, 349355, 1981.
 [3] C. Filippi and A. Agnetis. An asymptotically exact algorithm for the highmultiplicity bin packing problem. Math. Program., 104(1):21–37, 2005.

[4]
P. C. Gilmore and R. E. Gomory.
A linear programming approach to the cuttingstock problem
. Operations Research, 9:849–859, 1961.  [5] M. Goemans and T. Rothvoß. Polynomiality for Bin Packing with a Constant Number of Item Types. Proceedings of the TwentyFifth Annual ACMSIAM Symposium on Discrete Algorithms, 830839, 2013.

[6]
K. Jansen and R. SolisOba.
An OPT + 1 algorithm for the cutting stock problem with constant number of object lengths.
In Friedrich Eisenbrand and F. Bruce Shepherd, editors, Proceedings of the 14th International Conference on Integer Programming and Combinatorial Optimization
, IPCO 2010, pages 438– 449, 2010.  [7] D. S. Johnson. The NPcompleteness column: An ongoing guide: The tale of the second prover. Journal of Algorithms, Volume 13, Issue 3, 502524, 1992.
 [8] D. S. Johnson, A. Demers, J. D. Ullman, M. R. Garey and R. L. Graham. Worstcase performance bounds for simple onedimensional packing algorithms. SIAM Journal on Computing, Volume 3, Issue 4, 256278, 1974.
 [9] N. Karmarkar and R. M. Karp. An efficient approximation scheme for the onedimensional binpacking problem. Proceedings of the 23rd Annual IEEE Symposium on Foundations of Computer Science, Chicago, IL, 312320, 1982.
 [10] S. T. McCormick, S. R. Smallwood, and F. C. R. Spieksma. Polynomial algorithms for multiprocessor scheduling with a small number of job lengths. SODA, pages 509–517, 1997.
 [11] T. Rothvob. Approximating Bin Packing within O(log OPT * log log OPT) bins. 2013 IEEE 54th Annual Symposium on Foundations of Computer Science, 2029, 2013.