Rev | Line | |
---|
[12050] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
| 5 | using System.Threading.Tasks;
|
---|
| 6 | using HeuristicLab.Algorithms.Bandits;
|
---|
[12098] | 7 | using HeuristicLab.Algorithms.Bandits.BanditPolicies;
|
---|
[12050] | 8 | using HeuristicLab.Problems.GrammaticalOptimization;
|
---|
| 9 |
|
---|
[12098] | 10 | namespace HeuristicLab.Algorithms.MonteCarloTreeSearch.Base
|
---|
[12050] | 11 | {
|
---|
| 12 | public class TreeNode
|
---|
| 13 | {
|
---|
| 14 | public string phrase;
|
---|
| 15 | public TreeNode parent;
|
---|
[12832] | 16 | public TreeNode[] children;
|
---|
[12050] | 17 | public IBanditPolicyActionInfo actionInfo;
|
---|
[12832] | 18 | public ushort level;
|
---|
[12050] | 19 |
|
---|
[12832] | 20 | public TreeNode(TreeNode parent, string phrase, IBanditPolicyActionInfo actionInfo, ushort level)
|
---|
[12050] | 21 | {
|
---|
[12098] | 22 | this.parent = parent;
|
---|
[12050] | 23 | this.phrase = phrase;
|
---|
[12503] | 24 | this.actionInfo = actionInfo;
|
---|
[12762] | 25 | this.level = level;
|
---|
[12050] | 26 | }
|
---|
[12098] | 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 | }
|
---|
[12832] | 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 | }
|
---|
[12050] | 51 | }
|
---|
| 52 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.