Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/14/16 14:33:15 (8 years ago)
Author:
mkommend
Message:

#1087: Added checks for min and max objectives to testfunctions.

File:
1 edited

Legend:

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

    r14067 r14068  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using HeuristicLab.Common;
     
    6970    /// Returns whether the actual function constitutes a maximization or minimization problem.
    7071    /// </summary>
    71     public abstract bool[] Maximization(int objectives);
     72    public bool[] Maximization(int objectives) {
     73      CheckObjectives(objectives);
     74      return GetMaximization(objectives);
     75    }
     76    protected abstract bool[] GetMaximization(int objectives);
    7277    /// <summary>
    7378    /// Gets the lower and upper bound of the function.
    7479    /// </summary>
    75     public abstract double[,] Bounds(int objectives);
    76 
     80    public double[,] Bounds(int objectives) {
     81      CheckObjectives(objectives);
     82      return GetBounds(objectives);
     83    }
     84    protected abstract double[,] GetBounds(int objectives);
    7785
    7886    /// <summary>
    7987    /// retrieves the optimal pareto front (if known from a file)
    8088    /// </summary>
    81     public abstract IEnumerable<double[]> OptimalParetoFront(int objectives);
     89    public IEnumerable<double[]> OptimalParetoFront(int objectives) {
     90      CheckObjectives(objectives);
     91      return GetOptimalParetoFront(objectives);
     92    }
     93    protected abstract IEnumerable<double[]> GetOptimalParetoFront(int objectives);
    8294
    8395    /// <summary>
    8496    /// returns a Reference Point for Hypervolume calculation (default=(11|11))
    8597    /// </summary>
    86     public abstract double[] ReferencePoint(int objectives);
    87 
     98    public double[] ReferencePoint(int objectives) {
     99      CheckObjectives(objectives);
     100      return GetReferencePoint(objectives);
     101    }
     102    protected abstract double[] GetReferencePoint(int objectives);
    88103
    89104    /// <summary>
    90105    /// returns the best known Hypervolume for this test function   (default=-1)
    91     /// </summary>
     106    /// </summary>     
    92107    public virtual double BestKnownHypervolume(int objectives) {
     108      CheckObjectives(objectives);
     109      return GetBestKnownHypervolume(objectives);
     110    }
     111
     112    protected virtual double GetBestKnownHypervolume(int objectives) {
    93113      return -1;
     114    }
     115
     116    protected void CheckObjectives(int objectives) {
     117      if (objectives < MinimumObjectives) throw new ArgumentException(string.Format("There must be at least {0} objectives", MinimumObjectives));
     118      if (objectives > MaximumObjectives) throw new ArgumentException(string.Format("There must be at most {0} objectives", MaximumObjectives));
    94119    }
    95120
Note: See TracChangeset for help on using the changeset viewer.