Esempio n. 1
0
        /// <summary>
        /// Creates boxes of pickslip using the passed case. The newly created boxes are accepted
        /// only if the number of boxes created is less than the existing number of boxes.
        /// Returns whether the boxes were accepted.
        /// </summary>
        /// <param name="boxCase"></param>
        /// <returns></returns>
        private bool CreateBoxesUsingBoxCase(PickslipGroup pickslipGroup, BoxCase boxCase)
        {
            // Remember the current solution
            List <Box> curBoxes = pickslipGroup.RelinquishBoxList();

            // Create a new solution
            pickslipGroup.CreateBoxes(this, boxCase);
            if (curBoxes != null && pickslipGroup.Boxes.Count > curBoxes.Count)
            {
                // This solution is worse. Accept the previous solution as the final solution
                pickslipGroup.SetBoxList(curBoxes);
                return(false);
            }
            else
            {
                // The solution was accepted
                return(true);
            }
        }
Esempio n. 2
0
 public Box(BoxCase boxCase)
 {
     _boxCase = boxCase;
 }
Esempio n. 3
0
        /// <summary>
        /// Creates boxes for the pickslip group using the passed case.
        /// </summary>
        /// <param name="boxCase"></param>
        /// <returns></returns>
        /// <remarks>
        /// <para>
        /// If an SKU is too big for the case, we will put it in an empty case and log a warning.
        /// </para>
        /// </remarks>
        public void CreateBoxes(CustomerConstraints constraints, BoxCase boxCase)
        {
            //Variable created for storing the previous style and color
            //string previousStyle = string.Empty;
            //string previousColor = string.Empty;
            Sku prevSku = null;
            Box currentBox = new Box(boxCase);
            var query = from sku in this.AllSku
                        orderby sku.Style, sku.Color, sku.Identifier, sku.Dimension, sku.SkuSize
            select sku;

            foreach (Sku sku in query)
            {
                // Decide whether we want to possibly add this SKU to the same box
                bool bCanAddtoSameBox;
                if (prevSku == null)
                {
                    bCanAddtoSameBox = true;
                }
                else
                {
                    switch (constraints.SkuMixing)
                    {
                    case SkuPerBox.NoConstraint:
                        bCanAddtoSameBox = true;
                        break;

                    case SkuPerBox.SingleSku:
                        bCanAddtoSameBox = sku.UpcCode == prevSku.UpcCode;
                        break;

                    case SkuPerBox.SingleStyleColor:
                        bCanAddtoSameBox = sku.Style == prevSku.Style && sku.Color == prevSku.Color;
                        break;

                    default:
                        throw new NotImplementedException();
                    }
                }

                //If MaximumSKUPerBox is 0 or not defined ignore this.
                if (bCanAddtoSameBox && constraints.MaxSkuPerBox > 0)
                {
                    //Only add this SKU when total SKUs in box is less than max SKUs per box.
                    bCanAddtoSameBox = currentBox.AllSku.Count() < constraints.MaxSkuPerBox;
                }

                //In Case label wise Maximum Pieces per box is defined honor this.
                if (bCanAddtoSameBox && this._maxPiecesPerBox > 1)
                {
                    bCanAddtoSameBox = currentBox.TotalPieces < this._maxPiecesPerBox;
                }

                if (!bCanAddtoSameBox)
                {
                    //add the box in boxlist only box contain some pieces other wise discard the previous created box.
                    if (currentBox.TotalPieces > 0)
                    {
                        this.Boxes.Add(currentBox);
                    }
                    else
                    {
                        throw new NotImplementedException("Will this happen?");
                    }
                    currentBox = new Box(boxCase);
                }

                prevSku = sku;

                // Use all pieces of this SKU
                while (sku.AvailablePieces > 0)
                {
                    int usedPieces = currentBox.AcceptSku(sku, this._maxPiecesPerBox, this._minPiecesPerBox, constraints.BoxMaxWeight);
                    if (usedPieces < sku.AvailablePieces)
                    {
                        #region Debug
#if DEBUG
                        // This box could not accept all. So this box is complete.
                        if (usedPieces == 0 && currentBox.TotalPieces == 0)
                        {
                            // The box was empty and yet it did not accept any piece.
                            // This is not supposed to happen and will cause infinite loop.
                            throw new InvalidOperationException();
                        }
#endif
                        #endregion
                        this.Boxes.Add(currentBox);
                        currentBox = new Box(boxCase);
                    }
                    sku.ConsumedPieces += usedPieces;
                }
            }

            if (currentBox.TotalPieces == 0)
            {
                throw new InvalidOperationException("Will this happen ?");
            }
            this.Boxes.Add(currentBox);
            return;
        }