Free cookie consent management tool by TermsFeed Policy Generator

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

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

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

File size: 6.6 KB
RevLine 
[3651]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
[4068]22using System;
23using HeuristicLab.Analysis;
[3651]24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
[4068]27using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces;
[3651]28using HeuristicLab.Operators;
29using HeuristicLab.Parameters;
30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
31
32namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Analyzers {
33  /// <summary>
[3817]34  /// An operator that tracks the min average and max tree size.
[3651]35  /// </summary>
[3817]36  [Item("MinAverageMaxSymbolicExpressionTreeSizeAnalyzer", "An operator that tracks the min avgerage and max tree size.")]
[3651]37  [StorableClass]
[3817]38  public sealed class MinAverageMaxSymbolicExpressionTreeSizeAnalyzer : AlgorithmOperator, ISymbolicExpressionTreeAnalyzer {
[3651]39    private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
40    private const string SymbolicExpressionTreeSizeParameterName = "SymbolicExpressionTreeSize";
[3710]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";
[3651]45    private const string ResultsParameterName = "Results";
46
47    #region parameter properties
[3681]48    public ScopeTreeLookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter {
49      get { return (ScopeTreeLookupParameter<SymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }
[3651]50    }
[3681]51    public ScopeTreeLookupParameter<DoubleValue> SymbolicExpressionTreeSizeParameter {
52      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters[SymbolicExpressionTreeSizeParameterName]; }
[3651]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    }
[3710]60
[3681]61    [Storable]
62    private MinAverageMaxValueAnalyzer valueAnalyzer;
[3683]63    [Storable]
[3710]64    private UniformSubScopesProcessor subScopesProcessor;
[3681]65
[3651]66    #endregion
[3817]67    public MinAverageMaxSymbolicExpressionTreeSizeAnalyzer()
[3651]68      : base() {
[3659]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."));
[3651]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
[3710]74      subScopesProcessor = new UniformSubScopesProcessor();
75      SymbolicExpressionTreeSizeCalculator sizeCalculator = new SymbolicExpressionTreeSizeCalculator();
[3681]76      valueAnalyzer = new MinAverageMaxValueAnalyzer();
[3710]77
78      subScopesProcessor.Depth.Value = SymbolicExpressionTreeParameter.Depth;
[3651]79      sizeCalculator.SymbolicExpressionTreeParameter.ActualName = SymbolicExpressionTreeParameter.Name;
80      sizeCalculator.SymbolicExpressionTreeSizeParameter.ActualName = SymbolicExpressionTreeSizeParameter.Name;
[3681]81      valueAnalyzer.ValueParameter.ActualName = sizeCalculator.SymbolicExpressionTreeSizeParameter.Name;
82      valueAnalyzer.ValueParameter.Depth = SymbolicExpressionTreeSizeParameter.Depth;
[3710]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);
[3681]89      valueAnalyzer.ValuesParameter.ActualName = SymbolicExpressionTreeSizesParameter.Name;
[3651]90
[3710]91      OperatorGraph.InitialOperator = subScopesProcessor;
92      subScopesProcessor.Operator = sizeCalculator;
93      sizeCalculator.Successor = null;
94      subScopesProcessor.Successor = valueAnalyzer;
[3681]95      valueAnalyzer.Successor = null;
96
97      Initialize();
[3651]98    }
[3681]99
100    [StorableConstructor]
[3817]101    private MinAverageMaxSymbolicExpressionTreeSizeAnalyzer(bool deserializing) : base() { }
[3681]102
103    [StorableHook(HookType.AfterDeserialization)]
104    private void Initialize() {
105      SymbolicExpressionTreeParameter.DepthChanged += new EventHandler(SymbolicExpressionTreeParameter_DepthChanged);
[3683]106      SymbolicExpressionTreeSizeParameter.DepthChanged += new EventHandler(SymbolicExpressionTreeSizeParameter_DepthChanged);
[3681]107    }
108
109    public override IDeepCloneable Clone(Cloner cloner) {
[3817]110      MinAverageMaxSymbolicExpressionTreeSizeAnalyzer clone = (MinAverageMaxSymbolicExpressionTreeSizeAnalyzer)base.Clone(cloner);
[3681]111      clone.Initialize();
112      return clone;
113    }
114
115    private void SymbolicExpressionTreeParameter_DepthChanged(object sender, EventArgs e) {
[3683]116      OnDepthParameterChanged();
117    }
118
119    private void SymbolicExpressionTreeSizeParameter_DepthChanged(object sender, EventArgs e) {
120      OnDepthParameterChanged();
121    }
122
123    private void OnDepthParameterChanged() {
[3681]124      valueAnalyzer.ValueParameter.Depth = SymbolicExpressionTreeParameter.Depth;
[3710]125      subScopesProcessor.Depth.Value = SymbolicExpressionTreeParameter.Depth;
[3681]126    }
[3651]127  }
128}
Note: See TracBrowser for help on using the repository browser.