Changeset 11730 for branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.GrammaticalOptimization/RandomSearch.cs
- Timestamp:
- 01/02/15 16:08:21 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.GrammaticalOptimization/RandomSearch.cs
r11690 r11730 13 13 private readonly int maxLen; 14 14 private readonly Random random; 15 private readonly IProblem problem; 15 16 16 public RandomSearch( int maxLen) {17 public RandomSearch(IProblem problem, Random random, int maxLen) { 17 18 this.maxLen = maxLen; 18 this.random = new Random(31415); 19 this.random = random; 20 this.problem = problem; 19 21 } 20 22 21 public void Run( IProblem problem,int maxIterations) {23 public void Run(int maxIterations) { 22 24 double bestQuality = double.MinValue; 23 25 for (int i = 0; i < maxIterations; i++) { 24 var sentence = CreateSentence(problem.Grammar) ;25 var quality = problem.Evaluate(sentence) ;26 var sentence = CreateSentence(problem.Grammar).ToString(); 27 var quality = problem.Evaluate(sentence) / problem.GetBestKnownQuality(maxLen); 26 28 RaiseSolutionEvaluated(sentence, quality); 27 29 … … 33 35 } 34 36 35 private stringCreateSentence(IGrammar grammar) {36 var sentence = grammar.SentenceSymbol.ToString();37 private Sequence CreateSentence(IGrammar grammar) { 38 var sentence = new Sequence(grammar.SentenceSymbol); 37 39 return grammar.CompleteSentenceRandomly(random, sentence, maxLen); 38 40 }
Note: See TracChangeset
for help on using the changeset viewer.