## 3 The Proposed Algorithm
### Model Development for the Number of Machines Needed  
For any product, the batch size must be sufficient for the entire cycle period (e.g., month, quarter, etc.). Therefore, the cycle time for each product type can be set as 1, and each product has only one setup \(\left(T_{S}\right)\) in every production cycle. The time that a machine is busy setting up and producing the product type \(j\) in one cycle is (2):  
\[\left(T_{S}+\frac{\lambda_{j}}{\psi_{j}}\right) \tag{2}\]The total time needed for producing all the \(n\) types of products is (3):  
\[\sum_{j=1}^{n}\frac{\lambda_{j}}{\psi_{j}}+n\times T_{s} \tag{3}\]  
Therefore, the minimum number of machines required to theoretically meet the production plan (lower bound-LB) in one period is (4):  
\[LB_{M}=\left[\sum_{j=1}^{n}\frac{\lambda_{j}}{\psi_{j}}+n\times T_{s}\right]^{ +}\leq M\leq n \tag{4}\]  
The upper bound (UB) for the number of machines is the number of product types (each produces one product type). Therefore, the number of machines \(M\) is in the range: \(LB_{M}\leq M\leq n\). This problem of minimizing the number of machines required to produce \(n\) products is a special case of the BPP and the cyclic scheduling problem. In this context, each machine can be viewed as a circular \"container\" with a perimeter (capacity) of 1, and each product represents an \"item\" that must be placed in one container (produced by one machine). Since the problem is continuous and the cycle time for all products is 1, we can model the task of determining the minimum number of machines equivalent to solving a BPP. In this model, each machine is a \"container\" with a maximum capacity of 1, and the production time of each product, including the required setup time, represents an \"item\" to be packed into these containers. The goal is to allocate each product + setup time to a minimum number of machines so that the total time assigned to any single machine does not exceed its capacity within each cycle. As mentioned, the BPP is classified as NP-HARD, meaning no efficient algorithm exists to solve it. However, many heuristic algorithms exist to provide approximate solutions. For relatively small instances of the BPP, it can be solved optimally by formulating it as a binary linear programming problem. To obtain an optimal solution, we formulate an Integer Linear Programming (ILP) model that represents our adapted version of the bin packing problem. This formulation is presented later as Equation (5). Figure 1: Inventory levels for a single product—EPQ model. The first step for optimization of (1) is to find a \"good\" feasible solution for the number of machines C, commonly by a heuristic method. This ensures that a feasible solution exists, even if it is not optimal. One can apply the First-fit-decreasing (FFD), a well-known algorithm for the bin packing problem, to calculate the initial C. Its input is a sorted list of items of different sizes, where the biggest is the first. Its output is a partition of the items into bins of fixed capacity. For more details about the FFD see [12], who proved that \(C\leq\frac{11}{9}M^{*}+\frac{6}{9}\). Therefore, one can set \(C\) as an upper bound in the linear programming formulation (1). If the result of the FFD is \(C=LB_{M}\), then \(M^{*}=C\) and the linear programming of (1) is not needed. Applying the FFD algorithm, in our case, needs the following steps:  
**Step 1**: Rank the product types \((j=1,\ldots,n)\) in descending order according to (2). **Step 2**: Assign the product type ranked first to the first machine. **Step 3**: Try to assign the product type ranked second to the first machine. If it cannot be assigned to the first machine due to a lack of capacity (the setup time + the processing time of the first product type and the setup time + the processing time of the second product type is more than 1), then assign this product type to the next machine.