Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/01/15 16:32:26 (8 years ago)
Author:
gkronber
Message:

#2283 implemented bridge to HL (solve grammatical optimization problem instances with StandardGP and OffspringSelectionGP)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.GrammaticalOptimization/RandomSearch.cs

    r11793 r11846  
    33
    44namespace HeuristicLab.Algorithms.GrammaticalOptimization {
    5   public class RandomSearch {
    6     public event Action<string, double> FoundNewBestSolution;
    7     public event Action<string, double> SolutionEvaluated;
    8 
     5  public class RandomSearch : SolverBase {
    96    private readonly int maxLen;
    107    private readonly Random random;
     
    1714    }
    1815
    19     public void Run(int maxIterations) {
    20       double bestQuality = double.MinValue;
     16    public override void Run(int maxIterations) {
    2117      for (int i = 0; i < maxIterations; i++) {
    2218        var sentence = CreateSentence(problem.Grammar).ToString();
    2319        var quality = problem.Evaluate(sentence) / problem.BestKnownQuality(maxLen);
    24         RaiseSolutionEvaluated(sentence, quality);
    25 
    26         if (quality > bestQuality) {
    27           bestQuality = quality;
    28           RaiseFoundNewBestSolution(sentence, quality);
    29         }
     20        OnSolutionEvaluated(sentence, quality);
    3021      }
    3122    }
     
    3526      return grammar.CompleteSentenceRandomly(random, sentence, maxLen);
    3627    }
    37 
    38     private void RaiseSolutionEvaluated(string sentence, double quality) {
    39       var handler = SolutionEvaluated;
    40       if (handler != null) handler(sentence, quality);
    41     }
    42     private void RaiseFoundNewBestSolution(string sentence, double quality) {
    43       var handler = FoundNewBestSolution;
    44       if (handler != null) handler(sentence, quality);
    45     }
    4628  }
    4729}
Note: See TracChangeset for help on using the changeset viewer.