Пример #1
0
        /**
         * Main solver with threshold
         *
         * @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 Dictionary <List <BarSet>, int> solve(List <BarSet> orderSets, double stockLen)
        {
            List <BarSet> newOrders = removeOrderLongerThanStock(orderSets, stockLen);
            BarSets       orders    = new BarSets(newOrders);

            orders.sortDesc();

            Dictionary <BarSets, int> pttrnMap = new Dictionary <BarSets, int>();

            while (orders.count() > 0)
            {
                BarSets pttrn = optimizeToOneStock(stockLen, orders);
                if (pttrn == null)
                {
                    // Can't solve with condition, return empty result
                    break;
                }
                addPatternToDictionary(pttrnMap, pttrn);
                orders.substractAll(pttrn);
            }

            Dictionary <List <BarSet>, int> rstMap = new Dictionary <List <BarSet>, int>();

            foreach (KeyValuePair <BarSets, int> entry in pttrnMap)
            {
                rstMap.Add(entry.Key.getBarSets(), entry.Value);
            }
            return(rstMap);
        }
Пример #2
0
        public void TestOptimizeToOneStock(double stock, double minLeftover, double maxLeftover, double[] orderLens, int[] orderNums, double[] expectedNewPttrnPopLens)
        {
            BarSets      orders  = initPattern(orderLens, orderNums);
            MinMaxSolver sut     = new MinMaxSolver(minLeftover, maxLeftover);
            BarSets      pattern = sut.optimizeToOneStock(stock, orders);

            pattern.sortAsc();

            Assert.Equal(expectedNewPttrnPopLens.Length, pattern.count());
            foreach (double expectedPopLen in expectedNewPttrnPopLens)
            {
                Assert.Equal(expectedPopLen, pattern.popLen());
            }
        }
Пример #3
0
        public void TestCalKnapsack(double stock, double minLeftover, double maxLeftover, double[] orderLens, int[] orderNums, double[] expectedNewPttrnPopLens)
        {
            BarSets orders = initPattern(orderLens, orderNums);
            BarSets ret    = MinMaxSolver.calKnapsack(stock, orders);

            ret.sortAsc();

            // Assert.Equal("", ret.ToString());
            Assert.Equal(expectedNewPttrnPopLens.Length, ret.count());
            foreach (double expectedPopLen in expectedNewPttrnPopLens)
            {
                Assert.Equal(expectedPopLen, ret.popLen());
            }
        }