Ejemplo n.º 1
0
        private void CalculateTransitionMatrix(decimal[,] matrix, decimal[] side, TransitionMatrixType type)
        {
            int latest = -1;

            switch (type)
            {
            case TransitionMatrixType.Horizontal:
                for (int y = 0; y < Height; y++)
                {
                    for (int x = 0; x < Width; x++)
                    {
                        var state = StateMatrix[y, x];
                        if (latest != -1)
                        {
                            matrix[state, latest]++;
                        }
                        latest = state;
                    }
                }
                break;

            case TransitionMatrixType.Vertical:
                for (int x = 0; x < Width; x++)
                {
                    for (int y = 0; y < Height; y++)
                    {
                        var state = StateMatrix[y, x];
                        if (latest != -1)
                        {
                            matrix[state, latest]++;
                        }
                        latest = state;
                    }
                }
                break;

            default: break;
            }

            for (int x = 0; x < _statesCount; x++)
            {
                for (int y = 0; y < _statesCount; y++)
                {
                    side[x] += matrix[y, x];
                }
            }

            var total = (decimal)StateMatrix.Length - 1;

            for (int y = 0; y < _statesCount; y++)
            {
                for (int x = 0; x < _statesCount; x++)
                {
                    matrix[x, y] /= total;
                }

                side[y] /= total;
            }
        }
Ejemplo n.º 2
0
        internal StateValue GetSideStateColor(int latestState, TransitionMatrixType type)
        {
            var matrix = HorisontalSideTransitionMatrix;

            switch (type)
            {
            case TransitionMatrixType.Horizontal:
                matrix = HorisontalSideTransitionMatrix;
                break;

            case TransitionMatrixType.Vertical:
                matrix = VerticalSideTransitionMatrix;
                break;

            default: break;
            }

            var state = GetRandomStateIndex(matrix, latestState);

            return(_statesValues.GetStateValue(state));
        }