Changeset 3661 for trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/Analyzers/BestSingleObjectiveTestFunctionSolutionAnalyzer.cs
- Timestamp:
- 05/06/10 02:00:55 (14 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/Analyzers/BestSingleObjectiveTestFunctionSolutionAnalyzer.cs
r3660 r3661 36 36 /// An operator for analyzing the best solution for a SingleObjectiveTestFunction problem. 37 37 /// </summary> 38 [Item(" PopulationBestSingleObjectiveTestFunctionSolutionAnalyzer", "An operator for analyzing the best solution for a SingleObjectiveTestFunction problem.")]38 [Item("BestSingleObjectiveTestFunctionSolutionAnalyzer", "An operator for analyzing the best solution for a SingleObjectiveTestFunction problem.")] 39 39 [StorableClass] 40 class PopulationBestSingleObjectiveTestFunctionSolutionAnalyzer : SingleSuccessorOperator, IBestSingleObjectiveTestFunctionSolutionAnalyzer, IAnalyzer {40 class BestSingleObjectiveTestFunctionSolutionAnalyzer : SingleSuccessorOperator, IBestSingleObjectiveTestFunctionSolutionAnalyzer, IAnalyzer { 41 41 42 public ILookupParameter<ItemArray<RealVector>> RealVectorParameter {43 get { return ( ILookupParameter<ItemArray<RealVector>>)Parameters["RealVector"]; }42 public ScopeTreeLookupParameter<RealVector> RealVectorParameter { 43 get { return (ScopeTreeLookupParameter<RealVector>)Parameters["RealVector"]; } 44 44 } 45 45 ILookupParameter IBestSingleObjectiveTestFunctionSolutionAnalyzer.RealVectorParameter { 46 46 get { return RealVectorParameter; } 47 47 } 48 public ILookupParameter<ItemArray<DoubleValue>> QualityParameter {49 get { return ( ILookupParameter<ItemArray<DoubleValue>>)Parameters["Quality"]; }48 public ScopeTreeLookupParameter<DoubleValue> QualityParameter { 49 get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; } 50 50 } 51 51 ILookupParameter IBestSingleObjectiveTestFunctionSolutionAnalyzer.QualityParameter { … … 58 58 get { return (IValueLookupParameter<ResultCollection>)Parameters["Results"]; } 59 59 } 60 public IValueLookupParameter<ISingleObjectiveTestFunctionProblemEvaluator> EvaluatorParameter { 61 get { return (IValueLookupParameter<ISingleObjectiveTestFunctionProblemEvaluator>)Parameters["Evaluator"]; } 62 } 60 63 61 public PopulationBestSingleObjectiveTestFunctionSolutionAnalyzer()64 public BestSingleObjectiveTestFunctionSolutionAnalyzer() 62 65 : base() { 63 66 Parameters.Add(new ScopeTreeLookupParameter<RealVector>("RealVector", "The SingleObjectiveTestFunction solutions from which the best solution should be visualized.")); 64 65 67 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The qualities of the SingleObjectiveTestFunction solutions which should be visualized.")); 66 68 Parameters.Add(new LookupParameter<SingleObjectiveTestFunctionSolution>("BestSolution", "The best SingleObjectiveTestFunction solution.")); 67 69 Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the SingleObjectiveTestFunction solution should be stored.")); 70 Parameters.Add(new ValueLookupParameter<ISingleObjectiveTestFunctionProblemEvaluator>("Evaluator", "The evaluator with which the solution is evaluated.")); 68 71 } 69 72 70 73 public override IOperation Apply() { 71 ItemArray<RealVector> RealVectors = RealVectorParameter.ActualValue;74 ItemArray<RealVector> realVectors = RealVectorParameter.ActualValue; 72 75 ItemArray<DoubleValue> qualities = QualityParameter.ActualValue; 73 76 ResultCollection results = ResultsParameter.ActualValue; 77 ISingleObjectiveTestFunctionProblemEvaluator evaluator = EvaluatorParameter.ActualValue; 74 78 75 79 int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index; 76 80 SingleObjectiveTestFunctionSolution solution = BestSolutionParameter.ActualValue; 77 81 if (solution == null) { 78 solution = new SingleObjectiveTestFunctionSolution(RealVectors[i], QualityParameter.ActualValue[i]); 82 solution = new SingleObjectiveTestFunctionSolution(realVectors[i], qualities[i], evaluator); 83 solution.Population = realVectors; 79 84 BestSolutionParameter.ActualValue = solution; 80 85 81 86 results.Add(new Result("Best SingleObjectiveTestFunction Solution", solution)); 82 87 } else { 83 solution.RealVector = RealVectors[i]; 84 solution.Quality = QualityParameter.ActualValue[i]; 88 if (evaluator.Maximization && qualities[i].Value > solution.BestQuality.Value 89 || !evaluator.Maximization && qualities[i].Value < solution.BestQuality.Value) { 90 solution.BestRealVector = realVectors[i]; 91 solution.BestQuality = qualities[i]; 92 } 93 solution.Population = realVectors; 85 94 86 results["Best SingleObjectiveTestFunction Solution"].Value = solution;95 //results["Best SingleObjectiveTestFunction Solution"].Value = solution; 87 96 } 88 97
Note: See TracChangeset
for help on using the changeset viewer.