using System.Linq; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Operators; using HeuristicLab.Optimization; using HeuristicLab.Parameters; using HEAL.Attic; namespace HeuristicLab.Analysis.FitnessLandscape.Algorithms { [Item("RepeatedUpDownWalkAnalyzer", "Analyzes and consolidates repeated up down walk analyses.")] [StorableType("1B832D9F-7D75-41AB-94D1-D638F4067CC0")] public class RepeatedUpDownWalkAnalyzer : SingleSuccessorOperator, IRepeatsAnalyzer { #region Parameters public ScopeTreeLookupParameter DownWalkLengthValuesParameter { get { return (ScopeTreeLookupParameter)Parameters["DownWalkLengthValues"]; } } public ScopeTreeLookupParameter UpWalkLengthValuesParameter { get { return (ScopeTreeLookupParameter)Parameters["UpWalkLengthValues"]; } } public ScopeTreeLookupParameter DownWalkLenVarValuesParameter { get { return (ScopeTreeLookupParameter)Parameters["DownWalkLenVarValues"]; } } public ScopeTreeLookupParameter UpWalkLenVarValuesParameter { get { return (ScopeTreeLookupParameter)Parameters["UpWalkLenVarValues"]; } } public LookupParameter DownWalkLengthParameter { get { return (LookupParameter)Parameters["DownWalkLength"]; } } public LookupParameter UpWalkLengthParameter { get { return (LookupParameter)Parameters["UpWalkLength"]; } } public LookupParameter DownWalkLenVarParameter { get { return (LookupParameter)Parameters["DownWalkLenVar"]; } } public LookupParameter UpWalkLenVarParameter { get { return (LookupParameter)Parameters["UpWalkLenVar"]; } } public LookupParameter ResultsParameter { get { return (LookupParameter)Parameters["Results"]; } } #endregion #region Construction & Cloning [StorableConstructor] protected RepeatedUpDownWalkAnalyzer(StorableConstructorFlag _) : base(_) { } protected RepeatedUpDownWalkAnalyzer(RepeatedUpDownWalkAnalyzer original, Cloner cloner) : base(original, cloner) { } public RepeatedUpDownWalkAnalyzer() { Parameters.Add(new ScopeTreeLookupParameter("DownWalkLengthValues", "average down length values of repeats.", "DownWalkLength", 2)); Parameters.Add(new ScopeTreeLookupParameter("UpWalkLengthValues", "average up walk length values of repeats.", "UpWalkLength", 2)); Parameters.Add(new ScopeTreeLookupParameter("DownWalkLenVarValues", "down length variance values of repeats.", "DownWalkLenVar", 2)); Parameters.Add(new ScopeTreeLookupParameter("UpWalkLenVarValues", "down length variance values of repeats.", "UpWalkLenVar", 2)); Parameters.Add(new LookupParameter("DownWalkLength", "Consolidated average down walk length.")); Parameters.Add(new LookupParameter("UpWalkLength", "Consolidated average up walk length.")); Parameters.Add(new LookupParameter("DownWalkLenVar", "Consolidated down walk length variance.")); Parameters.Add(new LookupParameter("UpWalkLenVar", "Consolidated up walk length variance.")); Parameters.Add(new LookupParameter("Results", "The collection of all results.")); } public override IDeepCloneable Clone(Cloner cloner) { return new RepeatedUpDownWalkAnalyzer(this, cloner); } #endregion public override IOperation Apply() { AggregateValues(DownWalkLengthValuesParameter, DownWalkLengthParameter); AggregateValues(UpWalkLengthValuesParameter, UpWalkLengthParameter); AggregateValues(DownWalkLenVarValuesParameter, DownWalkLenVarParameter); AggregateValues(UpWalkLenVarValuesParameter, UpWalkLenVarParameter); return base.Apply(); } private void AggregateValues(ILookupParameter> valuesParameter, ILookupParameter averageParameter) { var results = ResultsParameter.ActualValue; var values = valuesParameter.ActualValue.Select(v => v.Value).ToList(); if (values.Count > 0) { var avg = new DoubleValue(values.Average()); averageParameter.ActualValue = avg; results.Remove(averageParameter.ActualName); results.Add(new Result(averageParameter.ActualName, avg)); } } } }