Ejemplo n.º 1
0
        /// <summary>
        /// Generuoja matricą
        /// </summary>
        /// <returns></returns>
        public int[,] GenerateMatrix()
        {
            var n = (int)Math.Pow(2, m);

            _rows    = m.CountCombination(r);
            _columns = n;
            Matrix   = new int[_rows, _columns];
            var bytes = BytesCounter.GetBytes(n, m);

            GetCombinations(bytes);

            for (int i = 0; i < _rows; i++)
            {
                for (int j = 0; j < _columns; j++)
                {
                    if (i == 0)
                    {
                        Matrix[i, j] = 1;
                    }
                    else
                    {
                        if (_combinations[i].Count == 1)
                        {
                            var index = _combinations[i].FirstOrDefault();
                            if (bytes[j].ElementAtOrDefault(index - 1) == '0')
                            {
                                Matrix[index, j] = 1;
                            }
                            else
                            {
                                Matrix[index, j] = 0;
                            }
                        }
                        else
                        {
                            var multiplication = 1;
                            foreach (var index in _combinations[i])
                            {
                                multiplication *= Matrix[index, j];
                            }
                            Matrix[i, j] = multiplication;
                        }
                    }
                }
            }

            return(Matrix);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gauna visus koeficientus kurie yra pradinis vektorius
        /// </summary>
        /// <param name="encodedVector"></param>
        /// <returns></returns>
        private List <int> GetVotes(List <int> encodedVector)
        {
            var n    = (int)Math.Pow(2, m);
            var rows = m.CountCombination(r);

            bytes = BytesCounter.GetBytes(n, m);

            for (int i = r; i >= 0; i--)
            {
                if (i == 0)
                {
                    w = new List <List <int> >();
                    for (int h = 0; h < n; h++)
                    {
                        wt = new List <int>();
                        for (int j = 0; j < n - 1; j++)
                        {
                            wt.Add(0);
                        }
                        wt.Insert(h, 1);
                        w.Add(wt);
                    }
                    CalculateDominantVote(n, encodedVector);
                }

                else
                {
                    int positionsMissingCount = m - i;
                    var missingPositionsList  = GetMissingPossitionsList(positionsMissingCount);

                    var tList = BytesCounter.GetBytes((int)Math.Pow(2, positionsMissingCount), positionsMissingCount);

                    foreach (var missingPosition in missingPositionsList)
                    {
                        w = new List <List <int> >();
                        foreach (var t in tList)
                        {
                            wt = new List <int>();
                            foreach (var _byte in bytes)
                            {
                                bool value = false;
                                for (int pos = 0; pos < positionsMissingCount; pos++)
                                {
                                    if (_byte[missingPosition[pos]] == t[pos])
                                    {
                                        value = true;
                                    }
                                    else
                                    {
                                        value = false;
                                        break;
                                    }
                                }
                                if (value == false)
                                {
                                    wt.Add(0);
                                }
                                else
                                {
                                    wt.Add(1);
                                }
                            }
                            w.Add(wt);
                        }
                        CalculateDominantVote(n, encodedVector);
                    }

                    if (finalVotes.Count != rows)
                    {
                        encodedVector = SubtractFromMainVector(rows, n, encodedVector);
                    }
                }
            }
            return(finalVotes);
        }