Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/Analyzers/BestSingleObjectiveTestFunctionSolutionAnalyzer.cs @ 3702

Last change on this file since 3702 was 3661, checked in by abeham, 14 years ago

#999

  • prepared TF visualization
  • removed obsolete TF solution analyzers
File size: 5.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using System.Text;
26using HeuristicLab.Optimization;
27using HeuristicLab.Data;
28using HeuristicLab.Core;
29using HeuristicLab.Operators;
30using HeuristicLab.Encodings.RealVectorEncoding;
31using HeuristicLab.Parameters;
32using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
33
34namespace HeuristicLab.Problems.TestFunctions.Analyzers {
35  /// <summary>
36  /// An operator for analyzing the best solution for a SingleObjectiveTestFunction problem.
37  /// </summary>
38  [Item("BestSingleObjectiveTestFunctionSolutionAnalyzer", "An operator for analyzing the best solution for a SingleObjectiveTestFunction problem.")]
39  [StorableClass]
40  class BestSingleObjectiveTestFunctionSolutionAnalyzer : SingleSuccessorOperator, IBestSingleObjectiveTestFunctionSolutionAnalyzer, IAnalyzer {
41
42    public ScopeTreeLookupParameter<RealVector> RealVectorParameter {
43      get { return (ScopeTreeLookupParameter<RealVector>)Parameters["RealVector"]; }
44    }
45    ILookupParameter IBestSingleObjectiveTestFunctionSolutionAnalyzer.RealVectorParameter {
46      get { return RealVectorParameter; }
47    }
48    public ScopeTreeLookupParameter<DoubleValue> QualityParameter {
49      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
50    }
51    ILookupParameter IBestSingleObjectiveTestFunctionSolutionAnalyzer.QualityParameter {
52      get { return QualityParameter; }
53    }
54    public ILookupParameter<SingleObjectiveTestFunctionSolution> BestSolutionParameter {
55      get { return (ILookupParameter<SingleObjectiveTestFunctionSolution>)Parameters["BestSolution"]; }
56    }
57    public IValueLookupParameter<ResultCollection> ResultsParameter {
58      get { return (IValueLookupParameter<ResultCollection>)Parameters["Results"]; }
59    }
60    public IValueLookupParameter<ISingleObjectiveTestFunctionProblemEvaluator> EvaluatorParameter {
61      get { return (IValueLookupParameter<ISingleObjectiveTestFunctionProblemEvaluator>)Parameters["Evaluator"]; }
62    }
63
64    public BestSingleObjectiveTestFunctionSolutionAnalyzer()
65      : base() {
66      Parameters.Add(new ScopeTreeLookupParameter<RealVector>("RealVector", "The SingleObjectiveTestFunction solutions from which the best solution should be visualized."));
67      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The qualities of the SingleObjectiveTestFunction solutions which should be visualized."));
68      Parameters.Add(new LookupParameter<SingleObjectiveTestFunctionSolution>("BestSolution", "The best SingleObjectiveTestFunction solution."));
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."));
71    }
72
73    public override IOperation Apply() {
74      ItemArray<RealVector> realVectors = RealVectorParameter.ActualValue;
75      ItemArray<DoubleValue> qualities = QualityParameter.ActualValue;
76      ResultCollection results = ResultsParameter.ActualValue;
77      ISingleObjectiveTestFunctionProblemEvaluator evaluator = EvaluatorParameter.ActualValue;
78
79      int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
80      SingleObjectiveTestFunctionSolution solution = BestSolutionParameter.ActualValue;
81      if (solution == null) {
82        solution = new SingleObjectiveTestFunctionSolution(realVectors[i], qualities[i], evaluator);
83        solution.Population = realVectors;
84        BestSolutionParameter.ActualValue = solution;
85
86        results.Add(new Result("Best SingleObjectiveTestFunction Solution", solution));
87      } else {
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;
94
95        //results["Best SingleObjectiveTestFunction Solution"].Value = solution;
96      }
97
98      return base.Apply();
99    }
100  }
101}
Note: See TracBrowser for help on using the repository browser.