Пример #1
0
        public static List <List <BarSet> > solveWithCleanUp(List <BarSet> orderSets, double stockLength)
        {
            // Sort DESC
            orderSets.Sort(delegate(BarSet a, BarSet b)
            {
                return(Math.Sign(b.len - a.len));
            });

            Pair <int, List <List <BarSet> > > remainRst = BruteForceSolver.solveRecursive(orderSets, stockLength);
            List <List <BarSet> > pttrns = remainRst.snd;

            // Remove BarSets in patterns that have num = 0
            for (int i = 0; i < pttrns.Count; i++)
            {
                List <BarSet> trimPtrn = new List <BarSet>();
                foreach (BarSet bs in pttrns[i])
                {
                    if (bs.num > 0)
                    {
                        trimPtrn.Add(bs);
                    }
                }
                pttrns[i] = trimPtrn;
            }

            return(pttrns);
        }
        /**
         * Main solver
         *
         * @param orderSets list of object of order length & order's length
         * @param stockLen  raw bar length to cut
         * @return Map of cutting pattern and num of them
         */
        public static Dictionary <List <BarSet>, int> solve(List <BarSet> orderSets, double stockLen)
        {
            Pair <Dictionary <List <BarSet>, int>, List <BarSet> > pair = solveByLinearProgramming(orderSets, stockLen);

            Dictionary <List <BarSet>, int> pttrnMap = pair.fst;
            List <BarSet> remainOrderSets            = pair.snd;

            List <List <BarSet> > remainPttrns = BruteForceSolver.solve(remainOrderSets, stockLen);

            // Add leftover to major result map
            foreach (List <BarSet> pattern in remainPttrns)
            {
                if (pattern.Count > 0)
                {
                    pttrnMap.Add(pattern, 1);
                }
            }

            return(pttrnMap);
        }