示例#1
0
        /*
         *      public PolyRelationsSieveProgress(GNFS gnfs, int a, uint b, int quantity, int valueRange, List<List<Relation>> free, List<Relation> smooth, List<Relation> rough)
         *              : this(gnfs, quantity, valueRange)
         *      {
         *              A = a;
         *              B = b;
         *
         *              Relations.FreeRelations = free;
         *              Relations.SmoothRelations = smooth;
         *              Relations.RoughRelations = rough;
         *      }
         */

        #endregion

        #region Processing / Computation

        public void GenerateRelations(CancellationToken cancelToken)
        {
            if (_gnfs.CurrentRelationsProgress.Relations.SmoothRelations.Any())
            {
                // SmoothRelationsCounter should reflect accurately
                Serialization.Save.Relations.Smooth.Append(_gnfs); // This method updates SmoothRelationsCounter correctly
                                                                   //_gnfs.CurrentRelationsProgress.Relations.SmoothRelations.Clear();
            }

            int roughRelationCounter = 0;

            if (_gnfs.CurrentRelationsProgress.Relations.RoughRelations.Any())
            {
                Serialization.Save.Relations.Rough.Append(_gnfs);
                //_gnfs.CurrentRelationsProgress.Relations.RoughRelations.Clear();
            }



            if (Quantity == -1)
            {
                Quantity = _gnfs.RationalFactorPairCollection.Count + _gnfs.AlgebraicFactorPairCollection.Count + _gnfs.QuadraticFactorPairCollection.Count + 1;
            }
            //else if (SmoothRelationsCounter >= Quantity)
            //{
            //	Quantity += 2000;
            //}

            if (A >= ValueRange)
            {
                ValueRange += 200;
            }

            ValueRange = ValueRange % 2 == 0 ? ValueRange + 1 : ValueRange;
            A          = (A % 2 == 0) ? A + 1 : A;

            int startA = A;

            while (B >= MaxB)
            {
                MaxB += 100;
            }

            _gnfs.LogMessage($"GenerateRelations: Quantity = {Quantity}, ValueRange = {ValueRange}, A = {A}, B = {B}, Max B = {MaxB}");

            while (SmoothRelationsCounter < Quantity)
            {
                if (cancelToken.IsCancellationRequested)
                {
                    break;
                }

                if (B > MaxB)
                {
                    break;
                }

                foreach (int a in SieveRange.GetSieveRangeContinuation(A, ValueRange))
                {
                    if (cancelToken.IsCancellationRequested)
                    {
                        break;
                    }

                    A = a;
                    if (GCD.AreCoprime(A, B))
                    {
                        Relation rel = new Relation(_gnfs, A, B);

                        rel.Sieve(_gnfs.CurrentRelationsProgress);

                        bool smooth = rel.IsSmooth;
                        if (smooth)
                        {
                            Serialization.Save.Relations.Smooth.Append(_gnfs, rel);

                            _gnfs.CurrentRelationsProgress.Relations.SmoothRelations.Add(rel);

                            _gnfs.LogMessage($"Found smooth relation: A = {rel.A}, B = {rel.B}");
                        }
                        else
                        {
                            _gnfs.CurrentRelationsProgress.Relations.RoughRelations.Add(rel);
                            roughRelationCounter++;

                            if (roughRelationCounter > 1000)
                            {
                                Serialization.Save.Relations.Rough.AppendList(_gnfs, _gnfs.CurrentRelationsProgress.Relations.RoughRelations);
                                _gnfs.CurrentRelationsProgress.Relations.RoughRelations.Clear();
                                roughRelationCounter = 0;
                            }
                        }
                    }
                }

                if (cancelToken.IsCancellationRequested)
                {
                    break;
                }

                B += 2;
                A  = startA;

                if (B % 11 == 0)
                {
                    _gnfs.LogMessage($"B = {B}");
                }
            }
        }
示例#2
0
        public void GenerateRelations(CancellationToken cancelToken)
        {
            if (_gnfs.CurrentRelationsProgress.Relations.SmoothRelations.Any())
            {
                // SmoothRelationsCounter should reflect accurately
                Serialization.Save.Relations.Smooth.Append(_gnfs);                 // This method updates SmoothRelationsCounter correctly
                //_gnfs.CurrentRelationsProgress.Relations.SmoothRelations.Clear();
            }

            /*
             * int roughRelationCounter = 0;
             * if (_gnfs.CurrentRelationsProgress.Relations.RoughRelations.Any())
             * {
             * Serialization.Save.Relations.Rough.Append(_gnfs);
             * _gnfs.CurrentRelationsProgress.Relations.RoughRelations.Clear();
             * }
             */

            if (SmoothRelations_TargetQuantity == -1)
            {
                SmoothRelations_TargetQuantity = SmoothRelationsRequiredForMatrixStep;
            }

            if (A >= ValueRange)
            {
                ValueRange += 200;
            }

            ValueRange = (ValueRange % 2 == 0) ? ValueRange + 1 : ValueRange;
            A          = (A % 2 == 0) ? A + 1 : A;

            BigInteger startA = A;

            while (B >= MaxB)
            {
                MaxB += 100;
            }

            _gnfs.LogMessage($"GenerateRelations: TargetQuantity = {SmoothRelations_TargetQuantity}, ValueRange = {ValueRange}, A = {A}, B = {B}, Max B = {MaxB}");

            while (SmoothRelationsCounter < SmoothRelations_TargetQuantity)
            {
                if (cancelToken.IsCancellationRequested)
                {
                    break;
                }

                if (B > MaxB)
                {
                    break;
                }

                foreach (BigInteger a in SieveRange.GetSieveRangeContinuation(A, ValueRange))
                {
                    if (cancelToken.IsCancellationRequested)
                    {
                        break;
                    }

                    A = a;
                    if (GCD.AreCoprime(A, B))
                    {
                        Relation rel = new Relation(_gnfs, A, B);

                        rel.Sieve(_gnfs.CurrentRelationsProgress);

                        bool smooth = rel.IsSmooth;
                        if (smooth)
                        {
                            Serialization.Save.Relations.Smooth.Append(_gnfs, rel);

                            _gnfs.CurrentRelationsProgress.Relations.SmoothRelations.Add(rel);

                            _gnfs.LogMessage($"Found smooth relation: A = {rel.A}, B = {rel.B}");
                        }
                        else
                        {
                            /*
                             * _gnfs.CurrentRelationsProgress.Relations.RoughRelations.Add(rel);
                             * roughRelationCounter++;
                             *
                             * if (roughRelationCounter > 1000)
                             * {
                             *      Serialization.Save.Relations.Rough.AppendList(_gnfs, _gnfs.CurrentRelationsProgress.Relations.RoughRelations);
                             *      _gnfs.CurrentRelationsProgress.Relations.RoughRelations.Clear();
                             *      roughRelationCounter = 0;
                             * }
                             */
                        }
                    }
                }

                if (cancelToken.IsCancellationRequested)
                {
                    break;
                }

                B += 1;
                A  = startA;

                //if (B % 11 == 0)
                _gnfs.LogMessage($"B = {B}");
            }
        }