Changeset 10411


Ignore:
Timestamp:
01/28/14 17:00:19 (5 years ago)
Author:
gkronber
Message:

#2026 refactoring

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Problems.GPDL/CodeGenerator/MonteCarloTreeSearchCodeGen.cs

    r10410 r10411  
    4646     
    4747      if(searchTree.tries < RANDOM_TRIES || Grammar.subtreeCount[state] == 0) {
    48         searchTree.tries++; // could be moved to UpdateTree
    4948        t = SampleTreeRandom(state);
    5049        if(Grammar.subtreeCount[state] == 0) {
     
    6564      } else {
    6665        if(Grammar.subtreeCount[state] == 1) {
    67           searchTree.tries++; // could be moved to updateTree
    6866          if(searchTree.children == null) {
    6967            int nChildren = Grammar.transition[state].Length;
     
    7169          }
    7270          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));
    7472          var altIdx = SelectAlternative(searchTree);
    7573          t = new Tree(altIdx, new Tree[1]);
     
    133131      if(trees.Count == 0 || searchTree == null) return;
    134132      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
    143135        for(int idx = t.subtrees.Length - 1 ; idx >= 0; idx--) {
    144136          trees.Push(t.subtrees[idx]);
     
    146138        UpdateSearchTree(searchTree, trees, quality);
    147139      } 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        }
    151156      }
    152157    }
Note: See TracChangeset for help on using the changeset viewer.