コード例 #1
0
        public void TestcalRequiredBarCore(double stock, double saw, double[] orderLens, int[] orderNums, int nRequiredBar, double expectedWastedLen, double lossRatio)
        {
            // Input
            double rawBarHeightInput    = stock;
            double sawWidthInput        = saw;
            var    requiredBarSetInputs = new List <BarSet>();
            var    expectedTotalBar     = 0;

            for (int i = 0; i < orderLens.Length; i++)
            {
                requiredBarSetInputs.Add(new BarSet(orderLens[i], orderNums[i]));
                expectedTotalBar += orderNums[i];
            }

            // Exercise
            var ret = CutOptimization.calRequiredBarCore(rawBarHeightInput, sawWidthInput, requiredBarSetInputs);

            // Assert
            int nTotalBar = UtilStatistics.sumInt(new List <int>(ret.Values));
            var wastedLen = UtilStatistics.calWastedLen(ret, stock, 200d);
            var totalBar  = UtilStatistics.calTotalBar(ret);

            Assert.Equal(expectedTotalBar, totalBar);
            Assert.Equal(nRequiredBar, nTotalBar);
            Assert.Equal(expectedWastedLen, wastedLen);
            Assert.InRange(wastedLen / (nTotalBar * stock), lossRatio - 0.01, lossRatio);
        }
コード例 #2
0
        public void TestcalRequiredBarCoreMinMax(double stock, double saw, double minLeftover, double maxLeftover, double[] orderLens, int[] orderNums, int nRequiredBar, double expectedWastedLen, double lossRatio)
        {
            // Input
            double rawBarHeightInput    = stock;
            double sawWidthInput        = saw;
            var    requiredBarSetInputs = new List <BarSet>();
            var    expectedTotalBar     = 0;

            for (int i = 0; i < orderLens.Length; i++)
            {
                requiredBarSetInputs.Add(new BarSet(orderLens[i], orderNums[i]));
                expectedTotalBar += orderNums[i];
            }

            // Exercise
            var ret = CutOptimization.calRequiredBarCoreMinMax(rawBarHeightInput, sawWidthInput, requiredBarSetInputs, minLeftover, maxLeftover);

            // Assert
            int nTotalStock = UtilStatistics.sumInt(new List <int>(ret.Values));
            var wastedLen   = UtilStatistics.calWastedLen(ret, stock, maxLeftover);
            var totalBar    = UtilStatistics.calTotalBar(ret);

            Assert.Equal(expectedTotalBar, totalBar);
            Assert.Equal(nRequiredBar, nTotalStock);
            Assert.Equal(expectedWastedLen, wastedLen);
            Assert.InRange(wastedLen / (nTotalStock * stock), lossRatio - 0.01, lossRatio);
            // assert within range
            foreach (KeyValuePair <List <BarSet>, int> entry in ret)
            {
                List <BarSet> barSets  = entry.Key;
                double        leftover = stock - new BarSets(barSets).countTotalLen();
                Assert.NotInRange(leftover, minLeftover + 0.001, maxLeftover - 0.001);
            }
        }
コード例 #3
0
        public void TestcalRequiredBarCoreMinMax_WithCantCutAll(double stock, double saw, double minLeftover, double maxLeftover, double[] orderLens, int[] orderNums, int nRequiredBar)
        {
            // Input
            double rawBarHeightInput    = stock;
            double sawWidthInput        = saw;
            var    requiredBarSetInputs = new List <BarSet>();

            for (int i = 0; i < orderLens.Length; i++)
            {
                requiredBarSetInputs.Add(new BarSet(orderLens[i], orderNums[i]));
            }

            // Exercise
            var ret = CutOptimization.calRequiredBarCoreMinMax(rawBarHeightInput, sawWidthInput, requiredBarSetInputs, minLeftover, maxLeftover);

            // Assert
            int nTotalStock = UtilStatistics.sumInt(new List <int>(ret.Values));

            Assert.Equal(nRequiredBar, nTotalStock);
            // assert within range
            foreach (KeyValuePair <List <BarSet>, int> entry in ret)
            {
                List <BarSet> barSets = entry.Key;
                double        cutLen  = new BarSets(barSets).countTotalLen();
                Assert.InRange(cutLen, 0, stock);
            }
        }