private List <string> GetElementDescriptions(SortedDictionary <string, List <CommissionElement> > elements)
        {
            List <string>     ret  = new List <string>();
            CommissionElement prev = new CommissionElement();

            foreach (KeyValuePair <string, List <CommissionElement> > p in elements)
            {
                int lastLen = 0;
                int count   = 0;
                foreach (CommissionElement e in p.Value)
                {
                    if (lastLen != e.GetInitialLength())
                    {
                        if (count != 0)
                        {
                            ret.Add(prev.ToString() + " Sztuk: " + count);
                            count = 0;
                        }
                    }

                    prev    = e;
                    lastLen = e.GetInitialLength();
                    ++count;
                }

                if (elements.Any())
                {
                    ret.Add(prev.ToString() + "  Sztuk: " + count);
                    ret.Add("");
                }
            }

            return(ret);
        }
        // Metoda próbuje wygenerować listę rozkrojową.
        private static bool TryAssignment(ref SortedDictionary <StoredElement, List <CommissionElement> > cutAssignment,
                                          List <StoredElement> store, List <CommissionElement> elementsToCut, bool bonding)
        {
            int secondIndex;

            while (elementsToCut.Any <CommissionElement>())
            {
                Tuple <int, int, int, int> indexLength  = new Tuple <int, int, int, int>(-1, -1, -1, -1);
                CommissionElement          largestToCut = elementsToCut[elementsToCut.Count - 1];
                int len = largestToCut.GetLength();

                int ind = FindSmallestPossible(store, len, -1);

                if (bonding)
                {
                    indexLength = FindSmallestPair(store, len);
                }

                if (ind == -1 && !bonding)
                {
                    return(false);
                }

                if (ind == -1 && (indexLength.Item1 == -1 || indexLength.Item2 == -1))
                {
                    return(false);
                }

                if (ind >= 0 && ((indexLength.Item1 == -1 || indexLength.Item2 == -1) ||
                                 (store[ind].GetLength() - len <= store[indexLength.Item1].GetLength() - indexLength.Item3 &&
                                  store[ind].GetLength() - len <= store[indexLength.Item2].GetLength() - indexLength.Item4)))
                {
                    if (!cutAssignment.ContainsKey(store[ind]))
                    {
                        cutAssignment.Add(store[ind], new List <CommissionElement>());
                    }
                    cutAssignment[store[ind]].Add(largestToCut);

                    elementsToCut.Remove(largestToCut);

                    int curr_len = store[ind].GetLength();

                    store[ind].SetLength(curr_len - len);
                    if (curr_len == len)
                    {
                        store.Remove(store[ind]);
                    }
                }
                else
                {
                    if (!cutAssignment.ContainsKey(store[indexLength.Item1]))
                    {
                        cutAssignment.Add(store[indexLength.Item1], new List <CommissionElement>());
                    }
                    cutAssignment[store[indexLength.Item1]].Add(
                        new CommissionElement("(" + largestToCut.GetLength().ToString() + ")", "", indexLength.Item3, 0));

                    if (!cutAssignment.ContainsKey(store[indexLength.Item2]))
                    {
                        cutAssignment.Add(store[indexLength.Item2], new List <CommissionElement>());
                    }
                    cutAssignment[store[indexLength.Item2]].Add(
                        new CommissionElement("(" + largestToCut.GetLength().ToString() + ")", "", indexLength.Item4, 0));

                    elementsToCut.Remove(largestToCut);

                    secondIndex = indexLength.Item2;

                    int curr_len = store[indexLength.Item1].GetLength();
                    store[indexLength.Item1].SetLength(curr_len - indexLength.Item3);
                    if (curr_len == indexLength.Item3)
                    {
                        store.Remove(store[indexLength.Item1]);

                        if (indexLength.Item1 < indexLength.Item2)
                        {
                            secondIndex = indexLength.Item2 - 1;
                        }
                        else
                        {
                            secondIndex = indexLength.Item2;
                        }
                    }

                    curr_len = store[secondIndex].GetLength();

                    store[secondIndex].SetLength(curr_len - indexLength.Item4);
                    if (curr_len == indexLength.Item4)
                    {
                        store.Remove(store[secondIndex]);
                    }
                }
            }

            return(true);
        }