Changeset 11792 for branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.GrammaticalOptimization/SequentialSearch.cs
- Timestamp:
- 01/16/15 18:26:35 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.GrammaticalOptimization/SequentialSearch.cs
r11770 r11792 57 57 Reset(); 58 58 59 for (int i = 0; !Done() && i < maxIterations; i++) {59 for (int i = 0; bestQuality < 1.0 && !Done() && i < maxIterations; i++) { 60 60 var phrase = SampleSentence(problem.Grammar); 61 61 // can fail on the last sentence … … 76 76 } 77 77 } 78 79 // clean up80 // Reset(); GC.Collect();81 78 } 82 79 … … 100 97 while (!phrase.IsTerminal) { 101 98 99 var newPhrases = GenerateFollowStates(g, phrase); 100 101 throw new NotImplementedException(); // TODO: reintroduce random-trie checking once the tree of all states has been reintroduced 102 102 //if (n.randomTries < randomTries) { 103 103 // n.randomTries++; … … 107 107 //} else { 108 108 109 var newPhrases = GenerateFollowStates(g, phrase); 110 111 // => select using bandit policy112 // failure means we simply restart113 if (!behaviourPolicy.TrySelect(random, phrase, newPhrases, out phrase)) {114 return false;115 }109 110 // => select using bandit policy 111 // failure means we simply restart 112 if (!behaviourPolicy.TrySelect(random, phrase, newPhrases, out phrase)) { 113 return false; 114 } 115 // } 116 116 stateChain.Add(phrase); 117 117 curDepth++; … … 125 125 private readonly Dictionary<ReadonlySequence, ReadonlySequence[]> cache; 126 126 private IEnumerable<ReadonlySequence> GenerateFollowStates(IGrammar g, ReadonlySequence phrase) { 127 throw new NotImplementedException(); 128 // TODO: Replace caching by a tree of all states. tree is only used for easily retrieving the follow-states of a state 127 129 ReadonlySequence[] follow; 128 if (!cache.TryGetValue(phrase, out follow)) {130 //if (!cache.TryGetValue(phrase, out follow)) { 129 131 char nt = phrase.FirstNonTerminal; 130 132 … … 142 144 follow[idx++] = new ReadonlySequence(newPhrase); 143 145 } 144 cache[phrase] = follow;145 }146 // cache[phrase] = follow; 147 //} 146 148 return follow; 147 149 }
Note: See TracChangeset
for help on using the changeset viewer.