Changeset 12411


Ignore:
Timestamp:
06/01/15 16:47:32 (4 years ago)
Author:
pfleck
Message:

#2027

  • Removed MaximumIterationsTerminator and MaximumEvaluatedSolutionsTermimator because they practically do the same.
  • Add the possibility for ThresholdTerminators to use a foreign parameter (e.g. MaximumSelectionPressure). This way the terminator can use parameters which are still relevant for the algorithm and still provide consistent management of the terminators.
  • Renamed IThresholdTerminator to ISingleValueTerminator.
Location:
branches/TerminationCriteria
Files:
1 deleted
5 edited
3 moved

Legend:

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

    r12410 r12411  
    2121
    2222using System;
     23using System.Collections.Generic;
    2324using System.Linq;
    2425using HeuristicLab.Analysis;
     
    110111      get { return (ValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; }
    111112    }
    112     private ValueParameter<IntValue> MaximumEvaluatedSolutionsParameter {
    113       get { return (ValueParameter<IntValue>)Parameters["MaximumEvaluatedSolutions"]; }
     113    private IFixedValueParameter<IntValue> MaximumEvaluatedSolutionsParameter {
     114      get { return (IFixedValueParameter<IntValue>)Parameters["MaximumEvaluatedSolutions"]; }
    114115    }
    115116    private IFixedValueParameter<BoolValue> FillPopulationWithParentsParameter {
     
    194195      set { AnalyzerParameter.Value = value; }
    195196    }
    196     public IntValue MaximumEvaluatedSolutions {
    197       get { return MaximumEvaluatedSolutionsParameter.Value; }
    198       set { MaximumEvaluatedSolutionsParameter.Value = value; }
     197    public int MaximumEvaluatedSolutions {
     198      get { return MaximumEvaluatedSolutionsParameter.Value.Value; }
     199      set { MaximumEvaluatedSolutionsParameter.Value.Value = value; }
    199200    }
    200201    public bool FillPopulationWithParents {
     
    221222    private SuccessfulOffspringAnalyzer successfulOffspringAnalyzer;
    222223    [Storable]
    223     private MaximumIterationsTerminator generationsTerminator;
    224     [Storable]
    225     private ComparisonTerminator<IntValue> evaluatedSolutionsTerminator;
     224    private ComparisonTerminator<IntValue> generationsTerminator;
     225    [Storable]
     226    private ComparisonTerminator<IntValue> evaluationsTerminator;
    226227    [Storable]
    227228    private ComparisonTerminator<DoubleValue> selectionPressureTerminator;
     
    255256      successfulOffspringAnalyzer = cloner.Clone(original.successfulOffspringAnalyzer);
    256257      generationsTerminator = cloner.Clone(original.generationsTerminator);
    257       evaluatedSolutionsTerminator = cloner.Clone(original.evaluatedSolutionsTerminator);
     258      evaluationsTerminator = cloner.Clone(original.evaluationsTerminator);
    258259      selectionPressureTerminator = cloner.Clone(original.selectionPressureTerminator);
    259260      qualityTerminator = cloner.Clone(original.qualityTerminator);
     
    284285      Parameters.Add(new ValueLookupParameter<IntValue>("SelectedParents", "How much parents should be selected each time the offspring selection step is performed until the population is filled. This parameter should be about the same or twice the size of PopulationSize for smaller problems, and less for large problems.", new IntValue(200)));
    285286      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze each generation.", new MultiAnalyzer()));
    286       Parameters.Add(new ValueParameter<IntValue>("MaximumEvaluatedSolutions", "The maximum number of evaluated solutions (approximately).", new IntValue(int.MaxValue)));
     287      Parameters.Add(new FixedValueParameter<IntValue>("MaximumEvaluatedSolutions", "The maximum number of evaluated solutions (approximately).", new IntValue(int.MaxValue)));
    287288      Parameters.Add(new FixedValueParameter<BoolValue>("FillPopulationWithParents", "True if the population should be filled with parent individual or false if worse children should be used when the maximum selection pressure is exceeded.", new BoolValue(false)) { Hidden = true });
    288289      Parameters.Add(new ValueParameter<MultiTerminator>("Termination", "The termination criteria which sould be checked.", new MultiTerminator()));
     
    344345      UpdateAnalyzers();
    345346
    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 
    354347      foreach (IDiscreteDoubleValueModifier modifier in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name))
    355348        ComparisonFactorModifierParameter.ValidValues.Add(modifier);
     
    357350      if (linearModifier != null) ComparisonFactorModifierParameter.Value = linearModifier;
    358351      ParameterizeComparisonFactorModifiers();
     352
     353      generationsTerminator = new ComparisonTerminator<IntValue>("Generations", ComparisonType.Less, MaximumGenerationsParameter) { Name = "Generations" };
     354      evaluationsTerminator = new ComparisonTerminator<IntValue>("EvaluatedSolutions", ComparisonType.Less, MaximumEvaluatedSolutionsParameter) { Name = "Evaluations" };
     355      selectionPressureTerminator = new ComparisonTerminator<DoubleValue>("SelectionPressure", ComparisonType.Less, MaximumSelectionPressure) { Name = "Selection Pressure" };
     356      qualityTerminator = new SingleObjectiveQualityTerminator() { Name = "Quality" };
     357      executionTimeTerminator = new ExecutionTimeTerminator(this, new TimeSpanValue(TimeSpan.FromMinutes(5)));
     358      ParameterizeTerminators();
     359      UpdateTerminators();
    359360
    360361      Initialize();
     
    503504    }
    504505    private void ParameterizeTerminators() {
    505       generationsTerminator.IterationsParameter.ActualName = "Generations";
    506       generationsTerminator.MaximumIterationsParameter = MaximumGenerationsParameter;
    507 
    508506      qualityTerminator.Parameterize(qualityAnalyzer.CurrentBestQualityParameter, Problem);
    509507    }
     
    566564    }
    567565    private void UpdateTerminators() {
    568       // ToDo restore checked state
    569       Terminators.Operators.Clear();
     566      var newTerminators = new Dictionary<ITerminator, bool> {
     567        {generationsTerminator, !Terminators.Operators.Contains(generationsTerminator) || Terminators.Operators.ItemChecked(generationsTerminator)},
     568        {selectionPressureTerminator, !Terminators.Operators.Contains(selectionPressureTerminator) || Terminators.Operators.ItemChecked(selectionPressureTerminator) },
     569        {evaluationsTerminator, Terminators.Operators.Contains(evaluationsTerminator) && Terminators.Operators.ItemChecked(evaluationsTerminator)},
     570        {qualityTerminator, Terminators.Operators.Contains(qualityTerminator) && Terminators.Operators.ItemChecked(qualityTerminator) },
     571        {executionTimeTerminator, Terminators.Operators.Contains(executionTimeTerminator) && Terminators.Operators.ItemChecked(executionTimeTerminator)}
     572      };
    570573      if (Problem != null) {
    571574        foreach (var terminator in Problem.Operators.OfType<ITerminator>())
    572           Terminators.Operators.Add(terminator);
    573       }
    574       Terminators.Operators.Add(generationsTerminator);
    575       Terminators.Operators.Add(evaluatedSolutionsTerminator);
    576       Terminators.Operators.Add(selectionPressureTerminator);
    577       Terminators.Operators.Add(qualityTerminator, checkedState: false);
    578       Terminators.Operators.Add(executionTimeTerminator, checkedState: false);
     575          newTerminators.Add(terminator, !Terminators.Operators.Contains(terminator) || Terminators.Operators.ItemChecked(terminator));
     576      }
     577
     578      Terminators.Operators.Clear();
     579      foreach (var newTerminator in newTerminators)
     580        Terminators.Operators.Add(newTerminator.Key, newTerminator.Value);
    579581    }
    580582    private OffspringSelectionGeneticAlgorithmMainLoop FindMainLoop(IOperator start) {
  • branches/TerminationCriteria/HeuristicLab.Termination/3.3/ComparisonTerminator.cs

    r12408 r12411  
    7171      Comparison = comparison;
    7272    }
     73    public ComparisonTerminator(string comparisonValueActualName, ComparisonType comparison, IFixedValueParameter<T> thresholdParameter)
     74      : this() {
     75      ComparisonValueParameter.ActualName = comparisonValueActualName;
     76      Comparison = comparison;
     77      ThresholdParameter = thresholdParameter;
     78    }
    7379
    7480    private void Initialize() {
  • branches/TerminationCriteria/HeuristicLab.Termination/3.3/HeuristicLab.Termination-3.3.csproj

    r12410 r12411  
    145145  </ItemGroup>
    146146  <ItemGroup>
    147     <Compile Include="IThresholdTerminator.cs" />
    148     <Compile Include="MaximumIterationsTerminator.cs" />
     147    <Compile Include="ISingleValueTerminator.cs" />
    149148    <Compile Include="SingleObjectiveQualityTerminator.cs" />
    150149    <Compile Include="ThresholdTerminator.cs" />
    151     <Compile Include="Views\ThresholdTerminatorView.cs">
     150    <Compile Include="Views\SingleValueTerminatorView.cs">
    152151      <SubType>UserControl</SubType>
    153152    </Compile>
    154     <Compile Include="Views\ThresholdTerminatorView.Designer.cs">
    155       <DependentUpon>ThresholdTerminatorView.cs</DependentUpon>
     153    <Compile Include="Views\SingleValueTerminatorView.Designer.cs">
     154      <DependentUpon>SingleValueTerminatorView.cs</DependentUpon>
    156155    </Compile>
    157156    <Compile Include="ITerminator.cs" />
  • branches/TerminationCriteria/HeuristicLab.Termination/3.3/ISingleValueTerminator.cs

    r12410 r12411  
    2323
    2424namespace HeuristicLab.Termination {
    25   public interface IThresholdTerminator : ITerminator {
     25  public interface ISingleValueTerminator : ITerminator {
    2626    IParameter ThresholdParameter { get; }
    2727  }
  • branches/TerminationCriteria/HeuristicLab.Termination/3.3/SingleObjectiveQualityTerminator.cs

    r12410 r12411  
    2727  [Item("SingleObjectiveQualityTerminator", "")]
    2828  public class SingleObjectiveQualityTerminator : ComparisonTerminator<DoubleValue> {
    29     public SingleObjectiveQualityTerminator() {
    30       Name = "Quality";
    31     }
     29    public SingleObjectiveQualityTerminator() { }
    3230
    3331    public void Parameterize(IParameter qualityParameter, ISingleObjectiveHeuristicOptimizationProblem problem) {
  • branches/TerminationCriteria/HeuristicLab.Termination/3.3/ThresholdTerminator.cs

    r12410 r12411  
    2727using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2828
    29 
    3029namespace HeuristicLab.Termination {
    3130  [Item("ThresholdTerminator", "Base class for all termination criteria which specifies some threshold.")]
    3231  [StorableClass]
    33   public abstract class ThresholdTerminator<T> : Terminator, IThresholdTerminator where T : class, IItem, IStringConvertibleValue, new() {
     32  public abstract class ThresholdTerminator<T> : Terminator, ISingleValueTerminator where T : class, IItem, IStringConvertibleValue, new() {
     33    [Storable]
     34    private IFixedValueParameter<T> thresholdParameter;
    3435    public IFixedValueParameter<T> ThresholdParameter {
    35       get { return (IFixedValueParameter<T>)Parameters["Threshold"]; }
     36      get { return thresholdParameter; }
     37      set {
     38        if (value == null) throw new ArgumentNullException("Threshold parameter must not be null.");
     39        if (value.Value == null) throw new ArgumentNullException("Threshold parameter value must not be null.");
     40        if (thresholdParameter == value) return;
     41
     42        if (thresholdParameter != null) Parameters.Remove(thresholdParameter);
     43        thresholdParameter = value;
     44        Parameters.Add(thresholdParameter);
     45        OnThresholdParameterChanged();
     46      }
    3647    }
    37     IParameter IThresholdTerminator.ThresholdParameter {
     48    IParameter ISingleValueTerminator.ThresholdParameter {
    3849      get { return ThresholdParameter; }
    3950    }
     
    5162    protected ThresholdTerminator(ThresholdTerminator<T> original, Cloner cloner)
    5263      : base(original, cloner) {
     64      thresholdParameter = cloner.Clone(original.thresholdParameter);
    5365      Initialize();
    5466    }
     
    5870      : base() {
    5971      if (threshold == null) throw new ArgumentNullException("threshold");
    60       Parameters.Add(new FixedValueParameter<T>("Threshold", "The limit of the termiation criterion.", threshold));
     72      thresholdParameter = new FixedValueParameter<T>("Threshold", "The limit of the termiation criterion.", threshold);
     73      Parameters.Add(thresholdParameter);
    6174      Initialize();
    6275    }
    6376
    6477    private void Initialize() {
    65       Threshold.ValueChanged += new EventHandler(Threshold_ValueChanged);
     78      RegisterThresholdParameterEvents();
    6679    }
    6780
     
    7386    }
    7487
     88    private void OnThresholdParameterChanged() {
     89      RegisterThresholdParameterEvents();
     90    }
     91
     92    private void RegisterThresholdParameterEvents() {
     93      Threshold.ValueChanged += new EventHandler(Threshold_ValueChanged);
     94    }
     95
    7596    public override string ToString() {
    7697      if (ThresholdParameter.Value == null) return Name;
  • branches/TerminationCriteria/HeuristicLab.Termination/3.3/Views/SingleValueTerminatorView.Designer.cs

    r12410 r12411  
    2525
    2626namespace HeuristicLab.Termination.Views {
    27   partial class ThresholdTerminatorView {
     27  partial class SingleValueTerminatorView {
    2828    /// <summary>
    2929    /// Required designer variable.
  • branches/TerminationCriteria/HeuristicLab.Termination/3.3/Views/SingleValueTerminatorView.cs

    r12410 r12411  
    2626
    2727  [View("ThresholdTerminator View")]
    28   [Content(typeof(IThresholdTerminator), true)]
    29   public partial class ThresholdTerminatorView : ItemView {
     28  [Content(typeof(ISingleValueTerminator), true)]
     29  public partial class SingleValueTerminatorView : ItemView {
    3030
    31     public new IThresholdTerminator Content {
    32       get { return (IThresholdTerminator)base.Content; }
     31    public new ISingleValueTerminator Content {
     32      get { return (ISingleValueTerminator)base.Content; }
    3333      set { base.Content = value; }
    3434    }
    3535
    36     public ThresholdTerminatorView() {
     36    public SingleValueTerminatorView() {
    3737      InitializeComponent();
    3838    }
Note: See TracChangeset for help on using the changeset viewer.