Free cookie consent management tool by TermsFeed Policy Generator

Changeset 13451


Ignore:
Timestamp:
12/11/15 15:19:24 (9 years ago)
Author:
bwerth
Message:

#1087 extensive testing; fixed minor bugs

Location:
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/MultiObjectiveTestFunctionProblem.cs

    r13448 r13451  
    148148        || ProblemSize > TestFunction.MaximumProblemSize)
    149149        ProblemSize = Math.Min(TestFunction.MaximumProblemSize, Math.Max(TestFunction.MinimumProblemSize, ProblemSize));
    150       //TODO problemsize dominates solutionSize
    151       SolutionSizeOnValueChanged(sender, eventArgs);
     150      if (SolutionSize < TestFunction.MinimumSolutionSize
     151        || SolutionSize > TestFunction.MaximumSolutionSize)
     152        SolutionSize = Math.Min(TestFunction.MaximumSolutionSize, Math.Max(TestFunction.MinimumSolutionSize, SolutionSize));
     153      TestFunction.ActualSolutionSize = SolutionSize;
    152154    }
    153155
     
    157159        SolutionSize = Math.Min(TestFunction.MaximumSolutionSize, Math.Max(TestFunction.MinimumSolutionSize, SolutionSize));
    158160      TestFunction.ActualSolutionSize = SolutionSize;
    159       OnReset();
     161      if (ProblemSize < TestFunction.MinimumProblemSize
     162        || ProblemSize > TestFunction.MaximumProblemSize)
     163        ProblemSize = Math.Min(TestFunction.MaximumProblemSize, Math.Max(TestFunction.MinimumProblemSize, ProblemSize));
    160164    }
    161165
     
    174178    }
    175179
    176    
     180
    177181    #endregion
    178182  }
    179183}
    180184
    181    
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Testfunctions/DTLZ1.cs

    r13448 r13451  
    3636    public override bool[] Maximization {
    3737      get {
    38         bool[] res = new bool[actualSolutionSize];
    39         for(int i =0; i < res.Length; i++)  res[i] = false; //TODO: diligent initialzation
    40         return res;
     38        return new bool[actualSolutionSize];
    4139      }
    4240    }
     
    5755    public override int MinimumProblemSize {
    5856      get {
    59         return Math.Max(2, ActualSolutionSize+1);
     57        return Math.Max(2, ActualSolutionSize);
    6058      }
    6159    }
     
    8482
    8583    private double[] Evaluate(RealVector r, int objectives) {
     84      if (r.Length < objectives) {
     85        throw new Exception("The dimensionality of the problem(ProblemSize) must be larger or equal than the dimensionality of the solution(SolutionSize) ");
     86      }
     87
    8688      double[] res = new double[objectives];
    8789
     
    98100      //calculating f0...fM-1
    99101      for (int i = 0; i < objectives; i++) {
    100         double f = 0.5 * i == 0 ? 1 : (1 - r[objectives - i - 1]) * (1 + g);
     102        double f = 0.5 * (i == 0 ? 1 : (1 - r[objectives - i - 1])) * (1 + g);
    101103        for (int j = 0; j < objectives - i - 1; j++) {
    102104          f *= r[j];
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Testfunctions/DTLZ2.cs

    r13448 r13451  
    3636    public override bool[] Maximization {
    3737      get {
    38         bool[] res = new bool[actualSolutionSize];
    39         for(int i =0; i < res.Length; i++)  res[i] = false; //TODO: diligent initialzation
    40         return res;
     38        return new bool[actualSolutionSize];
    4139      }
    4240    }
     
    4846    }
    4947
    50     public override int MaximumSolutionSize { //TODO ask Michael
     48    public override int MaximumSolutionSize {
    5149      get {
     50
    5251        return int.MaxValue;
    5352      }
     
    5655    public override int MinimumProblemSize {
    5756      get {
    58         return Math.Max(2,actualSolutionSize);
     57        return Math.Max(2, ActualSolutionSize);
    5958      }
    6059    }
     
    8281
    8382    private double[] Evaluate(RealVector r, int objectives) {
     83      if (r.Length < objectives) {
     84        throw new Exception("The dimensionality of the problem(ProblemSize) must be larger or equal than the dimensionality of the solution(SolutionSize) ");
     85      }
     86
    8487      double[] res = new double[objectives];
    8588
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Testfunctions/DTLZ3.cs

    r13448 r13451  
    1717  public class DTLZ3 : MultiObjectiveTestFunction {
    1818
     19    private int actualSolutionSize = 2;
     20    public override int ActualSolutionSize {
     21      get {
     22        return actualSolutionSize;
     23      }
     24
     25      set {
     26        actualSolutionSize = value;
     27      }
     28    }
     29
    1930    public override DoubleMatrix Bounds {
    2031      get {
     
    2536    public override bool[] Maximization {
    2637      get {
    27         bool[] res = new bool[((ValueParameter<IntValue>)Parameters["SolutionSize"]).Value.Value];
    28         for(int i =0; i < res.Length; i++)  res[i] = false; //TODO: diligent initialzation
    29         return res;
     38        return new bool[actualSolutionSize];
    3039      }
    3140    }
     
    3746    }
    3847
    39     public override int MaximumSolutionSize { //TODO ask Michael
     48    public override int MaximumSolutionSize {
    4049      get {
    41         return ((ValueParameter<IntValue>)Parameters["ProblemSize"]).Value.Value;
     50
     51        return int.MaxValue;
    4252      }
    4353    }
     
    4555    public override int MinimumProblemSize {
    4656      get {
    47         return 2;
     57        return Math.Max(2, ActualSolutionSize);
    4858      }
    4959    }
     
    5262      get {
    5363        return 2;
    54       }
    55     }
    56 
    57     public override int ActualSolutionSize {
    58       get {
    59         throw new NotImplementedException();
    60       }
    61 
    62       set {
    63         throw new NotImplementedException();
    6464      }
    6565    }
     
    7777
    7878    public override double[] Evaluate(RealVector r) {
    79       return Evaluate(r, ((ValueParameter<IntValue>)Parameters["SolutionSize"]).Value.Value);
     79      return Evaluate(r, ActualSolutionSize);
    8080    }
    8181
    8282    private double[] Evaluate(RealVector r, int objectives) {
     83      if (r.Length < objectives) {
     84        throw new Exception("The dimensionality of the problem(ProblemSize) must be larger or equal than the dimensionality of the solution(SolutionSize) ");
     85      }
    8386      double[] res = new double[objectives];
    8487
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Testfunctions/DTLZ4.cs

    r13448 r13451  
    1717  public class DTLZ4 : MultiObjectiveTestFunction {
    1818
     19    private int actualSolutionSize = 2;
     20    public override int ActualSolutionSize {
     21      get {
     22        return actualSolutionSize;
     23      }
     24
     25      set {
     26        actualSolutionSize = value;
     27      }
     28    }
     29
    1930    public override DoubleMatrix Bounds {
    2031      get {
     
    2536    public override bool[] Maximization {
    2637      get {
    27         bool[] res = new bool[((ValueParameter<IntValue>)Parameters["SolutionSize"]).Value.Value];
    28         for(int i =0; i < res.Length; i++)  res[i] = false; //TODO: diligent initialzation
    29         return res;
     38        return new bool[actualSolutionSize];
    3039      }
    3140    }
     
    3746    }
    3847
    39     public override int MaximumSolutionSize { //TODO ask Michael
     48    public override int MaximumSolutionSize {
    4049      get {
    41         return ((ValueParameter<IntValue>)Parameters["ProblemSize"]).Value.Value;
     50
     51        return int.MaxValue;
    4252      }
    4353    }
     
    4555    public override int MinimumProblemSize {
    4656      get {
    47         return 2;
     57        return Math.Max(3, ActualSolutionSize+1);
    4858      }
    4959    }
     
    5262      get {
    5363        return 2;
    54       }
    55     }
    56 
    57     public override int ActualSolutionSize {
    58       get {
    59         throw new NotImplementedException();
    60       }
    61 
    62       set {
    63         throw new NotImplementedException();
    6464      }
    6565    }
     
    7777
    7878    public override double[] Evaluate(RealVector r) {
    79       return Evaluate(r, ((ValueParameter<IntValue>)Parameters["SolutionSize"]).Value.Value);
     79      return Evaluate(r, ActualSolutionSize);
    8080    }
    8181
    8282    private double[] Evaluate(RealVector r, int objectives) {
     83      if (r.Length < objectives) {
     84        throw new Exception("The dimensionality of the problem(ProblemSize) must be larger or equal than the dimensionality of the solution(SolutionSize) ");
     85      }
    8386      double[] res = new double[objectives];
    8487
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Testfunctions/DTLZ5.cs

    r13448 r13451  
    1717  public class DTLZ5 : MultiObjectiveTestFunction {
    1818
     19    private int actualSolutionSize = 2;
     20    public override int ActualSolutionSize {
     21      get {
     22        return actualSolutionSize;
     23      }
     24
     25      set {
     26        actualSolutionSize = value;
     27      }
     28    }
     29
    1930    public override DoubleMatrix Bounds {
    2031      get {
     
    2536    public override bool[] Maximization {
    2637      get {
    27         bool[] res = new bool[((ValueParameter<IntValue>)Parameters["SolutionSize"]).Value.Value];
    28         for(int i =0; i < res.Length; i++)  res[i] = false; //TODO: diligent initialzation
    29         return res;
     38        return new bool[actualSolutionSize];
    3039      }
    3140    }
     
    3746    }
    3847
    39     public override int MaximumSolutionSize { //TODO ask Michael
     48    public override int MaximumSolutionSize {
    4049      get {
    41         return ((ValueParameter<IntValue>)Parameters["ProblemSize"]).Value.Value;
     50
     51        return int.MaxValue;
    4252      }
    4353    }
     
    4555    public override int MinimumProblemSize {
    4656      get {
    47         return 2;
     57        return Math.Max(2, ActualSolutionSize+1);
    4858      }
    4959    }
     
    5262      get {
    5363        return 2;
    54       }
    55     }
    56 
    57     public override int ActualSolutionSize {
    58       get {
    59         throw new NotImplementedException();
    60       }
    61 
    62       set {
    63         throw new NotImplementedException();
    6464      }
    6565    }
     
    7777
    7878    public override double[] Evaluate(RealVector r) {
    79       return Evaluate(r, ((ValueParameter<IntValue>)Parameters["SolutionSize"]).Value.Value);
     79      return Evaluate(r, ActualSolutionSize);
    8080    }
    8181
    8282    private double[] Evaluate(RealVector r, int objectives) {
     83      if (r.Length < objectives) {
     84        throw new Exception("The dimensionality of the problem(ProblemSize) must be larger than the dimensionality of the solution(SolutionSize) ");
     85      }
    8386      double[] res = new double[objectives];
    8487
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Testfunctions/DTLZ6.cs

    r13448 r13451  
    1717  public class DTLZ6 : MultiObjectiveTestFunction {
    1818
     19    private int actualSolutionSize = 2;
     20    public override int ActualSolutionSize {
     21      get {
     22        return actualSolutionSize;
     23      }
     24
     25      set {
     26        actualSolutionSize = value;
     27      }
     28    }
     29
    1930    public override DoubleMatrix Bounds {
    2031      get {
     
    2536    public override bool[] Maximization {
    2637      get {
    27         bool[] res = new bool[((ValueParameter<IntValue>)Parameters["SolutionSize"]).Value.Value];
    28         for(int i =0; i < res.Length; i++)  res[i] = false; //TODO: diligent initialzation
    29         return res;
     38        return new bool[actualSolutionSize];
    3039      }
    3140    }
     
    3746    }
    3847
    39     public override int MaximumSolutionSize { //TODO ask Michael
     48    public override int MaximumSolutionSize {
    4049      get {
    41         return ((ValueParameter<IntValue>)Parameters["ProblemSize"]).Value.Value;
     50
     51        return int.MaxValue;
    4252      }
    4353    }
     
    4555    public override int MinimumProblemSize {
    4656      get {
    47         return 2;
     57        return Math.Max(2, ActualSolutionSize);
    4858      }
    4959    }
     
    5262      get {
    5363        return 2;
    54       }
    55     }
    56 
    57     public override int ActualSolutionSize {
    58       get {
    59         throw new NotImplementedException();
    60       }
    61 
    62       set {
    63         throw new NotImplementedException();
    6464      }
    6565    }
     
    7777
    7878    public override double[] Evaluate(RealVector r) {
    79       return Evaluate(r, ((ValueParameter<IntValue>)Parameters["SolutionSize"]).Value.Value);
     79      return Evaluate(r, ActualSolutionSize);
    8080    }
    8181
    8282    private double[] Evaluate(RealVector r, int objectives) {
     83      if (r.Length < objectives) {
     84        throw new Exception("The dimensionality of the problem(ProblemSize) must be larger than or equal to the dimensionality of the solution(SolutionSize) ");
     85      }
    8386      double[] res = new double[objectives];
    8487
     
    9194      length = Math.Sqrt(length);
    9295      g = 1.0 + 9.0 / length * g;
     96      if (length == 0) { g = 1; }
    9397
    9498      //calculating f0...fM-2
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Testfunctions/DTLZ7.cs

    r13448 r13451  
    1717  public class DTLZ7 : MultiObjectiveTestFunction {
    1818
     19    private int actualSolutionSize = 2;
     20    public override int ActualSolutionSize {
     21      get {
     22        return actualSolutionSize;
     23      }
     24
     25      set {
     26        actualSolutionSize = value;
     27      }
     28    }
     29
    1930    public override DoubleMatrix Bounds {
    2031      get {
     
    2536    public override bool[] Maximization {
    2637      get {
    27         bool[] res = new bool[((ValueParameter<IntValue>)Parameters["SolutionSize"]).Value.Value];
    28         for(int i =0; i < res.Length; i++)  res[i] = false; //TODO: diligent initialzation
    29         return res;
     38        return new bool[actualSolutionSize];
    3039      }
    3140    }
     
    3746    }
    3847
    39     public override int MaximumSolutionSize { //TODO ask Michael
     48    public override int MaximumSolutionSize {
    4049      get {
    41         return ((ValueParameter<IntValue>)Parameters["ProblemSize"]).Value.Value;
     50
     51        return int.MaxValue;
    4252      }
    4353    }
     
    4555    public override int MinimumProblemSize {
    4656      get {
    47         return 2;
     57        return Math.Max(2, ActualSolutionSize*10);
    4858      }
    4959    }
     
    5262      get {
    5363        return 2;
    54       }
    55     }
    56 
    57     public override int ActualSolutionSize {
    58       get {
    59         throw new NotImplementedException();
    60       }
    61 
    62       set {
    63         throw new NotImplementedException();
    6464      }
    6565    }
     
    7777
    7878    public override double[] Evaluate(RealVector r) {
    79       return Evaluate(r, ((ValueParameter<IntValue>)Parameters["SolutionSize"]).Value.Value);
     79      return Evaluate(r, ActualSolutionSize);
    8080    }
    8181
    8282    private double[] Evaluate(RealVector r, int objectives) {
     83      if (r.Length < objectives) {
     84        throw new Exception("The dimensionality of the problem(ProblemSize) must be larger than or equal to ten times the dimensionality of the solution(SolutionSize) ");
     85      }
    8386      double[] res = new double[objectives];
    8487
    8588      //calculate f0...fM-1;
    8689      double n = 10 * objectives;
    87       for (int i = 0; i < objectives; i++) {
     90      for (int i = 1; i <= objectives; i++) {
    8891        double d = 0;
    89         for (int j = (int)Math.Floor((i - 1) * n / objectives); j < (int)Math.Floor(i * n / objectives); j++) {
     92        int c = 0;
     93        for (int j = (int)Math.Floor((i - 1) * n / objectives); j < Math.Min((int)Math.Floor(i * n / objectives), r.Length); j++) {
    9094          d += r[j];
     95          c++;
    9196        }
    92         d *= 1 / Math.Floor(n / objectives);
    93         res[i] = d;
     97        d *= 1.0 / c;
     98        res[i-1] = d;
    9499      }
    95100
    96101      //evaluate constraints g0...gM-2
    97102      for (int i = 0; i < objectives - 1; i++) {
    98         if (res[objectives - 1] + 4 * res[i] - 1 < 0) return null; //TODO null is not the way to go
     103        if (res[objectives - 1] + 4 * res[i] - 1 < 0) return MultiObjectiveTestFunction.IllegalValue(objectives,Maximization);
    99104      }
    100105      //evaluate gM-1
     
    103108        for (int j = 0; j < i; j++) min = Math.Min(min, res[i] + res[j]);
    104109      };
    105       if (2 * res[objectives - 1] + min - 1 < 0) return null;  //TODO null is not the way to go
     110      if (2 * res[objectives - 1] + min - 1 < 0) return MultiObjectiveTestFunction.IllegalValue(objectives, Maximization);
    106111
    107112      return res;
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Testfunctions/Kursawe.cs

    r13448 r13451  
    4242    public override int MinimumProblemSize {
    4343      get {
    44         return 2;
     44        return 3;
    4545      }
    4646    }
     
    7575      //objective 1
    7676      double f0 = 0.0;
    77       for (int i = 0; i < r.Length - 1; i++) {
     77      for (int i = 0; i < 2; i++) {
    7878        f0 += -10 * Math.Exp(-0.2 * Math.Sqrt(r[i] * r[i] + r[i + 1] * r[i + 1]));
    7979      }
    8080      //objective2
    8181      double f1 = 0.0;
    82       for (int i = 0; i < r.Length; i++) {
    83         f1 += Math.Pow(Math.Abs(r[i]), 0.2) + 5 * Math.Sin(Math.Pow(r[i], 3));
     82      for (int i = 0; i < 3; i++) {
     83        f1 += Math.Pow(Math.Abs(r[i]), 0.8) + 5 * Math.Sin(Math.Pow(r[i], 3));
    8484      }
    8585
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Testfunctions/MultiObjectiveTestFunction.cs

    r13448 r13451  
    3131  /// Base class for a test function evaluator.
    3232  /// </summary>
    33   [Item("Single-Objective Function", "Base class for single objective functions.")]
     33  [Item("Multi-Objective Function", "Base class for multi objective functions.")]
    3434  [StorableClass]
    3535  public abstract class MultiObjectiveTestFunction : ParameterizedNamedItem, IMultiObjectiveTestFunction {
     36    public static double[] IllegalValue(int size, bool[] maximization) {
     37      double[] res = new double[size];
     38      for(int i =0; i< size; i++) {
     39        res[i] = maximization[i] ? Double.MinValue : Double.MaxValue;
     40      }
     41      return res;
     42    }
     43
    3644    /// <summary>
    3745    /// These operators should not change their name through the GUI
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Testfunctions/SchafferN2.cs

    r13448 r13451  
    7777      //objective1
    7878      double f0;
    79       if (x <= 11) f0 = -x;
     79      if (x <= 1) f0 = -x;
    8080      else if (x <= 3) f0 = x - 2;
    8181      else if (x <= 4) f0 = 4 - x;
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Testfunctions/ZDT1.cs

    r13448 r13451  
    7676      for (int i = 1; i < r.Length; i++) g += r[i];
    7777      g = 1.0 + 9.0 * g / (r.Length - 1);
    78       return new double[] { r[0], g * (1.0 - Math.Sqrt(r[0] / g)) };
     78      double f1 = g * (1.0 - Math.Sqrt(r[0] / g));
     79      return new double[] { r[0], f1};
    7980    }
    8081  }
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Testfunctions/ZDT4.cs

    r13448 r13451  
    1818    public override DoubleMatrix Bounds {
    1919      get {
    20         return new DoubleMatrix(new double[,] { { -5, 5 } });   //TODO definition in the source is contradicting itself
     20        return new DoubleMatrix(new double[,] { { 0, 1 } });   //definition in the source is contradicting itself the known paretofront is for [0,1]
    2121      }
    2222    }
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Testfunctions/ZDT6.cs

    r13448 r13451  
    7575      double g = 0;
    7676      for (int i = 1; i < r.Length; i++) g += r[i];
    77       g = g = 1.0 + 9.0 * Math.Pow(g / (r.Length - 1), 0.25);
    78       double d = r[0] / g;
    79       return new double[] { 1 - Math.Exp(-4 * r[0]) * Math.Pow(Math.Sin(6 * Math.PI * r[0]), 6), g * (1.0 - d * d) };
     77      g = 1.0 + 9.0 * Math.Pow(g / (r.Length - 1), 0.25);
     78      double f1 = 1 - Math.Exp(-4 * r[0]) * Math.Pow(Math.Sin(6 * Math.PI * r[0]), 6);
     79      double d = f1 / g;
     80      return new double[] { f1, g*(1.0 - d * d) };
    8081    }
    8182  }
Note: See TracChangeset for help on using the changeset viewer.