Changeset 16159
- Timestamp:
- 09/20/18 13:18:47 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2886_SymRegGrammarEnumeration/Test/TreeHashingTest.cs
r16157 r16159 153 153 //const int nvars = 1; 154 154 //var variables = Enumerable.Range(1, nvars).Select(x => $"x{x}").ToArray(); 155 var variables = new[] { " b", "a" };155 var variables = new[] { "x", "y", "z", "w" }; 156 156 var grammar = new Grammar(variables, Enum.GetValues(typeof(GrammarRule)).Cast<GrammarRule>()); 157 157 158 int hash(SymbolList s)=> grammar.Hasher.CalcHashCode(s);158 Func<SymbolList, int> hash = s => grammar.Hasher.CalcHashCode(s); 159 159 160 160 List<SymbolList> sentences = EnumerateGrammarBreadth(grammar, length: 20, hashPhrases: false).ToList(); 161 Console.WriteLine( $"Breadth: {sentences.Count};{sentences.Select(hash).Distinct().Count() }");161 Console.WriteLine("Breadth: {0} generated, {1} distinct sentences", sentences.Count, sentences.GroupBy(hash).Count()); 162 162 163 163 sentences = EnumerateGrammarBreadth(grammar, length: 20, hashPhrases: true).ToList(); 164 Console.WriteLine( $"Breadth (hashed): {sentences.Count};{sentences.Select(hash).Distinct().Count() }");164 Console.WriteLine("Breadth (hashed): {0} generated, {1} distinct sentences", sentences.Count, sentences.GroupBy(hash).Count()); 165 165 166 166 sentences = EnumerateGrammarDepth(grammar, length: 20, hashPhrases: false).ToList(); 167 Console.WriteLine( $"Depth: {sentences.Count};{sentences.Select(hash).Distinct().Count() }");167 Console.WriteLine("Depth: {0} generated, {1} distinct sentences", sentences.Count, sentences.GroupBy(hash).Count()); 168 168 169 169 sentences = EnumerateGrammarDepth(grammar, length: 20, hashPhrases: true).ToList(); 170 Console.WriteLine( $"Depth (hashed): {sentences.Count};{sentences.Select(hash).Distinct().Count() }");170 Console.WriteLine("Depth (hashed): {0} generated, {1} distinct sentences", sentences.Count, sentences.GroupBy(hash).Count()); 171 171 } 172 172
Note: See TracChangeset
for help on using the changeset viewer.