Пример #1
0
 protected override void AllocateAll(IRequirementBatch batch)
 {
     foreach (var req in batch.Unallocated)
     {
         var stocks    = batch.GetAvailableStock(req.Product);
         var allocated = 0;
         foreach (var stock in stocks)
         {
             var quantity = Math.Min(req.Quantity - allocated, stock.Quantity);
             if (ShouldAllocate(stock, quantity))
             {
                 allocated += quantity;
                 batch.AddPurchaseOrderLine(stock.Supplier, stock.Product, stock.Cost, quantity);
                 if (req.Quantity == allocated)
                 {
                     break;
                 }
             }
             else
             {
                 break;
             }
         }
     }
 }
Пример #2
0
        protected override void AllocateAll(IRequirementBatch batch)
        {
            Reset();
            var requirements = batch.Unallocated
                               .Select(x => GetAllPremutations(x, batch.GetAvailableStock(x.Product).ToList()))
                               .ToArray();

            var premuter = new Premuting <PurchaseOrderLine[]>(requirements);

            premuter.Premute((combination, current, total) => ProcessPo(batch, combination, current, total));
            foreach (var item in _cheapest)
            {
                batch.AddPurchaseOrderLine(item);
            }
            ;
            OnProgress(true);
            Console.WriteLine();
            Console.WriteLine($"{nameof(BestCombinationAllocator)} - Cheapest {_lowestTotal} Most expensive: {_highestTotal}");
        }