Beispiel #1
0
        public void deal()
        {
            Wood newWood = new Wood(0, 0, 0, 0, 0);
            int  count   = 1;

            foreach (Wood wood in dataList)
            {
                dicernWood(wood);
            }

            for (int i = 0; i < sourceList.Count; i++)
            {
                dealList.Clear();
                if (sourceList[i].range > 0 && sourceList[i].packageNumber == 0)
                {
                    dealList.Add(sourceList[i]);

                    for (int j = 0; j < sourceList.Count; j++)
                    {
                        if (dealList.Count == sourceList[i].range)
                        {
                            for (int t = 0; t < dealList.Count; t++)
                            {
                                int index = sourceList.IndexOf(dealList[t]);
                                sourceList[index].packageNumber = count;
                            }
                            count++;
                            break;
                        }
                        else
                        {
                            if (sourceList[j].width == sourceList[i].width && sourceList[j].length == sourceList[i].length && sourceList[j].thickness == sourceList[i].thickness && sourceList[j].packageNumber == 0 && sourceList[j].id != sourceList[i].id)
                            {
                                dealList.Add(sourceList[j]);
                            }
                        }
                    }
                }
            }
            for (int i = 0; i < sourceList.Count; i++)
            {
                Boolean flag = false;
                if (sourceList[i].range > 0 && sourceList[i].packageNumber == 0)
                {
                    for (int k = sourceList[i].range - 1; k >= 1; k--)
                    {
                        double total = sourceList[i].value;
                        dealList.Clear();
                        dealList.Add(sourceList[i]);
                        bool note = true;
                        for (int j = 0; j < sourceList.Count; j++)
                        {
                            if (dealList.Count >= k)
                            {
                                if (sourceList[j].id != sourceList[i].id && sourceList[j].packageNumber == 0)
                                {
                                    /*if (sourceList[i].range == 30)
                                     * {
                                     *  note = false;
                                     * }*/
                                    int check = 0;
                                    if (sourceList[i].range != 30)
                                    {
                                        for (int z = 0; z < dealList.Count; z++)
                                        {
                                            if (sourceList[j].length - dealList[z].length > 162 || sourceList[j].length - dealList[z].length < -162)
                                            {
                                                break;
                                            }

                                            /* if (sourceList[j].range != 30 && note == false)
                                             * {
                                             *   break;
                                             * }*/
                                            else
                                            {
                                                check++;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        for (int z = 0; z < dealList.Count; z++)
                                        {
                                            if (sourceList[j].length - dealList[z].length > 162 || sourceList[j].length - dealList[z].length < -162 || sourceList[j].range != 30)
                                            {
                                                break;
                                            }
                                            else
                                            {
                                                check++;
                                            }
                                        }
                                    }
                                    if (check == dealList.Count)
                                    {
                                        total += sourceList[j].value;
                                        if (total <= 1)
                                        {
                                            //if (count == 18)
                                            //{
                                            //    MessageBox.Show(total.ToString() + ":" + sourceList[j].id);
                                            //}
                                            dealList.Add(sourceList[j]);
                                        }
                                        else
                                        {
                                            total -= sourceList[j].value;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (sourceList[j].width == sourceList[i].width && sourceList[j].length == sourceList[i].length && sourceList[j].thickness == sourceList[i].thickness && sourceList[j].packageNumber == 0 && sourceList[j].id != sourceList[i].id)
                                {
                                    dealList.Add(sourceList[j]);
                                    total += sourceList[j].value;
                                }
                            }
                        }

                        if (dealList.Count >= k)
                        {
                            flag = true;
                        }

                        if (flag == true)
                        {
                            for (int t = 0; t < dealList.Count; t++)
                            {
                                int index = sourceList.IndexOf(dealList[t]);
                                sourceList[index].packageNumber = count;
                            }

                            count++;
                            flag = false;
                            break;
                        }
                    }
                }
            }

            foreach (Wood wood in sourceList)
            {
                if (wood.packageNumber > 0)
                {
                    result.Add(wood);
                }
                else
                {
                    if (wood.range == 2)
                    {
                        two.Add(wood);
                    }
                    else if (wood.range == 3)
                    {
                        three.Add(wood);
                    }
                    else if (wood.range == 4)
                    {
                        four.Add(wood);
                    }
                    else if (wood.range == 5)
                    {
                        five.Add(wood);
                    }
                    else if (wood.range == 0)
                    {
                        wrongData.Add(wood);
                    }
                }
            }

            while (one.Count > 0)
            {
                newWood = one[0];
                one.RemoveAt(0);
                newWood.packageNumber = count;
                dist.Add(newWood);
                count++;
            }

            while (two.Count > 1)
            {
                for (int i = 0; i < 2; i++)
                {
                    newWood = two[0];
                    two.RemoveAt(0);
                    newWood.packageNumber = count;
                    dist.Add(newWood);
                }
                count++;
            }

            while (three.Count > 2)
            {
                for (int i = 0; i < 3; i++)
                {
                    newWood = three[0];
                    three.RemoveAt(0);
                    newWood.packageNumber = count;
                    dist.Add(newWood);
                }
                count++;
            }

            while (four.Count > 3)
            {
                for (int i = 0; i < 4; i++)
                {
                    newWood = four[0];
                    four.RemoveAt(0);
                    newWood.packageNumber = count;
                    dist.Add(newWood);
                }
                count++;
            }

            while (five.Count > 4)
            {
                for (int i = 0; i < 5; i++)
                {
                    newWood = five[0];
                    five.RemoveAt(0);
                    newWood.packageNumber = count;
                    dist.Add(newWood);
                }
                count++;
            }
            while (two.Count > 0 && four.Count > 1)
            {
                if (Math.Abs(two[0].length - four[0].length) <= 162 && Math.Abs(two[0].length - four[1].length) <= 162 && Math.Abs(four[0].length - four[1].length) <= 162)
                {
                    newWood = two[0];
                    two.RemoveAt(0);
                    newWood.packageNumber = count;
                    dist.Add(newWood);
                    for (int i = 0; i < 2; i++)
                    {
                        newWood = four[0];
                        four.RemoveAt(0);
                        newWood.packageNumber = count;
                        dist.Add(newWood);
                    }
                    count++;
                }
                else
                {
                    break;
                }
            }



            while (two.Count > 0 && five.Count > 0 && four.Count > 0)
            {
                if (Math.Abs(two[0].length - five[0].length) <= 162 && Math.Abs(two[0].length - four[0].length) <= 162 && Math.Abs(four[0].length - five[0].length) <= 162)
                {
                    newWood = two[0];
                    two.RemoveAt(0);
                    newWood.packageNumber = count;
                    dist.Add(newWood);
                    newWood = five[0];
                    five.RemoveAt(0);
                    newWood.packageNumber = count;
                    dist.Add(newWood);
                    newWood = four[0];
                    four.RemoveAt(0);
                    newWood.packageNumber = count;
                    dist.Add(newWood);
                    count++;
                }
                else
                {
                    break;
                }
            }

            while (three.Count > 0 && five.Count > 2)
            {
                if (Math.Abs(three[0].length - five[0].length) <= 162 && Math.Abs(three[0].length - five[1].length) <= 162 && Math.Abs(five[0].length - five[1].length) <= 162)
                {
                    newWood = three[0];
                    three.RemoveAt(0);
                    newWood.packageNumber = count;
                    dist.Add(newWood);
                    for (int i = 0; i < 2; i++)
                    {
                        newWood = five[0];
                        five.RemoveAt(0);
                        newWood.packageNumber = count;
                        dist.Add(newWood);
                    }
                    count++;
                }
                else
                {
                    break;
                }
            }

            while (two.Count > 0 && five.Count > 1)
            {
                if (Math.Abs(two[0].length - five[0].length) <= 162 && Math.Abs(two[0].length - five[1].length) <= 162 && Math.Abs(five[0].length - five[1].length) <= 162)
                {
                    newWood = two[0];
                    two.RemoveAt(0);
                    newWood.packageNumber = count;
                    dist.Add(newWood);
                    for (int i = 0; i < 1; i++)
                    {
                        newWood = five[0];
                        five.RemoveAt(0);
                        newWood.packageNumber = count;
                        dist.Add(newWood);
                    }
                    count++;
                }
                else
                {
                    break;
                }
            }

            while (four.Count > 0 && five.Count > 2)
            {
                if (Math.Abs(four[0].length - five[0].length) <= 162 && Math.Abs(four[0].length - five[1].length) <= 162 && Math.Abs(five[0].length - five[1].length) <= 162)
                {
                    newWood = four[0];
                    four.RemoveAt(0);
                    newWood.packageNumber = count;
                    dist.Add(newWood);
                    for (int i = 0; i < 3; i++)
                    {
                        newWood = five[0];
                        five.RemoveAt(0);
                        newWood.packageNumber = count;
                        dist.Add(newWood);
                    }
                    count++;
                }
                else
                {
                    break;
                }
            }

            while (two.Count > 0 && three.Count > 0)
            {
                if (Math.Abs(two[0].length - three[0].length) <= 162)
                {
                    newWood = two[0];
                    two.RemoveAt(0);
                    newWood.packageNumber = count;
                    dist.Add(newWood);
                    newWood = three[0];
                    three.RemoveAt(0);
                    newWood.packageNumber = count;
                    dist.Add(newWood);
                    count++;
                }
                else
                {
                    break;
                }
            }

            while (four.Count > 1 && three.Count > 0)
            {
                if (Math.Abs(three[0].length - four[0].length) <= 162 && Math.Abs(three[0].length - four[1].length) <= 162 && Math.Abs(four[0].length - four[1].length) <= 162)
                {
                    newWood = three[0];
                    three.RemoveAt(0);
                    newWood.packageNumber = count;
                    dist.Add(newWood);
                    for (int i = 0; i < 2; i++)
                    {
                        newWood = four[0];
                        four.RemoveAt(0);
                        newWood.packageNumber = count;
                        dist.Add(newWood);
                    }
                    count++;
                }
            }

            while (five.Count > 3)
            {
                if (Math.Abs(five[0].length - five[1].length) <= 162 && Math.Abs(five[0].length - five[2].length) <= 162 && Math.Abs(five[0].length - five[3].length) <= 162 && Math.Abs(five[1].length - five[2].length) <= 162 && Math.Abs(five[1].length - five[3].length) <= 162 && Math.Abs(five[2].length - five[3].length) <= 162)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        newWood = five[0];
                        five.RemoveAt(0);
                        newWood.packageNumber = count;
                        dist.Add(newWood);
                    }
                    count++;
                }
                else
                {
                    break;
                }
            }

            while (two.Count > 0 && four.Count > 0)
            {
                if (Math.Abs(two[0].length - four[0].length) <= 162)
                {
                    newWood = two[0];
                    two.RemoveAt(0);
                    newWood.packageNumber = count;
                    dist.Add(newWood);
                    newWood = four[0];
                    four.RemoveAt(0);
                    newWood.packageNumber = count;
                    dist.Add(newWood);
                    count++;
                }
                else
                {
                    break;
                }
            }

            while (four.Count > 2)
            {
                if (Math.Abs(four[0].length - four[1].length) <= 162 && Math.Abs(four[0].length - four[2].length) <= 162 && Math.Abs(four[1].length - four[2].length) <= 162)
                {
                    for (int i = 0; i < 3; i++)
                    {
                        newWood = four[0];
                        four.RemoveAt(0);
                        newWood.packageNumber = count;
                        dist.Add(newWood);
                    }
                    count++;
                }
                else
                {
                    break;
                }
            }

            while (three.Count > 0 && five.Count > 1)
            {
                if (Math.Abs(three[0].length - five[0].length) <= 162 && Math.Abs(three[0].length - five[1].length) <= 162 && Math.Abs(five[0].length - four[1].length) <= 162)
                {
                    newWood = three[0];
                    three.RemoveAt(0);
                    newWood.packageNumber = count;
                    dist.Add(newWood);
                    for (int i = 0; i < 2; i++)
                    {
                        newWood = five[0];
                        five.RemoveAt(0);
                        newWood.packageNumber = count;
                        dist.Add(newWood);
                    }
                    count++;
                }
                else
                {
                    break;
                }
            }

            while (four.Count > 1 && five.Count > 0)
            {
                if (Math.Abs(five[0].length - four[0].length) <= 162 && Math.Abs(five[0].length - four[1].length) <= 162 && Math.Abs(four[0].length - four[1].length) <= 162)
                {
                    for (int i = 0; i < 2; i++)
                    {
                        newWood = four[0];
                        four.RemoveAt(0);
                        newWood.packageNumber = count;
                        dist.Add(newWood);
                    }
                    newWood = five[0];
                    five.RemoveAt(0);
                    newWood.packageNumber = count;
                    dist.Add(newWood);
                    count++;
                }
                else
                {
                    break;
                }
            }

            while (two.Count > 0 && five.Count > 0)
            {
                if (Math.Abs(two[0].length - five[0].length) <= 162)
                {
                    newWood = two[0];
                    two.RemoveAt(0);
                    newWood.packageNumber = count;
                    dist.Add(newWood);
                    newWood = five[0];
                    five.RemoveAt(0);
                    newWood.packageNumber = count;
                    dist.Add(newWood);
                    count++;
                }
                else
                {
                    break;
                }
            }

            while (four.Count > 0 && five.Count > 1)
            {
                if (Math.Abs(four[0].length - five[0].length) <= 162 && Math.Abs(four[0].length - five[1].length) <= 162 && Math.Abs(five[0].length - five[1].length) <= 162)
                {
                    newWood = four[0];
                    four.RemoveAt(0);
                    newWood.packageNumber = count;
                    dist.Add(newWood);
                    for (int i = 0; i < 2; i++)
                    {
                        newWood = five[0];
                        five.RemoveAt(0);
                        newWood.packageNumber = count;
                        dist.Add(newWood);
                    }
                    count++;
                }
                else
                {
                    break;
                }
            }

            while (three.Count > 1)
            {
                if (Math.Abs(three[0].length - three[1].length) <= 162)
                {
                    for (int i = 0; i < 2; i++)
                    {
                        newWood = three[0];
                        three.RemoveAt(0);
                        newWood.packageNumber = count;
                        dist.Add(newWood);
                    }
                    count++;
                }
                else
                {
                    break;
                }
            }

            while (five.Count > 2)
            {
                if (Math.Abs(five[0].length - five[1].length) <= 162 && Math.Abs(five[0].length - five[2].length) <= 162 && Math.Abs(five[1].length - five[2].length) <= 162)
                {
                    for (int i = 0; i < 3; i++)
                    {
                        newWood = five[0];
                        five.RemoveAt(0);
                        newWood.packageNumber = count;
                        dist.Add(newWood);
                    }
                    count++;
                }
                else
                {
                    break;
                }
            }

            while (three.Count > 0 && four.Count > 0)
            {
                if (Math.Abs(three[0].length - four[0].length) <= 162)
                {
                    newWood = three[0];
                    three.RemoveAt(0);
                    newWood.packageNumber = count;
                    dist.Add(newWood);
                    newWood = four[0];
                    four.RemoveAt(0);
                    newWood.packageNumber = count;
                    dist.Add(newWood);
                    count++;
                }
                else
                {
                    break;
                }
            }

            while (three.Count > 0 && five.Count > 0)
            {
                if (Math.Abs(three[0].length - five[0].length) <= 162)
                {
                    newWood = three[0];
                    three.RemoveAt(0);
                    newWood.packageNumber = count;
                    dist.Add(newWood);
                    newWood = five[0];
                    five.RemoveAt(0);
                    newWood.packageNumber = count;
                    dist.Add(newWood);
                    count++;
                }
                else
                {
                    break;
                }
            }
            while (four.Count > 1)
            {
                if (Math.Abs(four[0].length - four[1].length) <= 162)
                {
                    for (int i = 0; i < 2; i++)
                    {
                        newWood = four[0];
                        four.RemoveAt(0);
                        newWood.packageNumber = count;
                        dist.Add(newWood);
                    }
                    count++;
                }
                else
                {
                    break;
                }
            }

            while (four.Count > 0 && five.Count > 0)
            {
                if (Math.Abs(four[0].length - five[0].length) <= 162)
                {
                    newWood = four[0];
                    four.RemoveAt(0);
                    newWood.packageNumber = count;
                    dist.Add(newWood);
                    newWood = five[0];
                    five.RemoveAt(0);
                    newWood.packageNumber = count;
                    dist.Add(newWood);
                    count++;
                }
                else
                {
                    break;
                }
            }

            while (five.Count > 1)
            {
                if (Math.Abs(five[0].length - five[1].length) <= 162)
                {
                    for (int i = 0; i < 2; i++)
                    {
                        newWood = five[0];
                        five.RemoveAt(0);
                        newWood.packageNumber = count;
                        dist.Add(newWood);
                    }
                    count++;
                }
                else
                {
                    break;
                }
            }

            //  MessageBox.Show(two.Count + ":" + three.Count + ":" + four.Count + ":" + five.Count + ":");

            if (two.Count > 0)
            {
                newWood = two[0];
                two.RemoveAt(0);
                newWood.packageNumber = count;
                dist.Add(newWood);
            }
            if (three.Count > 0)
            {
                newWood = three[0];
                three.RemoveAt(0);
                newWood.packageNumber = count;
                dist.Add(newWood);
            }
            if (four.Count > 0)
            {
                newWood = four[0];
                four.RemoveAt(0);
                newWood.packageNumber = count;
                dist.Add(newWood);
            }
            if (five.Count > 0)
            {
                newWood = five[0];
                five.RemoveAt(0);
                newWood.packageNumber = count;
                dist.Add(newWood);
            }

            for (int i = 0; i < wrongData.Count; i++)
            {
                wrongData[i].packageNumber = count;
                count++;
            }


            dist.AddRange(wrongData);
            dist.AddRange(result);
            dist.Sort();
        }
Beispiel #2
0
        public void dicernWood(Wood wood)
        {
            if (wood.width >= 800 && wood.length >= 800)
            {
                if (wood.thickness < 25)
                {
                    wood.range = 2;
                    wood.value = 0.50 * wood.num;
                    //two.Add(wood);
                }
                else
                {
                    wood.range = 1;
                    wood.value = 1;
                    // one.Add(wood);
                }
            }
            else if (wood.width < 800 && wood.width >= 600 && wood.length < 2440 && wood.length >= 1500)
            {
                wood.range = 2;
                wood.value = 0.50 * wood.num;
                // two.Add(wood);
            }
            else if (wood.width < 600 && wood.width >= 350 && wood.length < 2440 && wood.length >= 1900)
            {
                wood.value = 0.50 * wood.num;
                wood.range = 2;
                // two.Add(wood);
            }

            else if (wood.width < 800 && wood.width >= 600 && wood.length < 1500 && wood.length >= 800)
            {
                wood.value = 0.33 * wood.num;
                wood.range = 3;
                // three.Add(wood);
            }
            else if (wood.width < 600 && wood.width >= 350 && wood.length < 1900 && wood.length >= 1500)
            {
                wood.range = 3;
                wood.value = 0.33 * wood.num;
                // three.Add(wood);
            }

            else if (wood.width < 350 && wood.width >= 200 && wood.length < 2440 && wood.length >= 1990)
            {
                wood.range = 3;
                wood.value = 0.33 * wood.num;
                // three.Add(wood);
            }
            else if (wood.width < 200 && wood.length < 2440)
            {
                wood.range = 30;
                wood.value = 0.033 * wood.num;
            }
            else if (wood.width < 800 && wood.width >= 600 && wood.length < 800)
            {
                if (wood.thickness > 25)
                {
                    wood.range = 3;
                    wood.value = 0.33 * wood.num;
                    //three.Add(wood);
                }
                else
                {
                    wood.range = 4;
                    wood.value = 0.25 * wood.num;
                    //four.Add(wood);
                }
            }

            else if (wood.width < 600 && wood.width >= 350 && wood.length >= 800 && wood.length < 1500)
            {
                if (wood.thickness > 25)
                {
                    wood.range = 3;
                    wood.value = 0.33 * wood.num;
                    //three.Add(wood);
                }
                else
                {
                    wood.range = 4;
                    wood.value = 0.25 * wood.num;
                    //four.Add(wood);
                }
            }

            /*else if (wood.width < 450 && wood.width >= 320 && wood.length < 1200)
             * {
             *  if (wood.thickness > 25)
             *  {
             *      three.Add(wood);
             *  }
             *  else
             *  {
             *      four.Add(wood);
             *  }
             * }*/
            else if (wood.width < 600 && wood.width >= 200 && wood.length <= 800)
            {
                if (wood.thickness > 25)
                {
                    wood.range = 4;
                    wood.value = 0.25 * wood.num;
                    //four.Add(wood);
                }
                else
                {
                    wood.range = 5;
                    wood.value = 0.20 * wood.num;
                    //five.Add(wood);
                }
            }
            else
            {
                wood.range = 0;
                wood.value = 0 * wood.num;
                //wrongData.Add(wood);
            }


            sourceList.Add(wood);
        }