Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/21/18 09:18:49 (6 years ago)
Author:
bwerth
Message:

#2943 worked on MOBasicProblem - added Interfaces;reworked MOCalculators; several minor changes

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  
    3333  public class CrowdingAnalyzer : MOTFAnalyzer {
    3434
    35     public ILookupParameter<DoubleMatrix> BoundsParameter {
    36       get { return (ILookupParameter<DoubleMatrix>)Parameters["Bounds"]; }
    37     }
    38 
    3935    public IResultParameter<DoubleValue> CrowdingResultParameter {
    4036      get { return (IResultParameter<DoubleValue>)Parameters["Crowding"]; }
     
    5147
    5248    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)"));
    5650      CrowdingResultParameter.DefaultValue = new DoubleValue(double.NaN);
    57 
    5851    }
    5952
    6053    public override IOperation Apply() {
    6154      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);
    6556      CrowdingResultParameter.ActualValue.Value = crowdingDistance;
    66 
    6757      return base.Apply();
    6858    }
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/Analyzers/GenerationalDistanceAnalyzer.cs

    r15583 r16171  
    6464    public override IOperation Apply() {
    6565      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);
    6967      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);
    7469      return base.Apply();
    7570    }
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/Analyzers/HypervolumeAnalyzer.cs

    r15583 r16171  
    7676      var qualities = QualitiesParameter.ActualValue;
    7777      var testFunction = TestFunctionParameter.ActualValue;
    78       int objectives = qualities[0].Length;
     78      var objectives = qualities[0].Length;
    7979      var referencePoint = ReferencePointParameter.ActualValue;
    8080
    81       double best = BestKnownHypervolumeResultParameter.ActualValue.Value;
     81      var best = BestKnownHypervolumeResultParameter.ActualValue.Value;
    8282      if (referencePoint.SequenceEqual(testFunction.ReferencePoint(objectives))) {
    8383        best = Math.Max(best, testFunction.OptimalHypervolume(objectives));
    8484      }
    8585
    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));
    8987
    9088      if (hv > best) {
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/Analyzers/InvertedGenerationalDistanceAnalyzer.cs

    r15583 r16171  
    4747    }
    4848
    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 
    5749    [StorableConstructor]
    5850    protected InvertedGenerationalDistanceAnalyzer(bool deserializing) : base(deserializing) { }
     
    6254    }
    6355
     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
    6462    public override IOperation Apply() {
    6563      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);
    7065      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);
    7567      return base.Apply();
    7668    }
    77 
    78 
    7969  }
    8070}
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/Analyzers/ScatterPlotAnalyzer.cs

    r15583 r16171  
    5959      var individuals = IndividualsParameter.ActualValue;
    6060      var testFunction = TestFunctionParameter.ActualValue;
    61       int objectives = qualities[0].Length;
    62       int problemSize = individuals[0].Length;
     61      var objectives = qualities[0].Length;
     62      var problemSize = individuals[0].Length;
    6363
    64       double[][] optimalFront = new double[0][];
     64      var optimalFront = new double[0][];
    6565      var front = testFunction.OptimalParetoFront(objectives);
    6666      if (front != null) optimalFront = front.ToArray();
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/Analyzers/SpacingAnalyzer.cs

    r15583 r16171  
    5151    public override IOperation Apply() {
    5252      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);
    5654      return base.Apply();
    5755    }
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/HeuristicLab.Problems.TestFunctions.MultiObjective-3.3.csproj

    r16123 r16171  
    1717    <DebugType>full</DebugType>
    1818    <Optimize>false</Optimize>
    19     <OutputPath>..\..\bin\</OutputPath>
     19    <OutputPath>..\..\..\..\trunk\bin\</OutputPath>
    2020    <DefineConstants>DEBUG;TRACE</DefineConstants>
    2121    <ErrorReport>prompt</ErrorReport>
     
    9090    <Reference Include="HeuristicLab.Core-3.3">
    9191      <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>
    9592    </Reference>
    9693    <Reference Include="HeuristicLab.Encodings.RealVectorEncoding-3.3">
     
    134131    <Compile Include="Interfaces\IConstrainedTestFunction.cs" />
    135132    <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" />
    141133    <Compile Include="ParetoFrontScatterPlot.cs" />
    142134    <Compile Include="Utilities.cs" />
     
    206198      <Name>HeuristicLab.Analysis-3.3</Name>
    207199    </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>
    208204    <ProjectReference Include="..\..\HeuristicLab.Optimization\3.3\HeuristicLab.Optimization-3.3.csproj">
    209205      <Project>{14ab8d24-25bc-400c-a846-4627aa945192}</Project>
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/MultiObjectiveTestFunctionProblem.cs

    r15583 r16171  
    3838
    3939    #region Parameter Properties
    40     public IValueParameter<BoolArray> MaximizationParameter {
     40    public new IValueParameter<BoolArray> MaximizationParameter {
    4141      get { return (IValueParameter<BoolArray>)Parameters["Maximization"]; }
    4242    }
     
    5353      get { return (IValueParameter<IMultiObjectiveTestFunction>)Parameters["TestFunction"]; }
    5454    }
    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     }
    6155
    6256    #endregion
     
    6458    #region Properties
    6559    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); }
    7061    }
    7162
     
    8576      get { return TestFunctionParameter.Value; }
    8677      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; }
    9578    }
    9679    #endregion
     
    11699      Parameters.Add(new FixedValueParameter<IntValue>("Objectives", "The dimensionality of the solution vector (number of objectives).", new IntValue(2)));
    117100      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."));
    119101      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"));
    121102
    122103      Encoding.LengthParameter = ProblemSizeParameter;
     
    138119    public override void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results, IRandom random) {
    139120      base.Analyze(individuals, qualities, results, random);
    140       if (results.ContainsKey("Pareto Front")) {
     121      if (results.ContainsKey("Pareto Front"))
    141122        ((DoubleMatrix)results["Pareto Front"].Value).SortableView = true;
    142       }
    143123    }
    144124
     
    170150    #region Events
    171151    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);
    174156      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))));
    179162
    180163      BoundsParameter.Value = new DoubleMatrix(TestFunction.Bounds(Objectives));
    181       ReferencePointParameter.Value = new DoubleArray(TestFunction.ReferencePoint(Objectives));
    182164    }
    183165
     
    196178      ProblemSize = Math.Max(TestFunction.MinimumSolutionLength, Math.Min(ProblemSize, TestFunction.MaximumSolutionLength));
    197179      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))));
    199182      ParameterizeAnalyzers();
    200183      UpdateParameterValues();
     
    237220        analyzer.BestKnownFrontParameter.ActualName = BestKnownFrontParameter.Name;
    238221
    239         var crowdingAnalyzer = analyzer as CrowdingAnalyzer;
    240         if (crowdingAnalyzer != null) {
    241           crowdingAnalyzer.BoundsParameter.ActualName = BoundsParameter.Name;
    242         }
    243 
    244222        var scatterPlotAnalyzer = analyzer as ScatterPlotAnalyzer;
    245223        if (scatterPlotAnalyzer != null) {
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/NonDominatedSelect.cs

    r15583 r16171  
    2525
    2626  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   
    8928  }
    9029}
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/DTLZ/DTLZ.cs

    r15583 r16171  
    4242
    4343    protected override double[] GetReferencePoint(int objectives) {
    44       double[] rp = new double[objectives];
    45       for (int i = 0; i < objectives; i++) {
     44      var rp = new double[objectives];
     45      for (var i = 0; i < objectives; i++) {
    4646        rp[i] = 11;
    4747      }
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/DTLZ/DTLZ1.cs

    r15583 r16171  
    4848        throw new ArgumentException("The dimensionality of the problem(ProblemSize) must be larger than or equal to the number of objectives");
    4949      }
    50       double[] res = new double[objectives];
    51       int k = r.Length - objectives + 1;
     50      var res = new double[objectives];
     51      var k = r.Length - objectives + 1;
    5252      double g = 0;
    5353
    54       for (int i = r.Length - k; i < r.Length; i++) {
     54      for (var i = r.Length - k; i < r.Length; i++) {
    5555        g += (r[i] - 0.5) * (r[i] - 0.5) - Math.Cos(20.0 * Math.PI * (r[i] - 0.5));
    5656      };
     
    5858      g *= 100;
    5959
    60       for (int i = 0; i < objectives; i++) {
     60      for (var i = 0; i < objectives; i++) {
    6161        res[i] = 0.5 * (1.0 + g);
    62         for (int j = 0; j < objectives - i - 1; ++j)
     62        for (var j = 0; j < objectives - i - 1; ++j)
    6363          res[i] *= (r[j]);
    6464        if (i > 0)
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/DTLZ/DTLZ2.cs

    r15583 r16171  
    4848      }
    4949
    50       double[] res = new double[objectives];
     50      var res = new double[objectives];
    5151
    5252      //calculate g(Xm)
    5353      double g = 0;
    54       for (int i = objectives; i < r.Length; i++) {
    55         double d = r[i] - 0.5;
     54      for (var i = objectives; i < r.Length; i++) {
     55        var d = r[i] - 0.5;
    5656        g += d * d;
    5757      }
    5858
    5959      //calculating f0...fM-1
    60       for (int i = 0; i < objectives; i++) {
    61         double f = i == 0 ? 1 : (Math.Sin(r[objectives - i - 1] * Math.PI / 2)) * (1 + g);
    62         for (int j = 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++) {
    6363          f *= Math.Cos(r[j] * Math.PI / 2);
    6464        }
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/DTLZ/DTLZ3.cs

    r15583 r16171  
    4747        throw new ArgumentException("The dimensionality of the problem(ProblemSize) must be larger than or equal to the number of objectives");
    4848      }
    49       double[] res = new double[objectives];
     49      var res = new double[objectives];
    5050
    5151      //calculate g(Xm)
    5252      double sum = 0;
    53       int length = r.Length - objectives + 1;
    54       for (int i = r.Length - length; i < r.Length; i++) {
    55         double d = 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;
    5656        sum += d * d - Math.Cos(20 * Math.PI * d);
    5757      }
    58       double g = 100 * (length + sum);
     58      var g = 100 * (length + sum);
    5959
    6060      //calculating f0...fM-1
    61       for (int i = 0; i < objectives; i++) {
    62         double f = i == 0 ? 1 : (Math.Sin(r[objectives - i - 1] * Math.PI / 2)) * (1 + g);
    63         for (int j = 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++) {
    6464          f *= Math.Cos(r[j] * Math.PI / 2);
    6565        }
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/DTLZ/DTLZ4.cs

    r15583 r16171  
    4747        throw new ArgumentException("The dimensionality of the problem(ProblemSize) must be larger than or equal to the number of objectives");
    4848      }
    49       double[] res = new double[objectives];
     49      var res = new double[objectives];
    5050
    5151      //calculate g(Xm)
    5252      double g = 0;
    53       for (int i = objectives; i < r.Length; i++) {
    54         double d = r[i] - 0.5;
     53      for (var i = objectives; i < r.Length; i++) {
     54        var d = r[i] - 0.5;
    5555        g += d * d;
    5656      }
    5757
    5858      //calculating f0...fM-1
    59       for (int i = 0; i < objectives; i++) {
    60         double f = i == 0 ? 1 : (Math.Sin(Math.Pow(r[objectives - i - 1], 100) * Math.PI / 2)) * (1 + g);
    61         for (int j = 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++) {
    6262          f *= Math.Cos(Math.Pow(r[j], 100) * Math.PI / 2);
    6363        }
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/DTLZ/DTLZ5.cs

    r15583 r16171  
    4242        throw new ArgumentException("The dimensionality of the problem(ProblemSize) must be larger than or equal to the number of objectives");
    4343      }
    44       double[] res = new double[objectives];
     44      var res = new double[objectives];
    4545
    4646      //calculate g(Xm)
    4747      double g = 0;
    48       for (int i = objectives; i < r.Length; i++) {
    49         double d = r[i] - 0.5;
     48      for (var i = objectives; i < r.Length; i++) {
     49        var d = r[i] - 0.5;
    5050        g += d * d;
    5151      }
     
    5656
    5757      //calculating f0...fM-1
    58       for (int i = 0; i < objectives; i++) {
    59         double f = i == 0 ? 1 : (Math.Sin(phi(r[objectives - i - 1]) * Math.PI / 2)) * (1 + g);
    60         for (int j = 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++) {
    6161          f *= Math.Cos(phi(r[j]) * Math.PI / 2);
    6262        }
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/DTLZ/DTLZ6.cs

    r15583 r16171  
    4242        throw new ArgumentException("The dimensionality of the problem(ProblemSize) must be larger than or equal to the number of objectives");
    4343      }
    44       double[] res = new double[objectives];
     44      var res = new double[objectives];
    4545
    4646      //calculate g(Xm)
    4747      double g = 0;
    48       for (int i = objectives; i < r.Length; i++) {
     48      for (var i = objectives; i < r.Length; i++) {
    4949        g += Math.Pow(r[i], 0.1);
    5050      }
     
    5555
    5656      //calculating f0...fM-1
    57       for (int i = 0; i < objectives; i++) {
    58         double f = i == 0 ? 1 : (Math.Sin(phi(r[objectives - i - 1]) * Math.PI / 2)) * (1 + g);
    59         for (int j = 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++) {
    6060          f *= Math.Cos(phi(r[j]) * Math.PI / 2);
    6161        }
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/DTLZ/DTLZ7.cs

    r15583 r16171  
    4747        throw new ArgumentException("The dimensionality of the problem(ProblemSize) must be larger than or equal to the number of objectives");
    4848      }
    49       double[] res = new double[objectives];
     49      var res = new double[objectives];
    5050
    5151      //calculate g(Xm)
    5252      double g = 0, length = length = r.Length - objectives + 1;
    53       for (int i = objectives; i < r.Length; i++) {
     53      for (var i = objectives; i < r.Length; i++) {
    5454        g += r[i];
    5555      }
     
    5858
    5959      //calculating f0...fM-2
    60       for (int i = 0; i < objectives - 1; i++) {
     60      for (var i = 0; i < objectives - 1; i++) {
    6161        res[i] = r[i];
    6262      }
    6363      //calculate fM-1
    6464      double h = objectives;
    65       for (int i = 0; i < objectives - 1; i++) {
     65      for (var i = 0; i < objectives - 1; i++) {
    6666        h -= res[i] / (1 + g) * (1 + Math.Sin(3 * Math.PI * res[i]));
    6767      }
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/DTLZ/DTLZ8.cs

    r15583 r16171  
    3030  public class DTLZ8 : DTLZ, IConstrainedTestFunction {
    3131    public static double[] IllegalValue(int size, bool[] maximization) {
    32       double[] res = new double[size];
    33       for (int i = 0; i < size; i++) {
     32      var res = new double[size];
     33      for (var i = 0; i < size; i++) {
    3434        res[i] = maximization[i] ? Double.MinValue : Double.MaxValue;
    3535      }
     
    4949      double n = r.Length;
    5050      double M = objectives;
    51       double ratio = n / M;
    52       double[] res = new double[objectives];
    53       for (int j = 0; j < objectives; j++) {
     51      var ratio = n / M;
     52      var res = new double[objectives];
     53      for (var j = 0; j < objectives; j++) {
    5454        double sum = 0;
    55         for (int i = (int)(j * ratio); i < (j + 1) + ratio; i++) {
     55        for (var i = (int)(j * ratio); i < (j + 1) + ratio; i++) {
    5656          sum += r[i];
    5757        }
     
    5959        res[j] = sum;
    6060      }
    61       for (int j = 0; j < M - 1; j++) {
     61      for (var j = 0; j < M - 1; j++) {
    6262        if (res[objectives - 1] + 4 * res[j] - 1 < 0) return IllegalValue(objectives, GetMaximization(objectives));
    6363      }
    64       double min = Double.PositiveInfinity;
    65       for (int i = 0; i < res.Length - 1; i++) {
    66         for (int j = 0; j < i; j++) {
    67           double d = 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];
    6868          if (min < d) min = d;
    6969        }
     
    7878      double n = r.Length;
    7979      double M = objectives;
    80       double ratio = n / M;
    81       double[] res = new double[objectives];
    82       double[] constraints = new double[objectives];
    83       for (int j = 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++) {
    8484        double sum = 0;
    85         for (int i = (int)(j * ratio); i < (j + 1) + ratio; i++) {
     85        for (var i = (int)(j * ratio); i < (j + 1) + ratio; i++) {
    8686          sum += r[i];
    8787        }
     
    8989        res[j] = sum;
    9090      }
    91       for (int j = 0; j < M - 1; j++) {
    92         double d1 = 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;
    9393        constraints[j] = d1 < 0 ? -d1 : 0;
    9494      }
    95       double min = Double.PositiveInfinity;
    96       for (int i = 0; i < res.Length - 1; i++) {
    97         for (int j = 0; j < i; j++) {
    98           double d2 = 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];
    9999          if (min < d2) min = d2;
    100100        }
    101101      }
    102       double d = 2 * res[objectives - 1] + min - 1;
     102      var d = 2 * res[objectives - 1] + min - 1;
    103103      constraints[constraints.Length - 1] = d < 0 ? -d : 0;
    104104      return constraints;
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/IHR/IHR.cs

    r15583 r16171  
    2020#endregion
    2121using System;
     22using System.Linq;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Encodings.RealVectorEncoding;
     25using HeuristicLab.Optimization;
    2426using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2527
     
    3638
    3739    protected override double[] GetReferencePoint(int objectives) {
    38       double[] rp = new double[objectives];
    39       for (int i = 0; i < objectives; i++) {
     40      var rp = new double[objectives];
     41      for (var i = 0; i < objectives; i++) {
    4042        rp[i] = 11;
    4143      }
     
    5860    protected abstract double G(RealVector y);
    5961
     62    protected override double GetBestKnownHypervolume(int objectives) {
     63      return HypervolumeCalculator.CalculateHypervolume(GetOptimalParetoFront(objectives).ToArray(), GetReferencePoint(objectives), GetMaximization(objectives));
     64    }
    6065
    6166    protected double H(double x, RealVector r) {
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/IHR/IHR1.cs

    r15583 r16171  
    3131  public class IHR1 : IHR {
    3232    protected override IEnumerable<double[]> GetOptimalParetoFront(int objectives) {
    33       List<double[]> res = new List<double[]>();
    34       for (int i = 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);
    3636        r[0] = 1 / 500.0 * i;
    3737        res.Add(this.Evaluate(r, objectives));
    3838      }
    3939      return res;
    40     }
    41 
    42     protected override double GetBestKnownHypervolume(int objectives) {
    43       return Hypervolume.Calculate(GetOptimalParetoFront(objectives), GetReferencePoint(objectives), GetMaximization(objectives));
    4440    }
    4541
     
    6460
    6561    protected override double G(RealVector y) {
    66       double sum = 0.0;
    67       for (int i = 1; i < y.Length; i++) {
     62      var sum = 0.0;
     63      for (var i = 1; i < y.Length; i++) {
    6864        sum += HG(y[i]);
    6965      }
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/IHR/IHR2.cs

    r15583 r16171  
    3131  public class IHR2 : IHR {
    3232    protected override IEnumerable<double[]> GetOptimalParetoFront(int objectives) {
    33       List<double[]> res = new List<double[]>();
    34       for (int i = 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);
    3636        r[0] = 1 / 500.0 * i;
    3737
     
    3939      }
    4040      return res;
    41     }
    42 
    43     protected override double GetBestKnownHypervolume(int objectives) {
    44       return Hypervolume.Calculate(GetOptimalParetoFront(objectives), GetReferencePoint(objectives), GetMaximization(objectives));
    4541    }
    4642
     
    6662
    6763    protected override double G(RealVector y) {
    68       double sum = 0.0;
    69       for (int i = 1; i < y.Length; i++) {
     64      var sum = 0.0;
     65      for (var i = 1; i < y.Length; i++) {
    7066        sum += HG(y[i]);
    7167      }
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/IHR/IHR3.cs

    r15583 r16171  
    2121using System;
    2222using System.Collections.Generic;
     23using System.Linq;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
     
    3132  public class IHR3 : IHR {
    3233    protected override IEnumerable<double[]> GetOptimalParetoFront(int objectives) {
    33       List<double[]> res = new List<double[]>();
    34       for (int i = 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);
    3637        r[0] = 1 / 500.0 * i;
    3738
     
    3940      }
    4041      return res;
    41     }
    42 
    43     protected override double GetBestKnownHypervolume(int objectives) {
    44       return Hypervolume.Calculate(GetOptimalParetoFront(objectives), GetReferencePoint(objectives), GetMaximization(objectives));
    4542    }
    4643
     
    6663
    6764    protected override double G(RealVector y) {
    68       double sum = 0.0;
    69       for (int i = 1; i < y.Length; i++) {
     65      var sum = 0.0;
     66      for (var i = 1; i < y.Length; i++) {
    7067        sum += HG(y[i]);
    7168      }
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/IHR/IHR4.cs

    r15583 r16171  
    2121using System;
    2222using System.Collections.Generic;
     23using System.Linq;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
     
    3132  public class IHR4 : IHR {
    3233    protected override IEnumerable<double[]> GetOptimalParetoFront(int objectives) {
    33       List<double[]> res = new List<double[]>();
    34       for (int i = 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);
    3637        r[0] = 1 / 500.0 * i;
    3738        res.Add(this.Evaluate(r, objectives));
    3839      }
    3940      return res;
    40     }
    41 
    42     protected override double GetBestKnownHypervolume(int objectives) {
    43       return Hypervolume.Calculate(GetOptimalParetoFront(objectives), GetReferencePoint(objectives), GetMaximization(objectives));
    4441    }
    4542
     
    6966
    7067    protected override double G(RealVector y) {
    71       double sum = 0.0;
    72       for (int i = 1; i < y.Length; i++) {
     68      var sum = 0.0;
     69      for (var i = 1; i < y.Length; i++) {
    7370        sum += y[i] * y[i] - 10 * Math.Cos(4 * Math.PI * y[i]);
    7471      }
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/IHR/IHR6.cs

    r15583 r16171  
    2121using System;
    2222using System.Collections.Generic;
     23using System.Linq;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
     
    3132  public class IHR6 : IHR {
    3233    protected override IEnumerable<double[]> GetOptimalParetoFront(int objectives) {
    33       List<double[]> res = new List<double[]>();
    34       for (int i = 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);
    3637        r[0] = 1 / 500.0 * i;
    3738        res.Add(this.Evaluate(r, objectives));
    3839      }
    3940      return res;
    40     }
    41 
    42     protected override double GetBestKnownHypervolume(int objectives) {
    43       return Hypervolume.Calculate(GetOptimalParetoFront(objectives), GetReferencePoint(objectives), GetMaximization(objectives));
    4441    }
    4542
     
    6562
    6663    protected override double G(RealVector y) {
    67       double sum = 0.0;
    68       for (int i = 1; i < y.Length; i++) {
     64      var sum = 0.0;
     65      for (var i = 1; i < y.Length; i++) {
    6966        sum += HG(y[i]);
    7067      }
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/Misc/CIGTAB.cs

    r15583 r16171  
    2121using System;
    2222using System.Collections.Generic;
     23using System.Linq;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
    2526using HeuristicLab.Encodings.RealVectorEncoding;
     27using HeuristicLab.Optimization;
    2628using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2729
     
    4345
    4446    protected override IEnumerable<double[]> GetOptimalParetoFront(int objecitves) {
    45       List<double[]> res = new List<double[]>();
    46       for (int i = 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);
    4850        r[0] = 2 / 500.0 * i;
    4951        r[1] = 2 / 500.0 * i;
     
    5456
    5557    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));
    5759    }
    5860
     
    6870    public override double[] Evaluate(RealVector r, int objectives) {
    6971      if (objectives != 2) throw new ArgumentException("The CIGTAB problem must always have 2 objectives");
    70       double x = r[0];
     72      var x = r[0];
    7173      double a = 1000;
    72       double sum = x * x;
    73       for (int i = 1; i < r.Length - 1; i++) {
     74      var sum = x * x;
     75      for (var i = 1; i < r.Length - 1; i++) {
    7476        sum += a * r[i] * r[i];
    7577      }
     
    7779
    7880      //objective1
    79       double f0 = 1 / (a * a * r.Length) * sum;
     81      var f0 = 1 / (a * a * r.Length) * sum;
    8082
    8183      x = x - 2;
    8284      sum = x * x;
    83       for (int i = 1; i < r.Length - 1; i++) {
     85      for (var i = 1; i < r.Length - 1; i++) {
    8486        sum += a * (r[i] - 2) * (r[i] - 2);
    8587      }
     
    8789      sum += a * a * (r[r.Length - 1] - 2) * (r[r.Length - 1] - 2);
    8890      //objective0
    89       double f1 = 1 / (a * a * r.Length) * sum;
     91      var f1 = 1 / (a * a * r.Length) * sum;
    9092
    9193      return new double[] { f0, f1 };
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/Misc/ELLI1.cs

    r15583 r16171  
    2121using System;
    2222using System.Collections.Generic;
     23using System.Linq;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
    2526using HeuristicLab.Encodings.RealVectorEncoding;
     27using HeuristicLab.Optimization;
    2628using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2729
     
    4345
    4446    protected override IEnumerable<double[]> GetOptimalParetoFront(int objecitves) {
    45       List<double[]> res = new List<double[]>();
    46       for (int i = 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);
    4850        r[0] = 2 / 500.0 * i;
    4951        r[1] = 2 / 500.0 * i;
     
    5456
    5557    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));
    5759    }
    5860
     
    6971      if (objectives != 2) throw new ArgumentException("The ELLI problem must always have 2 objectives");
    7072      double a = 1000;
    71       double sum = 0.0;
    72       for (int i = 0; i < r.Length; i++) {
     73      var sum = 0.0;
     74      for (var i = 0; i < r.Length; i++) {
    7375        sum += Math.Pow(a, 2 * i / (r.Length - 1)) * r[i] * r[i];
    7476      }
    7577
    7678      //objective1
    77       double f0 = 1 / (a * a * r.Length) * sum;
     79      var f0 = 1 / (a * a * r.Length) * sum;
    7880
    7981      sum = 0.0;
    80       for (int i = 0; i < r.Length; i++) {
     82      for (var i = 0; i < r.Length; i++) {
    8183        sum += Math.Pow(a, 2 * i / (r.Length - 1)) * (r[i] - 2) * (r[i] - 2);
    8284      }
    8385      //objective0
    84       double f1 = 1 / (a * a * r.Length) * sum;
     86      var f1 = 1 / (a * a * r.Length) * sum;
    8587
    8688      return new double[] { f0, f1 };
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/Misc/Fonseca.cs

    r15583 r16171  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Linq;
    2425using HeuristicLab.Common;
    2526using HeuristicLab.Core;
    2627using HeuristicLab.Encodings.RealVectorEncoding;
     28using HeuristicLab.Optimization;
    2729using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2830
     
    4446
    4547    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));
    4749    }
    4850
     
    6567
    6668      //objective1
    67       for (int i = 0; i < r.Length; i++) {
    68         double d = r[i] - aux;
     69      for (var i = 0; i < r.Length; i++) {
     70        var d = r[i] - aux;
    6971        f0 += d * d;
    7072      }
     
    7274
    7375      //objective2
    74       double f1 = 0.0;
    75       for (int i = 0; i < r.Length; i++) {
    76         double d = r[i] + aux;
     76      var f1 = 0.0;
     77      for (var i = 0; i < r.Length; i++) {
     78        var d = r[i] + aux;
    7779        f1 += d * d;
    7880      }
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/Misc/Kursawe.cs

    r15583 r16171  
    2121using System;
    2222using System.Collections.Generic;
     23using System.Linq;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
    2526using HeuristicLab.Encodings.RealVectorEncoding;
     27using HeuristicLab.Optimization;
    2628using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2729
     
    4345
    4446    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));
    4648    }
    4749
     
    6567      if (objectives != 2) throw new ArgumentException("The Kursawe problem must always have 2 objectives");
    6668      //objective 1
    67       double f0 = 0.0;
    68       for (int i = 0; i < r.Length - 1; i++) {
     69      var f0 = 0.0;
     70      for (var i = 0; i < r.Length - 1; i++) {
    6971        f0 += -10 * Math.Exp(-0.2 * Math.Sqrt(r[i] * r[i] + r[i + 1] * r[i + 1]));
    7072      }
    7173      //objective2
    72       double f1 = 0.0;
    73       for (int i = 0; i < r.Length; i++) {
     74      var f1 = 0.0;
     75      for (var i = 0; i < r.Length; i++) {
    7476        f1 += Math.Pow(Math.Abs(r[i]), 0.8) + 5 * Math.Sin(Math.Pow(r[i], 3));
    7577      }
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/Misc/SchafferN1.cs

    r15583 r16171  
    2121using System;
    2222using System.Collections.Generic;
     23using System.Linq;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
    2526using HeuristicLab.Encodings.RealVectorEncoding;
     27using HeuristicLab.Optimization;
    2628using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2729
     
    4850
    4951    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));
    5153    }
    5254
     
    6365      if (objectives != 2) throw new ArgumentException("The Schaffer N1 problem must always have 2 objectives");
    6466      if (r.Length != 1) return null;
    65       double x = r[0];
     67      var x = r[0];
    6668
    6769      //objective1
    68       double f0 = x * x;
     70      var f0 = x * x;
    6971
    7072      //objective0
    71       double f1 = x - 2;
     73      var f1 = x - 2;
    7274      f1 *= f1;
    7375
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/Misc/SchafferN2.cs

    r15583 r16171  
    5959    public override double[] Evaluate(RealVector r, int objectives) {
    6060      if (objectives != 2) throw new ArgumentException("The Schaffer N1 problem must always have 2 objectives");
    61       double x = r[0];
     61      var x = r[0];
    6262
    6363      //objective1
     
    6969
    7070      //objective0
    71       double f1 = x - 5;
     71      var f1 = x - 5;
    7272      f1 *= f1;
    7373
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/ParetoFrontStore.cs

    r15583 r16171  
    2929  internal class ParetoFrontStore {
    3030    internal static IEnumerable<double[]> GetParetoFront(String filename) {
    31       List<double[]> data = new List<double[]>();
     31      var data = new List<double[]>();
    3232      var assembly = Assembly.GetExecutingAssembly();
    33       String ressourcename = typeof(ParetoFrontStore).Namespace + ".TestFunctions." + filename + ".pf";
     33      var ressourcename = typeof(ParetoFrontStore).Namespace + ".TestFunctions." + filename + ".pf";
    3434
    3535      //check if file is listed
     
    4242      while ((s = ressourceReader.ReadLine()) != null) {
    4343        var tokens = s.Split(new char[0], StringSplitOptions.RemoveEmptyEntries);
    44         double[] point = new double[tokens.Length];
    45         for (int i = 0; i < point.Length; i++) {
     44        var point = new double[tokens.Length];
     45        for (var i = 0; i < point.Length; i++) {
    4646          point[i] = Double.Parse(tokens[i], CultureInfo.InvariantCulture);
    4747        }
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/ZDT/ZDT1.cs

    r15583 r16171  
    4444    public override double[] Evaluate(RealVector r) {
    4545      double g = 0;
    46       for (int i = 1; i < r.Length; i++) g += r[i];
     46      for (var i = 1; i < r.Length; i++) g += r[i];
    4747      g = 1.0 + 9.0 * g / (r.Length - 1);
    48       double f0 = r[0];
    49       double f1 = g * (1.0 - Math.Sqrt(r[0] / g));
     48      var f0 = r[0];
     49      var f1 = g * (1.0 - Math.Sqrt(r[0] / g));
    5050      return new double[] { f0, f1 };
    5151    }
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/ZDT/ZDT2.cs

    r15583 r16171  
    4242    public override double[] Evaluate(RealVector r) {
    4343      double g = 0;
    44       for (int i = 1; i < r.Length; i++) g += r[i];
     44      for (var i = 1; i < r.Length; i++) g += r[i];
    4545      g = 1.0 + 9.0 * g / (r.Length - 1);
    46       double d = r[0] / g;
    47       double f0 = r[0];
    48       double f1 = g * (1.0 - d * d);
     46      var d = r[0] / g;
     47      var f0 = r[0];
     48      var f1 = g * (1.0 - d * d);
    4949      return new double[] { f0, f1 };
    5050    }
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/ZDT/ZDT3.cs

    r15583 r16171  
    4444    public override double[] Evaluate(RealVector r) {
    4545      double g = 0;
    46       for (int i = 1; i < r.Length; i++) g += r[i];
     46      for (var i = 1; i < r.Length; i++) g += r[i];
    4747      g = 1.0 + 9.0 * g / (r.Length - 1);
    48       double d = r[0] / g;
    49       double f0 = r[0];
    50       double f1 = 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]));
    5151      return new double[] { f0, f1 };
    5252    }
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/ZDT/ZDT4.cs

    r15583 r16171  
    3030  public class ZDT4 : ZDT {
    3131    protected override double[,] GetBounds(int objectives) {
    32       double[,] bounds = new double[objectives, 2];
     32      var bounds = new double[objectives, 2];
    3333      bounds[0, 0] = 0; bounds[0, 1] = 1;
    34       for (int i = 1; i < objectives; i++) {
     34      for (var i = 1; i < objectives; i++) {
    3535        bounds[i, 0] = -5;
    3636        bounds[i, 1] = 5;
     
    5353    public override double[] Evaluate(RealVector r) {
    5454      double g = 0;
    55       for (int i = 1; i < r.Length; i++) {
    56         double v = r[i];
     55      for (var i = 1; i < r.Length; i++) {
     56        var v = r[i];
    5757        g += v * v - 10 * Math.Cos(4 * Math.PI * v);
    5858      }
    5959      g = 1.0 + 10.0 * (r.Length - 1) + g;
    60       double d = r[0] / g;
    61       double f0 = r[0];
    62       double f1 = 1 - Math.Sqrt(d);
     60      var d = r[0] / g;
     61      var f0 = r[0];
     62      var f1 = 1 - Math.Sqrt(d);
    6363      return new double[] { f0, f1 };
    6464    }
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/ZDT/ZDT6.cs

    r15583 r16171  
    4343    public override double[] Evaluate(RealVector r) {
    4444      double g = 0;
    45       for (int i = 1; i < r.Length; i++) g += r[i];
     45      for (var i = 1; i < r.Length; i++) g += r[i];
    4646      g = 1.0 + 9.0 * Math.Pow(g / (r.Length - 1), 0.25);
    47       double f1 = 1 - Math.Exp(-4 * r[0]) * Math.Pow(Math.Sin(6 * Math.PI * r[0]), 6);
    48       double d = f1 / g;
    49       double f2 = 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);
    5050      return new double[] { f1, f2 };
    5151    }
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/Utilities.cs

    r15583 r16171  
    2626namespace HeuristicLab.Problems.TestFunctions.MultiObjective {
    2727  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 
    4728    internal static DoubleMatrix ToMatrix(IEnumerable<double[]> source) {
    4829      try {
    49         int firstDimension = source.Count();
    50         int secondDimension = source.GroupBy(row => row.Length).Single().Key; // throws InvalidOperationException if source is not rectangular
     30        var firstDimension = source.Count();
     31        var secondDimension = source.GroupBy(row => row.Length).Single().Key; // throws InvalidOperationException if source is not rectangular
    5132
    5233        var result = new DoubleMatrix(firstDimension, secondDimension);
    5334        var enumarator = source.GetEnumerator();
    54         for (int i = 0; i < firstDimension && enumarator.MoveNext(); ++i)
    55           for (int j = 0; j < secondDimension; ++j)
     35        for (var i = 0; i < firstDimension && enumarator.MoveNext(); ++i)
     36          for (var j = 0; j < secondDimension; ++j)
    5637            result[i, j] = enumarator.Current[j];
    5738        return result;
     
    6243    }
    6344
    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   
    7946  }
    8047}
Note: See TracChangeset for help on using the changeset viewer.