Free cookie consent management tool by TermsFeed Policy Generator

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

#1087 extensive testing; fixed minor bugs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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;
Note: See TracChangeset for help on using the changeset viewer.