Changeset 17546


Ignore:
Timestamp:
05/19/20 15:01:59 (2 weeks ago)
Author:
abeham
Message:

#2521: Introduce class to make parameter change handling easier, fix bug in SingleObjectiveProblem regarding MaximizationChanged

Location:
branches/2521_ProblemRefactoring
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/BinaryVectorEncoding.cs

    r17545 r17546  
    7676
    7777    private void RegisterEventHandlers() {
    78       LengthParameter.ValueChanged += (_, __) => {
    79         if (!LengthParameter.Value.ReadOnly) LengthParameter.Value.ValueChanged += (___, ____) => OnPropertyChanged(nameof(Length));
    80         OnPropertyChanged(nameof(Length));
    81       };
     78      IntValueParameterChangeHandler.Create(LengthParameter, () => OnPropertyChanged(nameof(Length)));
    8279    }
    8380
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/SingleObjectiveProblem.cs

    r17522 r17546  
    6262        if (Maximization == value) return;
    6363        MaximizationParameter.ForceValue(new BoolValue(value, @readonly: true));
    64         OnMaximizationChanged();
    6564      }
    6665    }
     
    7473      MaximizationParameter = cloner.Clone(original.MaximizationParameter);
    7574      ParameterizeOperators();
     75      RegisterEventHandlers();
    7676    }
    7777
    7878    protected SingleObjectiveProblem() : base() {
    79 
    8079      MaximizationParameter = new ValueParameter<BoolValue>("Maximization", "Whether the problem should be maximized (True) or minimized (False).", new BoolValue(false).AsReadOnly()) { Hidden = true, ReadOnly = true };
    8180      BestKnownQualityParameter = new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this problem.");
     
    9291
    9392      ParameterizeOperators();
     93      RegisterEventHandlers();
    9494    }
    9595
     
    106106
    107107      ParameterizeOperators();
     108      RegisterEventHandlers();
    108109    }
    109110
     
    111112    private void AfterDeserialization() {
    112113      ParameterizeOperators();
     114      RegisterEventHandlers();
    113115    }
    114116
     
    200202    }
    201203
     204    private void RegisterEventHandlers() {
     205      BoolValueParameterChangeHandler.Create(MaximizationParameter, OnMaximizationChanged);
     206    }
     207
    202208    #region ISingleObjectiveHeuristicOptimizationProblem Members
    203209    IParameter ISingleObjectiveHeuristicOptimizationProblem.MaximizationParameter {
  • branches/2521_ProblemRefactoring/HeuristicLab.Parameters/3.3/HeuristicLab.Parameters-3.3.csproj

    r17532 r17546  
    126126    <Compile Include="FixedValueParameter.cs" />
    127127    <Compile Include="OptionalConstrainedValueParameter.cs" />
     128    <Compile Include="ParameterChangeHandler.cs" />
    128129    <Compile Include="Plugin.cs" />
    129130    <Compile Include="ReferenceParameter.cs" />
     
    161162      <Project>{C36BD924-A541-4A00-AFA8-41701378DDC5}</Project>
    162163      <Name>HeuristicLab.Core-3.3</Name>
     164      <Private>False</Private>
     165    </ProjectReference>
     166    <ProjectReference Include="..\..\HeuristicLab.Data\3.3\HeuristicLab.Data-3.3.csproj">
     167      <Project>{bbab9df5-5ef3-4ba8-ade9-b36e82114937}</Project>
     168      <Name>HeuristicLab.Data-3.3</Name>
    163169      <Private>False</Private>
    164170    </ProjectReference>
  • branches/2521_ProblemRefactoring/HeuristicLab.Parameters/3.3/Plugin.cs.frame

    r17226 r17546  
    3232  [PluginDependency("HeuristicLab.Common.Resources", "3.3")]
    3333  [PluginDependency("HeuristicLab.Core", "3.3")]
     34  [PluginDependency("HeuristicLab.Data", "3.3")]
    3435  [PluginDependency("HeuristicLab.Attic", "1.0")]
    3536  public class HeuristicLabParametersPlugin : PluginBase {
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Binary/3.3/DeceptiveStepTrapProblem.cs

    r17544 r17546  
    2222#endregion
    2323
    24 using System;
    2524using HEAL.Attic;
    2625using HeuristicLab.Common;
     
    4544    public DeceptiveStepTrapProblem() : base() {
    4645      Parameters.Add(StepSizeParameter = new FixedValueParameter<IntValue>("Step Size", "", new IntValue(2)));
    47       offset = (TrapSize - StepSize) % StepSize;
     46      CalculateOffset();
    4847
    4948      RegisterParameterEvents();
     
    7978
    8079    private void RegisterParameterEvents() {
    81       StepSizeParameter.Value.ValueChanged += StepSizeOnChanged;
     80      IntValueParameterChangeHandler.Create(StepSizeParameter, CalculateOffset);
    8281    }
    8382
    84     protected override void TrapSizeOnChanged(object sender, EventArgs e) {
    85       base.TrapSizeOnChanged(sender, e);
    86       offset = (TrapSize - StepSize) % StepSize;
     83    protected override void TrapSizeOnChanged() {
     84      base.TrapSizeOnChanged();
     85      CalculateOffset();
    8786    }
    8887
    89     private void StepSizeOnChanged(object sender, EventArgs e) {
     88    private void CalculateOffset() {
    9089      offset = (TrapSize - StepSize) % StepSize;
    9190    }
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Binary/3.3/DeceptiveTrapProblem.cs

    r17545 r17546  
    107107
    108108    private void RegisterEventHandlers() {
    109       TrapSizeParameter.Value.ValueChanged += TrapSizeOnChanged;
    110       NumberOfTrapsParameter.Value.ValueChanged += NumberOfTrapsOnChanged;
     109      IntValueParameterChangeHandler.Create(TrapSizeParameter, TrapSizeOnChanged);
     110      IntValueParameterChangeHandler.Create(NumberOfTrapsParameter, NumberOfTrapsOnChanged);
    111111    }
    112112
    113     protected virtual void TrapSizeOnChanged(object sender, EventArgs e) {
     113    protected virtual void TrapSizeOnChanged() {
    114114      Dimension = TrapSize * NumberOfTraps;
    115115    }
    116116
    117     private void NumberOfTrapsOnChanged(object sender, EventArgs e) {
     117    private void NumberOfTrapsOnChanged() {
    118118      Dimension = TrapSize * NumberOfTraps;
    119119    }
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/SingleObjectiveExternalEvaluationProblem.cs

    r17382 r17546  
    9393    public ExternalEvaluationProblem(TEncoding encoding)
    9494      : base(encoding) {
    95       MaximizationParameter.ReadOnly = false;
    96       MaximizationParameter.Value = new BoolValue(); // is a read-only bool value in base class
    97       MaximizationParameter.ReadOnly = true;
     95      MaximizationParameter.ForceValue(new BoolValue()); // is a read-only bool value in base class
    9896      Parameters.Add(new OptionalValueParameter<EvaluationCache>("Cache", "Cache of previously evaluated solutions."));
    9997      Parameters.Add(new ValueParameter<CheckedItemCollection<IEvaluationServiceClient>>("Clients", "The clients that are used to communicate with the external application.", new CheckedItemCollection<IEvaluationServiceClient>() { new EvaluationServiceClient() }));
Note: See TracChangeset for help on using the changeset viewer.