1 | using System;
|
---|
2 | using System.Linq;
|
---|
3 | using HeuristicLab.Analysis.FitnessLandscape.DataTables;
|
---|
4 | using HeuristicLab.Common;
|
---|
5 | using HeuristicLab.Core;
|
---|
6 | using HeuristicLab.Data;
|
---|
7 | using HeuristicLab.Operators;
|
---|
8 | using HeuristicLab.Optimization;
|
---|
9 | using HeuristicLab.Parameters;
|
---|
10 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
11 |
|
---|
12 | namespace HeuristicLab.Analysis.FitnessLandscape.Algorithms {
|
---|
13 |
|
---|
14 | [Item("RepeatedUpDownWalkAnalyzer", "Analyzes and consolidates repeated up down walk analyses.")]
|
---|
15 | [StorableClass]
|
---|
16 | public class RepeatedUpDownWalkAnalyzer : SingleSuccessorOperator, IRepeatsAnalyzer {
|
---|
17 |
|
---|
18 | #region Parameters
|
---|
19 | public ScopeTreeLookupParameter<DoubleValue> DownWalkLengthValuesParameter {
|
---|
20 | get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["DownWalkLengthValues"]; }
|
---|
21 | }
|
---|
22 | public ScopeTreeLookupParameter<DoubleValue> UpWalkLengthValuesParameter {
|
---|
23 | get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["UpWalkLengthValues"]; }
|
---|
24 | }
|
---|
25 | public ScopeTreeLookupParameter<DoubleValue> DownWalkLenVarValuesParameter {
|
---|
26 | get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["DownWalkLenVarValues"]; }
|
---|
27 | }
|
---|
28 | public ScopeTreeLookupParameter<DoubleValue> UpWalkLenVarValuesParameter {
|
---|
29 | get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["UpWalkLenVarValues"]; }
|
---|
30 | }
|
---|
31 | public LookupParameter<DoubleValue> DownWalkLengthParameter {
|
---|
32 | get { return (LookupParameter<DoubleValue>)Parameters["DownWalkLength"]; }
|
---|
33 | }
|
---|
34 | public LookupParameter<DoubleValue> UpWalkLengthParameter {
|
---|
35 | get { return (LookupParameter<DoubleValue>)Parameters["UpWalkLength"]; }
|
---|
36 | }
|
---|
37 | public LookupParameter<DoubleValue> DownWalkLenVarParameter {
|
---|
38 | get { return (LookupParameter<DoubleValue>)Parameters["DownWalkLenVar"]; }
|
---|
39 | }
|
---|
40 | public LookupParameter<DoubleValue> UpWalkLenVarParameter {
|
---|
41 | get { return (LookupParameter<DoubleValue>)Parameters["UpWalkLenVar"]; }
|
---|
42 | }
|
---|
43 | public LookupParameter<ResultCollection> ResultsParameter {
|
---|
44 | get { return (LookupParameter<ResultCollection>)Parameters["Results"]; }
|
---|
45 | }
|
---|
46 | #endregion
|
---|
47 |
|
---|
48 | #region Construction & Cloning
|
---|
49 | [StorableConstructor]
|
---|
50 | protected RepeatedUpDownWalkAnalyzer(bool deserializing) : base(deserializing) { }
|
---|
51 | protected RepeatedUpDownWalkAnalyzer(RepeatedUpDownWalkAnalyzer original, Cloner cloner) : base(original, cloner) { }
|
---|
52 | public RepeatedUpDownWalkAnalyzer() {
|
---|
53 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("DownWalkLengthValues", "average down length values of repeats.", "DownWalkLength", 2));
|
---|
54 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("UpWalkLengthValues", "average up walk length values of repeats.", "UpWalkLength", 2));
|
---|
55 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("DownWalkLenVarValues", "down length variance values of repeats.", "DownWalkLenVar", 2));
|
---|
56 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("UpWalkLenVarValues", "down length variance values of repeats.", "UpWalkLenVar", 2));
|
---|
57 |
|
---|
58 | Parameters.Add(new LookupParameter<DoubleValue>("DownWalkLength", "Consolidated average down walk length."));
|
---|
59 | Parameters.Add(new LookupParameter<DoubleValue>("UpWalkLength", "Consolidated average up walk length."));
|
---|
60 | Parameters.Add(new LookupParameter<DoubleValue>("DownWalkLenVar", "Consolidated down walk length variance."));
|
---|
61 | Parameters.Add(new LookupParameter<DoubleValue>("UpWalkLenVar", "Consolidated up walk length variance."));
|
---|
62 |
|
---|
63 | Parameters.Add(new LookupParameter<ResultCollection>("Results", "The collection of all results."));
|
---|
64 | }
|
---|
65 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
66 | return new RepeatedUpDownWalkAnalyzer(this, cloner);
|
---|
67 | }
|
---|
68 | #endregion
|
---|
69 |
|
---|
70 | public override IOperation Apply() {
|
---|
71 | AggregateValues(DownWalkLengthValuesParameter, DownWalkLengthParameter);
|
---|
72 | AggregateValues(UpWalkLengthValuesParameter, UpWalkLengthParameter);
|
---|
73 | AggregateValues(DownWalkLenVarValuesParameter, DownWalkLenVarParameter);
|
---|
74 | AggregateValues(UpWalkLenVarValuesParameter, UpWalkLenVarParameter);
|
---|
75 | return base.Apply();
|
---|
76 | }
|
---|
77 |
|
---|
78 | private void AggregateValues(ILookupParameter<ItemArray<DoubleValue>> valuesParameter, ILookupParameter<DoubleValue> averageParameter) {
|
---|
79 | var results = ResultsParameter.ActualValue;
|
---|
80 | var values = valuesParameter.ActualValue.Select(v => v.Value).ToList();
|
---|
81 | if (values.Count > 0) {
|
---|
82 | var avg = new DoubleValue(values.Average());
|
---|
83 | averageParameter.ActualValue = avg;
|
---|
84 | results.Remove(averageParameter.ActualName);
|
---|
85 | results.Add(new Result(averageParameter.ActualName, avg));
|
---|
86 | }
|
---|
87 | }
|
---|
88 |
|
---|
89 | }
|
---|
90 | }
|
---|