[11659] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Diagnostics;
|
---|
| 4 | using System.Linq;
|
---|
| 5 | using System.Text;
|
---|
| 6 | using HeuristicLab.Algorithms.GrammaticalOptimization;
|
---|
| 7 | using HeuristicLab.Problems.GrammaticalOptimization;
|
---|
| 8 |
|
---|
| 9 | namespace Main {
|
---|
| 10 | class Program {
|
---|
| 11 | static void Main(string[] args) {
|
---|
[11690] | 12 | int maxIterations = 10000000;
|
---|
[11659] | 13 | int iterations = 0;
|
---|
| 14 | var sw = new Stopwatch();
|
---|
| 15 | double bestQuality = 0;
|
---|
| 16 | string bestSentence = "";
|
---|
| 17 |
|
---|
[11690] | 18 | var rs = new ExhaustiveDepthFirstSearch(17);
|
---|
[11659] | 19 |
|
---|
| 20 | rs.FoundNewBestSolution += (sentence, quality) => {
|
---|
| 21 | bestQuality = quality;
|
---|
| 22 | bestSentence = sentence;
|
---|
| 23 | Console.WriteLine("{0,10} {1,10:F5} {2,10:F5} {3}", iterations, bestQuality, quality, sentence);
|
---|
| 24 | };
|
---|
| 25 | rs.SolutionEvaluated += (sentence, quality) => {
|
---|
| 26 | iterations++;
|
---|
[11690] | 27 | if (iterations % 10000 == 0) {
|
---|
[11659] | 28 | Console.WriteLine("{0,10} {1,10:F5} {2,10:F5} {3}", iterations, bestQuality, quality, sentence);
|
---|
| 29 | }
|
---|
| 30 | };
|
---|
| 31 |
|
---|
| 32 |
|
---|
| 33 | sw.Start();
|
---|
| 34 |
|
---|
| 35 | rs.Run(new SymbolicRegressionPoly10Problem(), maxIterations);
|
---|
| 36 |
|
---|
| 37 | sw.Stop();
|
---|
| 38 |
|
---|
| 39 | Console.WriteLine("{0,10} Best soultion: {1,10:F5} {2}", iterations, bestQuality, bestSentence);
|
---|
| 40 | Console.WriteLine("{0:F2} sec {1,10:F1} sols/sec {2,10:F1} ns/sol",
|
---|
| 41 | sw.Elapsed.TotalSeconds,
|
---|
| 42 | maxIterations / (double)sw.Elapsed.TotalSeconds,
|
---|
| 43 | (double)sw.ElapsedMilliseconds * 1000 / maxIterations);
|
---|
| 44 | }
|
---|
| 45 | }
|
---|
| 46 | }
|
---|