Changeset 13405
 Timestamp:
 11/26/15 09:56:33 (9 years ago)
 Location:
 branches/ProblemRefactoring/HeuristicLab.Problems.TestFunctions/3.3
 Files:

 1 edited
 1 copied
Legend:
 Unmodified
 Added
 Removed

branches/ProblemRefactoring/HeuristicLab.Problems.TestFunctions/3.3/Functions/SchafferF6.cs
r13403 r13405 25 25 using HeuristicLab.Data; 26 26 using HeuristicLab.Encodings.RealVectorEncoding; 27 using HeuristicLab.Parameters;28 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 28 30 29 namespace HeuristicLab.Problems.TestFunctions { 31 30 /// <summary> 32 /// The generalized Rastrigin function y = Sum((x_i)^2 + A * (1  Cos(2pi*x_i))) is a highlymultimodal function that has its optimal value 0 at the origin.33 /// It is implemented as described in Eiben, A.E. and Smith, J.E. 2003. Introduction to Evolutionary Computation. Natural Computing Series, SpringerVerlag Berlin Heidelberg. 31 /// The generalized Rastrigin function y = 0.5 + (Sin^2(Sqrt(x^2 + y^2))  0.5) / (1 + 0.001 * (x^2 + y^2))^2 is a multimodal function that has its optimal value 0 at the origin. 32 34 33 /// </summary 35 [Item(" Rastrigin", "Evaluates the generalized Rastrigin function y = Sum((x_i)^2 + A * (1  Cos(2pi*x_i)))on a given point. The optimum of this function is 0 at the origin. It is implemented as described in Eiben, A.E. and Smith, J.E. 2003. Introduction to Evolutionary Computation. Natural Computing Series, SpringerVerlag Berlin Heidelberg.")]34 [Item("SchafferF6", "Evaluates the Schaffer F6 function y = 0.5 + (Sin^2(Sqrt(x^2 + y^2))  0.5) / (1 + 0.001 * (x^2 + y^2))^2 on a given point. The optimum of this function is 0 at the origin. It is implemented as described in Eiben, A.E. and Smith, J.E. 2003. Introduction to Evolutionary Computation. Natural Computing Series, SpringerVerlag Berlin Heidelberg.")] 36 35 [StorableClass] 37 public class Rastrigin: SingleObjectiveTestFunction {36 public class SchafferF6 : SingleObjectiveTestFunction { 38 37 /// <summary> 39 38 /// Returns false as the Rastrigin function is a minimization problem. … … 52 51 /// </summary> 53 52 public override DoubleMatrix Bounds { 54 get { return new DoubleMatrix(new double[,] { {  5.12, 5.12} }); }53 get { return new DoubleMatrix(new double[,] { { 100, 100 } }); } 55 54 } 56 55 /// <summary> 57 /// Gets the minimum problem size ( 1).56 /// Gets the minimum problem size (2). 58 57 /// </summary> 59 58 public override int MinimumProblemSize { 60 get { return 1; }59 get { return 2; } 61 60 } 62 61 /// <summary> 63 /// Gets the (theoretical) maximum problem size (2^31  1).62 /// Gets the maximum problem size (2). 64 63 /// </summary> 65 64 public override int MaximumProblemSize { 66 get { return int.MaxValue; } 67 } 68 /// <summary> 69 /// The parameter A is a parameter of the objective function y = Sum((x_i)^2 + A * (1  Cos(2pi*x_i))). Default is A = 10. 70 /// </summary> 71 public ValueParameter<DoubleValue> AParameter { 72 get { return (ValueParameter<DoubleValue>)Parameters["A"]; } 73 } 74 /// <summary> 75 /// The parameter A is a parameter of the objective function y = Sum((x_i)^2 + A * (1  Cos(2pi*x_i))). Default is A = 10. 76 /// </summary> 77 public DoubleValue A { 78 get { return AParameter.Value; } 79 set { if (value != null) AParameter.Value = value; } 65 get { return 2; } 80 66 } 81 67 … … 85 71 86 72 [StorableConstructor] 87 protected Rastrigin(bool deserializing) : base(deserializing) { } 88 protected Rastrigin(Rastrigin original, Cloner cloner) : base(original, cloner) { } 89 /// <summary> 90 /// Initializes a new instance of the RastriginEvaluator with one parameter (<c>A</c>). 91 /// </summary> 92 public Rastrigin() 93 : base() { 94 Parameters.Add(new ValueParameter<DoubleValue>("A", "The parameter A is a parameter of the objective function y = Sum((x_i)^2 + A * (1  Cos(2pi*x_i))). Default is A = 10.", new DoubleValue(10))); 95 } 73 protected SchafferF6(bool deserializing) : base(deserializing) { } 74 protected SchafferF6(SchafferF6 original, Cloner cloner) : base(original, cloner) { } 75 public SchafferF6() : base() { } 96 76 97 77 public override IDeepCloneable Clone(Cloner cloner) { 98 return new Rastrigin(this, cloner);78 return new SchafferF6(this, cloner); 99 79 } 100 80 … … 104 84 /// <param name="point">Ndimensional point for which the test function should be evaluated.</param> 105 85 /// <returns>The result value of the Rastrigin function at the given point.</returns> 106 public static double Apply(RealVector point , double a) {107 double result = a * point.Length;108 for (int i = 0; i < point.Length; i++) {109 result += point[i] * point[i];110 result = a * Math.Cos(2 * Math.PI * point[i]);111 }112 return (result);86 public static double Apply(RealVector point) { 87 if (point.Length != 2) throw new ArgumentException("The SchafferF6 can only be evaluated for two dimenional vectors"); 88 var sumSquare = point[0] * point[0] + point[1] * point[1]; 89 var sin = Math.Sin(Math.Sqrt(sumSquare)); 90 var nom = sin * sin  0.5; 91 var denom = (1 + 0.001 * sumSquare) * (1 + 0.001 * sumSquare); 92 return 0.5 + nom / denom; 113 93 } 114 94 … … 120 100 /// <returns>The result value of the Rastrigin function at the given point.</returns> 121 101 public override double Evaluate(RealVector point) { 122 return Apply(point , A.Value);102 return Apply(point); 123 103 } 124 104 } 
branches/ProblemRefactoring/HeuristicLab.Problems.TestFunctions/3.3/HeuristicLab.Problems.TestFunctions3.3.csproj
r13403 r13405 115 115 <ItemGroup> 116 116 <Compile Include="Functions\Random.cs" /> 117 <Compile Include="Functions\SchafferF6.cs" /> 117 118 <Compile Include="Improvers\SingleObjectiveTestFunctionImprovementOperator.cs" /> 118 119 <Compile Include="Instances\SOTFData.cs" />
Note: See TracChangeset
for help on using the changeset viewer.