Ejemplo n.º 1
0
        private void buttonGetFormules_Click(object sender, EventArgs e)
        {
            int bitsCount = (int)numericUpDownN.Value;

            richTextBox.Text = string.Empty;

            this.e = MathProcessor.GetAllEK((int)Math.Pow(2, bitsCount));
            b      = MathProcessor.GetAllEPKFromEK(this.e);

            if (checkBoxOutToWord.Checked)
            {
                string wordFilePath = Environment.CurrentDirectory + "\\Formules[" + (b.Length + 1) + "].docx";
                word.GenerateDocument(b, out a, wordFilePath);
                FillRichTextBoxFromWord(wordFilePath);
                progressBar.Value = 0;
            }
            else
            {
                string[] formules = MathProcessor.Formules(b, out a);
                for (int i = 0; i < formules.Length; i++)
                {
                    richTextBox.Text += "a" + i + " =" + formules[i] + Environment.NewLine;
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Получить бинарный код
        /// </summary>
        /// <param name="data">Входное число</param>
        /// <returns>Бинарный код</returns>
        public LongBits GetDKFromComparators(int data)
        {
            LongBits simpleCode         = GetEKFromComparators(data);
            LongBits simplePositionCode = MathProcessor.GetEPKFromEK(simpleCode);

            return(MathProcessor.GetDK(simplePositionCode));
        }
Ejemplo n.º 3
0
        private void buttonSaveToExel_Click(object sender, EventArgs e)
        {
            if (this.e == null || b == null || a == null)
            {
                throw new Exception("Сначала должны быть сгенерированы уравнения!");
            }

            string[] singleCodesString = this.e.Select(val => val.ToString()).ToArray();
            string[] bString           = b.Select(val => val.ToString()).ToArray();
            string[] binaryString      = MathProcessor.TransposeBitMatrix(a)
                                         .Select(val => val.ToString()).ToArray();
            ExcelTools excel = new ExcelTools(progressBar);

            excel.GenerateDocument(singleCodesString, bString, binaryString);
            excel.Dispose();
            progressBar.Value = 0;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Получить индексы битов с ошибками в последовательном позиционном коде
        /// </summary>
        /// <param name="data">Входное число</param>
        /// <returns>Индексы битов с ошибками в последовательном позиционном коде</returns>
        public int[] GetEKPErrorFromComparators(int data)
        {
            int      m = (int)Math.Pow(2, N) - 1;
            LongBits idealSimpleCode         = MathProcessor.GetEK(data, m);
            LongBits idealSimplePositionCode = MathProcessor.GetEPKFromEK(idealSimpleCode);

            LongBits realSimpleCode         = GetEKFromComparators(data);
            LongBits realSimplePositionCode = MathProcessor.GetEPKFromEK(realSimpleCode);

            List <int> errors = new List <int>();

            for (int i = 0; i < realSimpleCode.Length; i++)
            {
                if (idealSimplePositionCode[i] != realSimplePositionCode[i])
                {
                    errors.Add(i + 1);
                }
            }
            return(errors.ToArray());
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Создание документа docx с формулами ai
        /// </summary>
        /// <param name="transpB">Массив состовляющих ЕПК</param>
        /// <param name="a">ДК</param>
        /// <param name="path">Путь к результирующему файлу</param>
        public void GenerateDocument(LongBits[] b, out LongBits[] a, string path)
        {
            application = new Word.Application {
                Visible = false
            };
            try
            {
                document = application.Documents.Add();
                document.Range(0, 0).PageSetup.Orientation = WdOrientation.wdOrientLandscape;

                LongBits[] transpB = MathProcessor.TransposeBitMatrix(b);
                int        n       = MathProcessor.GetN(transpB.Length + 1);
                a = new LongBits[n];
                SetMaxValueBar(n);

                for (int i = n - 1; i >= 0; i--)
                {
                    List <string> formules = new List <string>();
                    a[i] = new LongBits(transpB[0].Length);
                    a[i] = ~a[i];
                    int kmax = (int)Math.Pow(2, n - 1 - i) - 1;
                    for (int k = 0; k <= kmax; k++)
                    {
                        int tmin = (int)Math.Pow(2, i) * (2 * k + 1);
                        int tmax = (int)Math.Pow(2, i + 1) * (k + 1) - 1;
                        for (int t = tmin; t <= tmax; t++)
                        {
                            if (formules.Count == 0 || formules[formules.Count - 1].Length > 250)
                            {
                                formules.Add(string.Empty);
                            }
                            formules[formules.Count - 1] += " b_" + t + notSign + " ";
                            a[i] &= ~transpB[t - 1];
                        }
                    }
                    a[i] = ~a[i];

                    document.Range(0, 0).Text += "\n ";
                    for (int index = formules.Count - 1; index >= 0; index--)
                    {
                        document.Range(0, 0).Text += "\n ";
                        BuildFormula(notSign);
                        BuildFormula(")", WdColor.wdColorWhite);
                        BuildFormula(formules[index]);
                        BuildFormula("(", WdColor.wdColorWhite);
                        if (index == 0)
                        {
                            BuildFormula("a_" + i + "=");
                        }
                        else
                        {
                            BuildFormula("          ");
                        }
                        document.OMaths.BuildUp();
                    }
                    PerformStepBar();
                }
                document.SaveAs(path);
            }
            finally
            {
                //Закрывание ворда
                document.Close();
                application.Quit();
            }
        }