Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.MonteCarloTreeSearch/Base/TreeNode.cs @ 13777

Last change on this file since 13777 was 13492, checked in by aballeit, 9 years ago

#2283 UCT parameter c

File size: 1.4 KB
Line 
1using HeuristicLab.Algorithms.Bandits;
2using System.Collections.Generic;
3using System.Linq;
4
5namespace HeuristicLab.Algorithms.MonteCarloTreeSearch.Base
6{
7    public class TreeNode
8    {
9        public string phrase;
10        public TreeNode parent;
11        public TreeNode[] children;
12        public IBanditPolicyActionInfo actionInfo;
13        public ushort level;
14
15        public TreeNode(TreeNode parent, string phrase, IBanditPolicyActionInfo actionInfo, ushort level)
16        {
17            this.parent = parent;
18            this.phrase = phrase;
19            this.actionInfo = actionInfo;
20            this.level = level;
21        }
22        public bool IsLeaf()
23        {
24            return children == null || !children.Any();
25        }
26
27        internal IEnumerable<IBanditPolicyActionInfo> GetChildActionInfos()
28        {
29            return children.Select(n => n.actionInfo);
30        }
31
32        internal void RemoveChildren(TreeNode currentNode)
33        {
34            TreeNode[] newChildren = new TreeNode[children.Length-1];
35            int counter = 0;
36            for (int i = 0; i < children.Length; i++)
37            {
38                if (children[i] != currentNode)
39                {
40                    newChildren[counter] = children[i];
41                    counter++;
42                }
43            }
44            children = newChildren;
45        }
46    }
47}
Note: See TracBrowser for help on using the repository browser.