Example #1
0
        /// <summary>
        /// Разбиение последовательности на части и ее преобразование с сохранением и отображением данных статистики
        /// </summary>
        private void Convert()
        {
            RDPAlgorithm.Additions       = 0;
            RDPAlgorithm.Multiplications = 0;

            MyPoint[] points = new MyPoint[SequenceSourse.Length];

            for (int i = 0; i < SequenceSourse.Length; i++)
            {
                points[i].X = i;
                points[i].Y = SequenceSourse[i];
            }

            int blockSize = int.Parse(textBoxBlockSize.Text);
            List <MyPoint[]> smoothSequence = new List <MyPoint[]>();
            List <Statistic> stat           = new List <Statistic>();

            progressBar.Maximum = points.Length / blockSize + 1;
            int smooothSeqLength = 0;
            int j = 0;

            for (int i = 0; i < points.Length; i += blockSize)
            {
                System.Diagnostics.Stopwatch swatch = new System.Diagnostics.Stopwatch(); // создаем объект
                Statistic blockStat = new Statistic
                {
                    Additions       = RDPAlgorithm.Additions,
                    Multiplications = RDPAlgorithm.Multiplications
                };
                RDPAlgorithm.MaxCalls = 0;
                RDPAlgorithm.Calls    = 0;
                swatch.Start(); // старт

                smoothSequence.Add(RDPAlgorithm.DouglasPeucker(points, i,
                                                               (i + blockSize < points.Length) ? i + blockSize : points.Length - 1,
                                                               (textBoxEpsilon.Text == "") ? 1 : (float)Math.Pow(float.Parse(textBoxEpsilon.Text), 2)));

                smooothSeqLength += smoothSequence.ElementAt(j++).Length - 1;
                //-1 чтобы убрать последний элемент, т.к. он будет началом следующего блока

                swatch.Stop(); // стоп

                //сохраняем статситку
                blockStat.Time = swatch.Elapsed;
                blockStat.BlockRezultLength = smoothSequence.ElementAt(i / blockSize).Length;
                blockStat.BlockRezultSize   = blockStat.BlockRezultLength * 3;
                blockStat.BlockSourseSize   = blockSize * 2;
                blockStat.Additions         = RDPAlgorithm.Additions - blockStat.Additions;
                blockStat.Multiplications   = RDPAlgorithm.Multiplications - blockStat.Multiplications;
                blockStat.СompressionRatio  =
                    (float)Math.Round(blockSize / (smoothSequence.ElementAt(i / blockSize).Length *1.5), 3);
                blockStat.RecursiveCalls = RDPAlgorithm.MaxCalls;

                stat.Add(blockStat);
                progressBar.Value++;
            }

            progressBar.Value                  = 0;
            dataGridView.DataSource            = stat;
            dataGridView.Columns[0].HeaderText = @"Время преобразования";
            dataGridView.Columns[1].HeaderText = @"Размер исходного блока, байт";
            dataGridView.Columns[2].HeaderText = @"Длина сжатого блока";
            dataGridView.Columns[3].HeaderText = @"Размер сжатого блока, байт";
            dataGridView.Columns[4].HeaderText = @"Слож ений";
            dataGridView.Columns[5].HeaderText = @"Умнож ений";
            dataGridView.Columns[6].HeaderText = @"Коэф. сжатия";
            dataGridView.Columns[7].HeaderText = @"Рекурсия";
            dataGridView.Columns[0].Width      = 100;
            dataGridView.RowHeadersWidth       = 60;
            for (int i = 1; i < 8; i++)
            {
                dataGridView.Columns[i].Width = 55;
            }
            for (int i = 0; i < stat.Count; i++)
            {
                dataGridView.Rows[i].HeaderCell.Value = (i + 1).ToString();
            }

            PRez = new MyPoint[smooothSeqLength + 1];
            j    = 0;
            foreach (var block in smoothSequence)
            {
                for (int i = 0; i < block.Length - 1; i++)
                {
                    PRez[j++] = block[i];
                }
            }
            PRez[j] = smoothSequence.Last().Last();

            textBoxKmin.Text           = stat.OrderBy(u => u.СompressionRatio).First().СompressionRatio.ToString();
            textBoxKmax.Text           = stat.OrderByDescending(u => u.СompressionRatio).First().СompressionRatio.ToString();
            textBoxRecursiveCalls.Text = stat.OrderByDescending(u => u.RecursiveCalls).First().RecursiveCalls.ToString();
        }
Example #2
0
        /// <summary>
        /// Разбиение последовательности на части и ее преобразование с сохранением и отображением данных статистики
        /// </summary>
        private void Convert()
        {
            RDPAlgorithm.Additions = 0;
            RDPAlgorithm.Multiplications = 0;

            MyPoint[] points = new MyPoint[SequenceSourse.Length];

            for (int i = 0; i < SequenceSourse.Length; i++)
            {
                points[i].X = i;
                points[i].Y = SequenceSourse[i];
            }

            int blockSize = int.Parse(textBoxBlockSize.Text);
            List<MyPoint[]> smoothSequence = new List<MyPoint[]>();
            List<Statistic> stat = new List<Statistic>();
            progressBar.Maximum = points.Length/blockSize + 1;
            int smooothSeqLength = 0;
            int j = 0;

            for (int i = 0; i < points.Length; i += blockSize)
            {
                System.Diagnostics.Stopwatch swatch = new System.Diagnostics.Stopwatch(); // создаем объект
                Statistic blockStat = new Statistic
                {
                    Additions = RDPAlgorithm.Additions,
                    Multiplications = RDPAlgorithm.Multiplications
                };
                RDPAlgorithm.MaxCalls = 0;
                RDPAlgorithm.Calls = 0;
                swatch.Start(); // старт

                smoothSequence.Add(RDPAlgorithm.DouglasPeucker(points, i,
                    (i + blockSize < points.Length) ? i + blockSize : points.Length - 1,
                    (textBoxEpsilon.Text == "") ? 1 : (float) Math.Pow(float.Parse(textBoxEpsilon.Text), 2)));

                smooothSeqLength += smoothSequence.ElementAt(j++).Length - 1;
                //-1 чтобы убрать последний элемент, т.к. он будет началом следующего блока

                swatch.Stop(); // стоп

                //сохраняем статситку
                blockStat.Time = swatch.Elapsed;
                blockStat.BlockRezultLength = smoothSequence.ElementAt(i/blockSize).Length;
                blockStat.BlockRezultSize = blockStat.BlockRezultLength*3;
                blockStat.BlockSourseSize = blockSize*2;
                blockStat.Additions = RDPAlgorithm.Additions - blockStat.Additions;
                blockStat.Multiplications = RDPAlgorithm.Multiplications - blockStat.Multiplications;
                blockStat.СompressionRatio =
                    (float) Math.Round(blockSize/(smoothSequence.ElementAt(i/blockSize).Length*1.5), 3);
                blockStat.RecursiveCalls = RDPAlgorithm.MaxCalls;

                stat.Add(blockStat);
                progressBar.Value++;
            }

            progressBar.Value = 0;
            dataGridView.DataSource = stat;
            dataGridView.Columns[0].HeaderText = @"Время преобразования";
            dataGridView.Columns[1].HeaderText = @"Размер исходного блока, байт";
            dataGridView.Columns[2].HeaderText = @"Длина сжатого блока";
            dataGridView.Columns[3].HeaderText = @"Размер сжатого блока, байт";
            dataGridView.Columns[4].HeaderText = @"Слож ений";
            dataGridView.Columns[5].HeaderText = @"Умнож ений";
            dataGridView.Columns[6].HeaderText = @"Коэф. сжатия";
            dataGridView.Columns[7].HeaderText = @"Рекурсия";
            dataGridView.Columns[0].Width = 100;
            dataGridView.RowHeadersWidth = 60;
            for (int i = 1; i < 8; i++)
                dataGridView.Columns[i].Width = 55;
            for (int i = 0; i < stat.Count; i++)
                dataGridView.Rows[i].HeaderCell.Value = (i + 1).ToString();

            PRez = new MyPoint[smooothSeqLength + 1];
            j = 0;
            foreach (var block in smoothSequence)
            {
                for (int i = 0; i < block.Length - 1; i++)
                    PRez[j++] = block[i];
            }
            PRez[j] = smoothSequence.Last().Last();

            textBoxKmin.Text = stat.OrderBy(u => u.СompressionRatio).First().СompressionRatio.ToString();
            textBoxKmax.Text = stat.OrderByDescending(u => u.СompressionRatio).First().СompressionRatio.ToString();
            textBoxRecursiveCalls.Text = stat.OrderByDescending(u => u.RecursiveCalls).First().RecursiveCalls.ToString();
        }