'Bin packing, how do I include multiple 'bin sizes'
The code below is working well, however it isn't quite what I am looking for. It finds an efficient way to cut variable sizes (user input) from one static stock size. I want to alter the code so it finds an efficient way to cut the variable sizes from multiple static stock sizes, 4 to be specific.
public static void binPacking(double[] FinalCuttingList, double size, int TotalCuts)
{
int StockLengthCount = 0;
double[] StockValues = new double[TotalCuts];
for (int i = 0; i < StockValues.length; i++)
StockValues[i] = size;
for (int i = 0; i < TotalCuts; i++)
for (int o = 0; o < StockValues.length; o++)
{
if (StockValues[o] - FinalCuttingList[i] >= 0)
{
StockValues[o] -= FinalCuttingList[i];
break;
}
}
for (int i = 0; i < StockValues.length; i++)
if (StockValues[i] != size)
StockLengthCount++;
System.out
.println("Number of 3400mm pieces required is :"
+ StockLengthCount);
}
static double[] sort(double[] sequence)
{
// Sort in descending order
for (int i = 0; i < sequence.length; i++)
for (int o = 0; o < sequence.length - 1; o++)
if (sequence[o] < sequence[o + 1])
{
sequence[o] = sequence[o] + sequence[o + 1];
sequence[o + 1] = sequence[o] - sequence[o + 1];
sequence[o] = sequence[o] - sequence[o + 1];
}
return sequence;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
