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

Last change on this file since 12832 was 12832, checked in by aballeit, 6 years ago

#2283 limit parallelism

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