コード例 #1
0
        public override void Solve()
        {
            base.Solve();

            Results.Add(new ArrayBoxModel <Fraction>($"Input (Using #{Method})", _matrix));

            switch (_method)
            {
            case LinearSolverMethod.Gauss:
            case LinearSolverMethod.GaussMain:
                Results.AddRange(
                    GaussSolver.GaussSolution(_matrix, _method == LinearSolverMethod.GaussMain)
                    );
                break;

            case LinearSolverMethod.SimpleIterations:
            case LinearSolverMethod.Seidel:
                Results.AddRange(
                    IterationsSolver.Solve(_matrix, Precision, _method == LinearSolverMethod.Seidel)
                    );
                break;

            default:
                Results.Add(new BoxModel("Not implemented method", $"Method {_method} is not implemented."));
                break;
            }
        }
コード例 #2
0
        private static void AnalyzeSamples(int n, int k, int d, Polynomial h, params AnalyzingSample[] samples)
        {
            var linearSystemsSolver         = new GaussSolver();
            var generatingPolynomialBuilder = new LiftingSchemeBasedBuilder(new GcdBasedBuilder(new RecursiveGcdFinder()),
                                                                            linearSystemsSolver);
            var decoder =
                new GsBasedDecoder(
                    new GsDecoder(new KotterAlgorithmBasedBuilder(new PascalsTriangleBasedCalcualtor()),
                                  new RrFactorizator()),
                    linearSystemsSolver)
            {
                TelemetryCollector = new GsBasedDecoderTelemetryCollectorForGsBasedDecoder()
            };

            var generatingPolynomial = generatingPolynomialBuilder.Build(n, d, h);

            _logger.LogInformation("Generating polynomial was restored");

            _logger.LogInformation("Samples analysis was started");
            Parallel.ForEach(samples,
                             new ParallelOptions {
                MaxDegreeOfParallelism = Math.Min((int)(Environment.ProcessorCount * 1.5d), samples.Length)
            },
                             x => PlaceNoiseIntoSamplesAndDecodeWrapperForParallelRunning(x, n, k, d, generatingPolynomial, decoder));
        }
コード例 #3
0
        //=== solve button
        private void ButtonSolve_Click(object sender, EventArgs e)
        {
            precision = Convert.ToInt32(textBoxPrecision.Text);

            GaussSolver gs = new GaussSolver();

            string[] solution = gs.Solve(precision);

            answer_form = new Answer(solution);

            answer_form.ShowDialog();

            SaveMatrix("result.txt");
        }
コード例 #4
0
        static StandardCodesFactoryTests()
        {
            var gaussSolver = new GaussSolver();

            CodesFactory
                = new StandardCodesFactory(
                      new LiftingSchemeBasedBuilder(new GcdBasedBuilder(new RecursiveGcdFinder()), gaussSolver),
                      new RsBasedDecoder(new BerlekampWelchDecoder(gaussSolver), gaussSolver),
                      new GsBasedDecoder(
                          new GsDecoder(new KotterAlgorithmBasedBuilder(new PascalsTriangleBasedCalcualtor()), new RrFactorizator()),
                          gaussSolver
                          )
                      );
        }
コード例 #5
0
        static LinearCodeDistanceAnalyzerTests()
        {
            var gaussSolver = new GaussSolver();
            var codesFactory
                = new StandardCodesFactory(
                      new LiftingSchemeBasedBuilder(new GcdBasedBuilder(new RecursiveGcdFinder()), gaussSolver),
                      new RsBasedDecoder(new BerlekampWelchDecoder(gaussSolver), gaussSolver),
                      new GsBasedDecoder(
                          new GsDecoder(new KotterAlgorithmBasedBuilder(new PascalsTriangleBasedCalcualtor()), new RrFactorizator()),
                          gaussSolver
                          )
                      );
            var wN7K3D4       = codesFactory.CreateN7K3D4();
            var wN8K4D4First  = new WaveletCode(8, 4, 4, new Polynomial(new PrimePowerOrderField(9), 2, 0, 1, 2, 1, 1));
            var wN8K4D4Second = new WaveletCode(8, 4, 4, new Polynomial(new PrimePowerOrderField(9), 2, 2, 1, 2, 0, 1));

            CodeDistanceAnalyzysTestCases
                = new TheoryData <CodeDistanceAnalyzerTestCase>
                {
                new CodeDistanceAnalyzerTestCase
                {
                    Field = wN7K3D4.Field,
                    InformationWordLength = wN7K3D4.InformationWordLength,
                    EncodingProcedure     = x => wN7K3D4.Encode(x.Select(value => wN7K3D4.Field.CreateElement(value)).ToArray()),
                    ExpectedCodeDistance  = wN7K3D4.CodeDistance
                },
                new CodeDistanceAnalyzerTestCase
                {
                    Field = wN8K4D4First.Field,
                    InformationWordLength = wN8K4D4First.InformationWordLength,
                    EncodingProcedure     = x => wN8K4D4First.Encode(x.Select(value => wN8K4D4First.Field.CreateElement(value)).ToArray()),
                    ExpectedCodeDistance  = wN8K4D4First.CodeDistance
                },
                new CodeDistanceAnalyzerTestCase
                {
                    Field = wN8K4D4Second.Field,
                    InformationWordLength = wN8K4D4Second.InformationWordLength,
                    EncodingProcedure     = x => wN8K4D4Second.Encode(x.Select(value => wN8K4D4Second.Field.CreateElement(value)).ToArray()),
                    ExpectedCodeDistance  = wN8K4D4Second.CodeDistance
                }
                };
        }
コード例 #6
0
        static Program()
        {
            var configuration = new ConfigurationBuilder()
                                .AddJsonFile("appsettings.json")
                                .Build();
            var loggerFactory = new LoggerFactory()
                                .AddSerilog(
                new LoggerConfiguration()
                .ReadFrom.Configuration(configuration)
                .Enrich.FromLogContext()
                .Enrich.WithProperty("Version", Assembly.GetEntryAssembly().GetName().Version.ToString(4))
                .CreateLogger()
                );

            Logger = loggerFactory.CreateLogger <Program>();

            NoiseGenerator = new RecursiveGenerator();
            WordsComparer  = new FieldElementsArraysComparer();

            LinearCodeDistanceAnalyzer     = new LinearCodeDistanceAnalyzer(loggerFactory.CreateLogger <LinearCodeDistanceAnalyzer>());
            MinimalSphereCoveringAnalyzer  = new MinimalSphereCoveringAnalyzer(NoiseGenerator, loggerFactory.CreateLogger <MinimalSphereCoveringAnalyzer>());
            ListsSizesDistributionAnalyzer = new ListsSizesDistributionAnalyzer(NoiseGenerator, loggerFactory.CreateLogger <ListsSizesDistributionAnalyzer>());

            var gaussSolver = new GaussSolver();

            TelemetryCollector = new GsBasedDecoderTelemetryCollectorForGsBasedDecoder();
            FixedDistanceCodesFactory
                = new StandardCodesFactory(
                      new LiftingSchemeBasedBuilder(new GcdBasedBuilder(new RecursiveGcdFinder()), gaussSolver),
                      new RsBasedDecoder(new BerlekampWelchDecoder(gaussSolver), gaussSolver),
                      new GsBasedDecoder(
                          new GsDecoder(new KotterAlgorithmBasedBuilder(new PascalsTriangleBasedCalculator()), new RrFactorizator()),
                          gaussSolver
                          )
            {
                TelemetryCollector = TelemetryCollector
            }
                      );
        }
コード例 #7
0
        public RsBasedDecoderTests()
        {
            var linearSystemSolver = new GaussSolver();

            _decoder = new RsBasedDecoder(new BerlekampWelchDecoder(linearSystemSolver), linearSystemSolver);
        }
コード例 #8
0
        private static void AnalyzeCode(int n, int k, int d, Polynomial h,
                                        int?placedErrorsCount = null, int?minCorrectValuesCount = null,
                                        int?samplesCount      = null, int?decodingThreadsCount  = null)
        {
            var maxErrorsCount = (int)Math.Floor(n - Math.Sqrt(n * (n - d)));
            var errorsCount    = placedErrorsCount ?? maxErrorsCount;

            if (errorsCount > maxErrorsCount)
            {
                throw new ArgumentException("Errors count is too large");
            }
            if (errorsCount < d - maxErrorsCount)
            {
                throw new ArgumentException("Errors count is too small");
            }

            var correctValuesCount = minCorrectValuesCount ?? n - errorsCount;

            if (correctValuesCount * correctValuesCount <= n * (n - d))
            {
                throw new ArgumentException("Correct values count is too small for decoding");
            }
            if (correctValuesCount > n - errorsCount)
            {
                throw new ArgumentException("Correct values count can't be larger than " + (n - errorsCount).ToString() + " for errors count " + errorsCount.ToString());
            }
            if (correctValuesCount >= n - (d - 1) / 2)
            {
                throw new ArgumentException("List size will be always equal to 1");
            }

            var linearSystemsSolver         = new GaussSolver();
            var generatingPolynomialBuilder = new LiftingSchemeBasedBuilder(new GcdBasedBuilder(new RecursiveGcdFinder()),
                                                                            linearSystemsSolver);
            var decoder =
                new GsBasedDecoder(
                    new GsDecoder(new KotterAlgorithmBasedBuilder(new PascalsTriangleBasedCalcualtor()),
                                  new RrFactorizator()),
                    linearSystemsSolver)
            {
                TelemetryCollector = new GsBasedDecoderTelemetryCollectorForGsBasedDecoder()
            };

            var generatingPolynomial = generatingPolynomialBuilder.Build(n, d, h);

            _logger.LogInformation("Start samples generation");
            var samplesGenerationTimer = Stopwatch.StartNew();
            var samples = GenerateSamples(n, k, generatingPolynomial, samplesCount).ToArray();

            samplesGenerationTimer.Stop();
            _logger.LogInformation("Samples were generated in {0} seconds", samplesGenerationTimer.Elapsed.TotalSeconds);

            _logger.LogInformation("Start errors positions generation");
            var errorsPositionsGenerationTimer = Stopwatch.StartNew();
            var errorsPositions = GenerateErrorsPositions(n, errorsCount).ToArray();

            errorsPositionsGenerationTimer.Stop();
            _logger.LogInformation("Errors positions were generated in {0} seconds", errorsPositionsGenerationTimer.Elapsed.TotalSeconds);

            _logger.LogInformation("Start noise decoding");
            var noiseGenerationTimer = Stopwatch.StartNew();

            samples = samples.SelectMany(x => errorsPositions.Select(y =>
                                                                     new AnalyzingSample(x)
            {
                ErrorPositions     = y,
                CurrentNoiseValue  = Enumerable.Repeat(1, errorsCount).ToArray(),
                CorrectValuesCount = correctValuesCount
            }))
                      .ToArray();
            Parallel.ForEach(samples,
                             new ParallelOptions {
                MaxDegreeOfParallelism = decodingThreadsCount ?? (int)(Environment.ProcessorCount * 1.5d)
            },
                             x => PlaceNoiseIntoSamplesAndDecodeWrapperForParallelRunning(x, n, k, d, generatingPolynomial, decoder));
            noiseGenerationTimer.Stop();
            _logger.LogInformation("Noise decoding was performed in {0} seconds", noiseGenerationTimer.Elapsed.TotalSeconds);
        }