Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Analyzers/MinAvgMaxSymbolicExpressionTreeSizeAnalyzer.cs @ 3710

Last change on this file since 3710 was 3710, checked in by gkronber, 14 years ago

Implemented reviewer comments. #893 (HeuristicLab 3.3.0 application review)

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