Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeNode.cs @ 3269

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

Implemented initialization of Variable and Constant terminal nodes. #938 (Data types and operators for regression problems)

File size: 3.1 KB
RevLine 
[3223]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 System.Xml;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
[3244]28using HeuristicLab.Data;
[3223]29
30namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
31  [StorableClass]
[3252]32  public class SymbolicExpressionTreeNode : ICloneable {
33    [Storable]
[3223]34    private List<SymbolicExpressionTreeNode> subTrees;
[3252]35    [Storable]
[3223]36    private Symbol symbol;
37
[3252]38    public SymbolicExpressionTreeNode() { }
[3223]39
40    public SymbolicExpressionTreeNode(Symbol symbol) {
41      subTrees = new List<SymbolicExpressionTreeNode>();
42      this.symbol = symbol;
43    }
44
[3252]45    // copy constructor
46    protected SymbolicExpressionTreeNode(SymbolicExpressionTreeNode original) {
47      symbol = original.symbol;
48      this.subTrees = new List<SymbolicExpressionTreeNode>();
49      foreach (var subtree in original.SubTrees) {
50        AddSubTree((SymbolicExpressionTreeNode)subtree.Clone());
51      }
52    }
[3223]53
[3244]54    public virtual bool HasLocalParameters {
[3223]55      get { return false; }
56    }
57
58    public virtual IList<SymbolicExpressionTreeNode> SubTrees {
59      get { return subTrees; }
60    }
61
62    public Symbol Symbol {
63      get { return symbol; }
64      protected set { symbol = value; }
65    }
66
[3244]67    public int GetSize() {
[3223]68      int size = 1;
69      foreach (SymbolicExpressionTreeNode tree in SubTrees) size += tree.GetSize();
70      return size;
71    }
72
[3244]73    public int GetHeight() {
[3223]74      int maxHeight = 0;
75      foreach (SymbolicExpressionTreeNode tree in SubTrees) maxHeight = Math.Max(maxHeight, tree.GetHeight());
76      return maxHeight + 1;
77    }
[3269]78   
79    public virtual void ResetLocalParameters(IRandom random) { }
80    public virtual void ShakeLocalParameters(IRandom random, double shakingFactor) { }
[3223]81
82    protected internal virtual void AddSubTree(SymbolicExpressionTreeNode tree) {
83      SubTrees.Add(tree);
84    }
85
86    protected internal virtual void InsertSubTree(int index, SymbolicExpressionTreeNode tree) {
87      SubTrees.Insert(index, tree);
88    }
89
90    protected internal virtual void RemoveSubTree(int index) {
91      SubTrees.RemoveAt(index);
92    }
[3237]93
[3252]94    #region ICloneable Members
95
96    public virtual object Clone() {
97      return new SymbolicExpressionTreeNode(this);
[3237]98    }
[3252]99
100    #endregion
[3223]101  }
102}
Note: See TracBrowser for help on using the repository browser.