Changeset 3315 for trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/Evaluators/GriewankEvaluator.cs
- Timestamp:
- 04/12/10 23:39:40 (14 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/Evaluators/GriewankEvaluator.cs
r3307 r3315 28 28 namespace HeuristicLab.Problems.TestFunctions { 29 29 /// <summary> 30 /// Griewangk Function<br/>31 /// Domain: [-600.0 , 600.0]^n<br/>32 /// Optimum: 0.0 at (0, 0, ..., 0)30 /// The Griewank function is introduced in Griewank, A.O. 1981. Generalized descent for global optimization. Journal of Optimization Theory and Applications 34, pp. 11-39. 31 /// It is a multimodal fitness function in the range [-600,600]^n. 32 /// Here it is implemented as described (without the modifications) in Locatelli, M. 2003. A note on the Griewank test function. Journal of Global Optimization 25, pp. 169-174, Springer. 33 33 /// </summary> 34 [Item("Griewan gkEvaluator", "Evaluates the Griewangk function on a given point. The optimum of this function is 0 at the origin.")]34 [Item("GriewankEvaluator", "Evaluates the Griewank function on a given point. The optimum of this function is 0 at the origin. It is introduced by Griewank A.O. 1981 and implemented as described (without the modifications) in Locatelli, M. 2003. A note on the Griewank test function. Journal of Global Optimization 25, pp. 169-174, Springer.")] 35 35 [StorableClass] 36 public class Griewan gkEvaluator : SingleObjectiveTestFunctionProblemEvaluator {36 public class GriewankEvaluator : SingleObjectiveTestFunctionProblemEvaluator { 37 37 /// <summary> 38 38 /// Returns false as the Griewangk function is a minimization problem. … … 54 54 } 55 55 /// <summary> 56 /// Gets the minimum problem size ( 2).56 /// Gets the minimum problem size (1). 57 57 /// </summary> 58 58 public override int MinimumProblemSize { 59 get { return 2; }59 get { return 1; } 60 60 } 61 61 /// <summary> … … 65 65 get { return int.MaxValue; } 66 66 } 67 68 /// <summary> 69 /// If dimension of the problem is less or equal than 100 the values of Math.Sqrt(i + 1) are precomputed. 70 /// </summary> 71 private double[] sqrts; 67 72 68 73 /// <summary> … … 84 89 85 90 result = result - val + 1; 86 return (result); 91 return result; 92 } 93 94 /// <summary> 95 /// Evaluates the test function for a specific <paramref name="point"/>. It uses an array of precomputed values for Math.Sqrt(i + 1) with i = 0..N 96 /// </summary> 97 /// <param name="point">N-dimensional point for which the test function should be evaluated.</param> 98 /// <param name="sqrts">The precomputed array of square roots.</param> 99 /// <returns>The result value of the Griewangk function at the given point.</returns> 100 private static double Apply(RealVector point, double[] sqrts) { 101 double result = 0; 102 double val = 0; 103 104 for (int i = 0; i < point.Length; i++) 105 result += point[i] * point[i]; 106 result = result / 4000; 107 108 val = Math.Cos(point[0]); 109 for (int i = 1; i < point.Length; i++) 110 val *= Math.Cos(point[i] / sqrts[i]); 111 112 result = result - val + 1; 113 return result; 87 114 } 88 115 … … 94 121 /// <returns>The result value of the Griewangk function at the given point.</returns> 95 122 protected override double EvaluateFunction(RealVector point) { 96 return Apply(point); 123 if (point.Length > 100) 124 return Apply(point); 125 else { 126 if (sqrts == null || sqrts.Length < point.Length) ComputeSqrts(point.Length); 127 return Apply(point, sqrts); 128 } 129 } 130 131 private void ComputeSqrts(int length) { 132 sqrts = new double[length]; 133 for (int i = 0; i < length; i++) sqrts[i] = Math.Sqrt(i + 1); 97 134 } 98 135 }
Note: See TracChangeset
for help on using the changeset viewer.