Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 4689 was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

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