Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2283 UCT parameter c

File size: 1.4 KB
RevLine 
[13492]1using HeuristicLab.Algorithms.Bandits;
[12050]2using System.Collections.Generic;
3using System.Linq;
4
[12098]5namespace HeuristicLab.Algorithms.MonteCarloTreeSearch.Base
[12050]6{
7    public class TreeNode
8    {
9        public string phrase;
10        public TreeNode parent;
[12832]11        public TreeNode[] children;
[12050]12        public IBanditPolicyActionInfo actionInfo;
[12832]13        public ushort level;
[12050]14
[12832]15        public TreeNode(TreeNode parent, string phrase, IBanditPolicyActionInfo actionInfo, ushort level)
[12050]16        {
[12098]17            this.parent = parent;
[12050]18            this.phrase = phrase;
[12503]19            this.actionInfo = actionInfo;
[12762]20            this.level = level;
[12050]21        }
[12098]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        }
[12832]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        }
[12050]46    }
47}
Note: See TracBrowser for help on using the repository browser.