Changeset 12403


Ignore:
Timestamp:
05/27/15 10:54:06 (7 years ago)
Author:
pfleck
Message:

#2027 Wired Maximization-Parameter for the Quality Terminator.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/TerminationCriteria/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/OffspringSelectionGeneticAlgorithm.cs

    r12402 r12403  
    387387    }
    388388
     389    protected override void RegisterProblemEvents() {
     390      base.RegisterProblemEvents();
     391      var maximizationParameter = (IValueParameter<BoolValue>)Problem.MaximizationParameter;
     392      if (maximizationParameter != null) maximizationParameter.ValueChanged += new EventHandler(MaximizationParameter_ValueChanged);
     393    }
     394    protected override void DeregisterProblemEvents() {
     395      var maximizationParameter = (IValueParameter<BoolValue>)Problem.MaximizationParameter;
     396      if (maximizationParameter != null) maximizationParameter.ValueChanged -= new EventHandler(MaximizationParameter_ValueChanged);
     397      base.DeregisterProblemEvents();
     398    }
     399
    389400    protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
    390401      ParameterizeStochasticOperator(Problem.SolutionCreator);
     
    429440      ParameterizeAnalyzers();
    430441    }
     442    private void MaximizationParameter_ValueChanged(object sender, EventArgs e) {
     443      ParameterizeTerminators();
     444    }
     445    private void QualityAnalyzer_CurrentBestQualityParameter_NameChanged(object sender, EventArgs e) {
     446      ParameterizeTerminators();
     447    }
    431448    #endregion
    432449
     
    437454      ElitesParameter.ValueChanged += new EventHandler(ElitesParameter_ValueChanged);
    438455      Elites.ValueChanged += new EventHandler(Elites_ValueChanged);
     456      qualityAnalyzer.CurrentBestQualityParameter.NameChanged += new EventHandler(QualityAnalyzer_CurrentBestQualityParameter_NameChanged);
    439457      if (Problem != null) {
    440458        Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
     
    487505    private void ParameterizeTerminators() {
    488506      if (Problem != null) {
    489         bool maximization = ((BoolValue)Problem.MaximizationParameter.ActualValue).Value;
    490         qualityTerminator.Comparison = new Comparison(maximization ? ComparisonType.GreaterOrEqual : ComparisonType.LessOrEqual);
    491         qualityTerminator.ValueParameter.ActualName = qualityAnalyzer.CurrentBestQualityParameter.Name;
    492         qualityTerminator.ThresholdParameter.Value = new DoubleValue(maximization ? double.MaxValue : double.MinValue);
    493       }
     507        var maximizationParameter = (IValueParameter<BoolValue>)Problem.MaximizationParameter;
     508        if (maximizationParameter != null) {
     509          bool maximization = maximizationParameter.Value.Value;
     510          qualityTerminator.Comparison = new Comparison(maximization ? ComparisonType.GreaterOrEqual : ComparisonType.LessOrEqual);
     511          qualityTerminator.ThresholdParameter.Value = new DoubleValue(maximization ? double.MaxValue : double.MinValue);
     512        }
     513      }
     514      qualityTerminator.ValueParameter.ActualName = qualityAnalyzer.CurrentBestQualityParameter.Name;
    494515    }
    495516    private void ParameterizeComparisonFactorModifiers() {
Note: See TracChangeset for help on using the changeset viewer.