[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] | 22 | using System;
|
---|
| 23 | using HeuristicLab.Analysis;
|
---|
[3651] | 24 | using HeuristicLab.Common;
|
---|
| 25 | using HeuristicLab.Core;
|
---|
| 26 | using HeuristicLab.Data;
|
---|
[4068] | 27 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces;
|
---|
[3651] | 28 | using HeuristicLab.Operators;
|
---|
| 29 | using HeuristicLab.Parameters;
|
---|
| 30 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 31 |
|
---|
| 32 | namespace 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
|
---|
[4722] | 67 | [StorableConstructor]
|
---|
| 68 | private MinAverageMaxSymbolicExpressionTreeSizeAnalyzer(bool deserializing) : base() { }
|
---|
| 69 | private MinAverageMaxSymbolicExpressionTreeSizeAnalyzer(MinAverageMaxSymbolicExpressionTreeSizeAnalyzer original, Cloner cloner)
|
---|
| 70 | : base(original, cloner) {
|
---|
| 71 | AfterDeserialization();
|
---|
| 72 | }
|
---|
[3817] | 73 | public MinAverageMaxSymbolicExpressionTreeSizeAnalyzer()
|
---|
[3651] | 74 | : base() {
|
---|
[3659] | 75 | Parameters.Add(new ScopeTreeLookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree whose size should be calculated."));
|
---|
| 76 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>(SymbolicExpressionTreeSizeParameterName, "The tree size of the symbolic expression tree."));
|
---|
[3651] | 77 | Parameters.Add(new ValueLookupParameter<DataTable>(SymbolicExpressionTreeSizesParameterName, "The data table to store the tree sizes."));
|
---|
| 78 | Parameters.Add(new ValueLookupParameter<VariableCollection>(ResultsParameterName, "The results collection where the analysis values should be stored."));
|
---|
| 79 |
|
---|
[3710] | 80 | subScopesProcessor = new UniformSubScopesProcessor();
|
---|
| 81 | SymbolicExpressionTreeSizeCalculator sizeCalculator = new SymbolicExpressionTreeSizeCalculator();
|
---|
[3681] | 82 | valueAnalyzer = new MinAverageMaxValueAnalyzer();
|
---|
[3710] | 83 |
|
---|
| 84 | subScopesProcessor.Depth.Value = SymbolicExpressionTreeParameter.Depth;
|
---|
[3651] | 85 | sizeCalculator.SymbolicExpressionTreeParameter.ActualName = SymbolicExpressionTreeParameter.Name;
|
---|
| 86 | sizeCalculator.SymbolicExpressionTreeSizeParameter.ActualName = SymbolicExpressionTreeSizeParameter.Name;
|
---|
[3681] | 87 | valueAnalyzer.ValueParameter.ActualName = sizeCalculator.SymbolicExpressionTreeSizeParameter.Name;
|
---|
| 88 | valueAnalyzer.ValueParameter.Depth = SymbolicExpressionTreeSizeParameter.Depth;
|
---|
[3710] | 89 | valueAnalyzer.AverageValueParameter.ActualName = AverageTreeSizeParameterName;
|
---|
| 90 | valueAnalyzer.CollectAverageValueInResultsParameter.Value = new BoolValue(false);
|
---|
| 91 | valueAnalyzer.MaxValueParameter.ActualName = MaxTreeSizeParameterName;
|
---|
| 92 | valueAnalyzer.CollectMaxValueInResultsParameter.Value = new BoolValue(false);
|
---|
| 93 | valueAnalyzer.MinValueParameter.ActualName = MinTreeSizeParameterName;
|
---|
| 94 | valueAnalyzer.CollectMinValueInResultsParameter.Value = new BoolValue(false);
|
---|
[3681] | 95 | valueAnalyzer.ValuesParameter.ActualName = SymbolicExpressionTreeSizesParameter.Name;
|
---|
[3651] | 96 |
|
---|
[3710] | 97 | OperatorGraph.InitialOperator = subScopesProcessor;
|
---|
| 98 | subScopesProcessor.Operator = sizeCalculator;
|
---|
| 99 | sizeCalculator.Successor = null;
|
---|
| 100 | subScopesProcessor.Successor = valueAnalyzer;
|
---|
[3681] | 101 | valueAnalyzer.Successor = null;
|
---|
| 102 |
|
---|
[4722] | 103 | AfterDeserialization();
|
---|
[3651] | 104 | }
|
---|
[3681] | 105 |
|
---|
| 106 |
|
---|
| 107 | [StorableHook(HookType.AfterDeserialization)]
|
---|
[4722] | 108 | private void AfterDeserialization() {
|
---|
[3681] | 109 | SymbolicExpressionTreeParameter.DepthChanged += new EventHandler(SymbolicExpressionTreeParameter_DepthChanged);
|
---|
[3683] | 110 | SymbolicExpressionTreeSizeParameter.DepthChanged += new EventHandler(SymbolicExpressionTreeSizeParameter_DepthChanged);
|
---|
[3681] | 111 | }
|
---|
| 112 |
|
---|
| 113 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[4722] | 114 | return new MinAverageMaxSymbolicExpressionTreeSizeAnalyzer(this, cloner);
|
---|
[3681] | 115 | }
|
---|
| 116 |
|
---|
| 117 | private void SymbolicExpressionTreeParameter_DepthChanged(object sender, EventArgs e) {
|
---|
[3683] | 118 | OnDepthParameterChanged();
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | private void SymbolicExpressionTreeSizeParameter_DepthChanged(object sender, EventArgs e) {
|
---|
| 122 | OnDepthParameterChanged();
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | private void OnDepthParameterChanged() {
|
---|
[3681] | 126 | valueAnalyzer.ValueParameter.Depth = SymbolicExpressionTreeParameter.Depth;
|
---|
[3710] | 127 | subScopesProcessor.Depth.Value = SymbolicExpressionTreeParameter.Depth;
|
---|
[3681] | 128 | }
|
---|
[3651] | 129 | }
|
---|
| 130 | }
|
---|