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 |
|
---|
22 | using System.Linq;
|
---|
23 | using HeuristicLab.Common;
|
---|
24 | using HeuristicLab.Core;
|
---|
25 | using HeuristicLab.Data;
|
---|
26 | using HeuristicLab.Operators;
|
---|
27 | using HeuristicLab.Optimization;
|
---|
28 | using HeuristicLab.Parameters;
|
---|
29 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
30 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
31 | using System.Collections.Generic;
|
---|
32 | using HeuristicLab.Analysis;
|
---|
33 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces;
|
---|
34 |
|
---|
35 | namespace 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 ScopeTreeLookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree whose size should be calculated."));
|
---|
65 | Parameters.Add(new ScopeTreeLookupParameter<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 | MinAverageMaxValueAnalyzer valuesAnalyzer = new MinAverageMaxValueAnalyzer();
|
---|
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 | }
|
---|