Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Analyzers/MinAverageMaxSymbolicExpressionTreeSizeAnalyzer.cs @ 7214

Last change on this file since 7214 was 7214, checked in by ascheibe, 13 years ago

#1706 adapted outdated plugins to changes in IAnalyzer

File size: 6.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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
22using System;
23using HeuristicLab.Analysis;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces;
28using HeuristicLab.Operators;
29using HeuristicLab.Parameters;
30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
31using HeuristicLab.PluginInfrastructure;
32
33namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Analyzers {
34  /// <summary>
35  /// An operator that tracks the min average and max tree size.
36  /// </summary>
37  [Item("MinAverageMaxSymbolicExpressionTreeSizeAnalyzer", "An operator that tracks the min avgerage and max tree size.")]
38  [StorableClass]
39  [NonDiscoverableType]
40  public sealed class MinAverageMaxSymbolicExpressionTreeSizeAnalyzer : AlgorithmOperator, ISymbolicExpressionTreeAnalyzer {
41    private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
42    private const string SymbolicExpressionTreeSizeParameterName = "SymbolicExpressionTreeSize";
43    private const string SymbolicExpressionTreeSizesParameterName = "Symbolic expression tree size";
44    private const string MinTreeSizeParameterName = "Min tree size";
45    private const string AverageTreeSizeParameterName = "Average tree size";
46    private const string MaxTreeSizeParameterName = "Max tree size";
47    private const string ResultsParameterName = "Results";
48
49    public bool EnabledByDefault {
50      get { return true; }
51    }
52
53    #region parameter properties
54    public ScopeTreeLookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter {
55      get { return (ScopeTreeLookupParameter<SymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }
56    }
57    public ScopeTreeLookupParameter<DoubleValue> SymbolicExpressionTreeSizeParameter {
58      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters[SymbolicExpressionTreeSizeParameterName]; }
59    }
60    public ValueLookupParameter<DataTable> SymbolicExpressionTreeSizesParameter {
61      get { return (ValueLookupParameter<DataTable>)Parameters[SymbolicExpressionTreeSizesParameterName]; }
62    }
63    public ValueLookupParameter<VariableCollection> ResultsParameter {
64      get { return (ValueLookupParameter<VariableCollection>)Parameters[ResultsParameterName]; }
65    }
66
67    [Storable]
68    private MinAverageMaxValueAnalyzer valueAnalyzer;
69    [Storable]
70    private UniformSubScopesProcessor subScopesProcessor;
71
72    #endregion
73    [StorableConstructor]
74    private MinAverageMaxSymbolicExpressionTreeSizeAnalyzer(bool deserializing) : base() { }
75    private MinAverageMaxSymbolicExpressionTreeSizeAnalyzer(MinAverageMaxSymbolicExpressionTreeSizeAnalyzer original, Cloner cloner)
76      : base(original, cloner) {
77      AfterDeserialization();
78    }
79    public MinAverageMaxSymbolicExpressionTreeSizeAnalyzer()
80      : base() {
81      Parameters.Add(new ScopeTreeLookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree whose size should be calculated."));
82      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>(SymbolicExpressionTreeSizeParameterName, "The tree size of the symbolic expression tree."));
83      Parameters.Add(new ValueLookupParameter<DataTable>(SymbolicExpressionTreeSizesParameterName, "The data table to store the tree sizes."));
84      Parameters.Add(new ValueLookupParameter<VariableCollection>(ResultsParameterName, "The results collection where the analysis values should be stored."));
85
86      subScopesProcessor = new UniformSubScopesProcessor();
87      SymbolicExpressionTreeSizeCalculator sizeCalculator = new SymbolicExpressionTreeSizeCalculator();
88      valueAnalyzer = new MinAverageMaxValueAnalyzer();
89
90      subScopesProcessor.Depth.Value = SymbolicExpressionTreeParameter.Depth;
91      sizeCalculator.SymbolicExpressionTreeParameter.ActualName = SymbolicExpressionTreeParameter.Name;
92      sizeCalculator.SymbolicExpressionTreeSizeParameter.ActualName = SymbolicExpressionTreeSizeParameter.Name;
93      valueAnalyzer.ValueParameter.ActualName = sizeCalculator.SymbolicExpressionTreeSizeParameter.Name;
94      valueAnalyzer.ValueParameter.Depth = SymbolicExpressionTreeSizeParameter.Depth;
95      valueAnalyzer.AverageValueParameter.ActualName = AverageTreeSizeParameterName;
96      valueAnalyzer.CollectAverageValueInResultsParameter.Value = new BoolValue(false);
97      valueAnalyzer.MaxValueParameter.ActualName = MaxTreeSizeParameterName;
98      valueAnalyzer.CollectMaxValueInResultsParameter.Value = new BoolValue(false);
99      valueAnalyzer.MinValueParameter.ActualName = MinTreeSizeParameterName;
100      valueAnalyzer.CollectMinValueInResultsParameter.Value = new BoolValue(false);
101      valueAnalyzer.ValuesParameter.ActualName = SymbolicExpressionTreeSizesParameter.Name;
102
103      OperatorGraph.InitialOperator = subScopesProcessor;
104      subScopesProcessor.Operator = sizeCalculator;
105      sizeCalculator.Successor = null;
106      subScopesProcessor.Successor = valueAnalyzer;
107      valueAnalyzer.Successor = null;
108
109      AfterDeserialization();
110    }
111
112
113    [StorableHook(HookType.AfterDeserialization)]
114    private void AfterDeserialization() {
115      SymbolicExpressionTreeParameter.DepthChanged += new EventHandler(SymbolicExpressionTreeParameter_DepthChanged);
116      SymbolicExpressionTreeSizeParameter.DepthChanged += new EventHandler(SymbolicExpressionTreeSizeParameter_DepthChanged);
117    }
118
119    public override IDeepCloneable Clone(Cloner cloner) {
120      return new MinAverageMaxSymbolicExpressionTreeSizeAnalyzer(this, cloner);
121    }
122
123    private void SymbolicExpressionTreeParameter_DepthChanged(object sender, EventArgs e) {
124      OnDepthParameterChanged();
125    }
126
127    private void SymbolicExpressionTreeSizeParameter_DepthChanged(object sender, EventArgs e) {
128      OnDepthParameterChanged();
129    }
130
131    private void OnDepthParameterChanged() {
132      valueAnalyzer.ValueParameter.Depth = SymbolicExpressionTreeParameter.Depth;
133      subScopesProcessor.Depth.Value = SymbolicExpressionTreeParameter.Depth;
134    }
135  }
136}
Note: See TracBrowser for help on using the repository browser.