示例#1
0
        public void BestFit(IFittingSet set)
        {
            set.Bins.Add(set.CreateNewBin());
              foreach (IFitting fit in set.Items)
              {
            fit.BinNumber = -1;
            IBin bestFit = null;

            for (int i = 0; i < set.Bins.Count; i++)
            {
              IBin bin = set.Bins[i];
              if (!bin.Closed && bin.SpaceRemaining > fit.Weight)
              {
            if (bestFit == null || bestFit.SpaceRemaining - fit.Weight < bin.SpaceRemaining - fit.Weight)
              bestFit = bin;
              }
            }

            if (bestFit != null)
            {
              fit.BinNumber = set.Bins.IndexOf(bestFit);
              bestFit.Add(fit);
            }

            if (fit.BinNumber == -1)
            {
              IBin bin = set.CreateNewBin();
              set.Bins.Add(bin);
              fit.BinNumber = set.Bins.Count - 1;
              bin.Add(fit);
            }
              }
        }
示例#2
0
        public void FirstFit(IFittingSet set)
        {
            set.Bins.Add(set.CreateNewBin());
              foreach (IFitting fit in set.Items)
              {
            fit.BinNumber = -1;
            for(int i=0; i<set.Bins.Count; i++)
            {
              IBin bin = set.Bins[i];
              if (!bin.Closed && bin.SpaceRemaining > fit.Weight)
              {
            fit.BinNumber = i;
            if(bin.Add(fit))
              break;
              }
            }

            if (fit.BinNumber == -1)
            {
              IBin bin = set.CreateNewBin();
              set.Bins.Add(bin);
              fit.BinNumber = set.Bins.Count - 1;
              bin.Add(fit);
            }
              }
        }