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 |
|
---|
22 | using System.Collections.Generic;
|
---|
23 | using System.Drawing;
|
---|
24 | using System.Linq;
|
---|
25 | using HeuristicLab.Common;
|
---|
26 | using HeuristicLab.Core;
|
---|
27 | using HeuristicLab.Data;
|
---|
28 | using HeuristicLab.Operators;
|
---|
29 | using HeuristicLab.Optimization;
|
---|
30 | using HeuristicLab.Optimization.Operators;
|
---|
31 | using HeuristicLab.Parameters;
|
---|
32 | using HEAL.Attic;
|
---|
33 |
|
---|
34 | namespace HeuristicLab.Analysis.FitnessLandscape {
|
---|
35 |
|
---|
36 | [StorableType("A603BC77-CAA7-468B-9206-500A196691E7")]
|
---|
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(StorableConstructorFlag _) : base(_) { }
|
---|
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 | } |
---|