Changeset 10411
- Timestamp:
- 01/28/14 17:00:19 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.GPDL/CodeGenerator/MonteCarloTreeSearchCodeGen.cs
r10410 r10411 46 46 47 47 if(searchTree.tries < RANDOM_TRIES || Grammar.subtreeCount[state] == 0) { 48 searchTree.tries++; // could be moved to UpdateTree49 48 t = SampleTreeRandom(state); 50 49 if(Grammar.subtreeCount[state] == 0) { … … 65 64 } else { 66 65 if(Grammar.subtreeCount[state] == 1) { 67 searchTree.tries++; // could be moved to updateTree68 66 if(searchTree.children == null) { 69 67 int nChildren = Grammar.transition[state].Length; … … 71 69 } 72 70 Debug.Assert(searchTree.children.Length == Grammar.transition[state].Length); 73 Debug.Assert(searchTree.tries - RANDOM_TRIES - 1== searchTree.children.Where(c=>c!=null).Sum(c=>c.tries));71 Debug.Assert(searchTree.tries - RANDOM_TRIES == searchTree.children.Where(c=>c!=null).Sum(c=>c.tries)); 74 72 var altIdx = SelectAlternative(searchTree); 75 73 t = new Tree(altIdx, new Tree[1]); … … 133 131 if(trees.Count == 0 || searchTree == null) return; 134 132 var t = trees.Pop(); 135 searchTree.sumQuality += quality; 136 if(quality > searchTree.bestQuality) 137 searchTree.bestQuality = quality; 138 if(searchTree.children == null) return; 139 if(t.subtrees == null) { 140 Debug.Assert(searchTree.children.Length == 1); 141 UpdateSearchTree(searchTree.children[0], trees, quality); 142 } else if(t.altIdx==-1) { 133 if(t.altIdx == -1) { 134 // for trees with multiple sub-trees 143 135 for(int idx = t.subtrees.Length - 1 ; idx >= 0; idx--) { 144 136 trees.Push(t.subtrees[idx]); … … 146 138 UpdateSearchTree(searchTree, trees, quality); 147 139 } else { 148 Debug.Assert(t.subtrees.Length == 1); 149 trees.Push(t.subtrees[0]); 150 UpdateSearchTree(searchTree.children[t.altIdx], trees, quality); 140 searchTree.sumQuality += quality; 141 searchTree.tries++; 142 if(quality > searchTree.bestQuality) 143 searchTree.bestQuality = quality; 144 if(t.subtrees != null) { 145 Debug.Assert(t.subtrees.Length == 1); 146 if(searchTree.children!=null) { 147 trees.Push(t.subtrees[0]); 148 UpdateSearchTree(searchTree.children[t.altIdx], trees, quality); 149 } 150 } else { 151 if(searchTree.children!=null) { 152 Debug.Assert(searchTree.children.Length == 1); 153 UpdateSearchTree(searchTree.children[0], trees, quality); 154 } 155 } 151 156 } 152 157 }
Note: See TracChangeset
for help on using the changeset viewer.