Changeset 17667 for branches/2825-NSGA3
- Timestamp:
- 07/13/20 14:20:24 (4 years ago)
- Location:
- branches/2825-NSGA3
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2825-NSGA3/HeuristicLab.Algorithms.NSGA3-3.3.Test/UtilityTests.cs
r17666 r17667 13 13 [DataRow(3, 6)] 14 14 [DataRow(4, 24)] 15 public void TestFactorial(int input, int result) 15 [DataRow(10, 3628800)] 16 [DataRow(12, 479001600)] 17 [DataRow(13, 6227020800)] 18 [DataRow(14, 87178291200)] 19 public void TestFactorial(int input, long result) 16 20 { 17 21 Assert.AreEqual(result, Utility.Factorial(input)); … … 21 25 [DataRow(-1)] 22 26 [DataRow(31)] 23 public void TestFactorial 2(int input)27 public void TestFactorialConstraint(int input) 24 28 { 25 29 Assert.ThrowsException<InvalidOperationException>(() => { Utility.Factorial(input); }); 26 30 } 31 32 [DataTestMethod] 33 [DataRow(14, 12, 91)] 34 public void TestNCR(int n, int r, int result) 35 { 36 Assert.AreEqual(result, Utility.NCR(n, r)); 37 } 27 38 } 28 39 } -
branches/2825-NSGA3/HeuristicLab.Algorithms.NSGA3/3.3/HeuristicLab.Algorithms.NSGA3-3.3.csproj
r17665 r17667 118 118 <Compile Include="Utility.cs" /> 119 119 </ItemGroup> 120 <ItemGroup> 121 <ProjectReference Include="..\..\..\..\trunk\HeuristicLab.Problems.TestFunctions.MultiObjective\3.3\HeuristicLab.Problems.TestFunctions.MultiObjective-3.3.csproj"> 122 <Project>{D53E8E48-CFAA-4F57-AC35-63BEF4476159}</Project> 123 <Name>HeuristicLab.Problems.TestFunctions.MultiObjective-3.3</Name> 124 </ProjectReference> 125 </ItemGroup> 120 126 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> 121 127 <!-- To modify your build process, add your task inside one of the targets below and uncomment it. -
branches/2825-NSGA3/HeuristicLab.Algorithms.NSGA3/3.3/NSGA3.cs
r17665 r17667 11 11 using HeuristicLab.Optimization; 12 12 using HeuristicLab.Parameters; 13 using HeuristicLab.Problems.TestFunctions.MultiObjective; 13 14 using HeuristicLab.Random; 14 15 … … 41 42 } 42 43 43 public int NumberOfObjectives => Problem.Maximization.Length; 44 public int NumberOfObjectives 45 { 46 get 47 { 48 if (!(Problem is MultiObjectiveTestFunctionProblem testFunctionProblem)) throw new NotSupportedException("Only test multi objective test function problems are supported"); 49 return testFunctionProblem.Objectives; 50 } 51 } 44 52 45 53 #endregion ProblemProperties … … 211 219 base.Initialize(cancellationToken); 212 220 213 PopulationSize.Value = ReferencePoint.GetNumberOfGeneratedReferencePoints(Problem.Maximization.Length); 221 int pop = ReferencePoint.GetNumberOfGeneratedReferencePoints(NumberOfObjectives); 222 PopulationSize.Value = pop; 214 223 InitResults(); 215 224 InitReferencePoints(); … … 264 273 // create copies of generated reference points (to preserve the original ones for 265 274 // the next generation) maybe todo: use cloner? 266 //ToNextGeneration(CreateCopyOfReferencePoints());267 275 268 276 List<Solution> qt = Mutate(Recombine(solutions)); -
branches/2825-NSGA3/HeuristicLab.Algorithms.NSGA3/3.3/ReferencePoint.cs
r17663 r17667 45 45 /// <param name="nDim"></param> 46 46 /// <returns></returns> 47 internalstatic int GetNumberOfGeneratedReferencePoints(int nDim)47 public static int GetNumberOfGeneratedReferencePoints(int nDim) 48 48 { 49 49 int outerDiv; … … 80 80 } 81 81 82 return GetNumberOfGeneratedReferencePoints(nDim, outerDiv, innerDiv); 83 } 84 85 internal static int GetNumberOfGeneratedReferencePoints(int nDim, int outerDiv, int innerDiv = 0) 86 { 87 return Utility.NCR(nDim + outerDiv - 1, outerDiv) + (innerDiv == 0 ? 0 : Utility.NCR(nDim + innerDiv - 1, innerDiv)); 82 int nRefPoints = GetNumberOfGeneratedReferencePoints(nDim, outerDiv, innerDiv); 83 return nRefPoints; 84 //return GetNumberOfGeneratedReferencePoints(nDim, outerDiv, innerDiv); 85 } 86 87 public static int GetNumberOfGeneratedReferencePoints(int nDim, int outerDiv, int innerDiv = 0) 88 { 89 int outerPoints = Utility.NCR(nDim + outerDiv - 1, outerDiv); 90 int innerPoints = innerDiv == 0 ? 0 : Utility.NCR(nDim + innerDiv - 1, innerDiv); 91 int nRefPoints = outerPoints + innerPoints; 92 return nRefPoints; 88 93 } 89 94 … … 101 106 /// <param name="nDim">The dimensionality of the Reference Points</param> 102 107 /// <returns></returns> 103 internalstatic List<ReferencePoint> GenerateReferencePoints(IRandom random, int nDim)108 public static List<ReferencePoint> GenerateReferencePoints(IRandom random, int nDim) 104 109 { 105 110 List<ReferencePoint> referencePoints; … … 151 156 /// not have inner reference points 152 157 /// </returns> 153 internalstatic List<ReferencePoint> GenerateReferencePoints(IRandom random, int nDim, int outerDiv, int innerDiv = 0)158 public static List<ReferencePoint> GenerateReferencePoints(IRandom random, int nDim, int outerDiv, int innerDiv = 0) 154 159 { 155 160 if (nDim <= 0) throw new ArgumentException("nDim must be greater than 0"); -
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.