Ejemplo n.º 1
0
        /// <summary>
        /// 获取所有的组合方案
        /// </summary>
        /// <param name="list"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        private List <OutPutValue> GetAllCompose(List <ProductGrid> list, ProductGrid index)
        {
            List <OutPutValue> newlist = new List <OutPutValue>();
            //先增加它本身
            OutPutValue outPutValue_self = new OutPutValue();

            outPutValue_self.productList.Add(index);
            newlist.Add(outPutValue_self);

            for (int y = 0; y < list.Count; y++)
            {
                List <ProductGrid> tempvalue = new List <ProductGrid>();
                tempvalue.Add(index);
                for (int t = y; t < list.Count; t++)
                {
                    if (list[t].WaiJing == index.WaiJing && list[t].BiHou == index.BiHou &&
                        list[t].CaiZhi == index.CaiZhi && list[t].Dengji == index.Dengji)
                    {
                        tempvalue.Add(list[t]);
                        OutPutValue outPutValue = new OutPutValue();
                        foreach (var tempproduct in tempvalue)
                        {
                            outPutValue.productList.Add(tempproduct);
                        }
                        newlist.Add(outPutValue);
                    }
                }
            }
            return(newlist);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 计算切割方案
        /// </summary>
        /// <param name="materialGrids"></param>
        /// <param name="productGrids"></param>
        /// <param name="loss"></param>
        /// <returns></returns>
        private List <OutPutValue> Calculation(List <MaterialGrid> materialGrids, List <ProductGrid> productGrids, int loss)
        {
            List <OutPutValue> outPutValues = new List <OutPutValue>();

            //按长度升序排列
            productGrids = productGrids.OrderBy(a => a.length).ToList();

            //先筛除相同尺寸的材料(不需要加入损耗)
            for (int i = productGrids.Count - 1; i >= 0; i--)
            {
                //加入匹配
                var haveindex = materialGrids.FirstOrDefault(a => a.length == productGrids[i].length &&
                                                             a.WaiJing == productGrids[i].WaiJing &&
                                                             a.BiHou == productGrids[i].BiHou &&
                                                             a.CaiZhi == productGrids[i].CaiZhi &&
                                                             a.Dengji == productGrids[i].Dengji);
                if (haveindex != null)
                {
                    OutPutValue outPut = new OutPutValue();
                    outPut.material   = haveindex;
                    outPut.Percentage = 1;
                    outPut.SumSun     = 0;
                    outPut.productList.Add(productGrids[i]);

                    outPutValues.Add(outPut);

                    //移除第一个匹配项
                    materialGrids.Remove(haveindex);
                    productGrids.Remove(productGrids[i]);
                }
            }

            //在计算利用率最大的(需要计入损耗)
            for (int i = productGrids.Count - 1; i >= 0; i--)
            {
                if (productGrids.Count - 1 < i)
                {
                    continue;
                }
                //获取需要计算的出料的所有组合
                var y_temp       = productGrids;
                var y_temp_index = y_temp[i];
                y_temp.Remove(productGrids[i]);
                //加入匹配
                var composelist = GetAllCompose(y_temp, y_temp_index);

                //原材料去重
                //var x_distinct = materialGrids.Distinct().OrderBy(a => a).ToList();
                var x_distinct = materialGrids.GroupBy(c => c.length).Select(c => c.First());

                float       temppercent = 0;
                OutPutValue tempoutput  = null;

                //遍历所有出料的组合
                foreach (OutPutValue outPut_temp in composelist)
                {
                    int tempsum = outPut_temp.SumProduct();
                    //加入匹配
                    var tempmu = x_distinct.FirstOrDefault(a => a.length >= tempsum &&
                                                           a.WaiJing == outPut_temp.productList[0].WaiJing &&
                                                           a.BiHou == outPut_temp.productList[0].BiHou &&
                                                           a.CaiZhi == outPut_temp.productList[0].CaiZhi &&
                                                           a.Dengji == outPut_temp.productList[0].Dengji);
                    //如果原材料为0,则未找到对应匹配的原材料,不进行处理
                    if (tempmu != null)
                    {
                        //计算利用率
                        int sun1 = loss * (outPut_temp.productList.Count() - 1);
                        int sun2 = loss * outPut_temp.productList.Count();
                        if (tempsum + sun1 == tempmu.length)
                        {
                            //如果总和长度与原材料相同(不需要计入最后一次损耗,并且直接输出)

                            temppercent = 1;

                            tempoutput            = outPut_temp;
                            tempoutput.material   = tempmu;
                            tempoutput.Percentage = temppercent;
                            tempoutput.SumSun     = sun1;
                            break;
                        }
                        else
                        {
                            //如果不相同,则需要计算利用率
                            tempsum = tempsum + sun2;
                            float temppercent_t = (float)tempsum / tempmu.length;
                            if (temppercent_t > temppercent && temppercent_t <= 1)
                            {
                                temppercent = temppercent_t;

                                tempoutput            = outPut_temp;
                                tempoutput.material   = tempmu;
                                tempoutput.Percentage = temppercent;
                                tempoutput.SumSun     = sun2;
                            }
                        }
                    }
                }

                if (tempoutput != null)
                {
                    outPutValues.Add(tempoutput);
                    materialGrids.Remove(tempoutput.material);
                    foreach (var tempy in tempoutput.productList)
                    {
                        productGrids.Remove(tempy);
                    }
                }
            }
            return(outPutValues);
        }