Changeset 16171 for branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective
- Timestamp:
- 09/21/18 09:18:49 (6 years ago)
- Location:
- branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3
- Files:
-
- 37 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/Analyzers/CrowdingAnalyzer.cs
r15583 r16171 33 33 public class CrowdingAnalyzer : MOTFAnalyzer { 34 34 35 public ILookupParameter<DoubleMatrix> BoundsParameter {36 get { return (ILookupParameter<DoubleMatrix>)Parameters["Bounds"]; }37 }38 39 35 public IResultParameter<DoubleValue> CrowdingResultParameter { 40 36 get { return (IResultParameter<DoubleValue>)Parameters["Crowding"]; } … … 51 47 52 48 public CrowdingAnalyzer() { 53 Parameters.Add(new LookupParameter<DoubleMatrix>("Bounds", 54 "The bounds of the solution given as either one line for all variables or a line for each variable. The first column specifies lower bound, the second upper bound.")); 55 Parameters.Add(new ResultParameter<DoubleValue>("Crowding", "The average corwding value of all points (excluding infinities)")); 49 Parameters.Add(new ResultParameter<DoubleValue>("Crowding", "The average corwding distance of all points (excluding infinities)")); 56 50 CrowdingResultParameter.DefaultValue = new DoubleValue(double.NaN); 57 58 51 } 59 52 60 53 public override IOperation Apply() { 61 54 var qualities = QualitiesParameter.ActualValue; 62 var bounds = BoundsParameter.ActualValue; 63 64 var crowdingDistance = Crowding.Calculate(qualities.Select(x => x.ToArray()), bounds.CloneAsMatrix()); 55 var crowdingDistance = CrowdingCalculator.CalculateCrowding(qualities); 65 56 CrowdingResultParameter.ActualValue.Value = crowdingDistance; 66 67 57 return base.Apply(); 68 58 } -
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/Analyzers/GenerationalDistanceAnalyzer.cs
r15583 r16171 64 64 public override IOperation Apply() { 65 65 var qualities = QualitiesParameter.ActualValue; 66 int objectives = qualities[0].Length; 67 68 var optimalfront = TestFunctionParameter.ActualValue.OptimalParetoFront(objectives); 66 var optimalfront = TestFunctionParameter.ActualValue.OptimalParetoFront(qualities[0].Length); 69 67 if (optimalfront == null) return base.Apply(); 70 71 var distance = GenerationalDistance.Calculate(qualities.Select(x => x.CloneAsArray()), optimalfront, Dampening); 72 GenerationalDistanceResultParameter.ActualValue.Value = distance; 73 68 GenerationalDistanceResultParameter.ActualValue.Value = GenerationalDistanceCalculator.CalculateGenerationalDistance(qualities, optimalfront, Dampening); 74 69 return base.Apply(); 75 70 } -
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/Analyzers/HypervolumeAnalyzer.cs
r15583 r16171 76 76 var qualities = QualitiesParameter.ActualValue; 77 77 var testFunction = TestFunctionParameter.ActualValue; 78 intobjectives = qualities[0].Length;78 var objectives = qualities[0].Length; 79 79 var referencePoint = ReferencePointParameter.ActualValue; 80 80 81 doublebest = BestKnownHypervolumeResultParameter.ActualValue.Value;81 var best = BestKnownHypervolumeResultParameter.ActualValue.Value; 82 82 if (referencePoint.SequenceEqual(testFunction.ReferencePoint(objectives))) { 83 83 best = Math.Max(best, testFunction.OptimalHypervolume(objectives)); 84 84 } 85 85 86 IEnumerable<double[]> front = NonDominatedSelect.SelectNonDominatedVectors(qualities.Select(q => q.ToArray()), testFunction.Maximization(objectives), true); 87 88 double hv = Hypervolume.Calculate(front, referencePoint.ToArray(), testFunction.Maximization(objectives)); 86 var hv = HypervolumeCalculator.CalculateHypervolume(qualities.Select(x=>x.CloneAsArray()).ToArray(), referencePoint.ToArray(), testFunction.Maximization(objectives)); 89 87 90 88 if (hv > best) { -
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/Analyzers/InvertedGenerationalDistanceAnalyzer.cs
r15583 r16171 47 47 } 48 48 49 public InvertedGenerationalDistanceAnalyzer() {50 Parameters.Add(new FixedValueParameter<DoubleValue>("Dampening", "", new DoubleValue(1)));51 Parameters.Add(new ResultParameter<DoubleValue>("Inverted Generational Distance", "The genrational distance between the current front and the optimal front"));52 InvertedGenerationalDistanceResultParameter.DefaultValue = new DoubleValue(double.NaN);53 54 }55 56 57 49 [StorableConstructor] 58 50 protected InvertedGenerationalDistanceAnalyzer(bool deserializing) : base(deserializing) { } … … 62 54 } 63 55 56 public InvertedGenerationalDistanceAnalyzer() { 57 Parameters.Add(new FixedValueParameter<DoubleValue>("Dampening", "", new DoubleValue(1))); 58 Parameters.Add(new ResultParameter<DoubleValue>("Inverted Generational Distance", "The genrational distance between the current front and the optimal front")); 59 InvertedGenerationalDistanceResultParameter.DefaultValue = new DoubleValue(double.NaN); 60 } 61 64 62 public override IOperation Apply() { 65 63 var qualities = QualitiesParameter.ActualValue; 66 var testFunction = TestFunctionParameter.ActualValue; 67 int objectives = qualities[0].Length; 68 69 var optimalfront = testFunction.OptimalParetoFront(objectives); 64 var optimalfront = TestFunctionParameter.ActualValue.OptimalParetoFront(qualities[0].Length); 70 65 if (optimalfront == null) return base.Apply(); 71 72 var invertedGenerationalDistance = InvertedGenerationalDistance.Calculate(qualities.Select(q => q.ToArray()), optimalfront, DampeningParameter.Value.Value); 73 InvertedGenerationalDistanceResultParameter.ActualValue.Value = invertedGenerationalDistance; 74 66 InvertedGenerationalDistanceResultParameter.ActualValue.Value = GenerationalDistanceCalculator.CalculateInverseGenerationalDistance(qualities, optimalfront, Dampening); 75 67 return base.Apply(); 76 68 } 77 78 79 69 } 80 70 } -
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/Analyzers/ScatterPlotAnalyzer.cs
r15583 r16171 59 59 var individuals = IndividualsParameter.ActualValue; 60 60 var testFunction = TestFunctionParameter.ActualValue; 61 intobjectives = qualities[0].Length;62 intproblemSize = individuals[0].Length;61 var objectives = qualities[0].Length; 62 var problemSize = individuals[0].Length; 63 63 64 double[][]optimalFront = new double[0][];64 var optimalFront = new double[0][]; 65 65 var front = testFunction.OptimalParetoFront(objectives); 66 66 if (front != null) optimalFront = front.ToArray(); -
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/Analyzers/SpacingAnalyzer.cs
r15583 r16171 51 51 public override IOperation Apply() { 52 52 var qualities = QualitiesParameter.ActualValue; 53 var spacing = Spacing.Calculate(qualities.Select(q => q.ToArray())); 54 SpacingResultParameter.ActualValue.Value = spacing; 55 53 SpacingResultParameter.ActualValue.Value = SpacingCalculator.CalculateSpacing(qualities); 56 54 return base.Apply(); 57 55 } -
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/HeuristicLab.Problems.TestFunctions.MultiObjective-3.3.csproj
r16123 r16171 17 17 <DebugType>full</DebugType> 18 18 <Optimize>false</Optimize> 19 <OutputPath>..\..\ bin\</OutputPath>19 <OutputPath>..\..\..\..\trunk\bin\</OutputPath> 20 20 <DefineConstants>DEBUG;TRACE</DefineConstants> 21 21 <ErrorReport>prompt</ErrorReport> … … 90 90 <Reference Include="HeuristicLab.Core-3.3"> 91 91 <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Core-3.3.dll</HintPath> 92 </Reference>93 <Reference Include="HeuristicLab.Data-3.3">94 <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Data-3.3.dll</HintPath>95 92 </Reference> 96 93 <Reference Include="HeuristicLab.Encodings.RealVectorEncoding-3.3"> … … 134 131 <Compile Include="Interfaces\IConstrainedTestFunction.cs" /> 135 132 <Compile Include="Interfaces\IMultiObjectiveTestFunctionAnalyzer.cs" /> 136 <Compile Include="Calculators\Crowding.cs" />137 <Compile Include="Calculators\Spacing.cs" />138 <Compile Include="Calculators\HyperVolume.cs" />139 <Compile Include="Calculators\InvertedGenerationalDistance.cs" />140 <Compile Include="Calculators\GenerationalDistance.cs" />141 133 <Compile Include="ParetoFrontScatterPlot.cs" /> 142 134 <Compile Include="Utilities.cs" /> … … 206 198 <Name>HeuristicLab.Analysis-3.3</Name> 207 199 </ProjectReference> 200 <ProjectReference Include="..\..\HeuristicLab.Data\3.3\HeuristicLab.Data-3.3.csproj"> 201 <Project>{bbab9df5-5ef3-4ba8-ade9-b36e82114937}</Project> 202 <Name>HeuristicLab.Data-3.3</Name> 203 </ProjectReference> 208 204 <ProjectReference Include="..\..\HeuristicLab.Optimization\3.3\HeuristicLab.Optimization-3.3.csproj"> 209 205 <Project>{14ab8d24-25bc-400c-a846-4627aa945192}</Project> -
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/MultiObjectiveTestFunctionProblem.cs
r15583 r16171 38 38 39 39 #region Parameter Properties 40 public IValueParameter<BoolArray> MaximizationParameter {40 public new IValueParameter<BoolArray> MaximizationParameter { 41 41 get { return (IValueParameter<BoolArray>)Parameters["Maximization"]; } 42 42 } … … 53 53 get { return (IValueParameter<IMultiObjectiveTestFunction>)Parameters["TestFunction"]; } 54 54 } 55 public IValueParameter<DoubleArray> ReferencePointParameter {56 get { return (IValueParameter<DoubleArray>)Parameters["ReferencePoint"]; }57 }58 public OptionalValueParameter<DoubleMatrix> BestKnownFrontParameter {59 get { return (OptionalValueParameter<DoubleMatrix>)Parameters["BestKnownFront"]; }60 }61 55 62 56 #endregion … … 64 58 #region Properties 65 59 public override bool[] Maximization { 66 get { 67 if (!Parameters.ContainsKey("Maximization")) return new bool[2]; 68 return MaximizationParameter.Value.ToArray(); 69 } 60 get{ return Parameters.ContainsKey(MaximizationParameterName) ? MaximizationParameter.Value.CloneAsArray() : new Fonseca().Maximization(2); } 70 61 } 71 62 … … 85 76 get { return TestFunctionParameter.Value; } 86 77 set { TestFunctionParameter.Value = value; } 87 }88 public DoubleArray ReferencePoint {89 get { return ReferencePointParameter.Value; }90 set { ReferencePointParameter.Value = value; }91 }92 public DoubleMatrix BestKnownFront {93 get { return BestKnownFrontParameter.Value; }94 set { BestKnownFrontParameter.Value = value; }95 78 } 96 79 #endregion … … 116 99 Parameters.Add(new FixedValueParameter<IntValue>("Objectives", "The dimensionality of the solution vector (number of objectives).", new IntValue(2))); 117 100 Parameters.Add(new ValueParameter<DoubleMatrix>("Bounds", "The bounds of the solution given as either one line for all variables or a line for each variable. The first column specifies lower bound, the second upper bound.", new DoubleMatrix(new double[,] { { -4, 4 } }))); 118 Parameters.Add(new ValueParameter<DoubleArray>("ReferencePoint", "The reference point used for hypervolume calculation."));119 101 Parameters.Add(new ValueParameter<IMultiObjectiveTestFunction>("TestFunction", "The function that is to be optimized.", new Fonseca())); 120 Parameters.Add(new OptionalValueParameter<DoubleMatrix>("BestKnownFront", "The currently best known Pareto front"));121 102 122 103 Encoding.LengthParameter = ProblemSizeParameter; … … 138 119 public override void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results, IRandom random) { 139 120 base.Analyze(individuals, qualities, results, random); 140 if (results.ContainsKey("Pareto Front")) {121 if (results.ContainsKey("Pareto Front")) 141 122 ((DoubleMatrix)results["Pareto Front"].Value).SortableView = true; 142 }143 123 } 144 124 … … 170 150 #region Events 171 151 private void UpdateParameterValues() { 172 MaximizationParameter.Value = (BoolArray)new BoolArray(TestFunction.Maximization(Objectives)).AsReadOnly(); 173 152 Parameters.Remove(MaximizationParameterName); 153 Parameters.Add(new FixedValueParameter<BoolArray>(MaximizationParameterName, "Set to false if the problem should be minimized.", (BoolArray)new BoolArray(TestFunction.Maximization(Objectives)).AsReadOnly())); 154 155 Parameters.Remove(BestKnownFrontParameterName); 174 156 var front = TestFunction.OptimalParetoFront(Objectives); 175 if (front != null) { 176 BestKnownFrontParameter.Value = (DoubleMatrix)Utilities.ToMatrix(front).AsReadOnly(); 177 } else BestKnownFrontParameter.Value = null; 178 157 var bkf = front != null ? (DoubleMatrix)Utilities.ToMatrix(front).AsReadOnly() : null; 158 Parameters.Add(new FixedValueParameter<DoubleMatrix>(BestKnownFrontParameterName, "A double matrix representing the best known qualites for this problem (aka points on the Pareto front). Points are to be given in a row-wise fashion.", bkf)); 159 160 Parameters.Remove(ReferencePointParameterName); 161 Parameters.Add(new FixedValueParameter<DoubleArray>(ReferencePointParameterName, "The refrence point for hypervolume calculations on this problem", new DoubleArray(TestFunction.ReferencePoint(Objectives)))); 179 162 180 163 BoundsParameter.Value = new DoubleMatrix(TestFunction.Bounds(Objectives)); 181 ReferencePointParameter.Value = new DoubleArray(TestFunction.ReferencePoint(Objectives));182 164 } 183 165 … … 196 178 ProblemSize = Math.Max(TestFunction.MinimumSolutionLength, Math.Min(ProblemSize, TestFunction.MaximumSolutionLength)); 197 179 Objectives = Math.Max(TestFunction.MinimumObjectives, Math.Min(Objectives, TestFunction.MaximumObjectives)); 198 ReferencePointParameter.ActualValue = new DoubleArray(TestFunction.ReferencePoint(Objectives)); 180 Parameters.Remove(ReferencePointParameterName); 181 Parameters.Add(new FixedValueParameter<DoubleArray>(ReferencePointParameterName, "The refrence point for hypervolume calculations on this problem", new DoubleArray(TestFunction.ReferencePoint(Objectives)))); 199 182 ParameterizeAnalyzers(); 200 183 UpdateParameterValues(); … … 237 220 analyzer.BestKnownFrontParameter.ActualName = BestKnownFrontParameter.Name; 238 221 239 var crowdingAnalyzer = analyzer as CrowdingAnalyzer;240 if (crowdingAnalyzer != null) {241 crowdingAnalyzer.BoundsParameter.ActualName = BoundsParameter.Name;242 }243 244 222 var scatterPlotAnalyzer = analyzer as ScatterPlotAnalyzer; 245 223 if (scatterPlotAnalyzer != null) { -
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/NonDominatedSelect.cs
r15583 r16171 25 25 26 26 public static class NonDominatedSelect { 27 public enum DominationResult { Dominates, IsDominated, IsNonDominated }; 28 29 public static IEnumerable<double[]> SelectNonDominatedVectors(IEnumerable<double[]> qualities, bool[] maximization, bool dominateOnEqualQualities) { 30 31 List<double[]> front = new List<double[]>(); 32 foreach (double[] row in qualities) { 33 bool insert = true; 34 for (int i = 0; i < front.Count; i++) { 35 DominationResult res = Dominates(front[i], row, maximization, dominateOnEqualQualities); 36 if (res == DominationResult.Dominates) { insert = false; break; } //Vector domiates Row 37 else if (res == DominationResult.IsDominated) { //Row dominates Vector 38 front.RemoveAt(i); 39 } 40 } 41 if (insert) { 42 front.Add(row); 43 } 44 } 45 46 return front; 47 } 48 49 public static IEnumerable<double[]> GetDominatingVectors(IEnumerable<double[]> qualities, double[] reference, bool[] maximization, bool dominateOnEqualQualities) { 50 List<double[]> front = new List<double[]>(); 51 foreach (double[] vec in qualities) { 52 if (Dominates(vec, reference, maximization, dominateOnEqualQualities) == DominationResult.Dominates) { 53 front.Add(vec); 54 } 55 } 56 return front; 57 } 58 59 public static DominationResult Dominates(double[] left, double[] right, bool[] maximizations, bool dominateOnEqualQualities) { 60 //mkommend Caution: do not use LINQ.SequenceEqual for comparing the two quality arrays (left and right) due to performance reasons 61 if (dominateOnEqualQualities) { 62 var equal = true; 63 for (int i = 0; i < left.Length; i++) { 64 if (left[i] != right[i]) { 65 equal = false; 66 break; 67 } 68 } 69 if (equal) return DominationResult.Dominates; 70 } 71 72 bool leftIsBetter = false, rightIsBetter = false; 73 for (int i = 0; i < left.Length; i++) { 74 if (IsDominated(left[i], right[i], maximizations[i])) rightIsBetter = true; 75 else if (IsDominated(right[i], left[i], maximizations[i])) leftIsBetter = true; 76 if (leftIsBetter && rightIsBetter) break; 77 } 78 79 if (leftIsBetter && !rightIsBetter) return DominationResult.Dominates; 80 if (!leftIsBetter && rightIsBetter) return DominationResult.IsDominated; 81 return DominationResult.IsNonDominated; 82 } 83 84 private static bool IsDominated(double left, double right, bool maximization) { 85 return maximization && left < right 86 || !maximization && left > right; 87 } 88 27 89 28 } 90 29 } -
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/DTLZ/DTLZ.cs
r15583 r16171 42 42 43 43 protected override double[] GetReferencePoint(int objectives) { 44 double[]rp = new double[objectives];45 for ( inti = 0; i < objectives; i++) {44 var rp = new double[objectives]; 45 for (var i = 0; i < objectives; i++) { 46 46 rp[i] = 11; 47 47 } -
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/DTLZ/DTLZ1.cs
r15583 r16171 48 48 throw new ArgumentException("The dimensionality of the problem(ProblemSize) must be larger than or equal to the number of objectives"); 49 49 } 50 double[]res = new double[objectives];51 intk = r.Length - objectives + 1;50 var res = new double[objectives]; 51 var k = r.Length - objectives + 1; 52 52 double g = 0; 53 53 54 for ( inti = r.Length - k; i < r.Length; i++) {54 for (var i = r.Length - k; i < r.Length; i++) { 55 55 g += (r[i] - 0.5) * (r[i] - 0.5) - Math.Cos(20.0 * Math.PI * (r[i] - 0.5)); 56 56 }; … … 58 58 g *= 100; 59 59 60 for ( inti = 0; i < objectives; i++) {60 for (var i = 0; i < objectives; i++) { 61 61 res[i] = 0.5 * (1.0 + g); 62 for ( intj = 0; j < objectives - i - 1; ++j)62 for (var j = 0; j < objectives - i - 1; ++j) 63 63 res[i] *= (r[j]); 64 64 if (i > 0) -
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/DTLZ/DTLZ2.cs
r15583 r16171 48 48 } 49 49 50 double[]res = new double[objectives];50 var res = new double[objectives]; 51 51 52 52 //calculate g(Xm) 53 53 double g = 0; 54 for ( inti = objectives; i < r.Length; i++) {55 doubled = r[i] - 0.5;54 for (var i = objectives; i < r.Length; i++) { 55 var d = r[i] - 0.5; 56 56 g += d * d; 57 57 } 58 58 59 59 //calculating f0...fM-1 60 for ( inti = 0; i < objectives; i++) {61 doublef = i == 0 ? 1 : (Math.Sin(r[objectives - i - 1] * Math.PI / 2)) * (1 + g);62 for ( intj = 0; j < objectives - i - 1; j++) {60 for (var i = 0; i < objectives; i++) { 61 var f = i == 0 ? 1 : (Math.Sin(r[objectives - i - 1] * Math.PI / 2)) * (1 + g); 62 for (var j = 0; j < objectives - i - 1; j++) { 63 63 f *= Math.Cos(r[j] * Math.PI / 2); 64 64 } -
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/DTLZ/DTLZ3.cs
r15583 r16171 47 47 throw new ArgumentException("The dimensionality of the problem(ProblemSize) must be larger than or equal to the number of objectives"); 48 48 } 49 double[]res = new double[objectives];49 var res = new double[objectives]; 50 50 51 51 //calculate g(Xm) 52 52 double sum = 0; 53 intlength = r.Length - objectives + 1;54 for ( inti = r.Length - length; i < r.Length; i++) {55 doubled = r[i] - 0.5;53 var length = r.Length - objectives + 1; 54 for (var i = r.Length - length; i < r.Length; i++) { 55 var d = r[i] - 0.5; 56 56 sum += d * d - Math.Cos(20 * Math.PI * d); 57 57 } 58 doubleg = 100 * (length + sum);58 var g = 100 * (length + sum); 59 59 60 60 //calculating f0...fM-1 61 for ( inti = 0; i < objectives; i++) {62 doublef = i == 0 ? 1 : (Math.Sin(r[objectives - i - 1] * Math.PI / 2)) * (1 + g);63 for ( intj = 0; j < objectives - i - 1; j++) {61 for (var i = 0; i < objectives; i++) { 62 var f = i == 0 ? 1 : (Math.Sin(r[objectives - i - 1] * Math.PI / 2)) * (1 + g); 63 for (var j = 0; j < objectives - i - 1; j++) { 64 64 f *= Math.Cos(r[j] * Math.PI / 2); 65 65 } -
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/DTLZ/DTLZ4.cs
r15583 r16171 47 47 throw new ArgumentException("The dimensionality of the problem(ProblemSize) must be larger than or equal to the number of objectives"); 48 48 } 49 double[]res = new double[objectives];49 var res = new double[objectives]; 50 50 51 51 //calculate g(Xm) 52 52 double g = 0; 53 for ( inti = objectives; i < r.Length; i++) {54 doubled = r[i] - 0.5;53 for (var i = objectives; i < r.Length; i++) { 54 var d = r[i] - 0.5; 55 55 g += d * d; 56 56 } 57 57 58 58 //calculating f0...fM-1 59 for ( inti = 0; i < objectives; i++) {60 doublef = i == 0 ? 1 : (Math.Sin(Math.Pow(r[objectives - i - 1], 100) * Math.PI / 2)) * (1 + g);61 for ( intj = 0; j < objectives - i - 1; j++) {59 for (var i = 0; i < objectives; i++) { 60 var f = i == 0 ? 1 : (Math.Sin(Math.Pow(r[objectives - i - 1], 100) * Math.PI / 2)) * (1 + g); 61 for (var j = 0; j < objectives - i - 1; j++) { 62 62 f *= Math.Cos(Math.Pow(r[j], 100) * Math.PI / 2); 63 63 } -
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/DTLZ/DTLZ5.cs
r15583 r16171 42 42 throw new ArgumentException("The dimensionality of the problem(ProblemSize) must be larger than or equal to the number of objectives"); 43 43 } 44 double[]res = new double[objectives];44 var res = new double[objectives]; 45 45 46 46 //calculate g(Xm) 47 47 double g = 0; 48 for ( inti = objectives; i < r.Length; i++) {49 doubled = r[i] - 0.5;48 for (var i = objectives; i < r.Length; i++) { 49 var d = r[i] - 0.5; 50 50 g += d * d; 51 51 } … … 56 56 57 57 //calculating f0...fM-1 58 for ( inti = 0; i < objectives; i++) {59 doublef = i == 0 ? 1 : (Math.Sin(phi(r[objectives - i - 1]) * Math.PI / 2)) * (1 + g);60 for ( intj = 0; j < objectives - i - 1; j++) {58 for (var i = 0; i < objectives; i++) { 59 var f = i == 0 ? 1 : (Math.Sin(phi(r[objectives - i - 1]) * Math.PI / 2)) * (1 + g); 60 for (var j = 0; j < objectives - i - 1; j++) { 61 61 f *= Math.Cos(phi(r[j]) * Math.PI / 2); 62 62 } -
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/DTLZ/DTLZ6.cs
r15583 r16171 42 42 throw new ArgumentException("The dimensionality of the problem(ProblemSize) must be larger than or equal to the number of objectives"); 43 43 } 44 double[]res = new double[objectives];44 var res = new double[objectives]; 45 45 46 46 //calculate g(Xm) 47 47 double g = 0; 48 for ( inti = objectives; i < r.Length; i++) {48 for (var i = objectives; i < r.Length; i++) { 49 49 g += Math.Pow(r[i], 0.1); 50 50 } … … 55 55 56 56 //calculating f0...fM-1 57 for ( inti = 0; i < objectives; i++) {58 doublef = i == 0 ? 1 : (Math.Sin(phi(r[objectives - i - 1]) * Math.PI / 2)) * (1 + g);59 for ( intj = 0; j < objectives - i - 1; j++) {57 for (var i = 0; i < objectives; i++) { 58 var f = i == 0 ? 1 : (Math.Sin(phi(r[objectives - i - 1]) * Math.PI / 2)) * (1 + g); 59 for (var j = 0; j < objectives - i - 1; j++) { 60 60 f *= Math.Cos(phi(r[j]) * Math.PI / 2); 61 61 } -
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/DTLZ/DTLZ7.cs
r15583 r16171 47 47 throw new ArgumentException("The dimensionality of the problem(ProblemSize) must be larger than or equal to the number of objectives"); 48 48 } 49 double[]res = new double[objectives];49 var res = new double[objectives]; 50 50 51 51 //calculate g(Xm) 52 52 double g = 0, length = length = r.Length - objectives + 1; 53 for ( inti = objectives; i < r.Length; i++) {53 for (var i = objectives; i < r.Length; i++) { 54 54 g += r[i]; 55 55 } … … 58 58 59 59 //calculating f0...fM-2 60 for ( inti = 0; i < objectives - 1; i++) {60 for (var i = 0; i < objectives - 1; i++) { 61 61 res[i] = r[i]; 62 62 } 63 63 //calculate fM-1 64 64 double h = objectives; 65 for ( inti = 0; i < objectives - 1; i++) {65 for (var i = 0; i < objectives - 1; i++) { 66 66 h -= res[i] / (1 + g) * (1 + Math.Sin(3 * Math.PI * res[i])); 67 67 } -
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/DTLZ/DTLZ8.cs
r15583 r16171 30 30 public class DTLZ8 : DTLZ, IConstrainedTestFunction { 31 31 public static double[] IllegalValue(int size, bool[] maximization) { 32 double[]res = new double[size];33 for ( inti = 0; i < size; i++) {32 var res = new double[size]; 33 for (var i = 0; i < size; i++) { 34 34 res[i] = maximization[i] ? Double.MinValue : Double.MaxValue; 35 35 } … … 49 49 double n = r.Length; 50 50 double M = objectives; 51 doubleratio = n / M;52 double[]res = new double[objectives];53 for ( intj = 0; j < objectives; j++) {51 var ratio = n / M; 52 var res = new double[objectives]; 53 for (var j = 0; j < objectives; j++) { 54 54 double sum = 0; 55 for ( inti = (int)(j * ratio); i < (j + 1) + ratio; i++) {55 for (var i = (int)(j * ratio); i < (j + 1) + ratio; i++) { 56 56 sum += r[i]; 57 57 } … … 59 59 res[j] = sum; 60 60 } 61 for ( intj = 0; j < M - 1; j++) {61 for (var j = 0; j < M - 1; j++) { 62 62 if (res[objectives - 1] + 4 * res[j] - 1 < 0) return IllegalValue(objectives, GetMaximization(objectives)); 63 63 } 64 doublemin = Double.PositiveInfinity;65 for ( inti = 0; i < res.Length - 1; i++) {66 for ( intj = 0; j < i; j++) {67 doubled = res[i] + res[j];64 var min = Double.PositiveInfinity; 65 for (var i = 0; i < res.Length - 1; i++) { 66 for (var j = 0; j < i; j++) { 67 var d = res[i] + res[j]; 68 68 if (min < d) min = d; 69 69 } … … 78 78 double n = r.Length; 79 79 double M = objectives; 80 doubleratio = n / M;81 double[]res = new double[objectives];82 double[]constraints = new double[objectives];83 for ( intj = 0; j < objectives; j++) {80 var ratio = n / M; 81 var res = new double[objectives]; 82 var constraints = new double[objectives]; 83 for (var j = 0; j < objectives; j++) { 84 84 double sum = 0; 85 for ( inti = (int)(j * ratio); i < (j + 1) + ratio; i++) {85 for (var i = (int)(j * ratio); i < (j + 1) + ratio; i++) { 86 86 sum += r[i]; 87 87 } … … 89 89 res[j] = sum; 90 90 } 91 for ( intj = 0; j < M - 1; j++) {92 doubled1 = res[objectives - 1] + 4 * res[j] - 1;91 for (var j = 0; j < M - 1; j++) { 92 var d1 = res[objectives - 1] + 4 * res[j] - 1; 93 93 constraints[j] = d1 < 0 ? -d1 : 0; 94 94 } 95 doublemin = Double.PositiveInfinity;96 for ( inti = 0; i < res.Length - 1; i++) {97 for ( intj = 0; j < i; j++) {98 doubled2 = res[i] + res[j];95 var min = Double.PositiveInfinity; 96 for (var i = 0; i < res.Length - 1; i++) { 97 for (var j = 0; j < i; j++) { 98 var d2 = res[i] + res[j]; 99 99 if (min < d2) min = d2; 100 100 } 101 101 } 102 doubled = 2 * res[objectives - 1] + min - 1;102 var d = 2 * res[objectives - 1] + min - 1; 103 103 constraints[constraints.Length - 1] = d < 0 ? -d : 0; 104 104 return constraints; -
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/IHR/IHR.cs
r15583 r16171 20 20 #endregion 21 21 using System; 22 using System.Linq; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Encodings.RealVectorEncoding; 25 using HeuristicLab.Optimization; 24 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 25 27 … … 36 38 37 39 protected override double[] GetReferencePoint(int objectives) { 38 double[]rp = new double[objectives];39 for ( inti = 0; i < objectives; i++) {40 var rp = new double[objectives]; 41 for (var i = 0; i < objectives; i++) { 40 42 rp[i] = 11; 41 43 } … … 58 60 protected abstract double G(RealVector y); 59 61 62 protected override double GetBestKnownHypervolume(int objectives) { 63 return HypervolumeCalculator.CalculateHypervolume(GetOptimalParetoFront(objectives).ToArray(), GetReferencePoint(objectives), GetMaximization(objectives)); 64 } 60 65 61 66 protected double H(double x, RealVector r) { -
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/IHR/IHR1.cs
r15583 r16171 31 31 public class IHR1 : IHR { 32 32 protected override IEnumerable<double[]> GetOptimalParetoFront(int objectives) { 33 List<double[]>res = new List<double[]>();34 for ( inti = 0; i <= 500; i++) {35 RealVector r = new RealVector(objectives);33 var res = new List<double[]>(); 34 for (var i = 0; i <= 500; i++) { 35 var r = new RealVector(objectives); 36 36 r[0] = 1 / 500.0 * i; 37 37 res.Add(this.Evaluate(r, objectives)); 38 38 } 39 39 return res; 40 }41 42 protected override double GetBestKnownHypervolume(int objectives) {43 return Hypervolume.Calculate(GetOptimalParetoFront(objectives), GetReferencePoint(objectives), GetMaximization(objectives));44 40 } 45 41 … … 64 60 65 61 protected override double G(RealVector y) { 66 doublesum = 0.0;67 for ( inti = 1; i < y.Length; i++) {62 var sum = 0.0; 63 for (var i = 1; i < y.Length; i++) { 68 64 sum += HG(y[i]); 69 65 } -
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/IHR/IHR2.cs
r15583 r16171 31 31 public class IHR2 : IHR { 32 32 protected override IEnumerable<double[]> GetOptimalParetoFront(int objectives) { 33 List<double[]>res = new List<double[]>();34 for ( inti = 0; i <= 500; i++) {35 RealVector r = new RealVector(objectives);33 var res = new List<double[]>(); 34 for (var i = 0; i <= 500; i++) { 35 var r = new RealVector(objectives); 36 36 r[0] = 1 / 500.0 * i; 37 37 … … 39 39 } 40 40 return res; 41 }42 43 protected override double GetBestKnownHypervolume(int objectives) {44 return Hypervolume.Calculate(GetOptimalParetoFront(objectives), GetReferencePoint(objectives), GetMaximization(objectives));45 41 } 46 42 … … 66 62 67 63 protected override double G(RealVector y) { 68 doublesum = 0.0;69 for ( inti = 1; i < y.Length; i++) {64 var sum = 0.0; 65 for (var i = 1; i < y.Length; i++) { 70 66 sum += HG(y[i]); 71 67 } -
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/IHR/IHR3.cs
r15583 r16171 21 21 using System; 22 22 using System.Collections.Generic; 23 using System.Linq; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; … … 31 32 public class IHR3 : IHR { 32 33 protected override IEnumerable<double[]> GetOptimalParetoFront(int objectives) { 33 List<double[]>res = new List<double[]>();34 for ( inti = 0; i <= 500; i++) {35 RealVector r = new RealVector(objectives);34 var res = new List<double[]>(); 35 for (var i = 0; i <= 500; i++) { 36 var r = new RealVector(objectives); 36 37 r[0] = 1 / 500.0 * i; 37 38 … … 39 40 } 40 41 return res; 41 }42 43 protected override double GetBestKnownHypervolume(int objectives) {44 return Hypervolume.Calculate(GetOptimalParetoFront(objectives), GetReferencePoint(objectives), GetMaximization(objectives));45 42 } 46 43 … … 66 63 67 64 protected override double G(RealVector y) { 68 doublesum = 0.0;69 for ( inti = 1; i < y.Length; i++) {65 var sum = 0.0; 66 for (var i = 1; i < y.Length; i++) { 70 67 sum += HG(y[i]); 71 68 } -
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/IHR/IHR4.cs
r15583 r16171 21 21 using System; 22 22 using System.Collections.Generic; 23 using System.Linq; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; … … 31 32 public class IHR4 : IHR { 32 33 protected override IEnumerable<double[]> GetOptimalParetoFront(int objectives) { 33 List<double[]>res = new List<double[]>();34 for ( inti = 0; i <= 500; i++) {35 RealVector r = new RealVector(objectives);34 var res = new List<double[]>(); 35 for (var i = 0; i <= 500; i++) { 36 var r = new RealVector(objectives); 36 37 r[0] = 1 / 500.0 * i; 37 38 res.Add(this.Evaluate(r, objectives)); 38 39 } 39 40 return res; 40 }41 42 protected override double GetBestKnownHypervolume(int objectives) {43 return Hypervolume.Calculate(GetOptimalParetoFront(objectives), GetReferencePoint(objectives), GetMaximization(objectives));44 41 } 45 42 … … 69 66 70 67 protected override double G(RealVector y) { 71 doublesum = 0.0;72 for ( inti = 1; i < y.Length; i++) {68 var sum = 0.0; 69 for (var i = 1; i < y.Length; i++) { 73 70 sum += y[i] * y[i] - 10 * Math.Cos(4 * Math.PI * y[i]); 74 71 } -
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/IHR/IHR6.cs
r15583 r16171 21 21 using System; 22 22 using System.Collections.Generic; 23 using System.Linq; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; … … 31 32 public class IHR6 : IHR { 32 33 protected override IEnumerable<double[]> GetOptimalParetoFront(int objectives) { 33 List<double[]>res = new List<double[]>();34 for ( inti = 0; i <= 500; i++) {35 RealVector r = new RealVector(objectives);34 var res = new List<double[]>(); 35 for (var i = 0; i <= 500; i++) { 36 var r = new RealVector(objectives); 36 37 r[0] = 1 / 500.0 * i; 37 38 res.Add(this.Evaluate(r, objectives)); 38 39 } 39 40 return res; 40 }41 42 protected override double GetBestKnownHypervolume(int objectives) {43 return Hypervolume.Calculate(GetOptimalParetoFront(objectives), GetReferencePoint(objectives), GetMaximization(objectives));44 41 } 45 42 … … 65 62 66 63 protected override double G(RealVector y) { 67 doublesum = 0.0;68 for ( inti = 1; i < y.Length; i++) {64 var sum = 0.0; 65 for (var i = 1; i < y.Length; i++) { 69 66 sum += HG(y[i]); 70 67 } -
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/Misc/CIGTAB.cs
r15583 r16171 21 21 using System; 22 22 using System.Collections.Generic; 23 using System.Linq; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; 25 26 using HeuristicLab.Encodings.RealVectorEncoding; 27 using HeuristicLab.Optimization; 26 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 29 … … 43 45 44 46 protected override IEnumerable<double[]> GetOptimalParetoFront(int objecitves) { 45 List<double[]>res = new List<double[]>();46 for ( inti = 0; i <= 500; i++) {47 RealVector r = new RealVector(2);47 var res = new List<double[]>(); 48 for (var i = 0; i <= 500; i++) { 49 var r = new RealVector(2); 48 50 r[0] = 2 / 500.0 * i; 49 51 r[1] = 2 / 500.0 * i; … … 54 56 55 57 protected override double GetBestKnownHypervolume(int objectives) { 56 return Hypervolume .Calculate(GetOptimalParetoFront(objectives), GetReferencePoint(objectives), GetMaximization(objectives));58 return HypervolumeCalculator.CalculateHypervolume(GetOptimalParetoFront(objectives).ToArray(), GetReferencePoint(objectives), GetMaximization(objectives)); 57 59 } 58 60 … … 68 70 public override double[] Evaluate(RealVector r, int objectives) { 69 71 if (objectives != 2) throw new ArgumentException("The CIGTAB problem must always have 2 objectives"); 70 doublex = r[0];72 var x = r[0]; 71 73 double a = 1000; 72 doublesum = x * x;73 for ( inti = 1; i < r.Length - 1; i++) {74 var sum = x * x; 75 for (var i = 1; i < r.Length - 1; i++) { 74 76 sum += a * r[i] * r[i]; 75 77 } … … 77 79 78 80 //objective1 79 doublef0 = 1 / (a * a * r.Length) * sum;81 var f0 = 1 / (a * a * r.Length) * sum; 80 82 81 83 x = x - 2; 82 84 sum = x * x; 83 for ( inti = 1; i < r.Length - 1; i++) {85 for (var i = 1; i < r.Length - 1; i++) { 84 86 sum += a * (r[i] - 2) * (r[i] - 2); 85 87 } … … 87 89 sum += a * a * (r[r.Length - 1] - 2) * (r[r.Length - 1] - 2); 88 90 //objective0 89 doublef1 = 1 / (a * a * r.Length) * sum;91 var f1 = 1 / (a * a * r.Length) * sum; 90 92 91 93 return new double[] { f0, f1 }; -
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/Misc/ELLI1.cs
r15583 r16171 21 21 using System; 22 22 using System.Collections.Generic; 23 using System.Linq; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; 25 26 using HeuristicLab.Encodings.RealVectorEncoding; 27 using HeuristicLab.Optimization; 26 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 29 … … 43 45 44 46 protected override IEnumerable<double[]> GetOptimalParetoFront(int objecitves) { 45 List<double[]>res = new List<double[]>();46 for ( inti = 0; i <= 500; i++) {47 RealVector r = new RealVector(2);47 var res = new List<double[]>(); 48 for (var i = 0; i <= 500; i++) { 49 var r = new RealVector(2); 48 50 r[0] = 2 / 500.0 * i; 49 51 r[1] = 2 / 500.0 * i; … … 54 56 55 57 protected override double GetBestKnownHypervolume(int objectives) { 56 return Hypervolume .Calculate(GetOptimalParetoFront(objectives), GetReferencePoint(objectives), GetMaximization(objectives));58 return HypervolumeCalculator.CalculateHypervolume(GetOptimalParetoFront(objectives).ToArray(), GetReferencePoint(objectives), GetMaximization(objectives)); 57 59 } 58 60 … … 69 71 if (objectives != 2) throw new ArgumentException("The ELLI problem must always have 2 objectives"); 70 72 double a = 1000; 71 doublesum = 0.0;72 for ( inti = 0; i < r.Length; i++) {73 var sum = 0.0; 74 for (var i = 0; i < r.Length; i++) { 73 75 sum += Math.Pow(a, 2 * i / (r.Length - 1)) * r[i] * r[i]; 74 76 } 75 77 76 78 //objective1 77 doublef0 = 1 / (a * a * r.Length) * sum;79 var f0 = 1 / (a * a * r.Length) * sum; 78 80 79 81 sum = 0.0; 80 for ( inti = 0; i < r.Length; i++) {82 for (var i = 0; i < r.Length; i++) { 81 83 sum += Math.Pow(a, 2 * i / (r.Length - 1)) * (r[i] - 2) * (r[i] - 2); 82 84 } 83 85 //objective0 84 doublef1 = 1 / (a * a * r.Length) * sum;86 var f1 = 1 / (a * a * r.Length) * sum; 85 87 86 88 return new double[] { f0, f1 }; -
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/Misc/Fonseca.cs
r15583 r16171 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Linq; 24 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Core; 26 27 using HeuristicLab.Encodings.RealVectorEncoding; 28 using HeuristicLab.Optimization; 27 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 30 … … 44 46 45 47 protected override double GetBestKnownHypervolume(int objectives) { 46 return Hypervolume .Calculate(GetOptimalParetoFront(objectives), GetReferencePoint(objectives), GetMaximization(objectives));48 return HypervolumeCalculator.CalculateHypervolume(GetOptimalParetoFront(objectives).ToArray(), GetReferencePoint(objectives), GetMaximization(objectives)); 47 49 } 48 50 … … 65 67 66 68 //objective1 67 for ( inti = 0; i < r.Length; i++) {68 doubled = r[i] - aux;69 for (var i = 0; i < r.Length; i++) { 70 var d = r[i] - aux; 69 71 f0 += d * d; 70 72 } … … 72 74 73 75 //objective2 74 doublef1 = 0.0;75 for ( inti = 0; i < r.Length; i++) {76 doubled = r[i] + aux;76 var f1 = 0.0; 77 for (var i = 0; i < r.Length; i++) { 78 var d = r[i] + aux; 77 79 f1 += d * d; 78 80 } -
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/Misc/Kursawe.cs
r15583 r16171 21 21 using System; 22 22 using System.Collections.Generic; 23 using System.Linq; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; 25 26 using HeuristicLab.Encodings.RealVectorEncoding; 27 using HeuristicLab.Optimization; 26 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 29 … … 43 45 44 46 protected override double GetBestKnownHypervolume(int objectives) { 45 return Hypervolume .Calculate(GetOptimalParetoFront(objectives), GetReferencePoint(objectives), GetMaximization(objectives));47 return HypervolumeCalculator.CalculateHypervolume(GetOptimalParetoFront(objectives).ToArray(), GetReferencePoint(objectives), GetMaximization(objectives)); 46 48 } 47 49 … … 65 67 if (objectives != 2) throw new ArgumentException("The Kursawe problem must always have 2 objectives"); 66 68 //objective 1 67 doublef0 = 0.0;68 for ( inti = 0; i < r.Length - 1; i++) {69 var f0 = 0.0; 70 for (var i = 0; i < r.Length - 1; i++) { 69 71 f0 += -10 * Math.Exp(-0.2 * Math.Sqrt(r[i] * r[i] + r[i + 1] * r[i + 1])); 70 72 } 71 73 //objective2 72 doublef1 = 0.0;73 for ( inti = 0; i < r.Length; i++) {74 var f1 = 0.0; 75 for (var i = 0; i < r.Length; i++) { 74 76 f1 += Math.Pow(Math.Abs(r[i]), 0.8) + 5 * Math.Sin(Math.Pow(r[i], 3)); 75 77 } -
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/Misc/SchafferN1.cs
r15583 r16171 21 21 using System; 22 22 using System.Collections.Generic; 23 using System.Linq; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; 25 26 using HeuristicLab.Encodings.RealVectorEncoding; 27 using HeuristicLab.Optimization; 26 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 29 … … 48 50 49 51 protected override double GetBestKnownHypervolume(int objectives) { 50 return Hypervolume .Calculate(GetOptimalParetoFront(objectives), GetReferencePoint(objectives), GetMaximization(objectives));52 return HypervolumeCalculator.CalculateHypervolume(GetOptimalParetoFront(objectives).ToArray(), GetReferencePoint(objectives), GetMaximization(objectives)); 51 53 } 52 54 … … 63 65 if (objectives != 2) throw new ArgumentException("The Schaffer N1 problem must always have 2 objectives"); 64 66 if (r.Length != 1) return null; 65 doublex = r[0];67 var x = r[0]; 66 68 67 69 //objective1 68 doublef0 = x * x;70 var f0 = x * x; 69 71 70 72 //objective0 71 doublef1 = x - 2;73 var f1 = x - 2; 72 74 f1 *= f1; 73 75 -
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/Misc/SchafferN2.cs
r15583 r16171 59 59 public override double[] Evaluate(RealVector r, int objectives) { 60 60 if (objectives != 2) throw new ArgumentException("The Schaffer N1 problem must always have 2 objectives"); 61 doublex = r[0];61 var x = r[0]; 62 62 63 63 //objective1 … … 69 69 70 70 //objective0 71 doublef1 = x - 5;71 var f1 = x - 5; 72 72 f1 *= f1; 73 73 -
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/ParetoFrontStore.cs
r15583 r16171 29 29 internal class ParetoFrontStore { 30 30 internal static IEnumerable<double[]> GetParetoFront(String filename) { 31 List<double[]>data = new List<double[]>();31 var data = new List<double[]>(); 32 32 var assembly = Assembly.GetExecutingAssembly(); 33 Stringressourcename = typeof(ParetoFrontStore).Namespace + ".TestFunctions." + filename + ".pf";33 var ressourcename = typeof(ParetoFrontStore).Namespace + ".TestFunctions." + filename + ".pf"; 34 34 35 35 //check if file is listed … … 42 42 while ((s = ressourceReader.ReadLine()) != null) { 43 43 var tokens = s.Split(new char[0], StringSplitOptions.RemoveEmptyEntries); 44 double[]point = new double[tokens.Length];45 for ( inti = 0; i < point.Length; i++) {44 var point = new double[tokens.Length]; 45 for (var i = 0; i < point.Length; i++) { 46 46 point[i] = Double.Parse(tokens[i], CultureInfo.InvariantCulture); 47 47 } -
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/ZDT/ZDT1.cs
r15583 r16171 44 44 public override double[] Evaluate(RealVector r) { 45 45 double g = 0; 46 for ( inti = 1; i < r.Length; i++) g += r[i];46 for (var i = 1; i < r.Length; i++) g += r[i]; 47 47 g = 1.0 + 9.0 * g / (r.Length - 1); 48 doublef0 = r[0];49 doublef1 = g * (1.0 - Math.Sqrt(r[0] / g));48 var f0 = r[0]; 49 var f1 = g * (1.0 - Math.Sqrt(r[0] / g)); 50 50 return new double[] { f0, f1 }; 51 51 } -
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/ZDT/ZDT2.cs
r15583 r16171 42 42 public override double[] Evaluate(RealVector r) { 43 43 double g = 0; 44 for ( inti = 1; i < r.Length; i++) g += r[i];44 for (var i = 1; i < r.Length; i++) g += r[i]; 45 45 g = 1.0 + 9.0 * g / (r.Length - 1); 46 doubled = r[0] / g;47 doublef0 = r[0];48 doublef1 = g * (1.0 - d * d);46 var d = r[0] / g; 47 var f0 = r[0]; 48 var f1 = g * (1.0 - d * d); 49 49 return new double[] { f0, f1 }; 50 50 } -
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/ZDT/ZDT3.cs
r15583 r16171 44 44 public override double[] Evaluate(RealVector r) { 45 45 double g = 0; 46 for ( inti = 1; i < r.Length; i++) g += r[i];46 for (var i = 1; i < r.Length; i++) g += r[i]; 47 47 g = 1.0 + 9.0 * g / (r.Length - 1); 48 doubled = r[0] / g;49 doublef0 = r[0];50 doublef1 = g * (1.0 - Math.Sqrt(d) - d * Math.Sin(10 * Math.PI * r[0]));48 var d = r[0] / g; 49 var f0 = r[0]; 50 var f1 = g * (1.0 - Math.Sqrt(d) - d * Math.Sin(10 * Math.PI * r[0])); 51 51 return new double[] { f0, f1 }; 52 52 } -
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/ZDT/ZDT4.cs
r15583 r16171 30 30 public class ZDT4 : ZDT { 31 31 protected override double[,] GetBounds(int objectives) { 32 double[,]bounds = new double[objectives, 2];32 var bounds = new double[objectives, 2]; 33 33 bounds[0, 0] = 0; bounds[0, 1] = 1; 34 for ( inti = 1; i < objectives; i++) {34 for (var i = 1; i < objectives; i++) { 35 35 bounds[i, 0] = -5; 36 36 bounds[i, 1] = 5; … … 53 53 public override double[] Evaluate(RealVector r) { 54 54 double g = 0; 55 for ( inti = 1; i < r.Length; i++) {56 doublev = r[i];55 for (var i = 1; i < r.Length; i++) { 56 var v = r[i]; 57 57 g += v * v - 10 * Math.Cos(4 * Math.PI * v); 58 58 } 59 59 g = 1.0 + 10.0 * (r.Length - 1) + g; 60 doubled = r[0] / g;61 doublef0 = r[0];62 doublef1 = 1 - Math.Sqrt(d);60 var d = r[0] / g; 61 var f0 = r[0]; 62 var f1 = 1 - Math.Sqrt(d); 63 63 return new double[] { f0, f1 }; 64 64 } -
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/ZDT/ZDT6.cs
r15583 r16171 43 43 public override double[] Evaluate(RealVector r) { 44 44 double g = 0; 45 for ( inti = 1; i < r.Length; i++) g += r[i];45 for (var i = 1; i < r.Length; i++) g += r[i]; 46 46 g = 1.0 + 9.0 * Math.Pow(g / (r.Length - 1), 0.25); 47 doublef1 = 1 - Math.Exp(-4 * r[0]) * Math.Pow(Math.Sin(6 * Math.PI * r[0]), 6);48 doubled = f1 / g;49 doublef2 = g * (1.0 - d * d);47 var f1 = 1 - Math.Exp(-4 * r[0]) * Math.Pow(Math.Sin(6 * Math.PI * r[0]), 6); 48 var d = f1 / g; 49 var f2 = g * (1.0 - d * d); 50 50 return new double[] { f1, f2 }; 51 51 } -
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/Utilities.cs
r15583 r16171 26 26 namespace HeuristicLab.Problems.TestFunctions.MultiObjective { 27 27 internal static class Utilities { 28 internal static double MinimumDistance(double[] point, IEnumerable<double[]> points) {29 if (point == null) throw new ArgumentNullException("Point must not be null.");30 if (points == null) throw new ArgumentNullException("Points must not be null.");31 if (!points.Any()) throw new ArgumentException("Points must not be empty.");32 33 double minDistance = double.MaxValue;34 foreach (double[] r in points) {35 if (r.Length != point.Length) throw new ArgumentException("Dimensions of Points and Point do not match.");36 37 double squaredDistance = 0;38 for (int i = 0; i < r.Length; i++) {39 squaredDistance += (point[i] - r[i]) * (point[i] - r[i]);40 }41 minDistance = Math.Min(squaredDistance, minDistance);42 }43 44 return Math.Sqrt(minDistance);45 }46 47 28 internal static DoubleMatrix ToMatrix(IEnumerable<double[]> source) { 48 29 try { 49 intfirstDimension = source.Count();50 intsecondDimension = source.GroupBy(row => row.Length).Single().Key; // throws InvalidOperationException if source is not rectangular30 var firstDimension = source.Count(); 31 var secondDimension = source.GroupBy(row => row.Length).Single().Key; // throws InvalidOperationException if source is not rectangular 51 32 52 33 var result = new DoubleMatrix(firstDimension, secondDimension); 53 34 var enumarator = source.GetEnumerator(); 54 for ( inti = 0; i < firstDimension && enumarator.MoveNext(); ++i)55 for ( intj = 0; j < secondDimension; ++j)35 for (var i = 0; i < firstDimension && enumarator.MoveNext(); ++i) 36 for (var j = 0; j < secondDimension; ++j) 56 37 result[i, j] = enumarator.Current[j]; 57 38 return result; … … 62 43 } 63 44 64 internal class DimensionComparer : IComparer<double[]> { 65 private readonly int dim; 66 private readonly int descending; 67 68 public DimensionComparer(int dimension, bool descending) { 69 this.dim = dimension; 70 this.descending = descending ? -1 : 1; 71 } 72 73 public int Compare(double[] x, double[] y) { 74 if (x[dim] < y[dim]) return -descending; 75 else if (x[dim] > y[dim]) return descending; 76 else return 0; 77 } 78 } 45 79 46 } 80 47 }
Note: See TracChangeset
for help on using the changeset viewer.