- Timestamp:
- 02/27/15 21:52:10 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.GrammaticalOptimization/Main/Program.cs
r12050 r12098 4 4 using HeuristicLab.Algorithms.Bandits.BanditPolicies; 5 5 using HeuristicLab.Algorithms.GrammaticalOptimization; 6 using HeuristicLab.Algorithms.MonteCarloTreeSearch; 7 using HeuristicLab.Algorithms.MonteCarloTreeSearch.Simulation; 6 8 using HeuristicLab.Problems.GrammaticalOptimization; 7 9 … … 18 20 19 21 20 namespace Main { 21 class Program { 22 static void Main(string[] args) { 23 CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture; 22 namespace Main 23 { 24 class Program 25 { 26 static void Main(string[] args) 27 { 28 CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture; 24 29 25 RunDemo();26 }30 RunDemo(); 31 } 27 32 28 33 29 private static void RunDemo() { 34 private static void RunDemo() 35 { 30 36 31 37 32 int maxIterations = 100000;33 int iterations = 0;38 int maxIterations = 100000; 39 int iterations = 0; 34 40 35 var globalStatistics = new SentenceSetStatistics();36 var random = new Random();41 var globalStatistics = new SentenceSetStatistics(); 42 var random = new Random(); 37 43 38 //var problem = new SymbolicRegressionPoly10Problem(); 39 //var problem = new SantaFeAntProblem(); 40 var problem = new RoyalPairProblem(); 41 //var problem = new EvenParityProblem(); 42 var alg = new SequentialSearch(problem, 23, random, 0, 43 new HeuristicLab.Algorithms.Bandits.GrammarPolicies.GenericGrammarPolicy(problem, new UCB1TunedPolicy())); 44 //var problem = new SymbolicRegressionPoly10Problem(); 45 //var problem = new SantaFeAntProblem(); 46 var problem = new RoyalPairProblem(); 47 //var problem = new EvenParityProblem(); 48 //var alg = new SequentialSearch(problem, 23, random, 0, 49 // new HeuristicLab.Algorithms.Bandits.GrammarPolicies.GenericGrammarPolicy(problem, new UCB1TunedPolicy())); 50 var alg = new MonteCarloTreeSearch(problem, 23, random, new UCB1Policy(), new RandomSimulation(problem, random, 23)); 44 51 45 52 46 alg.FoundNewBestSolution += (sentence, quality) => { 47 //Console.WriteLine("{0}", globalStatistics); 48 }; 53 alg.FoundNewBestSolution += (sentence, quality) => 54 { 55 //Console.WriteLine("{0}", globalStatistics); 56 }; 49 57 50 alg.SolutionEvaluated += (sentence, quality) => { 51 iterations++; 52 globalStatistics.AddSentence(sentence, quality); 58 alg.SolutionEvaluated += (sentence, quality) => 59 { 60 iterations++; 61 globalStatistics.AddSentence(sentence, quality); 53 62 54 // comment this if you don't want to see solver statistics 55 if (iterations % 100 == 0) { 56 if (iterations % 10000 == 0) Console.Clear(); 57 Console.SetCursorPosition(0, 0); 58 alg.PrintStats(); 63 // comment this if you don't want to see solver statistics 64 if (iterations % 100 == 0) 65 { 66 if (iterations % 10000 == 0) Console.Clear(); 67 Console.SetCursorPosition(0, 0); 68 alg.PrintStats(); 69 } 70 71 // uncomment this if you want to collect statistics of the generated sentences 72 // if (iterations % 1000 == 0) { 73 // Console.WriteLine("{0}", globalStatistics); 74 // } 75 }; 76 77 var sw = new Stopwatch(); 78 sw.Start(); 79 alg.Run(maxIterations); 80 sw.Stop(); 81 82 Console.Clear(); 83 alg.PrintStats(); 84 Console.WriteLine(globalStatistics); 85 Console.WriteLine("{0:F2} sec {1,10:F1} sols/sec {2,10:F1} ns/sol", 86 sw.Elapsed.TotalSeconds, 87 maxIterations / (double)sw.Elapsed.TotalSeconds, 88 (double)sw.ElapsedMilliseconds * 1000 / maxIterations); 59 89 } 60 61 // uncomment this if you want to collect statistics of the generated sentences62 // if (iterations % 1000 == 0) {63 // Console.WriteLine("{0}", globalStatistics);64 // }65 };66 67 var sw = new Stopwatch();68 sw.Start();69 alg.Run(maxIterations);70 sw.Stop();71 72 Console.Clear();73 alg.PrintStats();74 Console.WriteLine(globalStatistics);75 Console.WriteLine("{0:F2} sec {1,10:F1} sols/sec {2,10:F1} ns/sol",76 sw.Elapsed.TotalSeconds,77 maxIterations / (double)sw.Elapsed.TotalSeconds,78 (double)sw.ElapsedMilliseconds * 1000 / maxIterations);79 90 } 80 }81 91 }
Note: See TracChangeset
for help on using the changeset viewer.