/// Use random locations (drunkard's walk algorithm). public override void InitializeIterations() { Random generator = new Random(); _bestPoints = new OptimizingPoint[3]; if (double.IsNaN(_result)) { _result = generator.NextDouble(); } _bestPoints[0] = _pointFactory.CreatePoint(_result, _f); _bestPoints[1] = _pointFactory.CreatePoint(generator.NextDouble() + _bestPoints[0].Position, _f); _bestPoints[2] = _pointFactory.CreatePoint(generator.NextDouble() + _bestPoints[1].Position, _f); }
/// Apply bisection on points 1 and n /// @param n int index of worst point of bisected interval private void ReducePoints(int n) { double x = _bestPoints[1].Position; x += GoldenSection * (_bestPoints[n].Position - x); OptimizingPoint newPoint = _pointFactory.CreatePoint(x, _f); if (newPoint.BetterThan(_bestPoints[1])) { _bestPoints[2 - n] = _bestPoints[1]; _bestPoints[1] = newPoint; } else { _bestPoints[n] = newPoint; } }