Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape/Analysis/FitnessCloudAnalyzer.cs @ 16573

Last change on this file since 16573 was 16573, checked in by gkronber, 5 years ago

#2520: changed HeuristicLab.FLA addon to compile with new HL.Persistence

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
21using System.Drawing;
22using System.Linq;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Operators;
26using HeuristicLab.Optimization.Operators;
27using HeuristicLab.Parameters;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29using HEAL.Attic;
30
31namespace HeuristicLab.Analysis.FitnessLandscape.Analysis {
32
33  [StorableType("4156976F-4E61-48BA-B598-FEA872F2E948")]
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(StorableConstructorFlag _) : base(_) { }
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.