#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.Linq; using HeuristicLab.Analysis.FitnessLandscape.DataTables; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Operators; using HeuristicLab.Optimization.Operators; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Analysis.FitnessLandscape.Analysis { [StorableClass] public class RuggednessAnalyzer : AlgorithmOperator, IQualityTrailAnalyzer { public bool EnabledByDefault { get { return false; } } #region Parameters public LookupParameter QualityTrailParameter { get { return (LookupParameter)Parameters["Quality Trail"]; } } public LookupParameter CorrelationLengthTableParameter { get { return (LookupParameter)Parameters["CorrelationLengthTable"]; } } public LookupParameter AutocorrelationParameter { get { return (LookupParameter)Parameters["Autocorrelation"]; } } public LookupParameter ResultsParameter { get { return (LookupParameter)Parameters["Results"]; } } public LookupParameter AutoCorrelation1Parameter { get { return (LookupParameter)Parameters["AutoCorrelation1"]; } } public LookupParameter CorrelationLengthParameter { get { return (LookupParameter)Parameters["CorrelationLength"]; } } #endregion [StorableConstructor] protected RuggednessAnalyzer(bool deserializing) : base(deserializing) { } protected RuggednessAnalyzer(RuggednessAnalyzer original, Cloner cloner) : base(original, cloner) { } public RuggednessAnalyzer() { Parameters.Add(new LookupParameter("Quality Trail", "The quality of the solution")); Parameters.Add(new LookupParameter("CorrelationLengthTable", "Maximum nr of steps between statistically significantly correlated quality values")); Parameters.Add(new LookupParameter("Autocorrelation", "Autocorrelation function of successive quality values")); Parameters.Add(new LookupParameter("Results", "The collection of all results of this algorithm")); Parameters.Add(new LookupParameter("AutoCorrelation1", "Autocorrelation for one mutation step.")); Parameters.Add(new LookupParameter("CorrelationLength", "The correlation length.")); var resultsCollector = new ResultsCollector(); resultsCollector.CollectedValues.Add(new LookupParameter(CorrelationLengthTableParameter.Name)); resultsCollector.CollectedValues.Add(new LookupParameter(AutocorrelationParameter.Name)); resultsCollector.CollectedValues.Add(new LookupParameter(AutoCorrelation1Parameter.Name)); resultsCollector.CollectedValues.Add(new LookupParameter(CorrelationLengthParameter.Name)); OperatorGraph.InitialOperator = resultsCollector; resultsCollector.Successor = null; } public override IDeepCloneable Clone(Cloner cloner) { return new RuggednessAnalyzer(this, cloner); } public override IOperation Apply() { DataTable correlationLengthTable = GetOrCreateCorrelationLengthTable(); AutoCorrelationTable autocorrelationTable = GetOrCreateAutoCorrelationTable(); DataTable qualityTrail = QualityTrailParameter.ActualValue; if (qualityTrail != null && qualityTrail.Rows.Count > 0) { double[] autocorrelationValues; int correlationLength = RuggednessCalculator.CalculateCorrelationLength(qualityTrail.Rows.First().Values.ToArray(), out autocorrelationValues); correlationLengthTable.Rows["Correlation Length"].Values.Add(correlationLength); autocorrelationTable.Rows["Auto Correlation"].Values.Clear(); autocorrelationTable.Rows["Auto Correlation"].Values.AddRange(autocorrelationValues); CorrelationLengthParameter.ActualValue = new IntValue(correlationLength); AutoCorrelation1Parameter.ActualValue = new DoubleValue(autocorrelationValues.Length > 1 ? autocorrelationValues[1] : 0.0); } return base.Apply(); } private AutoCorrelationTable GetOrCreateAutoCorrelationTable() { AutoCorrelationTable autocorrelationTable = AutocorrelationParameter.ActualValue; if (autocorrelationTable == null) { autocorrelationTable = new AutoCorrelationTable("Auto Correlation"); AutocorrelationParameter.ActualValue = autocorrelationTable; var row = new DataRow("Auto Correlation"); row.VisualProperties.StartIndexZero = true; autocorrelationTable.Rows.Add(row); } return autocorrelationTable; } private DataTable GetOrCreateCorrelationLengthTable() { DataTable correlationLengthTable = CorrelationLengthTableParameter.ActualValue; if (correlationLengthTable == null) { correlationLengthTable = new DataTable("Correlation Length"); CorrelationLengthTableParameter.ActualValue = correlationLengthTable; correlationLengthTable.Rows.Add(new DataRow("Correlation Length")); } return correlationLengthTable; } } }