Пример #1
0
        /// @return boolean	true if a better point was found
        /// @exception DhbIllegalDimension if dimension of initial value is 0.
        private bool AddReflection(DhbVector centerOfgravity)
        {
            DhbVector reflectedVector = centerOfgravity * 2;

            reflectedVector.AccumulateNegated(
                _simplex[_result.Length].Position);
            OptimizingVector reflectedPoint =
                _pointFactory.CreateVector(reflectedVector, _f);

            if (reflectedPoint.BetterThan(_simplex[0]))
            {
                reflectedVector.ScaledBy(2);
                reflectedVector.AccumulateNegated(centerOfgravity);
                OptimizingVector expandedPoint =
                    _pointFactory.CreateVector(reflectedVector, _f);
                if (expandedPoint.BetterThan(reflectedPoint))
                {
                    AddBestPoint(expandedPoint);
                }
                else
                {
                    AddBestPoint(reflectedPoint);
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #2
0
        /// Add a new best point to the simplex
        /// @param v DhbOptimizing.OptimizingVector
        private void AddBestPoint(OptimizingVector v)
        {
            int n = _simplex.Length;

            while (--n > 0)
            {
                _simplex[n] = _simplex[n - 1];
            }
            _simplex[0] = v;
        }
Пример #3
0
        /// @return boolean	true if a better point was found
        /// @param g DhbVector	summit whose median is contracted
        /// @exception DhbIllegalDimension if dimension of initial value is 0.
        private bool AddContraction(DhbVector g)
        {
            g.Accumulate(_simplex[_result.Length].Position);
            g.ScaledBy(0.5);
            OptimizingVector contractedPoint = _pointFactory.CreateVector(g, _f);

            if (contractedPoint.BetterThan(_simplex[0]))
            {
                AddBestPoint(contractedPoint);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #4
0
        /// @param x DhbVector
        public override void CollectPoint(object x)
        {
            OptimizingVector v = _pointFactory.CreateVector((DhbVector)x, _f);

            if (_fillIndex == 0 || _bestPoints[_fillIndex - 1].BetterThan(v))
            {
                _bestPoints[_fillIndex++] = v;
                return;
            }
            int n = 0;
            int m = _fillIndex - 1;

            if (_bestPoints[0].BetterThan(v))
            {
                int k;
                while (m - n > 1)
                {
                    k = (n + m) / 2;
                    if (v.BetterThan(_bestPoints[k]))
                    {
                        m = k;
                    }
                    else
                    {
                        n = k;
                    }
                }
                n = m;
            }
            for (m = _fillIndex; m > n; m--)
            {
                _bestPoints[m] = _bestPoints[m - 1];
            }
            _bestPoints[n] = v;
            _fillIndex    += 1;
        }
Пример #5
0
 /// @return boolean	true if the receiver is "better" than
 ///												the supplied point
 /// @param point OptimizingVector
 public abstract bool BetterThan(OptimizingVector entity);
Пример #6
0
 /// @return bool	true if the receiver is "better" than
 ///												the supplied point
 /// @param point OptimizingVector
 public override bool BetterThan(OptimizingVector point)
 {
     return(this.Value < point.Value);
 }