Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Analyzers/SymbolicExpressionTreeSizeAnalyzer.cs @ 3662

Last change on this file since 3662 was 3662, checked in by swagner, 14 years ago

Worked on refactoring of algorithm analysis and tracing (#999)

  • adapted analyzers
File size: 4.4 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.Encodings.SymbolicExpressionTreeEncoding.Interfaces;
33using HeuristicLab.Analysis;
34
35namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Analyzers {
36  /// <summary>
37  /// An operator that tracks the tree size of a symbolic expression tree.
38  /// </summary>
39  [Item("SymbolicExpressionTreeSizeAnalyzer", "An operator that tracks the tree size of symbolic expression trees.")]
40  [StorableClass]
41  public sealed class SymbolicExpressionTreeSizeAnalyzer : AlgorithmOperator, ISymbolicExpressionTreeAnalyzer {
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<SymbolicExpressionTree> SymbolicExpressionTreeParameter {
50      get { return (ILookupParameter<SymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }
51    }
52    public ILookupParameter<DoubleValue> SymbolicExpressionTreeSizeParameter {
53      get { return (ILookupParameter<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
62    #endregion
63
64    public SymbolicExpressionTreeSizeAnalyzer()
65      : base() {
66      Parameters.Add(new LookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree whose size should be calculated."));
67      Parameters.Add(new LookupParameter<DoubleValue>(SymbolicExpressionTreeSizeParameterName, "The tree size of the symbolic expression tree."));
68      Parameters.Add(new ValueLookupParameter<DataTable>(SymbolicExpressionTreeSizesParameterName, "The data table to store the tree sizes."));
69      Parameters.Add(new ValueLookupParameter<VariableCollection>(ResultsParameterName, "The results collection where the analysis values should be stored."));
70
71
72      SymbolicExpressionTreeSizeCalculator sizeCalculator = new SymbolicExpressionTreeSizeCalculator();
73      ValueAnalyzer valueAnalyzer = new ValueAnalyzer();
74      sizeCalculator.SymbolicExpressionTreeParameter.ActualName = SymbolicExpressionTreeParameter.Name;
75      sizeCalculator.SymbolicExpressionTreeSizeParameter.ActualName = SymbolicExpressionTreeSizeParameter.Name;
76      valueAnalyzer.ValueParameter.ActualName = sizeCalculator.SymbolicExpressionTreeSizeParameter.Name;
77      valueAnalyzer.ValueParameter.Depth = 0;
78      valueAnalyzer.ValuesParameter.ActualName = SymbolicExpressionTreeSizesParameter.Name;
79      valueAnalyzer.ResultsParameter.ActualName = ResultsParameter.Name;
80
81      OperatorGraph.InitialOperator = sizeCalculator;
82      sizeCalculator.Successor = valueAnalyzer;
83      valueAnalyzer.Successor = null;
84    }
85  }
86}
Note: See TracBrowser for help on using the repository browser.