Changeset 17658
- Timestamp:
- 07/07/20 21:52:47 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2825-NSGA3/HeuristicLab.Algorithms.NSGA3/3.3/Utility.cs
r17616 r17658 94 94 internal static TOut Min<TIn, TOut>(Func<TIn, TOut> func, IEnumerable<TIn> inputs) where TOut : IComparable 95 95 { 96 //var it = inputs.GetEnumerator();97 //it.MoveNext();98 //var minValue = func(it.Current);99 //while (it.MoveNext())100 //{101 // var currentValue = func(it.Current);102 // if (minValue.CompareTo(currentValue) > 0) minValue = currentValue;103 //}104 105 //return minValue;106 96 return MinArgMin(func, inputs).Item2; 107 97 } … … 112 102 } 113 103 104 /// <summary> 105 /// Finds the value amongst <paramref name="inputs" /> such that the output value returned 106 /// by <paramref name="func" /> is minimal. 107 /// </summary> 108 /// <typeparam name="TIn">The input type for the function.</typeparam> 109 /// <typeparam name="TOut">The comparable output type of the function.</typeparam> 110 /// <param name="func">The function for which to find the minimal value.</param> 111 /// <param name="inputs"> 112 /// The function arguments for which to find the one with the minimum output value when 113 /// given to <paramref name="func" />. 114 /// </param> 115 /// <returns></returns> 114 116 internal static Tuple<TIn, TOut> MinArgMin<TIn, TOut>(Func<TIn, TOut> func, IEnumerable<TIn> inputs) where TOut : IComparable 115 117 { 118 if (inputs == null) throw new ArgumentNullException(nameof(inputs)); 116 119 var it = inputs.GetEnumerator(); 117 it.MoveNext(); 120 var hasItems = it.MoveNext(); 121 if (!hasItems) throw new InvalidOperationException("No items given to find the minimum of"); 122 123 // find minimum argument and minimum value 118 124 var minArg = it.Current; 119 125 var minValue = func(it.Current); … … 134 140 internal static TOut Max<TIn, TOut>(Func<TIn, TOut> func, IEnumerable<TIn> inputs) where TOut : IComparable 135 141 { 136 //var it = inputs.GetEnumerator();137 //it.MoveNext();138 //var maxValue = func(it.Current);139 //while (it.MoveNext())140 //{141 // var currentValue = func(it.Current);142 // if (maxValue.CompareTo(currentValue) < 0) maxValue = currentValue;143 //}144 145 //return maxValue;146 142 return MaxArgMax(func, inputs).Item2; 147 143 } … … 152 148 } 153 149 150 /// <summary> 151 /// Finds the value amongst <paramref name="inputs" /> such that the output value returned 152 /// by <paramref name="func" /> is as big as possible. 153 /// </summary> 154 /// <typeparam name="TIn">The input type for the function.</typeparam> 155 /// <typeparam name="TOut">The comparable output type of the function.</typeparam> 156 /// <param name="func">The function for which to find the biggest value.</param> 157 /// <param name="inputs"> 158 /// The function arguments for which to find the one with the biggest output value when 159 /// given to <paramref name="func" />. 160 /// </param> 161 /// <returns></returns> 154 162 internal static Tuple<TIn, TOut> MaxArgMax<TIn, TOut>(Func<TIn, TOut> func, IEnumerable<TIn> inputs) where TOut : IComparable 155 163 { 164 if (inputs == null) throw new ArgumentNullException(nameof(inputs)); 156 165 var it = inputs.GetEnumerator(); 157 it.MoveNext(); 166 var hasItems = it.MoveNext(); 167 if (!hasItems) throw new InvalidOperationException("No items given to find the maximum of"); 168 169 // find maximum argument and maximum value 158 170 var maxArg = it.Current; 159 171 var maxValue = func(it.Current);
Note: See TracChangeset
for help on using the changeset viewer.