Changeset 12893 for branches/HeuristicLab.Problems.GrammaticalOptimization-gkr/HeuristicLab.Problems.GrammaticalOptimization/Problems/SantaFeAntProblem.cs
- Timestamp:
- 08/24/15 13:56:27 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.GrammaticalOptimization-gkr/HeuristicLab.Problems.GrammaticalOptimization/Problems/SantaFeAntProblem.cs
r12876 r12893 30 30 // here we use a modified grammar which has only one syntax tree for each sentence 31 31 32 public IEnumerable<string> OptimalSentences { 33 get { 34 return new string[] 35 { 36 "?(m)(ll?(m)(r))mr", 37 "?(m)(rr?(m)(l))ml", 38 "r?(m)(ll?(m)(r))m", 39 "l?(m)(rr?(m)(l))m", 40 "mr?(m)(ll?(m)(r))", 41 "ml?(m)(rr?(m)(l))", 42 "?(m)(ll?(m)(l))ml", 43 "?(m)(rr?(m)(r))mr", 44 "l?(m)(ll?(m)(l))m", 45 "r?(m)(rr?(m)(r))m", 46 "ml?(m)(ll?(m)(l))", 47 "mr?(m)(rr?(m)(r))", 48 }; 49 } 50 } 32 51 33 52 private readonly IGrammar grammar; … … 138 157 139 158 public IEnumerable<Feature> GetFeatures(string phrase) { 140 yield return new Feature(phrase, 1.0); 159 for (int idx = 0; idx < 15; idx++) { 160 foreach (var t in Grammar.TerminalSymbols) 161 yield return new Feature(t.ToString(), phrase.Length > idx ? phrase[idx] == t ? 1 : 0 : 0); 162 } 141 163 //var ant = new Ant(false); 142 164 //int p = 0; … … 166 188 } 167 189 } 190 public bool IsOptimalPhrase(string phrase) { 191 var firstNonTerminalIdx = new Sequence(phrase).FirstNonTerminalIndex; 192 if (firstNonTerminalIdx == -1) firstNonTerminalIdx = phrase.Length; 193 return OptimalSentences.Any(s => s.Substring(0, firstNonTerminalIdx) == phrase.Substring(0, firstNonTerminalIdx)); 194 } 195 168 196 } 169 197
Note: See TracChangeset
for help on using the changeset viewer.