Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/Main/Program.cs @ 11690

Last change on this file since 11690 was 11690, checked in by gkronber, 9 years ago

#2283: added exhaustive BFS and DFS

File size: 1.4 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Diagnostics;
4using System.Linq;
5using System.Text;
6using HeuristicLab.Algorithms.GrammaticalOptimization;
7using HeuristicLab.Problems.GrammaticalOptimization;
8
9namespace Main {
10  class Program {
11    static void Main(string[] args) {
12      int maxIterations = 10000000;
13      int iterations = 0;
14      var sw = new Stopwatch();
15      double bestQuality = 0;
16      string bestSentence = "";
17
18      var rs = new ExhaustiveDepthFirstSearch(17);
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++;
27        if (iterations % 10000 == 0) {
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}
Note: See TracBrowser for help on using the repository browser.