Free cookie consent management tool by TermsFeed Policy Generator

source: branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Analyzers/MinAverageMaxSymbolicExpressionTreeSizeAnalyzer.cs @ 6479

Last change on this file since 6479 was 4722, checked in by swagner, 14 years ago

Merged cloning refactoring branch back into trunk (#922)

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