Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.GP/3.3/BaseClasses/FunctionTree.cs @ 2700

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

Renamed FunctionBase to Function and FunctionTreeBase to FunctionTree. #748 (FunctionLibraryView is empty).

File size: 3.4 KB
RevLine 
[2210]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;
[2218]27using System.Xml;
[2210]28
29namespace HeuristicLab.GP {
[2700]30  public class FunctionTree : IFunctionTree {
[2210]31    private List<IFunctionTree> subTrees;
32    private IFunction function;
33
[2700]34    public FunctionTree() {
[2211]35    }
36
[2700]37    public FunctionTree(IFunction function) {
[2210]38      subTrees = new List<IFunctionTree>();
39      this.function = function;
40    }
41
[2700]42    protected FunctionTree(FunctionTree original) {
[2210]43      this.function = original.Function;
44      this.subTrees = new List<IFunctionTree>(original.SubTrees.Count);
45      foreach (IFunctionTree originalSubTree in original.SubTrees) {
[2218]46        this.SubTrees.Add((IFunctionTree)originalSubTree.Clone());
[2210]47      }
48    }
49
50    #region IFunctionTree Members
51    public virtual bool HasLocalParameters {
52      get { return false; }
53    }
54
[2211]55    public virtual IList<IFunctionTree> SubTrees {
[2210]56      get { return subTrees; }
57    }
58
59    public IFunction Function {
60      get { return function; }
[2216]61      protected set { function = value; }
[2210]62    }
63
64    public int GetSize() {
65      int size = 1;
[2211]66      foreach (IFunctionTree tree in SubTrees) size += tree.GetSize();
[2210]67      return size;
68    }
69
70    public int GetHeight() {
71      int maxHeight = 0;
[2211]72      foreach (IFunctionTree tree in SubTrees) maxHeight = Math.Max(maxHeight, tree.GetHeight());
[2210]73      return maxHeight + 1;
74    }
75
76    public virtual IOperation CreateShakingOperation(IScope scope) {
77      return null;
78    }
79
80    public virtual IOperation CreateInitOperation(IScope scope) {
81      return null;
82    }
83
84    public void AddSubTree(IFunctionTree tree) {
[2211]85      SubTrees.Add(tree);
[2210]86    }
87
[2211]88    public virtual void InsertSubTree(int index, IFunctionTree tree) {
89      SubTrees.Insert(index, tree);
[2210]90    }
91
[2211]92    public virtual void RemoveSubTree(int index) {
93      SubTrees.RemoveAt(index);
[2210]94    }
95
[2365]96    public override string ToString() {
[2235]97      return Function.Name;
98    }
99
[2218]100    #endregion
101
102    #region IStorable Members
103
104    public Guid Guid {
105      get { throw new NotSupportedException(); }
106    }
107
108    public virtual object Clone() {
[2700]109      return new FunctionTree(this);
[2210]110    }
111
[2218]112    public object Clone(IDictionary<Guid, object> clonedObjects) {
113      throw new NotImplementedException();
114    }
115
116    public virtual XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
[2219]117      return null;
[2218]118    }
119
120    public virtual void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
121    }
122
[2210]123    #endregion
124  }
125}
Note: See TracBrowser for help on using the repository browser.