Changeset 12829 for branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.MonteCarloTreeSearch
- Timestamp:
- 08/02/15 14:44:48 (9 years ago)
- Location:
- branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.MonteCarloTreeSearch
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.MonteCarloTreeSearch/MonteCarloTreeSearch.cs
r12827 r12829 28 28 protected readonly ISimulation simulation; 29 29 protected TreeNode rootNode; 30 protected bool isPaused = false;31 protected object pauseLock = new object();32 30 protected int goodSelections; 33 31 … … 59 57 60 58 public bool StopRequested { get; set; } 61 62 public bool IsPaused 63 { 64 get { return this.isPaused; } 65 } 66 59 67 60 public int GoodSelections { get { return this.goodSelections; } } 68 61 … … 81 74 Reset(); 82 75 int selections = 0; 76 TreeNode currentNode; 77 string phrase; 78 string simulatedPhrase; 79 double quality; 80 83 81 for (int i = 0; !StopRequested && i < maxIterations; i++) 84 82 { 85 lock (pauseLock) 86 { 87 if (isPaused) 88 { 89 Monitor.Wait(pauseLock); 90 } 91 } 92 TreeNode currentNode = rootNode; 83 currentNode = rootNode; 93 84 94 85 while (!currentNode.IsLeaf()) … … 101 92 } 102 93 103 stringphrase = currentNode.phrase;94 phrase = currentNode.phrase; 104 95 105 96 if (!grammar.IsTerminal(phrase) && phrase.Length <= maxLen) … … 114 105 if (currentNode.phrase.Length <= maxLen) 115 106 { 116 string simulatedPhrase; 117 double quality = simulation.Simulate(currentNode, out simulatedPhrase); 107 quality = simulation.Simulate(currentNode, out simulatedPhrase); 118 108 OnSolutionEvaluated(simulatedPhrase, quality); 119 109 … … 126 116 { 127 117 // create children on the first visit 118 Sequence newSequence; 119 TreeNode childNode; 128 120 if (treeNode.children == null) 129 121 { … … 140 132 foreach (Sequence alternative in grammar.GetAlternatives(symbol)) 141 133 { 142 SequencenewSequence = new Sequence(phrase);134 newSequence = new Sequence(phrase); 143 135 newSequence.ReplaceAt(i, 1, alternative); 144 136 if (newSequence.Length <= maxLen) 145 137 { 146 TreeNodechildNode = new TreeNode(treeNode, newSequence.ToString(),138 childNode = new TreeNode(treeNode, newSequence.ToString(), 147 139 behaviourPolicy.CreateActionInfo(), treeNode.level + 1); 148 140 treeNode.children.Add(childNode); … … 350 342 return HexConverter(Color.FromArgb(newR, newG, newB)); 351 343 } 352 353 public void PauseContinue()354 {355 lock (pauseLock)356 {357 if (isPaused)358 {359 isPaused = false;360 Monitor.Pulse(pauseLock);361 }362 else363 {364 isPaused = true;365 }366 }367 }368 344 } 369 345 } -
branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.MonteCarloTreeSearch/MonteCarloTreeSearch_PruneLeaves.cs
r12827 r12829 22 22 Reset(); 23 23 int selections = 0; 24 TreeNode currentNode; 25 string phrase; 26 string simulatedPhrase; 27 double quality; 24 28 for (int i = 0; !StopRequested && i < maxIterations; i++) 25 29 { 26 lock (pauseLock) 27 { 28 if (isPaused) 29 { 30 Monitor.Wait(pauseLock); 31 } 32 } 33 TreeNode currentNode = rootNode; 30 currentNode = rootNode; 34 31 35 32 while (!currentNode.IsLeaf()) … … 42 39 } 43 40 44 stringphrase = currentNode.phrase;41 phrase = currentNode.phrase; 45 42 46 43 if (phrase.Length <= maxLen) … … 71 68 if (currentNode.phrase.Length <= maxLen) 72 69 { 73 string simulatedPhrase; 74 double quality = simulation.Simulate(currentNode, out simulatedPhrase); 70 quality = simulation.Simulate(currentNode, out simulatedPhrase); 75 71 OnSolutionEvaluated(simulatedPhrase, quality); 76 72
Note: See TracChangeset
for help on using the changeset viewer.