Exemplo n.º 1
0
        /// <summary>
        /// Performs Best Fit with "Best" Defined as the fit which will result in the lowest remaining length in the Bin being fitted into.
        /// </summary>
        /// <param name="Bins"></param>
        /// <param name="Items"></param>
        static void BestFitMinRemainingLength(ref List <Bin> Bins, ref List <Item> Items)
        {
            double MaximumBinLength = FittingResultComputer.ComputeMaximumBinLength(Bins);

            for (int i = 0; i < Items.Count; i++) // For each Item, in the order they appear:
            {
                Item    Item        = Items[i];
                Boolean AnyFitFound = false;
                double  MinimumWastedLengthRemaining = MaximumBinLength;
                int     IndexOfBestFitBin            = -1;
                for (int j = 0; j < Bins.Count; j++) // For each Bin, in the order they appear:
                {
                    Bin Bin = Bins[j];
                    if (Item.Length <= Bin.RemainingLength && Item.Effect <= Bin.Resistance)
                    {
                        if (Bin.RemainingLength - Item.Length < MinimumWastedLengthRemaining)
                        {
                            MinimumWastedLengthRemaining = Bin.RemainingLength - Item.Length;
                            IndexOfBestFitBin            = j;
                            AnyFitFound = true;
                        }
                    }
                }
                if (AnyFitFound == false)
                {
                    //Console.WriteLine("Failed to fit Item " + i);
                }
                else
                {
                    AddItemToBin(Bins[IndexOfBestFitBin], Item);
                }
            }
        }
Exemplo n.º 2
0
 public FittingResult(List <Bin> Bins, List <Item> Items, FitStrategy FitStrategy, TimeSpan TimeElapsed)
 {
     this.FitStrategy        = FitStrategy;
     this.Bins               = Bins;
     this.Items              = Items;
     this.TimeElapsedInTicks = TimeElapsed.Ticks;
     NumberOfBinsUsed        = FittingResultComputer.ComputeNumberOfBinsUsed(Bins);
     NumberOfItemsNotFitted  = FittingResultComputer.ComputeNumberOfItemsNotFitted(Items);
     TotalWastedLength       = FittingResultComputer.ComputeTotalWastedLength(Bins);
     TotalRemainingLength    = FittingResultComputer.ComputeTotalRemainingLength(Bins);
 }