Changeset 14404 for branches/MOCMAEvolutionStrategy/HeuristicLab.Algorithms.MOCMAEvolutionStrategy/3.3/CrowdingIndicator.cs
- Timestamp:
- 11/21/16 15:52:53 (7 years ago)
- Location:
- branches
- Files:
-
- 2 edited
- 2 copied
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches
-
Property
svn:global-ignores
set to
bin
-
Property
svn:global-ignores
set to
-
branches/MOCMAEvolutionStrategy/HeuristicLab.Algorithms.MOCMAEvolutionStrategy/3.3/CrowdingIndicator.cs
r14269 r14404 20 20 #endregion 21 21 22 using HeuristicLab.Data;23 22 using System; 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HeuristicLab.Common; 26 using HeuristicLab.Core; 25 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 using HeuristicLab.Core;27 using HeuristicLab.Common;28 28 using HeuristicLab.Problems.TestFunctions.MultiObjective; 29 29 … … 31 31 [Item("CrowdingIndicator", "Selection of Offspring based on CrowdingDistance")] 32 32 [StorableClass] 33 class CrowdingIndicator : Item, IIndicator {33 internal class CrowdingIndicator : Item, IIndicator { 34 34 35 public int LeastContributer<TR>(IEnumerable<TR> front, Func<TR, double[]> extractor, MultiObjectiveTestFunctionProblem problem) { 36 var bounds = problem.Bounds; 37 var extracted = front.Select(extractor.Invoke).ToArray(); 38 var pointsums = new double[extracted.Length]; 35 39 36 public int LeastContributer<R>(R[] front, Func<R, double[]> extractor, MultiObjectiveTestFunctionProblem problem) { 37 DoubleMatrix bounds = problem.Bounds; 38 int mindex = 1; 39 double min = Double.MaxValue; 40 double[] pointsums = new double[front.Count()]; 41 42 for (int dim = 0; dim < problem.Objectives; dim++) { 43 double[] arr = front.Select(x => extractor.Invoke(x)[dim]).ToArray(); 40 for (var dim = 0; dim < problem.Objectives; dim++) { 41 var arr = extracted.Select(x => x[dim]).ToArray(); 44 42 Array.Sort(arr); 45 double fmax = problem.Bounds[dim % bounds.Rows, 1]; 46 double fmin = bounds[dim % bounds.Rows, 0]; 47 int pointIdx = 0; 48 foreach (R point in front) { 49 double d = 0; 50 int pos = Array.BinarySearch(arr, extractor.Invoke(point)[dim]); 51 52 d = pos != 0 && pos != arr.Count() - 1 ? (arr[pos + 1] - arr[pos - 1]) / (fmax - fmin) : Double.PositiveInfinity; 43 var fmax = problem.Bounds[dim % bounds.Rows, 1]; 44 var fmin = bounds[dim % bounds.Rows, 0]; 45 var pointIdx = 0; 46 foreach (var point in extracted) { 47 var pos = Array.BinarySearch(arr, point[dim]); 48 var d = pos != 0 && pos != arr.Length - 1 ? (arr[pos + 1] - arr[pos - 1]) / (fmax - fmin) : double.PositiveInfinity; 53 49 pointsums[pointIdx] += d; 54 55 56 50 pointIdx++; 57 51 } 58 52 } 59 53 //find min 60 for (int pointIdx = 0; pointIdx < pointsums.Length; pointIdx++) { 61 double d = pointsums[pointIdx]; 62 if (!Double.IsInfinity(d) && min > d) { 63 mindex = pointIdx; 64 min = d; 65 } 66 } 67 68 return mindex; 69 } 70 71 72 73 public override IDeepCloneable Clone(Cloner cloner) { 74 return new CrowdingIndicator(this, cloner); 54 return pointsums.Where(x => !double.IsInfinity(x)).ArgMin(); 75 55 } 76 56 77 57 [StorableConstructor] 78 58 protected CrowdingIndicator(bool deserializing) : base(deserializing) { } 79 protected CrowdingIndicator(CrowdingIndicator original, Cloner cloner) 80 : base(original, cloner) { 81 } 59 protected CrowdingIndicator(CrowdingIndicator original, Cloner cloner) : base(original, cloner) { } 60 public override IDeepCloneable Clone(Cloner cloner) { return new CrowdingIndicator(this, cloner); } 82 61 public CrowdingIndicator() { } 83 62 }
Note: See TracChangeset
for help on using the changeset viewer.