- Timestamp:
- 04/10/15 16:12:08 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.GrammaticalOptimization-gkr/Main/Program.cs
r12295 r12298 1 1 using System; 2 using System.Collections.Generic; 2 3 using System.Diagnostics; 3 4 using System.Globalization; 5 using System.Linq; 6 using System.Text.RegularExpressions; 4 7 using HeuristicLab.Algorithms.Bandits.BanditPolicies; 5 8 using HeuristicLab.Algorithms.Bandits.GrammarPolicies; … … 38 41 39 42 var globalStatistics = new SentenceSetStatistics(); 43 ResetAlleleStatistics(); 40 44 var random = new Random(); 41 45 … … 66 70 iterations++; 67 71 globalStatistics.AddSentence(sentence, quality); 68 72 UpdateAlleleStatistics(sentence); 69 73 // comment this if you don't want to see solver statistics 70 74 if (iterations % 100 == 0) { 71 if (iterations % 1000 == 0) Console.Clear(); 75 if (iterations % 1000 == 0) { 76 Console.Clear(); 77 } 72 78 Console.SetCursorPosition(0, 0); 73 alg.PrintStats(); 74 //policy.PrintStats(); 79 Console.WriteLine(iterations); 80 WriteAlleleStatistics(); 81 Console.WriteLine(globalStatistics.BestSentenceQuality); 82 Console.WriteLine(globalStatistics.BestSentence); 83 Console.WriteLine(globalStatistics); 84 //alg.PrintStats(); 85 policy.PrintStats(); 86 //ResetAlleleStatistics(); 75 87 } 76 88 77 89 // uncomment this if you want to collect statistics of the generated sentences 78 90 //if (iterations % 100 == 0) { … … 94 106 } 95 107 } 108 109 private static void UpdateAlleleStatistics(string sentence) { 110 for (int i = 0; i < sentence.Length; i++) { 111 var allele = sentence.Substring(i, 1); 112 if (alleleStatistics.ContainsKey(allele)) alleleStatistics[allele]++; 113 } 114 for (int i = 0; i < sentence.Length - 2; i+=2) { 115 var allele = sentence.Substring(i, 3); 116 if (alleleStatistics.ContainsKey(allele)) alleleStatistics[allele]++; 117 } 118 for (int i = 0; i < sentence.Length - 4; i+=2) { 119 var allele = sentence.Substring(i, 5); 120 if (alleleStatistics.ContainsKey(allele)) alleleStatistics[allele]++; 121 } 122 } 123 124 125 private static Dictionary<string, int> alleleStatistics; 126 127 private static void ResetAlleleStatistics() { 128 alleleStatistics = new Dictionary<string, int>() 129 { 130 {"a", 0}, 131 {"b", 0}, 132 {"c", 0}, 133 {"d", 0}, 134 {"e", 0}, 135 {"f", 0}, 136 {"g", 0}, 137 {"h", 0}, 138 {"i", 0}, 139 {"j", 0}, 140 {"a*b", 0}, 141 {"b*a", 0}, 142 {"c*d", 0}, 143 {"d*c", 0}, 144 {"e*f", 0}, 145 {"f*e", 0}, 146 {"a*g*i", 0}, 147 {"a*i*g", 0}, 148 {"g*a*i", 0}, 149 {"g*i*a", 0}, 150 {"i*g*a", 0}, 151 {"i*a*g", 0}, 152 {"j*c*f", 0}, 153 {"j*f*c", 0}, 154 {"c*j*f", 0}, 155 {"c*f*j", 0}, 156 {"f*c*j", 0}, 157 {"f*j*c", 0} 158 }; 159 } 160 161 162 private static void WriteAlleleStatistics() { 163 double count = alleleStatistics.Sum(e => e.Value); 164 foreach (var entry in alleleStatistics.OrderByDescending(e=>e.Value)) { 165 Console.WriteLine("{0,-10} {1,-10}", entry.Key, entry.Value); 166 } 167 } 96 168 } 97 169 }
Note: See TracChangeset
for help on using the changeset viewer.