public virtual Solution Decode(IntegerVector intVec, PackingShape binShape, IList <PackingItem> items, bool useStackingConstraints)
        {
            var      sequenceMatrix = IntegerVectorProblem.GenerateSequenceMatrix(intVec);
            Solution result         = CreateSolution(binShape, useStackingConstraints);

            //Fill bins according to grouping vector
            IList <int> remainingIDs = new List <int>();

            foreach (var sequence in sequenceMatrix)
            {
                remainingIDs = remainingIDs.Concat(sequence).ToList();
                result.Bins.Add(CreatePacking(result, ref remainingIDs, items, useStackingConstraints));
            }
            result.UpdateBinPackings();

            //Try to put remaining items in existing bins
            var temp = new List <int>(remainingIDs);

            foreach (int id in temp)
            {
                foreach (BinPacking3D bp in result.Bins)
                {
                    var position = FindPositionForItem(bp, items[id], useStackingConstraints);
                    if (position != null)
                    {
                        bp.PackItem(id, items[id], position);
                        remainingIDs.Remove(id);
                        break;
                    }
                }
            }

            //Put still remaining items in new bins
            while (remainingIDs.Count > 0)
            {
                result.Bins.Add(CreatePacking(result, ref remainingIDs, items, useStackingConstraints));
            }
            result.UpdateBinPackings();

            // gkronber: original implementation by Helm also updates the encoded solution (TODO)
            // var newSolution = new int[intVec.Length];
            // int binIndex = 0;
            // foreach (var bp in result.BinPackings) {
            //   foreach (var entry in bp.ItemPositions)
            //     newSolution[entry.Key] = binIndex;
            //   binIndex++;
            // }
            // solution.GroupingVector = new IntegerVector(newSolution);

            return(result);
        }
 // cloning
 private IntegerVectorProblem(IntegerVectorProblem original, Cloner cloner)
     : base(original, cloner)
 {
     RegisterEventHandlers();
 }