Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/21/20 17:06:15 (4 years ago)
Author:
abeham
Message:

#2521: worked on multi-objective test function

File:
1 edited

Legend:

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

    r17587 r17690  
    1919 */
    2020#endregion
     21
    2122using System;
    2223using System.Threading;
     
    7576
    7677      BestKnownFrontParameter.Hidden = true;
     78      BestKnownFrontParameter.ReadOnly = true;
     79      ReferencePointParameter.ReadOnly = true;
    7780
    7881      UpdateParameterValues();
     
    8285
    8386    private void RegisterEventHandlers() {
    84       TestFunctionParameter.ValueChanged += TestFunctionParameterOnValueChanged;
    85       ObjectivesParameter.Value.ValueChanged += ObjectivesOnValueChanged;
     87      IntValueParameterChangeHandler.Create(ObjectivesParameter, ObjectivesOnChanged);
     88      ParameterChangeHandler<IMultiObjectiveTestFunction>.Create(TestFunctionParameter, TestFunctionOnChanged);
    8689    }
    8790
     
    113116
    114117    #region Events
    115     private void UpdateParameterValues() {
    116       Maximization = TestFunction.Maximization(Objectives);
    117 
    118       Parameters.Remove(BestKnownFrontParameterName);
    119       var front = TestFunction.OptimalParetoFront(Objectives);
    120       var bkf = front != null ? (DoubleMatrix)Utilities.ToMatrix(front).AsReadOnly() : null;
    121       Parameters.Add(new FixedValueParameter<DoubleMatrix>(BestKnownFrontParameterName, "A double matrix representing the best known qualities for this problem (aka points on the Pareto front). Points are to be given in a row-wise fashion.", bkf));
    122 
    123       Parameters.Remove(ReferencePointParameterName);
    124       Parameters.Add(new FixedValueParameter<DoubleArray>(ReferencePointParameterName, "The reference point for hypervolume calculations on this problem", new DoubleArray(TestFunction.ReferencePoint(Objectives))));
    125 
    126       BoundsRefParameter.Value = new DoubleMatrix(TestFunction.Bounds(Objectives));
    127     }
    128 
    129     protected override void OnEncodingChanged() {
    130       base.OnEncodingChanged();
    131       UpdateParameterValues();
    132     }
    133 
    134     protected override void OnEvaluatorChanged() {
    135       base.OnEvaluatorChanged();
    136       UpdateParameterValues();
    137     }
    138 
    139118    protected override void DimensionOnChanged() {
    140119      base.DimensionOnChanged();
     
    142121        Dimension = Math.Min(TestFunction.MaximumSolutionLength, Math.Max(TestFunction.MinimumSolutionLength, Dimension));
    143122      UpdateParameterValues();
     123      OnReset();
    144124    }
    145125
    146     private void TestFunctionParameterOnValueChanged(object sender, EventArgs eventArgs) {
     126    protected virtual void TestFunctionOnChanged() {
    147127      Dimension = Math.Max(TestFunction.MinimumSolutionLength, Math.Min(Dimension, TestFunction.MaximumSolutionLength));
    148128      Objectives = Math.Max(TestFunction.MinimumObjectives, Math.Min(Objectives, TestFunction.MaximumObjectives));
    149       Parameters.Remove(ReferencePointParameterName);
    150       Parameters.Add(new FixedValueParameter<DoubleArray>(ReferencePointParameterName, "The reference point for hypervolume calculations on this problem", new DoubleArray(TestFunction.ReferencePoint(Objectives))));
    151129      UpdateParameterValues();
    152130      OnReset();
    153131    }
    154132
    155     private void ObjectivesOnValueChanged(object sender, EventArgs eventArgs) {
     133    protected virtual void ObjectivesOnChanged() {
    156134      Objectives = Math.Min(TestFunction.MaximumObjectives, Math.Max(TestFunction.MinimumObjectives, Objectives));
    157135      UpdateParameterValues();
     136      OnReset();
    158137    }
    159138    #endregion
    160139
    161140    #region Helpers
     141    private void UpdateParameterValues() {
     142      Maximization = TestFunction.Maximization(Objectives);
     143
     144      BestKnownFrontParameter.Value = DoubleMatrix.FromRows(TestFunction.OptimalParetoFront(Objectives));
     145      ReferencePoint = TestFunction.ReferencePoint(Objectives);
     146
     147      BoundsRefParameter.Value = new DoubleMatrix(TestFunction.Bounds(Objectives));
     148    }
     149
    162150    private void InitializeOperators() {
    163151      Operators.Add(new CrowdingAnalyzer());
Note: See TracChangeset for help on using the changeset viewer.