- Timestamp:
- 04/08/13 18:57:53 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/Improvers/SingleObjectiveTestFunctionImprovementOperator.cs
r8987 r9345 21 21 22 22 using System; 23 using System.Reflection;24 23 using HeuristicLab.Common; 25 24 using HeuristicLab.Core; … … 126 125 throw new ArgumentException("Cannot improve solution because it has the wrong type."); 127 126 128 MethodInfo evaluationMethod = Evaluator.GetType().GetMethod("EvaluateFunction", 129 BindingFlags.Instance | BindingFlags.NonPublic, 130 null, 131 new[] { typeof(RealVector) }, 132 null); 133 Func<RealVector, double> functionEvaluator = x => (double)evaluationMethod.Invoke(Evaluator, new object[] { x }); 134 double bestSolQuality = functionEvaluator(bestSol); 127 double bestSolQuality = Evaluator.EvaluateFunction(bestSol); 135 128 136 129 // create perturbed solutions … … 146 139 for (int i = 0; i < ImprovementAttempts.Value; i++) { 147 140 // order according to their objective function value 148 Array.Sort(simplex, (x, y) => functionEvaluator(x).CompareTo(functionEvaluator(y)));141 Array.Sort(simplex, (x, y) => Evaluator.EvaluateFunction(x).CompareTo(Evaluator.EvaluateFunction(y))); 149 142 150 143 // calculate centroid … … 160 153 for (int j = 0; j < reflectionPoint.Length; j++) 161 154 reflectionPoint[j] = centroid[j] + Alpha.Value * (centroid[j] - simplex[simplex.Length - 1][j]); 162 double reflectionPointQuality = functionEvaluator(reflectionPoint);163 if ( functionEvaluator(simplex[0]) <= reflectionPointQuality164 && reflectionPointQuality < functionEvaluator(simplex[simplex.Length - 2]))155 double reflectionPointQuality = Evaluator.EvaluateFunction(reflectionPoint); 156 if (Evaluator.EvaluateFunction(simplex[0]) <= reflectionPointQuality 157 && reflectionPointQuality < Evaluator.EvaluateFunction(simplex[simplex.Length - 2])) 165 158 simplex[simplex.Length - 1] = reflectionPoint; 166 159 167 160 // expansion 168 if (reflectionPointQuality < functionEvaluator(simplex[0])) {161 if (reflectionPointQuality < Evaluator.EvaluateFunction(simplex[0])) { 169 162 RealVector expansionPoint = new RealVector(bestSol.Length); 170 163 for (int j = 0; j < expansionPoint.Length; j++) 171 164 expansionPoint[j] = centroid[j] + Beta.Value * (reflectionPoint[j] - centroid[j]); 172 simplex[simplex.Length - 1] = functionEvaluator(expansionPoint) < reflectionPointQuality ? expansionPoint : reflectionPoint;165 simplex[simplex.Length - 1] = Evaluator.EvaluateFunction(expansionPoint) < reflectionPointQuality ? expansionPoint : reflectionPoint; 173 166 } 174 167 175 168 // contraction 176 if ( functionEvaluator(simplex[simplex.Length - 2]) <= reflectionPointQuality177 && reflectionPointQuality < functionEvaluator(simplex[simplex.Length - 1])) {169 if (Evaluator.EvaluateFunction(simplex[simplex.Length - 2]) <= reflectionPointQuality 170 && reflectionPointQuality < Evaluator.EvaluateFunction(simplex[simplex.Length - 1])) { 178 171 RealVector outsideContractionPoint = new RealVector(bestSol.Length); 179 172 for (int j = 0; j < outsideContractionPoint.Length; j++) 180 173 outsideContractionPoint[j] = centroid[j] + Gamma.Value * (reflectionPoint[j] - centroid[j]); 181 if ( functionEvaluator(outsideContractionPoint) <= reflectionPointQuality) {174 if (Evaluator.EvaluateFunction(outsideContractionPoint) <= reflectionPointQuality) { 182 175 simplex[simplex.Length - 1] = outsideContractionPoint; 183 if ( functionEvaluator(reflectionPoint) >= functionEvaluator(simplex[simplex.Length - 1])) {176 if (Evaluator.EvaluateFunction(reflectionPoint) >= Evaluator.EvaluateFunction(simplex[simplex.Length - 1])) { 184 177 RealVector insideContractionPoint = new RealVector(bestSol.Length); 185 178 for (int j = 0; j < insideContractionPoint.Length; j++) 186 179 insideContractionPoint[j] = centroid[j] - Gamma.Value * (reflectionPoint[j] - centroid[j]); 187 if ( functionEvaluator(insideContractionPoint) < functionEvaluator(simplex[simplex.Length - 1])) simplex[simplex.Length - 1] = insideContractionPoint;180 if (Evaluator.EvaluateFunction(insideContractionPoint) < Evaluator.EvaluateFunction(simplex[simplex.Length - 1])) simplex[simplex.Length - 1] = insideContractionPoint; 188 181 } 189 182 }
Note: See TracChangeset
for help on using the changeset viewer.