#region License Information
/* HeuristicLab
* Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using HeuristicLab.Common;
using HeuristicLab.Core;
using HeuristicLab.Data;
using HeuristicLab.Operators;
using HeuristicLab.Optimization;
using HeuristicLab.Optimization.Operators;
using HeuristicLab.Parameters;
using HEAL.Attic;
namespace HeuristicLab.Analysis.FitnessLandscape {
[StorableType("A603BC77-CAA7-468B-9206-500A196691E7")]
public abstract class FitnessDistanceCorrelationAnalyzer : AlgorithmOperator, IAnalyzer {
public bool EnabledByDefault {
get { return false; }
}
#region Parameters
public ScopeTreeLookupParameter QualityParameter {
get { return (ScopeTreeLookupParameter)Parameters["Quality"]; }
}
public ValueLookupParameter FDCParameter {
get { return (ValueLookupParameter)Parameters["FDC"]; }
}
public ValueLookupParameter ResultsParameter {
get { return (ValueLookupParameter)Parameters["Results"]; }
}
#endregion
[StorableConstructor]
protected FitnessDistanceCorrelationAnalyzer(StorableConstructorFlag _) : base(_) { }
protected FitnessDistanceCorrelationAnalyzer(FitnessDistanceCorrelationAnalyzer original, Cloner cloner)
: base(original, cloner) { }
public FitnessDistanceCorrelationAnalyzer() {
Parameters.Add(new ScopeTreeLookupParameter("Quality", "The quality of the solution"));
Parameters.Add(new ValueLookupParameter("FDC", "The data table the stores all observed fitness/distance values"));
Parameters.Add(new ValueLookupParameter("Results", "The collection of all results of this algorithm"));
var resultsCollector = new ResultsCollector();
resultsCollector.CollectedValues.Add(new LookupParameter(FDCParameter.Name));
OperatorGraph.InitialOperator = resultsCollector;
resultsCollector.Successor = null;
}
protected abstract IEnumerable GetDistancesToBestKnownSolution();
public override IOperation Apply() {
ScatterPlot plot = FDCParameter.ActualValue;
if (plot == null) {
plot = new ScatterPlot();
plot.Name = "Fitness Distance Correlation";
plot.XAxisName = "Quality";
plot.YAxisName = "Distance";
FDCParameter.ActualValue = plot;
}
plot.Add(EnumerateFDC().ToList());
return base.Apply();
}
private IEnumerable EnumerateFDC() {
var qualities = QualityParameter.ActualValue.Select(d => d.Value).ToList();
var distances = GetDistancesToBestKnownSolution().ToList();
if (qualities.Count == distances.Count) {
var qIt = qualities.GetEnumerator();
var dIt = distances.GetEnumerator();
while (qIt.MoveNext() && dIt.MoveNext()) {
yield return new PointF((float)qIt.Current, (float)dIt.Current);
}
}
}
}
}