- Timestamp:
- 07/21/20 17:06:15 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/MultiObjectiveProblem.cs
r17620 r17690 38 38 where TEncoding : class, IEncoding<TEncodedSolution> 39 39 where TEncodedSolution : class, IEncodedSolution { 40 #region Parameter names41 public const string BestKnownFrontParameterName = "BestKnownFront";42 public const string ReferencePointParameterName = "ReferencePoint";43 #endregion44 40 45 41 #region Parameter properties 46 42 [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; } 53 45 #endregion 54 46 … … 60 52 : base(original, cloner) { 61 53 MaximizationParameter = cloner.Clone(original.MaximizationParameter); 54 BestKnownFrontParameter = cloner.Clone(original.BestKnownFrontParameter); 55 ReferencePointParameter = cloner.Clone(original.ReferencePointParameter); 62 56 ParameterizeOperators(); 63 57 } 64 58 65 59 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")); 70 63 Operators.Add(Evaluator); 71 64 Operators.Add(new MultiObjectiveAnalyzer<TEncodedSolution>()); … … 92 85 public virtual IReadOnlyList<double[]> BestKnownFront { 93 86 get { 94 if (!Parameters.ContainsKey(BestKnownFrontParameterName)) return null;95 87 var mat = BestKnownFrontParameter.Value; 96 88 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(); 119 90 } 120 91 } 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 } 121 99 public virtual double[] ReferencePoint { 122 get { return ReferencePointParameter.Value != null ? ReferencePointParameter.Value.CloneAsArray() : null; }100 get { return ReferencePointParameter.Value?.CloneAsArray(); } 123 101 set { ReferencePointParameter.Value = new DoubleArray(value); } 124 102 }
Note: See TracChangeset
for help on using the changeset viewer.