Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2457_ExpertSystem/HeuristicLab.Analysis.FitnessLandscape/3.3/Analysis/FitnessCloudAnalyzer.cs @ 16189

Last change on this file since 16189 was 13583, checked in by abeham, 9 years ago

#2457:

  • Added stripped-down version of FLA branch
  • Added appropriate calculators
  • Fixed detecting maximization in RLD view
File size: 3.6 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.Drawing;
23using System.Linq;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Operators;
27using HeuristicLab.Optimization.Operators;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30
31namespace HeuristicLab.Analysis.FitnessLandscape {
32
33  [StorableClass]
34  public class FitnessCloudAnalyzer : AlgorithmOperator, IQualityTrailAnalyzer {
35    public bool EnabledByDefault {
36      get { return false; }
37    }
38
39    #region Parameters
40    public LookupParameter<DataTable> QualityTrailParameter {
41      get { return (LookupParameter<DataTable>)Parameters["Quality Trail"]; }
42    }
43    public LookupParameter<ScatterPlot> FitnessCloudParameter {
44      get { return (LookupParameter<ScatterPlot>)Parameters["Fitness Cloud"]; }
45    }
46    public LookupParameter<VariableCollection> ResultsParameter {
47      get { return (LookupParameter<VariableCollection>)Parameters["Results"]; }
48    }
49    #endregion
50
51    [StorableConstructor]
52    protected FitnessCloudAnalyzer(bool deserializing) : base(deserializing) { }
53    protected FitnessCloudAnalyzer(FitnessCloudAnalyzer original, Cloner cloner) : base(original, cloner) { }
54
55    public FitnessCloudAnalyzer() {
56      Parameters.Add(new LookupParameter<DataTable>("Quality Trail", "The qualities of the solutions"));
57      Parameters.Add(new LookupParameter<ScatterPlot>("Fitness Cloud", "Information stability development over time"));
58      Parameters.Add(new LookupParameter<VariableCollection>("Results", "The collection of all results of this algorithm"));
59
60      var resultsCollector = new ResultsCollector();
61      resultsCollector.CollectedValues.Add(new LookupParameter<ScatterPlot>(FitnessCloudParameter.Name));
62
63      OperatorGraph.InitialOperator = resultsCollector;
64      resultsCollector.Successor = null;
65    }
66
67    public override IDeepCloneable Clone(Cloner cloner) {
68      return new FitnessCloudAnalyzer(this, cloner);
69    }
70
71    public override IOperation Apply() {
72      ScatterPlot fitnessCloud = FitnessCloudParameter.ActualValue;
73      if (fitnessCloud == null) {
74        fitnessCloud = new ScatterPlot();
75        FitnessCloudParameter.ActualValue = fitnessCloud;
76        fitnessCloud.Name = "Fitness Cloud";
77        fitnessCloud.XAxisName = "Fitness";
78        fitnessCloud.YAxisName = "Neighboring Fitness";
79      }
80
81      DataTable qualityTrail = QualityTrailParameter.ActualValue;
82      if (qualityTrail != null && qualityTrail.Rows.Count > 0) {
83        var qualities = qualityTrail.Rows.First().Values.ToList();
84        if (qualities.Count > 2) {
85          fitnessCloud.Add(Utils.Delta(qualities, (a, b) => new PointF((float)a, (float)b)));
86        }
87      }
88      return base.Apply();
89    }
90  }
91}
Note: See TracBrowser for help on using the repository browser.