Line | |
---|
1 | using HeuristicLab.Algorithms.Bandits;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 |
|
---|
5 | namespace 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.