Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Analyzers/PopulationMinAvgMaxTreeSizeAnalyzer.cs @ 3651

Last change on this file since 3651 was 3651, checked in by gkronber, 14 years ago

Implemented analyzers for symbolic expression tree encoding, artificial ant problem and symbolic regression problem. #999 (Refactor algorithm analysis and tracing)

File size: 4.8 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.Linq;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Operators;
27using HeuristicLab.Optimization;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
31using System.Collections.Generic;
32using HeuristicLab.Analysis;
33using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces;
34
35namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Analyzers {
36  /// <summary>
37  /// An operator that tracks the min avgerage and max tree size in the population.
38  /// </summary>
39  [Item("PopulationMinAvgMaxTreeSizeAnalyzer", "An operator that tracks the min avgerage and max tree size in the population.")]
40  [StorableClass]
41  public sealed class PopulationMinAvgMaxTreeSizeAnalyzer : AlgorithmOperator, ISymbolicExpressionTreePopulationAnalyzer {
42    private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
43    private const string SymbolicExpressionTreeSizeParameterName = "SymbolicExpressionTreeSize";
44    private const string SymbolicExpressionTreeSizesParameterName = "SymbolicExpressionTreeSizes";
45    private const string ResultsParameterName = "Results";
46
47
48    #region parameter properties
49    public ILookupParameter<ItemArray<SymbolicExpressionTree>> SymbolicExpressionTreeParameter {
50      get { return (ILookupParameter<ItemArray<SymbolicExpressionTree>>)Parameters[SymbolicExpressionTreeParameterName]; }
51    }
52    public ILookupParameter<ItemArray<DoubleValue>> SymbolicExpressionTreeSizeParameter {
53      get { return (ILookupParameter<ItemArray<DoubleValue>>)Parameters[SymbolicExpressionTreeSizeParameterName]; }
54    }
55    public ValueLookupParameter<DataTable> SymbolicExpressionTreeSizesParameter {
56      get { return (ValueLookupParameter<DataTable>)Parameters[SymbolicExpressionTreeSizesParameterName]; }
57    }
58    public ValueLookupParameter<VariableCollection> ResultsParameter {
59      get { return (ValueLookupParameter<VariableCollection>)Parameters[ResultsParameterName]; }
60    }
61    #endregion
62    public PopulationMinAvgMaxTreeSizeAnalyzer()
63      : base() {
64      Parameters.Add(new SubScopesLookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree whose size should be calculated."));
65      Parameters.Add(new SubScopesLookupParameter<DoubleValue>(SymbolicExpressionTreeSizeParameterName, "The tree size of the symbolic expression tree."));
66      Parameters.Add(new ValueLookupParameter<DataTable>(SymbolicExpressionTreeSizesParameterName, "The data table to store the tree sizes."));
67      Parameters.Add(new ValueLookupParameter<VariableCollection>(ResultsParameterName, "The results collection where the analysis values should be stored."));
68
69      UniformSubScopesProcessor subScopesProcessor = new UniformSubScopesProcessor();
70      SymbolicExpressionTreeSizeCalculator sizeCalculator = new SymbolicExpressionTreeSizeCalculator();
71      PopulationMinAverageMaxValueAnalyzer valuesAnalyzer = new PopulationMinAverageMaxValueAnalyzer();
72      sizeCalculator.SymbolicExpressionTreeParameter.ActualName = SymbolicExpressionTreeParameter.Name;
73      sizeCalculator.SymbolicExpressionTreeSizeParameter.ActualName = SymbolicExpressionTreeSizeParameter.Name;
74      valuesAnalyzer.ValueParameter.ActualName = sizeCalculator.SymbolicExpressionTreeSizeParameter.Name;
75      valuesAnalyzer.ValuesParameter.ActualName = SymbolicExpressionTreeSizesParameter.Name;
76      valuesAnalyzer.ResultsParameter.ActualName = ResultsParameter.Name;
77      valuesAnalyzer.AverageValueParameter.ActualName = "Avg. Tree Size";
78      valuesAnalyzer.MaxValueParameter.ActualName = "Max Tree Size";
79      valuesAnalyzer.MinValueParameter.ActualName = "Min Tree Size";
80
81      OperatorGraph.InitialOperator = subScopesProcessor;
82      subScopesProcessor.Operator = sizeCalculator;
83      subScopesProcessor.Successor = valuesAnalyzer;
84      valuesAnalyzer.Successor = null;
85    }
86  }
87}
Note: See TracBrowser for help on using the repository browser.