[3651] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[9456] | 3 | * Copyright (C) 2002-2013 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;
|
---|
| 27 | using HeuristicLab.Operators;
|
---|
| 28 | using HeuristicLab.Parameters;
|
---|
| 29 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 30 |
|
---|
[5499] | 31 | namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
|
---|
[3651] | 32 | /// <summary>
|
---|
[5499] | 33 | /// An operator that tracks the min average and max length of symbolic expression trees.
|
---|
[3651] | 34 | /// </summary>
|
---|
[5499] | 35 | [Item("MinAverageMaxSymbolicExpressionTreeLengthAnalyzer", "An operator that tracks the min avgerage and max length of symbolic expression trees.")]
|
---|
[3651] | 36 | [StorableClass]
|
---|
[5499] | 37 | public sealed class MinAverageMaxSymbolicExpressionTreeLengthAnalyzer : AlgorithmOperator, ISymbolicExpressionTreeAnalyzer {
|
---|
[3651] | 38 | private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
|
---|
[5499] | 39 | private const string SymbolicExpressionTreeLengthParameterName = "SymbolicExpressionTreeLength";
|
---|
| 40 | private const string SymbolicExpressionTreeLengthsParameterName = "Symbolic expression tree length";
|
---|
| 41 | private const string MinTreeLengthParameterName = "Minimal symbolic expression tree length";
|
---|
| 42 | private const string AverageTreeLengthParameterName = "Average symbolic expression tree length";
|
---|
| 43 | private const string MaxTreeLengthParameterName = "Maximal symbolic expression tree length";
|
---|
[3651] | 44 | private const string ResultsParameterName = "Results";
|
---|
| 45 |
|
---|
[7172] | 46 | public bool EnabledByDefault {
|
---|
| 47 | get { return true; }
|
---|
| 48 | }
|
---|
| 49 |
|
---|
[3651] | 50 | #region parameter properties
|
---|
[5510] | 51 | public IScopeTreeLookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter {
|
---|
| 52 | get { return (IScopeTreeLookupParameter<ISymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }
|
---|
[3651] | 53 | }
|
---|
[5499] | 54 | public ScopeTreeLookupParameter<DoubleValue> SymbolicExpressionTreeLengthParameter {
|
---|
| 55 | get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters[SymbolicExpressionTreeLengthParameterName]; }
|
---|
[3651] | 56 | }
|
---|
[5499] | 57 | public ValueLookupParameter<DataTable> SymbolicExpressionTreeLengthsParameter {
|
---|
| 58 | get { return (ValueLookupParameter<DataTable>)Parameters[SymbolicExpressionTreeLengthsParameterName]; }
|
---|
[3651] | 59 | }
|
---|
| 60 | public ValueLookupParameter<VariableCollection> ResultsParameter {
|
---|
| 61 | get { return (ValueLookupParameter<VariableCollection>)Parameters[ResultsParameterName]; }
|
---|
| 62 | }
|
---|
[3710] | 63 |
|
---|
[3681] | 64 | [Storable]
|
---|
| 65 | private MinAverageMaxValueAnalyzer valueAnalyzer;
|
---|
[3683] | 66 | [Storable]
|
---|
[3710] | 67 | private UniformSubScopesProcessor subScopesProcessor;
|
---|
[3681] | 68 |
|
---|
[3651] | 69 | #endregion
|
---|
[5499] | 70 |
|
---|
[4722] | 71 | [StorableConstructor]
|
---|
[5499] | 72 | private MinAverageMaxSymbolicExpressionTreeLengthAnalyzer(bool deserializing) : base() { }
|
---|
| 73 | private MinAverageMaxSymbolicExpressionTreeLengthAnalyzer(MinAverageMaxSymbolicExpressionTreeLengthAnalyzer original, Cloner cloner)
|
---|
[4722] | 74 | : base(original, cloner) {
|
---|
[7501] | 75 | valueAnalyzer = cloner.Clone(original.valueAnalyzer);
|
---|
| 76 | subScopesProcessor = cloner.Clone(original.subScopesProcessor);
|
---|
[4722] | 77 | AfterDeserialization();
|
---|
| 78 | }
|
---|
[5499] | 79 | public MinAverageMaxSymbolicExpressionTreeLengthAnalyzer()
|
---|
[3651] | 80 | : base() {
|
---|
[5510] | 81 | Parameters.Add(new ScopeTreeLookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree whose length should be calculated."));
|
---|
[5499] | 82 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>(SymbolicExpressionTreeLengthParameterName, "The length of the symbolic expression tree."));
|
---|
| 83 | Parameters.Add(new ValueLookupParameter<DataTable>(SymbolicExpressionTreeLengthsParameterName, "The data table to store the symbolic expression tree lengths."));
|
---|
[3651] | 84 | Parameters.Add(new ValueLookupParameter<VariableCollection>(ResultsParameterName, "The results collection where the analysis values should be stored."));
|
---|
| 85 |
|
---|
[3710] | 86 | subScopesProcessor = new UniformSubScopesProcessor();
|
---|
[5499] | 87 | SymbolicExpressionTreeLengthCalculator lengthCalculator = new SymbolicExpressionTreeLengthCalculator();
|
---|
[3681] | 88 | valueAnalyzer = new MinAverageMaxValueAnalyzer();
|
---|
[3710] | 89 |
|
---|
| 90 | subScopesProcessor.Depth.Value = SymbolicExpressionTreeParameter.Depth;
|
---|
[5499] | 91 | lengthCalculator.SymbolicExpressionTreeParameter.ActualName = SymbolicExpressionTreeParameter.Name;
|
---|
| 92 | lengthCalculator.SymbolicExpressionTreeLengthParameter.ActualName = SymbolicExpressionTreeLengthParameter.Name;
|
---|
| 93 | valueAnalyzer.ValueParameter.ActualName = lengthCalculator.SymbolicExpressionTreeLengthParameter.Name;
|
---|
| 94 | valueAnalyzer.ValueParameter.Depth = SymbolicExpressionTreeLengthParameter.Depth;
|
---|
| 95 | valueAnalyzer.AverageValueParameter.ActualName = AverageTreeLengthParameterName;
|
---|
[3710] | 96 | valueAnalyzer.CollectAverageValueInResultsParameter.Value = new BoolValue(false);
|
---|
[5499] | 97 | valueAnalyzer.MaxValueParameter.ActualName = MaxTreeLengthParameterName;
|
---|
[3710] | 98 | valueAnalyzer.CollectMaxValueInResultsParameter.Value = new BoolValue(false);
|
---|
[5499] | 99 | valueAnalyzer.MinValueParameter.ActualName = MinTreeLengthParameterName;
|
---|
[3710] | 100 | valueAnalyzer.CollectMinValueInResultsParameter.Value = new BoolValue(false);
|
---|
[5499] | 101 | valueAnalyzer.ValuesParameter.ActualName = SymbolicExpressionTreeLengthsParameter.Name;
|
---|
[3651] | 102 |
|
---|
[3710] | 103 | OperatorGraph.InitialOperator = subScopesProcessor;
|
---|
[5499] | 104 | subScopesProcessor.Operator = lengthCalculator;
|
---|
| 105 | lengthCalculator.Successor = null;
|
---|
[3710] | 106 | subScopesProcessor.Successor = valueAnalyzer;
|
---|
[3681] | 107 | valueAnalyzer.Successor = null;
|
---|
| 108 |
|
---|
[4722] | 109 | AfterDeserialization();
|
---|
[3651] | 110 | }
|
---|
[3681] | 111 |
|
---|
| 112 |
|
---|
| 113 | [StorableHook(HookType.AfterDeserialization)]
|
---|
[4722] | 114 | private void AfterDeserialization() {
|
---|
[3681] | 115 | SymbolicExpressionTreeParameter.DepthChanged += new EventHandler(SymbolicExpressionTreeParameter_DepthChanged);
|
---|
[5549] | 116 | SymbolicExpressionTreeLengthParameter.DepthChanged += new EventHandler(SymbolicExpressionTreeLengthParameter_DepthChanged);
|
---|
[3681] | 117 | }
|
---|
| 118 |
|
---|
| 119 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[5499] | 120 | return new MinAverageMaxSymbolicExpressionTreeLengthAnalyzer(this, cloner);
|
---|
[3681] | 121 | }
|
---|
| 122 |
|
---|
| 123 | private void SymbolicExpressionTreeParameter_DepthChanged(object sender, EventArgs e) {
|
---|
[3683] | 124 | OnDepthParameterChanged();
|
---|
| 125 | }
|
---|
| 126 |
|
---|
[5549] | 127 | private void SymbolicExpressionTreeLengthParameter_DepthChanged(object sender, EventArgs e) {
|
---|
[3683] | 128 | OnDepthParameterChanged();
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | private void OnDepthParameterChanged() {
|
---|
[3681] | 132 | valueAnalyzer.ValueParameter.Depth = SymbolicExpressionTreeParameter.Depth;
|
---|
[3710] | 133 | subScopesProcessor.Depth.Value = SymbolicExpressionTreeParameter.Depth;
|
---|
[3681] | 134 | }
|
---|
[3651] | 135 | }
|
---|
| 136 | }
|
---|