// Bin-packing with unit bin sizes and item sizes drawn // randomly between 0 and 1. public class BinPacking { // Implement the First-Fit algorithm. The bin size is 1. // itemSizes[i] = size of item i. static int[] firstFit (double[] itemSizes) { // INSERT YOUR CODE HERE. // Return an int array bins[i] where // bins[i] = which bin item i gets assigned to. // Temporarily: return null; } // Implement the Decreasing-First-Fit algorithm. The bin size is 1. // itemSizes[i] = size of item i. static int[] decreasingFirstFit (double[] itemSizes) { // INSERT YOUR CODE HERE. // Return an int array bins[i] where // bins[i] = which bin item i gets assigned to. // Temporarily: return null; } ///////////////////////////////////////////////////////////////////// // Number of samples used in each experiment trial. static int numSamples = 10; public static void main (String[] argv) { try { int numItems = 10; // Read number of items from command-line, if given. if (argv.length != 0) numItems = Integer.parseInt (argv[0]); runTests (numItems); } catch (Exception e) { e.printStackTrace(); } } static void runTests (int numItems) { // Maintain totals for averages of First-Fit (FF) and Decreasing-First-Fit (DFF). double totalFF=0, totalDFF=0; for (int n=0; n= numItems) ) { System.out.println ("Bad bin number"); System.exit(1); } if (bins[i] > max) max = bins[i]; } // Now check sizes. for (int i=0; i 1.0) { System.out.println ("Bin overflow: bin# " + i); System.exit(1); } } // Return number of bins used. return max+1; } }