Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/18/20 18:55:08 (4 years ago)
Author:
abeham
Message:

#2521: worked on refactoring, worked a lot on binary encoding / problems

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/MultiObjectiveTestFunctionProblem.cs

    r17320 r17544  
    3737  public class MultiObjectiveTestFunctionProblem : RealVectorMultiObjectiveProblem, IProblemInstanceConsumer<MOTFData>, IMultiObjectiveProblemDefinition<RealVectorEncoding, RealVector> {
    3838    #region Parameter Properties
    39     public IFixedValueParameter<IntValue> ProblemSizeParameter {
    40       get { return (IFixedValueParameter<IntValue>)Parameters["ProblemSize"]; }
    41     }
    4239    public IFixedValueParameter<IntValue> ObjectivesParameter {
    4340      get { return (IFixedValueParameter<IntValue>)Parameters["Objectives"]; }
    44     }
    45     public IValueParameter<DoubleMatrix> BoundsParameter {
    46       get { return (IValueParameter<DoubleMatrix>)Parameters["Bounds"]; }
    4741    }
    4842    public IValueParameter<IMultiObjectiveTestFunction> TestFunctionParameter {
     
    5246
    5347    #region Properties
    54     public int ProblemSize {
    55       get { return ProblemSizeParameter.Value.Value; }
    56       set { ProblemSizeParameter.Value.Value = value; }
    57     }
    5848    public new int Objectives {
    5949      get { return ObjectivesParameter.Value.Value; }
    6050      set { ObjectivesParameter.Value.Value = value; }
    61     }
    62     public DoubleMatrix Bounds {
    63       get { return BoundsParameter.Value; }
    64       set { BoundsParameter.Value = value; }
    6551    }
    6652    public IMultiObjectiveTestFunction TestFunction {
     
    8571
    8672    public MultiObjectiveTestFunctionProblem() : base() {
    87       Parameters.Add(new FixedValueParameter<IntValue>("ProblemSize", "The dimensionality of the problem instance (number of variables in the function).", new IntValue(2)));
    8873      Parameters.Add(new FixedValueParameter<IntValue>("Objectives", "The dimensionality of the solution vector (number of objectives).", new IntValue(2)));
    89       Parameters.Add(new ValueParameter<DoubleMatrix>("Bounds", "The bounds of the solution given as either one line for all variables or a line for each variable. The first column specifies lower bound, the second upper bound.", new DoubleMatrix(new double[,] { { -4, 4 } })));
    9074      Parameters.Add(new ValueParameter<IMultiObjectiveTestFunction>("TestFunction", "The function that is to be optimized.", new Fonseca()));
    9175
    92       Encoding.LengthParameter = ProblemSizeParameter;
    93       Encoding.BoundsParameter = BoundsParameter;
    9476      BestKnownFrontParameter.Hidden = true;
    9577
     
    10183    private void RegisterEventHandlers() {
    10284      TestFunctionParameter.ValueChanged += TestFunctionParameterOnValueChanged;
    103       ProblemSizeParameter.Value.ValueChanged += ProblemSizeOnValueChanged;
    10485      ObjectivesParameter.Value.ValueChanged += ObjectivesOnValueChanged;
    10586    }
     
    156137    }
    157138
     139    protected override void DimensionOnChanged() {
     140      base.DimensionOnChanged();
     141      if (Dimension < TestFunction.MinimumSolutionLength || Dimension > TestFunction.MaximumSolutionLength)
     142        Dimension = Math.Min(TestFunction.MaximumSolutionLength, Math.Max(TestFunction.MinimumSolutionLength, Dimension));
     143      UpdateParameterValues();
     144    }
     145
    158146    private void TestFunctionParameterOnValueChanged(object sender, EventArgs eventArgs) {
    159       ProblemSize = Math.Max(TestFunction.MinimumSolutionLength, Math.Min(ProblemSize, TestFunction.MaximumSolutionLength));
     147      Dimension = Math.Max(TestFunction.MinimumSolutionLength, Math.Min(Dimension, TestFunction.MaximumSolutionLength));
    160148      Objectives = Math.Max(TestFunction.MinimumObjectives, Math.Min(Objectives, TestFunction.MaximumObjectives));
    161149      Parameters.Remove(ReferencePointParameterName);
     
    163151      UpdateParameterValues();
    164152      OnReset();
    165     }
    166 
    167     private void ProblemSizeOnValueChanged(object sender, EventArgs eventArgs) {
    168       ProblemSize = Math.Min(TestFunction.MaximumSolutionLength, Math.Max(TestFunction.MinimumSolutionLength, ProblemSize));
    169       UpdateParameterValues();
    170153    }
    171154
Note: See TracChangeset for help on using the changeset viewer.