Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2635_HeuristicLab.OSGAEvaluator/HeuristicLab.OSGAEvaluator/AdjustedEvaluatedSolutionsAnalyzer.cs @ 17300

Last change on this file since 17300 was 16818, checked in by bburlacu, 6 years ago

#2635: Update solution to .net framework version 4.6.1, switch to new persistence, add plugin frame file and prebuild event.

File size: 3.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 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 HEAL.Attic;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Optimization;
27using HeuristicLab.Parameters;
28using HeuristicLab.Problems.DataAnalysis.Symbolic;
29using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;
30
31namespace HeuristicLab.OSGAEvaluator {
32  [Item("AdjustedEvaluatedSolutionsAnalyzer", "Analyzer which aggregates the adjusted evaluated solutions count from the predictive evaluator.")]
33  [StorableType("791A5594-FC15-41AF-9D06-86D1313C4C8B")]
34  public class AdjustedEvaluatedSolutionsAnalyzer : SymbolicDataAnalysisSingleObjectiveAnalyzer {
35    private const string EvaluatorParameterName = "Evaluator";
36    private const string AdjustedEvaluatedSolutionsResultName = "AdjustedEvaluatedSolutions";
37
38    public ILookupParameter<SymbolicRegressionSingleObjectiveEvaluator> EvaluatorParameter {
39      get { return (ILookupParameter<SymbolicRegressionSingleObjectiveEvaluator>)Parameters[EvaluatorParameterName]; }
40    }
41
42    public SymbolicRegressionSingleObjectiveEvaluator Evaluator {
43      get { return EvaluatorParameter.ActualValue; }
44    }
45
46    public AdjustedEvaluatedSolutionsAnalyzer() {
47      Parameters.Add(new LookupParameter<SymbolicRegressionSingleObjectiveEvaluator>(EvaluatorParameterName));
48    }
49
50    [StorableConstructor]
51    protected AdjustedEvaluatedSolutionsAnalyzer(StorableConstructorFlag _) : base(_) { }
52
53    protected AdjustedEvaluatedSolutionsAnalyzer(AdjustedEvaluatedSolutionsAnalyzer original, Cloner cloner) : base(original, cloner) { }
54
55    public override IDeepCloneable Clone(Cloner cloner) {
56      return new AdjustedEvaluatedSolutionsAnalyzer(this, cloner);
57    }
58
59    public override IOperation Apply() {
60      var evaluator = Evaluator as SymbolicRegressionSingleObjectiveOsgaEvaluator;
61
62      if (evaluator == null)
63        return base.Apply();
64
65      var results = ResultCollectionParameter.ActualValue;
66      if (!results.ContainsKey(AdjustedEvaluatedSolutionsResultName)) {
67        results.Add(new Result(AdjustedEvaluatedSolutionsResultName, new DoubleValue(0)));
68      }
69      var adjustedEvaluatedSolutions = (DoubleValue)results[AdjustedEvaluatedSolutionsResultName].Value;
70      adjustedEvaluatedSolutions.Value += evaluator.AdjustedEvaluatedSolutions;
71      evaluator.AdjustedEvaluatedSolutions = 0;
72
73      return base.Apply();
74    }
75  }
76}
Note: See TracBrowser for help on using the repository browser.