Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.GrammaticalOptimization/SolverBase.cs @ 13808

Last change on this file since 13808 was 11846, checked in by gkronber, 10 years ago

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

File size: 1.1 KB
Line 
1using System;
2using HeuristicLab.Problems.GrammaticalOptimization;
3
4namespace HeuristicLab.Algorithms.GrammaticalOptimization {
5  public abstract class SolverBase : ISolver {
6    public event Action<string, double> FoundNewBestSolution;
7    public event Action<string, double> SolutionEvaluated;
8
9    protected double bestQuality = double.NegativeInfinity;
10
11    protected SolverBase() { }
12
13    public abstract void Run(int maxEvaluations);
14
15    protected virtual void OnSolutionEvaluated(string sentence, double quality) {
16      RaiseSolutionEvaluated(sentence, quality);
17      if (quality > bestQuality) {
18        bestQuality = quality;
19        RaiseFoundNewBestSolution(sentence, quality);
20      }
21    }
22
23    private void RaiseSolutionEvaluated(string sentence, double quality) {
24      var handler = SolutionEvaluated;
25      if (handler != null) handler(sentence, quality);
26    }
27    private void RaiseFoundNewBestSolution(string sentence, double quality) {
28      var handler = FoundNewBestSolution;
29      if (handler != null) handler(sentence, quality);
30    }
31  }
32}
Note: See TracBrowser for help on using the repository browser.