Free cookie consent management tool by TermsFeed Policy Generator

source: branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/BaseClasses/FunctionTreeBase.cs @ 2211

Last change on this file since 2211 was 2211, checked in by gkronber, 15 years ago

#713

  • renamed MinArity and MaxArity properties
  • fixed a caching bug in the Dataset
  • renamed BakedTreeEvaluator to HL3TreeEvaluator
  • deleted class BakedFunctionTree
File size: 2.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 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;
23using System.Collections.Generic;
24using System.Text;
25using HeuristicLab.Core;
26using HeuristicLab.GP.Interfaces;
27
28namespace HeuristicLab.GP {
29  public class FunctionTreeBase : IFunctionTree {
30    private List<IFunctionTree> subTrees;
31    private IFunction function;
32
33    public FunctionTreeBase() {
34    }
35
36    public FunctionTreeBase(IFunction function) {
37      subTrees = new List<IFunctionTree>();
38      this.function = function;
39    }
40
41    protected FunctionTreeBase(FunctionTreeBase original) {
42      this.function = original.Function;
43      this.subTrees = new List<IFunctionTree>(original.SubTrees.Count);
44      foreach (IFunctionTree originalSubTree in original.SubTrees) {
45        this.SubTrees.Add(originalSubTree.Clone());
46      }
47    }
48
49    #region IFunctionTree Members
50    public virtual bool HasLocalParameters {
51      get { return false; }
52    }
53
54    public virtual IList<IFunctionTree> SubTrees {
55      get { return subTrees; }
56    }
57
58    public IFunction Function {
59      get { return function; }
60      protected set {
61        function = value;
62      }
63    }
64
65    public int GetSize() {
66      int size = 1;
67      foreach (IFunctionTree tree in SubTrees) size += tree.GetSize();
68      return size;
69    }
70
71    public int GetHeight() {
72      int maxHeight = 0;
73      foreach (IFunctionTree tree in SubTrees) maxHeight = Math.Max(maxHeight, tree.GetHeight());
74      return maxHeight + 1;
75    }
76
77    public virtual IOperation CreateShakingOperation(IScope scope) {
78      return null;
79    }
80
81    public virtual IOperation CreateInitOperation(IScope scope) {
82      return null;
83    }
84
85    public void AddSubTree(IFunctionTree tree) {
86      SubTrees.Add(tree);
87    }
88
89    public virtual void InsertSubTree(int index, IFunctionTree tree) {
90      SubTrees.Insert(index, tree);
91    }
92
93    public virtual void RemoveSubTree(int index) {
94      SubTrees.RemoveAt(index);
95    }
96
97    public virtual IFunctionTree Clone() {
98      return new FunctionTreeBase(this);
99    }
100
101    #endregion
102  }
103}
Note: See TracBrowser for help on using the repository browser.