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.Optimization/3.3/BasicProblems/MultiObjectiveProblem.cs

    r17620 r17690  
    3838    where TEncoding : class, IEncoding<TEncodedSolution>
    3939    where TEncodedSolution : class, IEncodedSolution {
    40     #region Parameter names
    41     public const string BestKnownFrontParameterName = "BestKnownFront";
    42     public const string ReferencePointParameterName = "ReferencePoint";
    43     #endregion
    4440
    4541    #region Parameter properties
    4642    [Storable] public IValueParameter<BoolArray> MaximizationParameter { get; }
    47     public IValueParameter<DoubleMatrix> BestKnownFrontParameter {
    48       get { return (IValueParameter<DoubleMatrix>)Parameters[BestKnownFrontParameterName]; }
    49     }
    50     public IValueParameter<DoubleArray> ReferencePointParameter {
    51       get { return (IValueParameter<DoubleArray>)Parameters[ReferencePointParameterName]; }
    52     }
     43    [Storable] public IValueParameter<DoubleMatrix> BestKnownFrontParameter { get; }
     44    [Storable] public IValueParameter<DoubleArray> ReferencePointParameter { get; }
    5345    #endregion
    5446
     
    6052      : base(original, cloner) {
    6153      MaximizationParameter = cloner.Clone(original.MaximizationParameter);
     54      BestKnownFrontParameter = cloner.Clone(original.BestKnownFrontParameter);
     55      ReferencePointParameter = cloner.Clone(original.ReferencePointParameter);
    6256      ParameterizeOperators();
    6357    }
    6458
    6559    protected MultiObjectiveProblem(TEncoding encoding) : base(encoding) {
    66       MaximizationParameter = new ValueParameter<BoolArray>("Maximization", "The dimensions correspond to the different objectives: False if the objective should be minimized, true if it should be maximized..", new BoolArray(new bool[] { }, @readonly: true));
    67       Parameters.Add(MaximizationParameter);
    68       Parameters.Add(new OptionalValueParameter<DoubleMatrix>(BestKnownFrontParameterName, "A double matrix representing the best known qualites for this problem (aka points on the Pareto front). Points are to be given in a row-wise fashion."));
    69       Parameters.Add(new OptionalValueParameter<DoubleArray>(ReferencePointParameterName, "The reference point for hypervolume calculations on this problem"));
     60      Parameters.Add(MaximizationParameter = new ValueParameter<BoolArray>("Maximization", "The dimensions correspond to the different objectives: False if the objective should be minimized, true if it should be maximized..", new BoolArray(new bool[] { }, @readonly: true)));
     61      Parameters.Add(BestKnownFrontParameter = new OptionalValueParameter<DoubleMatrix>("Best Known Front", "A double matrix representing the best known qualites for this problem (aka points on the Pareto front). Points are to be given in a row-wise fashion."));
     62      Parameters.Add(ReferencePointParameter = new OptionalValueParameter<DoubleArray>("Reference Point", "The reference point for hypervolume calculations on this problem"));
    7063      Operators.Add(Evaluator);
    7164      Operators.Add(new MultiObjectiveAnalyzer<TEncodedSolution>());
     
    9285    public virtual IReadOnlyList<double[]> BestKnownFront {
    9386      get {
    94         if (!Parameters.ContainsKey(BestKnownFrontParameterName)) return null;
    9587        var mat = BestKnownFrontParameter.Value;
    9688        if (mat == null) return null;
    97         var v = new double[mat.Rows][];
    98         for (var i = 0; i < mat.Rows; i++) {
    99           var r = v[i] = new double[mat.Columns];
    100           for (var j = 0; j < mat.Columns; j++) {
    101             r[j] = mat[i, j];
    102           }
    103         }
    104         return v;
    105       }
    106       set {
    107         if (value == null || value.Count == 0) {
    108           BestKnownFrontParameter.Value = new DoubleMatrix();
    109           return;
    110         }
    111         var mat = new DoubleMatrix(value.Count, value[0].Length);
    112         for (int i = 0; i < value.Count; i++) {
    113           for (int j = 0; j < value[i].Length; j++) {
    114             mat[i, j] = value[i][j];
    115           }
    116         }
    117 
    118         BestKnownFrontParameter.Value = mat;
     89        return mat.CloneByRows().ToList();
    11990      }
    12091    }
     92    public virtual void SetBestKnownFront(IList<double[]> front) {
     93      if (front == null || front.Count == 0) {
     94        BestKnownFrontParameter.Value = null;
     95        return;
     96      }
     97      BestKnownFrontParameter.Value = DoubleMatrix.FromRows(front);
     98    }
    12199    public virtual double[] ReferencePoint {
    122       get { return ReferencePointParameter.Value != null ? ReferencePointParameter.Value.CloneAsArray() : null; }
     100      get { return ReferencePointParameter.Value?.CloneAsArray(); }
    123101      set { ReferencePointParameter.Value = new DoubleArray(value); }
    124102    }
Note: See TracChangeset for help on using the changeset viewer.