Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/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
RevLine 
[3651]1#region License Information
2/* HeuristicLab
[5445]3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[3651]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;
[5809]31using HeuristicLab.PluginInfrastructure;
[3651]32
33namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Analyzers {
34  /// <summary>
[3817]35  /// An operator that tracks the min average and max tree size.
[3651]36  /// </summary>
[3817]37  [Item("MinAverageMaxSymbolicExpressionTreeSizeAnalyzer", "An operator that tracks the min avgerage and max tree size.")]
[3651]38  [StorableClass]
[5809]39  [NonDiscoverableType]
[3817]40  public sealed class MinAverageMaxSymbolicExpressionTreeSizeAnalyzer : AlgorithmOperator, ISymbolicExpressionTreeAnalyzer {
[3651]41    private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
42    private const string SymbolicExpressionTreeSizeParameterName = "SymbolicExpressionTreeSize";
[3710]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";
[3651]47    private const string ResultsParameterName = "Results";
48
49    #region parameter properties
[3681]50    public ScopeTreeLookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter {
51      get { return (ScopeTreeLookupParameter<SymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }
[3651]52    }
[3681]53    public ScopeTreeLookupParameter<DoubleValue> SymbolicExpressionTreeSizeParameter {
54      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters[SymbolicExpressionTreeSizeParameterName]; }
[3651]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    }
[3710]62
[3681]63    [Storable]
64    private MinAverageMaxValueAnalyzer valueAnalyzer;
[3683]65    [Storable]
[3710]66    private UniformSubScopesProcessor subScopesProcessor;
[3681]67
[3651]68    #endregion
[4722]69    [StorableConstructor]
70    private MinAverageMaxSymbolicExpressionTreeSizeAnalyzer(bool deserializing) : base() { }
71    private MinAverageMaxSymbolicExpressionTreeSizeAnalyzer(MinAverageMaxSymbolicExpressionTreeSizeAnalyzer original, Cloner cloner)
72      : base(original, cloner) {
73      AfterDeserialization();
74    }
[3817]75    public MinAverageMaxSymbolicExpressionTreeSizeAnalyzer()
[3651]76      : base() {
[3659]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."));
[3651]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
[3710]82      subScopesProcessor = new UniformSubScopesProcessor();
83      SymbolicExpressionTreeSizeCalculator sizeCalculator = new SymbolicExpressionTreeSizeCalculator();
[3681]84      valueAnalyzer = new MinAverageMaxValueAnalyzer();
[3710]85
86      subScopesProcessor.Depth.Value = SymbolicExpressionTreeParameter.Depth;
[3651]87      sizeCalculator.SymbolicExpressionTreeParameter.ActualName = SymbolicExpressionTreeParameter.Name;
88      sizeCalculator.SymbolicExpressionTreeSizeParameter.ActualName = SymbolicExpressionTreeSizeParameter.Name;
[3681]89      valueAnalyzer.ValueParameter.ActualName = sizeCalculator.SymbolicExpressionTreeSizeParameter.Name;
90      valueAnalyzer.ValueParameter.Depth = SymbolicExpressionTreeSizeParameter.Depth;
[3710]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);
[3681]97      valueAnalyzer.ValuesParameter.ActualName = SymbolicExpressionTreeSizesParameter.Name;
[3651]98
[3710]99      OperatorGraph.InitialOperator = subScopesProcessor;
100      subScopesProcessor.Operator = sizeCalculator;
101      sizeCalculator.Successor = null;
102      subScopesProcessor.Successor = valueAnalyzer;
[3681]103      valueAnalyzer.Successor = null;
104
[4722]105      AfterDeserialization();
[3651]106    }
[3681]107
108
109    [StorableHook(HookType.AfterDeserialization)]
[4722]110    private void AfterDeserialization() {
[3681]111      SymbolicExpressionTreeParameter.DepthChanged += new EventHandler(SymbolicExpressionTreeParameter_DepthChanged);
[3683]112      SymbolicExpressionTreeSizeParameter.DepthChanged += new EventHandler(SymbolicExpressionTreeSizeParameter_DepthChanged);
[3681]113    }
114
115    public override IDeepCloneable Clone(Cloner cloner) {
[4722]116      return new MinAverageMaxSymbolicExpressionTreeSizeAnalyzer(this, cloner);
[3681]117    }
118
119    private void SymbolicExpressionTreeParameter_DepthChanged(object sender, EventArgs e) {
[3683]120      OnDepthParameterChanged();
121    }
122
123    private void SymbolicExpressionTreeSizeParameter_DepthChanged(object sender, EventArgs e) {
124      OnDepthParameterChanged();
125    }
126
127    private void OnDepthParameterChanged() {
[3681]128      valueAnalyzer.ValueParameter.Depth = SymbolicExpressionTreeParameter.Depth;
[3710]129      subScopesProcessor.Depth.Value = SymbolicExpressionTreeParameter.Depth;
[3681]130    }
[3651]131  }
132}
Note: See TracBrowser for help on using the repository browser.