- Timestamp:
- 10/04/19 14:23:08 (5 years ago)
- Location:
- branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Interfaces/IMultiObjectiveProblemDefinition.cs
r17309 r17315 28 28 public interface IMultiObjectiveProblemDefinition { 29 29 int Objectives { get; } 30 IReadOnlyList<bool>Maximization { get; }30 bool[] Maximization { get; } 31 31 IReadOnlyList<double[]> BestKnownFront { get; } 32 32 double[] ReferencePoint { get; } -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/MultiObjectiveProblem.cs
r17309 r17315 37 37 where TEncodedSolution : class, IEncodedSolution { 38 38 #region Parameternames 39 public const string MaximizationParameterName = "Maximization"; 39 40 public const string BestKnownFrontParameterName = "BestKnownFront"; 40 41 public const string ReferencePointParameterName = "ReferencePoint"; … … 42 43 43 44 #region Parameterproperties 44 [Storable] protected IValueParameter<BoolArray> MaximizationParameter { get; } 45 public IValueParameter<BoolArray> MaximizationParameter { 46 get { return (IValueParameter<BoolArray>)Parameters[MaximizationParameterName]; } 47 } 45 48 public IValueParameter<DoubleMatrix> BestKnownFrontParameter { 46 49 get { return (IValueParameter<DoubleMatrix>)Parameters[BestKnownFrontParameterName]; } … … 57 60 protected MultiObjectiveProblem(MultiObjectiveProblem<TEncoding, TEncodedSolution> original, Cloner cloner) 58 61 : base(original, cloner) { 59 MaximizationParameter = cloner.Clone(original.MaximizationParameter);60 62 ParameterizeOperators(); 61 63 } 62 64 63 65 protected MultiObjectiveProblem() : base() { 64 MaximizationParameter = new ValueParameter<BoolArray>("Maximization", "Set to false if the problem should be minimized.", new BoolArray(new[] { false, false }).AsReadOnly()) { Hidden = true, ReadOnly = true }; 65 Parameters.Add(MaximizationParameter); 66 Parameters.Add(new ValueParameter<BoolArray>(MaximizationParameterName, "Set to false if the problem should be minimized.", (BoolArray)new BoolArray(Maximization).AsReadOnly())); 66 67 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.")); 67 68 Parameters.Add(new OptionalValueParameter<DoubleArray>(ReferencePointParameterName, "The refrence point for hypervolume calculations on this problem")); … … 72 73 73 74 protected MultiObjectiveProblem(TEncoding encoding) : base(encoding) { 74 MaximizationParameter = new ValueParameter<BoolArray>("Maximization", "Set to false if the problem should be minimized.", new BoolArray(new[] { false, false }).AsReadOnly()) { Hidden = true, ReadOnly = true }; 75 Parameters.Add(MaximizationParameter); 75 Parameters.Add(new ValueParameter<BoolArray>(MaximizationParameterName, "Set to false if the problem should be minimized.", (BoolArray)new BoolArray(Maximization).AsReadOnly())); 76 76 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.")); 77 77 Parameters.Add(new OptionalValueParameter<DoubleArray>(ReferencePointParameterName, "The refrence point for hypervolume calculations on this problem")); … … 89 89 get { return Maximization.Length; } 90 90 } 91 IReadOnlyList<bool> IMultiObjectiveProblemDefinition.Maximization { 92 get { return Maximization.CloneAsArray(); } 93 } 94 public BoolArray Maximization { 95 get { return MaximizationParameter.Value; } 96 set { 97 if (Maximization == value) return; 98 MaximizationParameter.ReadOnly = false; 99 MaximizationParameter.Value = value.AsReadOnly(); 100 MaximizationParameter.ReadOnly = true; 101 } 102 } 91 public abstract bool[] Maximization { get; } 103 92 104 93 public virtual IReadOnlyList<double[]> BestKnownFront { … … 179 168 #region IMultiObjectiveHeuristicOptimizationProblem Members 180 169 IParameter IMultiObjectiveHeuristicOptimizationProblem.MaximizationParameter { 181 get { return MaximizationParameter; }170 get { return Parameters[MaximizationParameterName]; } 182 171 } 183 172 IMultiObjectiveEvaluator IMultiObjectiveHeuristicOptimizationProblem.Evaluator { -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/MultiObjective/DominationCalculator.cs
r17309 r17315 47 47 /// <param name="dominateOnEqualQualities">Whether solutions of exactly equal quality should dominate one another.</param> 48 48 /// <returns>The pareto front containing the best solutions and their associated quality resp. fitness.</returns> 49 public static List<Tuple<T, double[]>> CalculateBestParetoFront<T>(T[] solutions, double[][] qualities, IReadOnlyList<bool>maximization, bool dominateOnEqualQualities = true) {49 public static List<Tuple<T, double[]>> CalculateBestParetoFront<T>(T[] solutions, double[][] qualities, bool[] maximization, bool dominateOnEqualQualities = true) { 50 50 var populationSize = solutions.Length; 51 51 Dictionary<T, List<int>> dominatedIndividuals; … … 72 72 /// <param name="dominateOnEqualQualities">Whether solutions of exactly equal quality should dominate one another.</param> 73 73 /// <returns>A sorted list of the pareto fronts from best to worst.</returns> 74 public static List<List<Tuple<T, double[]>>> CalculateAllParetoFronts<T>(T[] solutions, double[][] qualities, IReadOnlyList<bool>maximization, out int[] rank, bool dominateOnEqualQualities = true) {74 public static List<List<Tuple<T, double[]>>> CalculateAllParetoFronts<T>(T[] solutions, double[][] qualities, bool[] maximization, out int[] rank, bool dominateOnEqualQualities = true) { 75 75 var populationSize = solutions.Length; 76 76 … … 101 101 } 102 102 103 private static List<Tuple<T, double[]>> CalculateBestFront<T>(T[] solutions, double[][] qualities, IReadOnlyList<bool>maximization, bool dominateOnEqualQualities, int populationSize, out Dictionary<T, List<int>> dominatedIndividuals, out int[] dominationCounter, out int[] rank) {103 private static List<Tuple<T, double[]>> CalculateBestFront<T>(T[] solutions, double[][] qualities, bool[] maximization, bool dominateOnEqualQualities, int populationSize, out Dictionary<T, List<int>> dominatedIndividuals, out int[] dominationCounter, out int[] rank) { 104 104 var front = new List<Tuple<T, double[]>>(); 105 105 dominatedIndividuals = new Dictionary<T, List<int>>(); … … 155 155 /// <param name="dominateOnEqualQualities">Whether solutions of exactly equal quality should dominate one another.</param> 156 156 /// <returns>A sorted list of the pareto fronts where each front contains the indices of the <paramref name="solutions"/> and <paramref name="qualities"/>.</returns> 157 public static List<List<int>> CalculateAllParetoFrontsIndices<T>(T[] solutions, double[][] qualities, IReadOnlyList<bool>maximization, bool dominateOnEqualQualities = true) {157 public static List<List<int>> CalculateAllParetoFrontsIndices<T>(T[] solutions, double[][] qualities, bool[] maximization, bool dominateOnEqualQualities = true) { 158 158 return CalculateAllParetoFrontsIndices(solutions, qualities, maximization, out var rank, dominateOnEqualQualities); 159 159 } … … 178 178 /// <param name="dominateOnEqualQualities">Whether solutions of exactly equal quality should dominate one another.</param> 179 179 /// <returns>A sorted list of the pareto fronts where each front contains the indices of the <paramref name="solutions"/> and <paramref name="qualities"/>.</returns> 180 public static List<List<int>> CalculateAllParetoFrontsIndices<T>(T[] solutions, double[][] qualities, IReadOnlyList<bool>maximization, out int[] rank, bool dominateOnEqualQualities = true) {180 public static List<List<int>> CalculateAllParetoFrontsIndices<T>(T[] solutions, double[][] qualities, bool[] maximization, out int[] rank, bool dominateOnEqualQualities = true) { 181 181 var populationSize = solutions.Length; 182 182 … … 207 207 } 208 208 209 private static List<int> CalculateBestFrontIndices<T>(T[] solutions, double[][] qualities, IReadOnlyList<bool>maximization, bool dominateOnEqualQualities, int populationSize, List<int>[] dominatedIndividuals, int[] dominationCounter, int[] rank) {209 private static List<int> CalculateBestFrontIndices<T>(T[] solutions, double[][] qualities, bool[] maximization, bool dominateOnEqualQualities, int populationSize, List<int>[] dominatedIndividuals, int[] dominationCounter, int[] rank) { 210 210 var front = new List<int>(); 211 211 for (var pI = 0; pI < populationSize - 1; pI++) { … … 244 244 /// <param name="dominateOnEqualQualities">Whether the result should be Dominates in case both fitness vectors are exactly equal</param> 245 245 /// <returns>Dominates if left dominates right, IsDominated if right dominates left and IsNonDominated otherwise.</returns> 246 public static DominationResult Dominates(double[] left, double[] right, IReadOnlyList<bool>maximizations, bool dominateOnEqualQualities) {246 public static DominationResult Dominates(double[] left, double[] right, bool[] maximizations, bool dominateOnEqualQualities) { 247 247 //mkommend Caution: do not use LINQ.SequenceEqual for comparing the two quality arrays (left and right) due to performance reasons 248 248 if (dominateOnEqualQualities) { -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/MultiObjective/HypervolumeCalculator.cs
r17309 r17315 26 26 namespace HeuristicLab.Optimization { 27 27 public static class HypervolumeCalculator { 28 public static double[] CalculateNadirPoint(IEnumerable<double[]> qualities, IReadOnlyList<bool>maximization) {28 public static double[] CalculateNadirPoint(IEnumerable<double[]> qualities, bool[] maximization) { 29 29 var res = maximization.Select(m => m ? double.MaxValue : double.MinValue).ToArray(); 30 30 foreach (var quality in qualities) … … 59 59 /// </summary> 60 60 /// 61 public static double CalculateHypervolume(IList<double[]> qualities, double[] referencePoint, IReadOnlyList<bool>maximization) {61 public static double CalculateHypervolume(IList<double[]> qualities, double[] referencePoint, bool[] maximization) { 62 62 qualities = qualities.Where(vec => DominationCalculator.Dominates(vec, referencePoint, maximization, false) == DominationResult.Dominates).ToArray(); 63 63 if (qualities.Count== 0) return 0; //TODO computation for negative hypervolume? 64 if (maximization. Count== 2)64 if (maximization.Length == 2) 65 65 return Calculate2D(qualities, referencePoint, maximization); 66 66 67 if ( maximization.All(x => !x))67 if (Array.TrueForAll(maximization, x => !x)) 68 68 return CalculateMultiDimensional(qualities, referencePoint); 69 69 throw new NotImplementedException("HypervolumeCalculator calculation for more than two dimensions is supported only with minimization problems."); … … 78 78 /// <param name="maximization"></param> 79 79 /// <returns></returns> 80 public static double Calculate2D(IList<double[]> front, double[] referencePoint, IReadOnlyList<bool>maximization) {80 public static double Calculate2D(IList<double[]> front, double[] referencePoint, bool[] maximization) { 81 81 if (front == null) throw new ArgumentNullException("front"); 82 82 if (referencePoint == null) throw new ArgumentNullException("referencePoint");
Note: See TracChangeset
for help on using the changeset viewer.