Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2895_PushGP_GenealogyAnalysis/HeuristicLab.Problems.ProgramSynthesis/Push/Data/Tree/TreeNode.cs

Last change on this file was 15771, checked in by bburlacu, 6 years ago

#2895: Add solution skeleton for PushGP with genealogy analysis.

File size: 814 bytes
Line 
1using System.Collections.Generic;
2
3namespace HeuristicLab.Problems.ProgramSynthesis {
4  public class TreeNode<T> {
5    public T Value { get; set; }
6    public IList<TreeNode<T>> Children { get; private set; }
7    public int Count { get; private set; }
8
9    public TreeNode() {
10      Children = new List<TreeNode<T>>();
11      Count = 1;
12    }
13
14    public TreeNode(T value) : this() {
15      Value = value;
16    }
17
18    public void Add(T value) {
19      Children.Add(new TreeNode<T>(value));
20      Count++;
21    }
22
23    public void AddNode(TreeNode<T> node) {
24      Children.Add(node);
25      Count += node.Count;
26    }
27
28    public void ReplaceNode(int index, TreeNode<T> node) {
29      Count -= Children[index].Count;
30      Children[index] = node;
31      Count += node.Count;
32    }
33  }
34}
Note: See TracBrowser for help on using the repository browser.