Esempio n. 1
0
        public void ReductionTestBig()
        {
            int[,] actualWeights = GenerateMatrixWithValue(sizeN: 6, value: 0);

            // some random values that change nothing
            actualWeights[0, 2] = 3;
            actualWeights[1, 3] = 6;
            actualWeights[1, 5] = 1;
            actualWeights[3, 1] = 13;
            actualWeights[3, 5] = 3;
            actualWeights[5, 0] = 0;
            actualWeights[5, 1] = 8;

            // minimum value in this row - 4
            actualWeights[4, 0] = Infinity;
            actualWeights[4, 1] = 22;
            actualWeights[4, 2] = Infinity;
            actualWeights[4, 3] = 23;
            actualWeights[4, 4] = Infinity;
            actualWeights[4, 5] = 4;

            const int expectedReductionResult = 4;

            int[,] expectedWeights = (int[, ])actualWeights.Clone();
            for (int i = 0; i < 6; i++)
            {
                expectedWeights[4, i] -= expectedReductionResult;
            }


            int actualReductionResult = BranchAndBound.Reduction(actualWeights);

            Assert.Equal(expectedReductionResult, actualReductionResult);
            Assert.True(actualWeights.AreDeepEqual(expectedWeights));
        }
Esempio n. 2
0
        public void ReductionTestSmall()
        {
            int[,] actualWeights = GenerateSampleWeights();

            int[,] expectedWeights = new int[3, 3];
            expectedWeights[0, 0]  = Infinity;
            expectedWeights[0, 1]  = 0;
            expectedWeights[0, 2]  = 0;

            expectedWeights[1, 0] = 0;
            expectedWeights[1, 1] = Infinity;
            expectedWeights[1, 2] = 0;

            expectedWeights[2, 0] = 1;
            expectedWeights[2, 1] = 0;
            expectedWeights[2, 2] = Infinity;

            const int expectedReductionResult = 11;
            int       actualReductionResult   = BranchAndBound.Reduction(actualWeights);

            Assert.Equal(expectedReductionResult, actualReductionResult);

            // test does not care about the main diagonal
            SetMainDiagonal(actualWeights, Infinity);
            Assert.True(actualWeights.AreDeepEqual(expectedWeights));
        }
Esempio n. 3
0
        public void CrossReductionTest()
        {
            int[,] actualWeights = GenerateSampleWeights();

            int[,] expectedWeights = (int[, ])actualWeights.Clone();
            (var i, var j)         = (1, 2);
            (var h, var v)         = (5, 3);
            expectedWeights[i, 0] -= h;
            expectedWeights[i, 1] -= h;
            expectedWeights[0, j] -= v;
            expectedWeights[2, j] -= v;
            expectedWeights[i, j]  = BranchAndBound.Infinity;

            BranchAndBound.SubstractCross(actualWeights, pos: (i, j), mins: (h, v));

            Assert.True(actualWeights.AreDeepEqual(expectedWeights));
        }