Free cookie consent management tool by TermsFeed Policy Generator

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

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

Added 'special treatment' of operators that use LookupParameters instead of ScopeTreeLookupParameters contained in analyzers. #999

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