Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PersistenceSpeedUp/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Analyzers/MinAverageMaxSymbolicExpressionTreeSizeAnalyzer.cs @ 6307

Last change on this file since 6307 was 5809, checked in by mkommend, 14 years ago

#1418: Reintegrated branch into trunk.

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    #region parameter properties
50    public ScopeTreeLookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter {
51      get { return (ScopeTreeLookupParameter<SymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }
52    }
53    public ScopeTreeLookupParameter<DoubleValue> SymbolicExpressionTreeSizeParameter {
54      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters[SymbolicExpressionTreeSizeParameterName]; }
55    }
56    public ValueLookupParameter<DataTable> SymbolicExpressionTreeSizesParameter {
57      get { return (ValueLookupParameter<DataTable>)Parameters[SymbolicExpressionTreeSizesParameterName]; }
58    }
59    public ValueLookupParameter<VariableCollection> ResultsParameter {
60      get { return (ValueLookupParameter<VariableCollection>)Parameters[ResultsParameterName]; }
61    }
62
63    [Storable]
64    private MinAverageMaxValueAnalyzer valueAnalyzer;
65    [Storable]
66    private UniformSubScopesProcessor subScopesProcessor;
67
68    #endregion
69    [StorableConstructor]
70    private MinAverageMaxSymbolicExpressionTreeSizeAnalyzer(bool deserializing) : base() { }
71    private MinAverageMaxSymbolicExpressionTreeSizeAnalyzer(MinAverageMaxSymbolicExpressionTreeSizeAnalyzer original, Cloner cloner)
72      : base(original, cloner) {
73      AfterDeserialization();
74    }
75    public MinAverageMaxSymbolicExpressionTreeSizeAnalyzer()
76      : base() {
77      Parameters.Add(new ScopeTreeLookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree whose size should be calculated."));
78      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>(SymbolicExpressionTreeSizeParameterName, "The tree size of the symbolic expression tree."));
79      Parameters.Add(new ValueLookupParameter<DataTable>(SymbolicExpressionTreeSizesParameterName, "The data table to store the tree sizes."));
80      Parameters.Add(new ValueLookupParameter<VariableCollection>(ResultsParameterName, "The results collection where the analysis values should be stored."));
81
82      subScopesProcessor = new UniformSubScopesProcessor();
83      SymbolicExpressionTreeSizeCalculator sizeCalculator = new SymbolicExpressionTreeSizeCalculator();
84      valueAnalyzer = new MinAverageMaxValueAnalyzer();
85
86      subScopesProcessor.Depth.Value = SymbolicExpressionTreeParameter.Depth;
87      sizeCalculator.SymbolicExpressionTreeParameter.ActualName = SymbolicExpressionTreeParameter.Name;
88      sizeCalculator.SymbolicExpressionTreeSizeParameter.ActualName = SymbolicExpressionTreeSizeParameter.Name;
89      valueAnalyzer.ValueParameter.ActualName = sizeCalculator.SymbolicExpressionTreeSizeParameter.Name;
90      valueAnalyzer.ValueParameter.Depth = SymbolicExpressionTreeSizeParameter.Depth;
91      valueAnalyzer.AverageValueParameter.ActualName = AverageTreeSizeParameterName;
92      valueAnalyzer.CollectAverageValueInResultsParameter.Value = new BoolValue(false);
93      valueAnalyzer.MaxValueParameter.ActualName = MaxTreeSizeParameterName;
94      valueAnalyzer.CollectMaxValueInResultsParameter.Value = new BoolValue(false);
95      valueAnalyzer.MinValueParameter.ActualName = MinTreeSizeParameterName;
96      valueAnalyzer.CollectMinValueInResultsParameter.Value = new BoolValue(false);
97      valueAnalyzer.ValuesParameter.ActualName = SymbolicExpressionTreeSizesParameter.Name;
98
99      OperatorGraph.InitialOperator = subScopesProcessor;
100      subScopesProcessor.Operator = sizeCalculator;
101      sizeCalculator.Successor = null;
102      subScopesProcessor.Successor = valueAnalyzer;
103      valueAnalyzer.Successor = null;
104
105      AfterDeserialization();
106    }
107
108
109    [StorableHook(HookType.AfterDeserialization)]
110    private void AfterDeserialization() {
111      SymbolicExpressionTreeParameter.DepthChanged += new EventHandler(SymbolicExpressionTreeParameter_DepthChanged);
112      SymbolicExpressionTreeSizeParameter.DepthChanged += new EventHandler(SymbolicExpressionTreeSizeParameter_DepthChanged);
113    }
114
115    public override IDeepCloneable Clone(Cloner cloner) {
116      return new MinAverageMaxSymbolicExpressionTreeSizeAnalyzer(this, cloner);
117    }
118
119    private void SymbolicExpressionTreeParameter_DepthChanged(object sender, EventArgs e) {
120      OnDepthParameterChanged();
121    }
122
123    private void SymbolicExpressionTreeSizeParameter_DepthChanged(object sender, EventArgs e) {
124      OnDepthParameterChanged();
125    }
126
127    private void OnDepthParameterChanged() {
128      valueAnalyzer.ValueParameter.Depth = SymbolicExpressionTreeParameter.Depth;
129      subScopesProcessor.Depth.Value = SymbolicExpressionTreeParameter.Depth;
130    }
131  }
132}
Note: See TracBrowser for help on using the repository browser.