- Timestamp:
- 07/13/20 14:20:24 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2825-NSGA3/HeuristicLab.Algorithms.NSGA3/3.3/Utility.cs
r17664 r17667 6 6 namespace HeuristicLab.Algorithms.NSGA3 7 7 { 8 internalstatic class Utility8 public static class Utility 9 9 { 10 internalstatic List<T> Concat<T>(List<T> list1, List<T> list2)10 public static List<T> Concat<T>(List<T> list1, List<T> list2) 11 11 { 12 12 List<T> resultList = new List<T>(list1.Count + list2.Count); … … 25 25 /// <param name="r"></param> 26 26 /// <returns></returns> 27 /// <exception cref=" ArgumentException">27 /// <exception cref="InvalidOperationException"> 28 28 /// Thrown, when <paramref name="r" /> > <paramref name="n" /> or when <paramref name="r" 29 29 /// /> < 1. 30 30 /// </exception> 31 internalstatic int NCR(int n, int r)31 public static int NCR(int n, int r) 32 32 { 33 if (n < r) throw new ArgumentException($"Constraint was not met: n >= r (n = {n}, r = {r})");34 if (r < 1) throw new ArgumentException($"Constraint was not met: r >= 1 (r = {r})");35 if (n == r) return n;36 return Factorial(n) / (Factorial(r) * Factorial(n - r));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})"); 35 if (n == r) return 1; 36 return (int)(Factorial(n) / (Factorial(r) * Factorial(n - r))); 37 37 } 38 38 39 internal static intFactorial(int n)39 public static long Factorial(int n) 40 40 { 41 if (n < = 0) throw new ArgumentException($"Constraint for n was not met: 0 <n <= 30 (n = {n})");42 intproduct = 1;41 if (n < 0 || n > 30) throw new InvalidOperationException($"Constraint for n was not met: 0 <= n <= 30 (n = {n})"); 42 long product = 1; 43 43 for (int i = 2; i <= n; i++) 44 44 product *= i; … … 47 47 } 48 48 49 internalstatic DoubleMatrix ConvertToDoubleMatrix(List<ReferencePoint> referencePoints)49 public static DoubleMatrix ConvertToDoubleMatrix(List<ReferencePoint> referencePoints) 50 50 { 51 51 return new DoubleMatrix(ToArray(referencePoints)); 52 52 } 53 53 54 internalstatic double[][] ToFitnessMatrix(this List<Solution> solutions)54 public static double[][] ToFitnessMatrix(this List<Solution> solutions) 55 55 { 56 56 double[][] data = new double[solutions.Count][]; … … 68 68 } 69 69 70 internalstatic DoubleMatrix ToMatrix(this IEnumerable<IReadOnlyList<double>> data)70 public static DoubleMatrix ToMatrix(this IEnumerable<IReadOnlyList<double>> data) 71 71 { 72 72 var d2 = data.ToArray(); … … 92 92 } 93 93 94 internalstatic TOut Min<TIn, TOut>(Func<TIn, TOut> func, IEnumerable<TIn> inputs) where TOut : IComparable94 public static TOut Min<TIn, TOut>(Func<TIn, TOut> func, IEnumerable<TIn> inputs) where TOut : IComparable 95 95 { 96 96 return MinArgMin(func, inputs).Item2; 97 97 } 98 98 99 internalstatic TIn ArgMin<TIn, TOut>(Func<TIn, TOut> func, IEnumerable<TIn> inputs) where TOut : IComparable99 public static TIn ArgMin<TIn, TOut>(Func<TIn, TOut> func, IEnumerable<TIn> inputs) where TOut : IComparable 100 100 { 101 101 return MinArgMin(func, inputs).Item1; … … 114 114 /// </param> 115 115 /// <returns></returns> 116 internalstatic Tuple<TIn, TOut> MinArgMin<TIn, TOut>(Func<TIn, TOut> func, IEnumerable<TIn> inputs) where TOut : IComparable116 public static Tuple<TIn, TOut> MinArgMin<TIn, TOut>(Func<TIn, TOut> func, IEnumerable<TIn> inputs) where TOut : IComparable 117 117 { 118 118 if (func == null) throw new ArgumentNullException(nameof(func)); … … 139 139 } 140 140 141 internalstatic TOut Max<TIn, TOut>(Func<TIn, TOut> func, IEnumerable<TIn> inputs) where TOut : IComparable141 public static TOut Max<TIn, TOut>(Func<TIn, TOut> func, IEnumerable<TIn> inputs) where TOut : IComparable 142 142 { 143 143 return MaxArgMax(func, inputs).Item2; 144 144 } 145 145 146 internalstatic TIn ArgMax<TIn, TOut>(Func<TIn, TOut> func, IEnumerable<TIn> inputs) where TOut : IComparable146 public static TIn ArgMax<TIn, TOut>(Func<TIn, TOut> func, IEnumerable<TIn> inputs) where TOut : IComparable 147 147 { 148 148 return MaxArgMax(func, inputs).Item1; … … 161 161 /// </param> 162 162 /// <returns></returns> 163 internalstatic Tuple<TIn, TOut> MaxArgMax<TIn, TOut>(Func<TIn, TOut> func, IEnumerable<TIn> inputs) where TOut : IComparable163 public static Tuple<TIn, TOut> MaxArgMax<TIn, TOut>(Func<TIn, TOut> func, IEnumerable<TIn> inputs) where TOut : IComparable 164 164 { 165 165 if (func == null) throw new ArgumentNullException(nameof(func));
Note: See TracChangeset
for help on using the changeset viewer.