Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape/FDC/FitnessDistanceCorrelationAnalyzer.cs @ 15777

Last change on this file since 15777 was 7176, checked in by gkronber, 13 years ago

#1696 adapted analyzers to compile with changes of r7172 (#1584)

File size: 3.8 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.Collections.Generic;
23using System.Drawing;
24using System.Linq;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Data;
28using HeuristicLab.Operators;
29using HeuristicLab.Optimization;
30using HeuristicLab.Optimization.Operators;
31using HeuristicLab.Parameters;
32using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
33
34namespace HeuristicLab.Analysis.FitnessLandscape {
35
36  [StorableClass]
37  public abstract class FitnessDistanceCorrelationAnalyzer : AlgorithmOperator, IAnalyzer {
38    public bool EnabledByDefault {
39      get { return false; }
40    }
41
42    #region Parameters
43    public ScopeTreeLookupParameter<DoubleValue> QualityParameter {
44      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
45    }
46    public ValueLookupParameter<ScatterPlot> FDCParameter {
47      get { return (ValueLookupParameter<ScatterPlot>)Parameters["FDC"]; }
48    }
49    public ValueLookupParameter<VariableCollection> ResultsParameter {
50      get { return (ValueLookupParameter<VariableCollection>)Parameters["Results"]; }
51    }
52    #endregion
53
54    [StorableConstructor]
55    protected FitnessDistanceCorrelationAnalyzer(bool deserializing) : base(deserializing) { }
56    protected FitnessDistanceCorrelationAnalyzer(FitnessDistanceCorrelationAnalyzer original, Cloner cloner)
57      : base(original, cloner) { }
58
59    public FitnessDistanceCorrelationAnalyzer() {
60      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The quality of the solution"));
61      Parameters.Add(new ValueLookupParameter<ScatterPlot>("FDC", "The data table the stores all observed fitness/distance values"));
62      Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The collection of all results of this algorithm"));
63
64      var resultsCollector = new ResultsCollector();
65      resultsCollector.CollectedValues.Add(new LookupParameter<ScatterPlot>(FDCParameter.Name));
66
67      OperatorGraph.InitialOperator = resultsCollector;
68      resultsCollector.Successor = null;
69    }
70
71    protected abstract IEnumerable<double> GetDistancesToBestKnownSolution();
72
73    public override IOperation Apply() {
74      ScatterPlot plot = FDCParameter.ActualValue;
75      if (plot == null) {
76        plot = new ScatterPlot();
77        plot.Name = "Fitness Distance Correlation";
78        plot.XAxisName = "Quality";
79        plot.YAxisName = "Distance";
80        FDCParameter.ActualValue = plot;
81      }
82      plot.Add(EnumerateFDC().ToList());
83      return base.Apply();
84    }
85
86    private IEnumerable<PointF> EnumerateFDC() {
87      var qualities = QualityParameter.ActualValue.Select(d => d.Value).ToList();
88      var distances = GetDistancesToBestKnownSolution().ToList();
89      if (qualities.Count == distances.Count) {
90        var qIt = qualities.GetEnumerator();
91        var dIt = distances.GetEnumerator();
92        while (qIt.MoveNext() && dIt.MoveNext()) {
93          yield return new PointF((float)qIt.Current, (float)dIt.Current);
94        }
95      }
96    }
97  }
98}
Note: See TracBrowser for help on using the repository browser.