Exemplo n.º 1
0
        /// <summary>
        /// Создает код на основе полученной матрицы, устонавливая его основные параметры.
        /// </summary>
        /// <param name="generatingMatrix">Порождающая матрица</param>
        /// <param name="line">Система уравнений, порождающая код</param>
        public Code(SolutionsMatrix generatingMatrix, string[] line)
        {
            if (generatingMatrix.Matrix.Count < generatingMatrix.Matrix[0].Length)
            {
                throw new CodeGeneratingException("Система имеет недостаточно решений для генерации кода.");
            }

            this.generatingMatrix = generatingMatrix;
            systemOfEquations     = line;
            allCodeWords          = new BaseMatrix();
            for (int possibleCodeNumber = 0; possibleCodeNumber < Math.Pow(2, K); possibleCodeNumber++)
            {
                int[]      intArrayPossibleCodeNumber = MyStatics.ToBinaryIntArray(possibleCodeNumber, K);
                BaseMatrix vectorPossibleCodeNumber   = new BaseMatrix();
                for (int i = 0; i < K; i++)
                {
                    int[] nextLine = { intArrayPossibleCodeNumber[i] };
                    vectorPossibleCodeNumber.Matrix.Add(nextLine);
                }
                BaseMatrix vectorPossibleCode = MyStatics.Multiplication(vectorPossibleCodeNumber, generatingMatrix);
                allCodeWords.Matrix.Add(vectorPossibleCode.Matrix[0]);
            }

            this.t = (MyStatics.FindMinDistance(AllCodeWords) - 1) / 2;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Решает систему уравнений.
        /// </summary>
        /// <param name="equationsSystem">Система уравнений</param>
        /// <returns>Решение системы уравнений</returns>
        public SolutionsMatrix Solve(List <Equation> equationsSystem)
        {
            if (equationsSystem == null)
            {
                throw new NullReferenceException("Система уравнений пуста!");
            }
            if (equationsSystem.Count == 0)
            {
                throw new NullReferenceException("Введите систему уравнений!");
            }

            matrix = new SolutionsMatrix();

            // Перебор всех возможных решений.
            for (int possibleSolution = 0; possibleSolution < Math.Pow(2, equationsSystem[0].GroupSize); possibleSolution++)
            {
                // Представление номера возможного решения в двоичном виде.
                int[] intArrayPossibleSolution = MyStatics.ToBinaryIntArray(possibleSolution, equationsSystem[0].GroupSize);

                // Создание проверочного листа - элемента, помогающего определить принадлежит ли решение множеству решений данной системы.
                checkingList = new СheckList(equationsSystem);

                // Заполнение проверочного листа возможным решением.
                checkingList.FillingTheCheckList(intArrayPossibleSolution);

                /// Сверка значений полученного в результате подстановки решения в проверочный лист и значения,
                /// которое должно быть по условию.
                /// В случае полного совпадения решение, которое подставлялось в проверочный лист?
                /// добавляется в матрицу решений системы уравнений.
                if (checkingList.IsItRightSolution())
                {
                    matrix.Matrix.Add(intArrayPossibleSolution);
                }
            }
            return(matrix);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Генерирует алгеброгеометрический код.
        /// </summary>
        /// <param name="sender">CodeGeneratingWindow</param>
        /// <param name="e">RoutedEventArgs</param>
        private void NextWindowButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                t.Content = "";
                if (groupSize == 0)
                {
                    throw new ArgumentNullException("количество переменных", "Невведено количество переменных!");
                }

                /*
                 *              for (int i = 0; i < equations.Document.Blocks.Count; i++)
                 *              {
                 *                  equations.Document.Blocks.ElementAt<Block>(i).Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0));
                 *              }
                 */
                foreach (Block block in equations.Document.Blocks)
                {
                    block.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0));
                }

                #region Формирование системы уравнений в памяти
                line  = new TextRange(equations.Document.ContentStart, equations.Document.ContentEnd).Text;
                lines = line.Split('\n');

                for (int i = 0; i < lines.Length; i++)
                {
                    try
                    {
                        if (i != lines.Length - 1)
                        {
                            lines[i] = lines[i].Remove(lines[i].Length - 1, 1);
                        }
                        MyStatics.Reading(lines[i], groupSize, systemOfEquations, i);
                    }
                    catch (TokenizerException ex)
                    {
                        t.Content += (i + 1) + " уравнение: " + ex.Message + "\n";
                        equations.Document.Blocks.ElementAt <Block>(ex.Index).Foreground = new SolidColorBrush(Color.FromArgb(255, 200, 21, 21));
                        flag = false;
                    }
                    catch (ParserException ex)
                    {
                        t.Content += (i + 1) + " уравнение: " + ex.Message + "\n";
                        equations.Document.Blocks.ElementAt <Block>(ex.Index).Foreground = new SolidColorBrush(Color.FromArgb(255, 200, 21, 21));
                        flag = false;
                    }
                    catch (UnknownCodeMessageException ex)
                    {
                        t.Content += (i + 1) + " уравнение: " + ex.Message + "\n";
                        equations.Document.Blocks.ElementAt <Block>(ex.Index).Foreground = new SolidColorBrush(Color.FromArgb(255, 200, 21, 21));
                        flag = false;
                    }
                }
                #endregion

                if (flag)
                {
                    #region  ешение системы уравнений
                    theAnswer = solver.Solve(systemOfEquations);
                    if (theAnswer.Matrix.Count == 0)
                    {
                        throw new NullReferenceException("Система уравнений не имеет решений!");
                    }
                    #endregion

                    #region Формирование кода и вывод на экран его основных параметров
                    AGCode = new Code(theAnswer, lines);

                    CodeDescriptionWindow win = new CodeDescriptionWindow(AGCode);
                    win.Top  = this.Top;
                    win.Left = this.Left;
                    win.Show();
                    this.Close();
                    #endregion
                }
                flag = true;
            }
            catch (CodeGeneratingException ex)
            {
                t.Content = ex.Message;
                foreach (Block block in equations.Document.Blocks)
                {
                    block.Foreground = new SolidColorBrush(Color.FromArgb(255, 200, 21, 21));
                }
            }
            catch (ArgumentNullException)
            {
                size.IsDropDownOpen = true;
            }
            catch (NullReferenceException ex)
            {
                t.Content += ex.Message;
                foreach (Block block in equations.Document.Blocks)
                {
                    block.Foreground = new SolidColorBrush(Color.FromArgb(255, 200, 21, 21));
                }
            }
            catch (TokenizerException ex)
            {
                t.Content += ex.Message + "\n";
                equations.Document.Blocks.ElementAt(ex.Index).Foreground = new SolidColorBrush(Color.FromArgb(255, 200, 21, 21));
            }
            catch (ParserException ex)
            {
                t.Content += ex.Message + "\n";
                equations.Document.Blocks.ElementAt(ex.Index).Foreground = new SolidColorBrush(Color.FromArgb(255, 200, 21, 21));
            }
            catch (UnknownCodeMessageException ex)
            {
                t.Content += ex.Message + "\n";
                equations.Document.Blocks.ElementAt(ex.Index).Foreground = new SolidColorBrush(Color.FromArgb(255, 200, 21, 21));
            }
            finally
            {
                systemOfEquations = new List <Equation>();
            }
        }