Changeset 12832 for branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.MonteCarloTreeSearch
- Timestamp:
- 08/03/15 00:03:18 (9 years ago)
- Location:
- branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.MonteCarloTreeSearch
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.MonteCarloTreeSearch/Base/TreeNode.cs
r12762 r12832 14 14 public string phrase; 15 15 public TreeNode parent; 16 public List<TreeNode>children;16 public TreeNode[] children; 17 17 public IBanditPolicyActionInfo actionInfo; 18 public int level;18 public ushort level; 19 19 20 public TreeNode(TreeNode parent, string phrase, IBanditPolicyActionInfo actionInfo, int level)20 public TreeNode(TreeNode parent, string phrase, IBanditPolicyActionInfo actionInfo, ushort level) 21 21 { 22 22 this.parent = parent; … … 34 34 return children.Select(n => n.actionInfo); 35 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 } 36 51 } 37 52 } -
branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.MonteCarloTreeSearch/MonteCarloTreeSearch.cs
r12829 r12832 120 120 if (treeNode.children == null) 121 121 { 122 treeNode.children = new List<TreeNode>();122 List<TreeNode> newChildren = new List<TreeNode>(); 123 123 124 124 var phrase = new Sequence(treeNode.phrase); … … 137 137 { 138 138 childNode = new TreeNode(treeNode, newSequence.ToString(), 139 behaviourPolicy.CreateActionInfo(), treeNode.level + 1);140 treeNode.children.Add(childNode);139 behaviourPolicy.CreateActionInfo(), (ushort) (treeNode.level + 1)); 140 newChildren.Add(childNode); 141 141 } 142 142 } 143 143 } 144 144 } 145 treeNode.children = newChildren.ToArray(); 145 146 } 146 147 } … … 164 165 } 165 166 166 private void GetTreeInfosRek(TreeInfos treeInfos, List<TreeNode>children)167 { 168 treeInfos.TotalNodes += children. Count;167 private void GetTreeInfosRek(TreeInfos treeInfos, TreeNode[] children) 168 { 169 treeInfos.TotalNodes += children.Length; 169 170 foreach (TreeNode child in children) 170 171 { … … 342 343 return HexConverter(Color.FromArgb(newR, newG, newB)); 343 344 } 345 346 public void FreeAll() 347 { 348 rootNode = null; 349 GC.Collect(); 350 } 344 351 } 345 352 } -
branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.MonteCarloTreeSearch/MonteCarloTreeSearch_PruneLeaves.cs
r12829 r12832 47 47 { 48 48 // already removed all child nodes so remove it too.. 49 currentNode.parent. children.Remove(currentNode);49 currentNode.parent.RemoveChildren(currentNode); 50 50 continue; 51 51 } … … 63 63 // Version 2: 64 64 // remove currentNode from tree.. 65 currentNode.parent. children.Remove(currentNode);65 currentNode.parent.RemoveChildren(currentNode); 66 66 } 67 67 }
Note: See TracChangeset
for help on using the changeset viewer.