Ejemplo n.º 1
0
        public void UpdateNarrows(Rational[] userNarrows = null)
        {
            _narrows = new Rational[_involvedPrimeCount];
            _error   = null;

            // set default narrows
            foreach (Rational item in _items)
            {
                Rational narrow = NarrowUtils.MakeNarrow(item, _baseItem);
                SetNarrow(narrow);
            }

            // set custom user narrows
            if (userNarrows != null)
            {
                var invalidNarrows = new List <Rational>();
                foreach (Rational narrow in userNarrows)
                {
                    if (narrow.IsDefault())
                    {
                        continue;
                    }
                    if (!IsInRange(narrow))
                    {
                        invalidNarrows.Add(narrow);
                    }
                    else
                    {
                        SetNarrow(narrow);
                    }
                }
                if (invalidNarrows.Count > 0)
                {
                    _error = "Narrows out of subgroup: " + String.Join(", ", invalidNarrows);
                }
            }

            // !!! he we should check if resulting narrows can solve each generated rational;
            //   currently we add all missing narrows (even if it's out of subgroup) instead.

            /*
             * for (int i = 0; i < _narrows.Length; ++i) {
             *  if (_narrows[i].IsDefault()) {
             *      _narrows[i] = NarrowUtils.MakeNarrow(Rational.Prime(i), _baseItem); // default narrow prime
             *  }
             * }
             */
#if DEBUG
            Debug.WriteLine("Narrows set: " + Rational.FormatRationals(_narrows));
#endif
        }