예제 #1
0
        private static PackedBunches DoPack(IList <IGoods> goodsList, int knapsackSize, int overloadRange, PackedBunches packedBunches)
        {
            if (packedBunches != null)
            {
                knapsackSize = knapsackSize - packedBunches.Size;
            }

            List <IGoods> children = new List <IGoods>();

            foreach (IGoodsBunch item in goodsList)
            {
                if (item != null && item.Items != null && item.Size > 0 && (packedBunches == null || !packedBunches.Value.Contains(item)))
                {
                    children.AddRange(item.Items);
                }
            }
            PackedBunches result = DoPack(children, knapsackSize, overloadRange);

            if (result != null && result.Size >= knapsackSize)
            {
                result.AddRange(packedBunches);
                return(result);
            }

            return(packedBunches != null?DoPack(goodsList, knapsackSize + packedBunches.Size, overloadRange, null) : null);
        }
예제 #2
0
 internal void AddRange(PackedBunches packedInfo)
 {
     if (packedInfo != null)
     {
         _size = _size + packedInfo._size;
         _value.AddRange(packedInfo._value);
     }
 }
예제 #3
0
        private static PackedBunches DoPack(IList <IGoods> goodsList, int knapsackSize, int overloadRange)
        {
            PackedBunches packedBunches = PassablyPack(goodsList, knapsackSize + overloadRange, knapsackSize);

            if (packedBunches != null && packedBunches.Size >= knapsackSize)
            {
                return(packedBunches);
            }
            return(DoPack(goodsList, knapsackSize, overloadRange, packedBunches));
        }
예제 #4
0
        /// <summary>
        /// 打包(在超载范围内需撑满)
        /// </summary>
        /// <param name="goodsList">一组物品(含集束)</param>
        /// <param name="knapsackSize">背包规格</param>
        /// <param name="overloadRange">超载范围</param>
        /// <returns>是否成功</returns>
        public static PackedBunches Pack(IList <IGoods> goodsList, int knapsackSize, int overloadRange)
        {
            if (goodsList == null)
            {
                throw new ArgumentNullException(nameof(goodsList));
            }
            if (overloadRange < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(overloadRange));
            }

            PackedBunches result = DoPack(goodsList, knapsackSize, overloadRange);

            return(result != null && result.Size >= knapsackSize ? result : null);
        }