Free cookie consent management tool by TermsFeed Policy Generator

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

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

GP Refactoring #713

  • cleaned code
  • reintegrated GP.Boolean and GP.SantaFe
  • worked on serialization of function trees
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 { function = value; }
61    }
62
63    public int GetSize() {
64      int size = 1;
65      foreach (IFunctionTree tree in SubTrees) size += tree.GetSize();
66      return size;
67    }
68
69    public int GetHeight() {
70      int maxHeight = 0;
71      foreach (IFunctionTree tree in SubTrees) maxHeight = Math.Max(maxHeight, tree.GetHeight());
72      return maxHeight + 1;
73    }
74
75    public virtual IOperation CreateShakingOperation(IScope scope) {
76      return null;
77    }
78
79    public virtual IOperation CreateInitOperation(IScope scope) {
80      return null;
81    }
82
83    public void AddSubTree(IFunctionTree tree) {
84      SubTrees.Add(tree);
85    }
86
87    public virtual void InsertSubTree(int index, IFunctionTree tree) {
88      SubTrees.Insert(index, tree);
89    }
90
91    public virtual void RemoveSubTree(int index) {
92      SubTrees.RemoveAt(index);
93    }
94
95    public virtual IFunctionTree Clone() {
96      return new FunctionTreeBase(this);
97    }
98
99    #endregion
100  }
101}
Note: See TracBrowser for help on using the repository browser.