- Timestamp:
- 08/02/20 11:39:51 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2825-NSGA3/HeuristicLab.Algorithms.NSGA3/3.3/Utility.cs
r17679 r17707 32 32 { 33 33 if (n < r) throw new InvalidOperationException($"Constraint was not met: n >= r (n = {n}, r = {r})"); 34 if (r < 1) throw new InvalidOperationException($"Constraint was not met: r >= 1(r = {r})");34 if (r < 0) throw new InvalidOperationException($"Constraint was not met: r >= 0 (r = {r})"); 35 35 if (n == r) return 1; 36 return (int)(Factorial(n) / (Factorial(r) * Factorial(n - r))); 37 } 38 39 public static long Factorial(int n) 36 37 r = Math.Max(r, n - r); 38 39 long range1 = RangeMultiplication(r + 1, n - r); 40 return (int)(range1 / Factorial(n - r)); 41 } 42 43 private static long RangeMultiplication(int start, int count) 44 { 45 long s = 1; 46 return LeftFold((long a, int b) => checked(a * b), new List<int>(Enumerable.Range(start, count)), s); 47 } 48 49 private static T2 LeftFold<T1, T2>(Func<T2, T1, T2> func, List<T1> elements, T2 start) 50 { 51 var item = start; 52 foreach (var element in elements) 53 item = func(item, element); 54 55 return item; 56 } 57 58 public static long Factorial(long n) 40 59 { 41 60 if (n < 0 || n > 30) throw new InvalidOperationException($"Constraint for n was not met: 0 <= n <= 30 (n = {n})"); 42 61 long product = 1; 43 for ( inti = 2; i <= n; i++)62 for (long i = 2; i <= n; i++) 44 63 product *= i; 45 64 46 65 return product; 47 66 } 67 48 68 public static double[][] ToJaggedArray(this DoubleMatrix m) 49 69 { … … 94 114 { 95 115 if (referencePoints == null || !referencePoints.Any()) throw new ArgumentException($"{nameof(referencePoints)} is null or empty"); 96 int nDim = referencePoints.First().NumberOfDimensions;116 int obj = referencePoints.First().Objectives; 97 117 int pointCount = referencePoints.Count; 98 double[,] array = new double[ nDim, pointCount];118 double[,] array = new double[obj, pointCount]; 99 119 100 120 for (int p = 0; p < pointCount; p++) 101 for (int d = 0; d < nDim; d++)121 for (int d = 0; d < obj; d++) 102 122 array[d, p] = referencePoints[p].Values[d]; 103 123
Note: See TracChangeset
for help on using the changeset viewer.