Пример #1
0
 private void DeductItems(StockManager stock, CuttingInstructions cuttingInstructions)
 {
     stock.DeductFromStock(cuttingInstructions.StockLength,
                           cuttingInstructions.Cost,
                           cuttingInstructions.Quantity);
     foreach (var cutItem in cuttingInstructions.Items)
     {
         var item = Items.SingleOrDefault(i => i.Length == cutItem.Length);
         if (item == null)
             throw new InvalidOperationException("No item of that length " + cutItem.Length + " exists.");
         item.ReduceQuantityBy(cutItem.Quantity * cuttingInstructions.Quantity);
     }
 }
Пример #2
0
 private void DeductItems(StockManager stock, CuttingInstructions cuttingInstructions)
 {
     stock.DeductFromStock(cuttingInstructions.StockLength,
                           cuttingInstructions.Cost,
                           cuttingInstructions.Quantity);
     foreach (var cutItem in cuttingInstructions.Items)
     {
         var item = Items.SingleOrDefault(i => i.Length == cutItem.Length);
         if (item == null)
         {
             throw new InvalidOperationException("No item of that length " + cutItem.Length + " exists.");
         }
         item.ReduceQuantityBy(cutItem.Quantity * cuttingInstructions.Quantity);
     }
 }
Пример #3
0
        private CuttingInstructions GetBestInstructionsForRemainingPieces(StockManager stock)
        {
            if (!HasRemainingPieces)
            {
                return(null);
            }
            CuttingInstructions best = null;

            foreach (var stockItem in stock.Items)
            {
                var current = new CuttingInstructions(stock.ShapeId,
                                                      stockItem.Length,
                                                      stockItem.Cost,
                                                      stockItem.Kerf,
                                                      Items.Where(i => i.Quantity > 0)
                                                      .Select(i => i.Clone()));
                current.Optimize();
                if (best == null)
                {
                    best = current;
                }
                else
                {
                    if (current.Waste < best.Waste)
                    {
                        best = current;
                    }
                    else if (current.Waste == best.Waste)
                    {
                        var currentNumberOfCuts = current.Items.Sum(i => i.Quantity);
                        var bestNumberOfCuts    = best.Items.Sum(i => i.Quantity);
                        if (currentNumberOfCuts < bestNumberOfCuts)
                        {
                            best = current;
                        }
                        else if (currentNumberOfCuts == bestNumberOfCuts && current.StockLength > best.StockLength)
                        {
                            best = current;
                        }
                    }
                }
            }
            if (best != null)
            {
                DeductItems(stock, best);
            }
            return(best);
        }
Пример #4
0
 private CuttingInstructions GetBestInstructionsForRemainingPieces(StockManager stock)
 {
     if (!HasRemainingPieces)
         return null;
     CuttingInstructions best = null;
     foreach (var stockItem in stock.Items)
     {
         var current = new CuttingInstructions(stock.ShapeId,
                                               stockItem.Length,
                                               stockItem.Cost,
                                               stockItem.Kerf,
                                               Items.Where(i => i.Quantity > 0)
                                                   .Select(i => i.Clone()));
         current.Optimize();
         if (best == null)
         {
             best = current;
         }
         else
         {
             if (current.Waste < best.Waste)
             {
                 best = current;
             }
             else if (current.Waste == best.Waste)
             {
                 var currentNumberOfCuts = current.Items.Sum(i => i.Quantity);
                 var bestNumberOfCuts = best.Items.Sum(i => i.Quantity);
                 if (currentNumberOfCuts < bestNumberOfCuts)
                     best = current;
                 else if (currentNumberOfCuts == bestNumberOfCuts && current.StockLength > best.StockLength)
                     best = current;
             }
         }
     }
     if (best != null)
         DeductItems(stock, best);
     return best;
 }