Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Analyzers/SymbolicExpressionTreeSizeCalculator.cs @ 3988

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

Implemented reviewer comments. #893 (HeuristicLab 3.3.0 application review)

File size: 3.2 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;
32
33namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Analyzers {
34  /// <summary>
35  /// An operator that outputs the tree size of a symbolic expression tree.
36  /// </summary>
37  [Item("SymbolicExpressionTreeSizeCalculator", "An operator that outputs the tree size of a symbolic expression tree.")]
38  [StorableClass]
39  public sealed class SymbolicExpressionTreeSizeCalculator : SingleSuccessorOperator {
40    private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
41    private const string SymbolicExpressionTreeSizeParameterName = "SymbolicExpressionTreeSize";
42
43    #region parameter properties
44    public ILookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter {
45      get { return (ILookupParameter<SymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }
46    }
47    public ILookupParameter<DoubleValue> SymbolicExpressionTreeSizeParameter {
48      get { return (ILookupParameter<DoubleValue>)Parameters[SymbolicExpressionTreeSizeParameterName]; }
49    }
50    #endregion
51
52    #region properties
53    public SymbolicExpressionTree SymbolicExpressionTree {
54      get { return SymbolicExpressionTreeParameter.ActualValue; }
55    }
56    public DoubleValue SymbolicExpressionTreeSize {
57      get { return SymbolicExpressionTreeSizeParameter.ActualValue; }
58      set { SymbolicExpressionTreeSizeParameter.ActualValue = value; }
59    }
60    #endregion
61
62    public SymbolicExpressionTreeSizeCalculator()
63      : base() {
64      Parameters.Add(new LookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree whose size should be calculated."));
65      Parameters.Add(new LookupParameter<DoubleValue>(SymbolicExpressionTreeSizeParameterName, "The tree size of the symbolic expression tree."));
66    }
67
68    public override IOperation Apply() {
69      SymbolicExpressionTree tree = SymbolicExpressionTree;
70      SymbolicExpressionTreeSize = new DoubleValue(tree.Size);
71      return base.Apply();
72    }
73  }
74}
Note: See TracBrowser for help on using the repository browser.