Beispiel #1
0
        public void Evaluate_Redirect_1()
        {
            const int EXPECTED_RESULT = 3;

            const ushort MAX_VALUE = ushort.MaxValue;
            var          slicer    = new Mock <ISlicer>();
            var          secondary = new Mock <IRowValleyOptimizer>();
            var          optimizer = new MatrixOptimizer(slicer.Object, secondary.Object);

            const int OTHER = 1;
            var       stats = new MatrixRowSummary
            {
                SelfPercent = null,
                Row         = OTHER,
                Clusters    = new[] {
                    new ValueCluster {
                        Value     = MAX_VALUE,
                        First     = EXPECTED_RESULT,
                        NoOfTimes = 1,
                    }
                },
                NoOfStates          = 2,
                NoOfNonZeroPercents = 1,
                NoOfZeroPercents    = 1
            };

            var result = optimizer.Evaluate(MAX_VALUE, stats);

            Assert.AreEqual(SolutionType.Redirect, result.Approach);
            Assert.AreEqual(EXPECTED_RESULT, result.Branch);
        }
Beispiel #2
0
        public void CheckRecords_1()
        {
            // TAKE N x N matrix
            const int COUNT      = 3;
            const int EXPECTED_1 = 1000;
            var       row        = new ushort[] { EXPECTED_1, EXPECTED_1, EXPECTED_1 };
            var       slicer     = new Mock <ISlicer>();
            var       secondary  = new Mock <IRowValleyOptimizer>();
            var       optimizer  = new MatrixOptimizer(slicer.Object, secondary.Object);
            var       result     = optimizer.Investigate1DArray(0, row);

            Assert.AreEqual(COUNT, result.NoOfStates);
            Assert.AreEqual(COUNT, result.NoOfNonZeroPercents);
            Assert.AreEqual(0, result.NoOfZeroPercents);

            Assert.IsNotNull(result.Clusters);
            Assert.AreEqual(1, result.Clusters.Length);

            {
                var record = result.Clusters[0];

                Assert.AreEqual(EXPECTED_1, record.Value);
                Assert.AreEqual(0, record.First);
                Assert.AreEqual(COUNT, record.NoOfTimes);
            }
        }
Beispiel #3
0
        public void ZeroMatrix()
        {
            var source = new ushort[][]
            {
                new ushort[] { 0, 0, 0, 0 },
                new ushort[] { 0, 0, 0, 0 },
                new ushort[] { 0, 0, 0, 0 },
                new ushort[] { 0, 0, 0, 0 },
            };

            const ushort MAX_PROBABILITY = 100;
            var          slicer          = new Mock <ISlicer>();
            var          secondary       = new Mock <IRowValleyOptimizer>();
            var          optimizer       = new MatrixOptimizer(slicer.Object, secondary.Object);


            ushort[] rowDenominators = new[] {
                MAX_PROBABILITY,
                MAX_PROBABILITY,
                MAX_PROBABILITY,
                MAX_PROBABILITY,
            };
            var solution = optimizer.Optimize(rowDenominators, source);

            Assert.IsNotNull(solution);
            Assert.IsNotNull(solution.Rows);
            Assert.IsTrue(solution.IsOptimized);

            foreach (var row in solution.Rows)
            {
                Assert.IsNotNull(row);
                Assert.AreEqual(SolutionType.NoOperation, row.Approach);
            }
        }
Beispiel #4
0
        public void Evaluate_NoOperation()
        {
            var stats = new MatrixRowSummary
            {
                NoOfStates       = 4,
                NoOfZeroPercents = 4
            };

            const ushort ROW_DENOMINATOR = 0;
            var          slicer          = new Mock <ISlicer>();
            var          secondary       = new Mock <IRowValleyOptimizer>();
            var          optimizer       = new MatrixOptimizer(slicer.Object, secondary.Object);
            var          result          = optimizer.Evaluate(ROW_DENOMINATOR, stats);

            Assert.AreEqual(SolutionType.NoOperation, result.Approach);
        }
Beispiel #5
0
        public void CheckAllZeros_SingleRow()
        {
            var slicer    = new Mock <ISlicer>();
            var secondary = new Mock <IRowValleyOptimizer>();
            var optimizer = new MatrixOptimizer(slicer.Object, secondary.Object);

            // TAKE N x N matrix
            const int COUNT  = 8;
            var       row    = new ushort[COUNT];
            var       result = optimizer.Investigate1DArray(0, row);

            Assert.AreEqual(COUNT, result.NoOfStates);
            Assert.AreEqual(0, result.NoOfNonZeroPercents);
            Assert.AreEqual(COUNT, result.NoOfZeroPercents);
            Assert.IsFalse(result.SelfPercent.HasValue);
        }
Beispiel #6
0
        public void CheckRecords_Empty()
        {
            // TAKE N x N matrix
            const int COUNT     = 0;
            var       row       = new ushort[] { };
            var       slicer    = new Mock <ISlicer>();
            var       secondary = new Mock <IRowValleyOptimizer>();
            var       optimizer = new MatrixOptimizer(slicer.Object, secondary.Object);
            var       result    = optimizer.Investigate1DArray(0, row);

            Assert.AreEqual(COUNT, result.NoOfStates);
            Assert.AreEqual(COUNT, result.NoOfNonZeroPercents);
            Assert.AreEqual(0, result.NoOfZeroPercents);

            Assert.IsNotNull(result.Clusters);
            Assert.AreEqual(0, result.Clusters.Length);
        }
Beispiel #7
0
        public void CheckAlNonZeros_SingleRow()
        {
            // TAKE N x N matrix
            const int    COUNT        = 4;
            const ushort SELF_PERCENT = 100;
            var          row          = new ushort[] { SELF_PERCENT, 200, 300, 400 };
            var          slicer       = new Mock <ISlicer>();
            var          secondary    = new Mock <IRowValleyOptimizer>();
            var          optimizer    = new MatrixOptimizer(slicer.Object, secondary.Object);
            var          result       = optimizer.Investigate1DArray(0, row);

            Assert.AreEqual(COUNT, result.NoOfStates);
            Assert.AreEqual(COUNT, result.NoOfNonZeroPercents);
            Assert.AreEqual(0, result.NoOfZeroPercents);
            Assert.IsTrue(result.SelfPercent.HasValue);
            Assert.AreEqual(SELF_PERCENT, result.SelfPercent.Value);
        }
Beispiel #8
0
        public void Setup()
        {
            var source = new ushort[4, 4]
            {
                { 0, 1, 1, 1 },
                { 2, 0, 2, 2 },
                { 3, 3, 0, 3 },
                { 6, 6, 6, 0 },
            };

            var slicer    = new Mock <ISlicer>();
            var secondary = new Mock <IRowValleyOptimizer>();
            var optimizer = new MatrixOptimizer(slicer.Object, secondary.Object);

            var rowDenominators = new ushort[] { 3, 6, 9, 18 };

            mSolution = optimizer.Optimize(rowDenominators, source);
        }
Beispiel #9
0
        public void Setup()
        {
            var source = new ushort[4, 4]
            {
                { 1, 1, 1, 1 },   // EVEN ALL
                { 0, 1, 0, 0 },   // DEAD END
                { 0, 100, 0, 0 }, // REDIRECT
                { 0, 0, 0, 0 },   // NO-OP
            };

            var slicer    = new Mock <ISlicer>();
            var secondary = new Mock <IRowValleyOptimizer>();
            var optimizer = new MatrixOptimizer(slicer.Object, secondary.Object);

            var rowDenominators = new ushort[] { 4, 1, 100, 1 };

            mSolution = optimizer.Optimize(rowDenominators, source);
        }
Beispiel #10
0
        public void Setup()
        {
            var source = new ushort[4, 4]
            {
                { 1, 0, 0, 0 },
                { 0, 1, 0, 0 },
                { 0, 0, 1, 0 },
                { 0, 0, 0, 1 },
            };

            var slicer    = new Mock <ISlicer>();
            var secondary = new Mock <IRowValleyOptimizer>();
            var optimizer = new MatrixOptimizer(slicer.Object, secondary.Object);

            const ushort MaxProbability = 1;

            var rowDenominators = new[] { MaxProbability, MaxProbability, MaxProbability, MaxProbability };

            mSolution = optimizer.Optimize(rowDenominators, source);
        }
Beispiel #11
0
        public void Evaluate_Unoptimized_0()
        {
            const int PERCENT_0 = 60;
            const int PERCENT_1 = 35;
            const int PERCENT_2 = 3;
            const int PERCENT_3 = 2;

            var stats = new MatrixRowSummary
            {
                SelfPercent         = PERCENT_0,
                NoOfStates          = 4,
                NoOfNonZeroPercents = 4,
                NoOfZeroPercents    = 0,
                Clusters            = new ValueCluster[] {
                    new ValueCluster
                    {
                        Value = PERCENT_0,
                    },
                    new ValueCluster
                    {
                        Value = PERCENT_1,
                    },
                    new ValueCluster
                    {
                        Value = PERCENT_2,
                    },
                    new ValueCluster
                    {
                        Value = PERCENT_3,
                    },
                },
            };

            const ushort MAX_PROBABILITY = 100;
            var          slicer          = new Mock <ISlicer>();
            var          secondary       = new Mock <IRowValleyOptimizer>();
            var          optimizer       = new MatrixOptimizer(slicer.Object, secondary.Object);
            var          result          = optimizer.Evaluate(MAX_PROBABILITY, stats);

            Assert.AreEqual(SolutionType.Unoptimized, result.Approach);
        }
Beispiel #12
0
        public void IdentityMatrix()
        {
            var source = new ushort[4, 4]
            {
                { 1, 0, 0, 0 },
                { 0, 1, 0, 0 },
                { 0, 0, 1, 0 },
                { 0, 0, 0, 1 },
            };

            var slicer    = new Mock <ISlicer>();
            var secondary = new Mock <IRowValleyOptimizer>();
            var optimizer = new MatrixOptimizer(slicer.Object, secondary.Object);

            const ushort MaxProbability = 1;

            var rowDenominators = new[] { MaxProbability, MaxProbability, MaxProbability, MaxProbability };

            var solution = optimizer.Optimize(rowDenominators, source);

            Assert.IsNotNull(solution);

            Assert.AreEqual(4, solution.NoOfStates);
            Assert.IsNotNull(solution.Rows);
            Assert.IsTrue(solution.IsOptimized);

            // SHOULD BE ALL

            for (var i = 0; i < 4; i++)
            {
                var row = solution.Rows[i];
                Assert.IsNotNull(row);
                Assert.AreEqual(SolutionType.DeadEnd, row.Approach);
                Assert.AreEqual(i, row.Branch);
            }
        }