Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/01/15 14:21:02 (9 years ago)
Author:
pfleck
Message:

#2027

  • Added IThresholdTerminator interface for more flexibility. The ThresholdTerminatorView now uses the interface instead of a concrete terminator.
  • Added MaximumIterationsTerminator and SingleObjectiveQualityTerminator as common used Terminators.
File:
1 edited

Legend:

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

    r12408 r12410  
    8383      get { return (IFixedValueParameter<BoolValue>)Parameters["ReevaluateElites"]; }
    8484    }
    85     private ValueParameter<IntValue> MaximumGenerationsParameter {
    86       get { return (ValueParameter<IntValue>)Parameters["MaximumGenerations"]; }
     85    private IFixedValueParameter<IntValue> MaximumGenerationsParameter {
     86      get { return (IFixedValueParameter<IntValue>)Parameters["MaximumGenerations"]; }
    8787    }
    8888    private ValueLookupParameter<DoubleValue> SuccessRatioParameter {
     
    158158      set { ReevaluateElitesParameter.Value.Value = value; }
    159159    }
    160     public IntValue MaximumGenerations {
    161       get { return MaximumGenerationsParameter.Value; }
    162       set { MaximumGenerationsParameter.Value = value; }
     160    public int MaximumGenerations {
     161      get { return MaximumGenerationsParameter.Value.Value; }
     162      set { MaximumGenerationsParameter.Value.Value = value; }
    163163    }
    164164    public DoubleValue SuccessRatio {
     
    194194      set { AnalyzerParameter.Value = value; }
    195195    }
    196 
    197196    public IntValue MaximumEvaluatedSolutions {
    198197      get { return MaximumEvaluatedSolutionsParameter.Value; }
     
    222221    private SuccessfulOffspringAnalyzer successfulOffspringAnalyzer;
    223222    [Storable]
    224     private ComparisonTerminator<IntValue> generationsTerminator;
     223    private MaximumIterationsTerminator generationsTerminator;
    225224    [Storable]
    226225    private ComparisonTerminator<IntValue> evaluatedSolutionsTerminator;
     
    228227    private ComparisonTerminator<DoubleValue> selectionPressureTerminator;
    229228    [Storable]
    230     private ComparisonTerminator<DoubleValue> qualityTerminator;
     229    private SingleObjectiveQualityTerminator qualityTerminator;
    231230    [Storable]
    232231    private ExecutionTimeTerminator executionTimeTerminator;
     
    276275      Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1)));
    277276      Parameters.Add(new FixedValueParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)", new BoolValue(false)) { Hidden = true });
    278       Parameters.Add(new ValueParameter<IntValue>("MaximumGenerations", "The maximum number of generations which should be processed.", new IntValue(1000)));
     277      Parameters.Add(new FixedValueParameter<IntValue>("MaximumGenerations", "The maximum number of generations which should be processed.", new IntValue(1000)));
    279278      Parameters.Add(new ValueLookupParameter<DoubleValue>("SuccessRatio", "The ratio of successful to total children that should be achieved.", new DoubleValue(1)));
    280279      Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactorLowerBound", "The lower bound of the comparison factor (start).", new DoubleValue(0)));
     
    339338      ParameterizeSelectors();
    340339
     340      qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
     341      selectionPressureAnalyzer = new ValueAnalyzer();
     342      successfulOffspringAnalyzer = new SuccessfulOffspringAnalyzer();
     343      ParameterizeAnalyzers();
     344      UpdateAnalyzers();
     345
     346      generationsTerminator = new MaximumIterationsTerminator();
     347      evaluatedSolutionsTerminator = new ComparisonTerminator<IntValue>("EvaluatedSolutions", ComparisonType.Less, new IntValue(int.MaxValue)) { Name = "Evaluations" };
     348      selectionPressureTerminator = new ComparisonTerminator<DoubleValue>("SelectionPressure", ComparisonType.Less, new DoubleValue(200)) { Name = "Selection Pressure" };
     349      qualityTerminator = new SingleObjectiveQualityTerminator();
     350      executionTimeTerminator = new ExecutionTimeTerminator(this, new TimeSpanValue(TimeSpan.FromMinutes(5))) { Name = "Execution Time" };
     351      ParameterizeTerminators();
     352      UpdateTerminators();
     353
    341354      foreach (IDiscreteDoubleValueModifier modifier in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name))
    342355        ComparisonFactorModifierParameter.ValidValues.Add(modifier);
     
    344357      if (linearModifier != null) ComparisonFactorModifierParameter.Value = linearModifier;
    345358      ParameterizeComparisonFactorModifiers();
    346 
    347       qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
    348       selectionPressureAnalyzer = new ValueAnalyzer();
    349       successfulOffspringAnalyzer = new SuccessfulOffspringAnalyzer();
    350       ParameterizeAnalyzers();
    351       UpdateAnalyzers();
    352 
    353       generationsTerminator = new ComparisonTerminator<IntValue>("Generations", ComparisonType.Less, new IntValue(50)) { Name = "Generations" };
    354       evaluatedSolutionsTerminator = new ComparisonTerminator<IntValue>("EvaluatedSolutions", ComparisonType.Less, new IntValue(int.MaxValue)) { Name = "Evaluations" };
    355       selectionPressureTerminator = new ComparisonTerminator<DoubleValue>("SelectionPressure", ComparisonType.Less, new DoubleValue(200)) { Name = "Selection Pressure" };
    356       qualityTerminator = new ComparisonTerminator<DoubleValue>(new DoubleValue()) { Name = "Quality" };
    357       executionTimeTerminator = new ExecutionTimeTerminator(this, new TimeSpanValue(TimeSpan.FromMinutes(5))) { Name = "Execution Time" };
    358       ParameterizeTerminators();
    359       UpdateTerminators();
    360359
    361360      Initialize();
     
    504503    }
    505504    private void ParameterizeTerminators() {
    506       qualityTerminator.ComparisonValueParameter.ActualName = qualityAnalyzer.CurrentBestQualityParameter.Name;
    507       if (Problem != null) {
    508         var maximizationParameter = (IValueParameter<BoolValue>)Problem.MaximizationParameter;
    509         if (maximizationParameter != null) {
    510           bool maximization = maximizationParameter.Value.Value;
    511           qualityTerminator.Comparison = maximization ? ComparisonType.Less : ComparisonType.Greater;
    512           qualityTerminator.Threshold.Value = maximization ? double.MaxValue : double.MinValue;
    513         }
    514       }
     505      generationsTerminator.IterationsParameter.ActualName = "Generations";
     506      generationsTerminator.MaximumIterationsParameter = MaximumGenerationsParameter;
     507
     508      qualityTerminator.Parameterize(qualityAnalyzer.CurrentBestQualityParameter, Problem);
    515509    }
    516510    private void ParameterizeComparisonFactorModifiers() {
     
    572566    }
    573567    private void UpdateTerminators() {
     568      // ToDo restore checked state
    574569      Terminators.Operators.Clear();
    575570      if (Problem != null) {
Note: See TracChangeset for help on using the changeset viewer.