Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2521_ProblemRefactoring/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/MultiObjectiveTestFunction.cs @ 16723

Last change on this file since 16723 was 16723, checked in by abeham, 5 years ago

#2521: merged changes from r15684 to trunk HEAD (r16716) and resolved all merge conflicts

  • it doesn't build
File size: 6.5 KB
RevLine 
[13421]1#region License Information
2/* HeuristicLab
[16723]3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[13421]4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
[14068]22using System;
[13620]23using System.Collections.Generic;
[13421]24using HeuristicLab.Common;
25using HeuristicLab.Core;
[13672]26using HeuristicLab.Data;
[13421]27using HeuristicLab.Encodings.RealVectorEncoding;
[13672]28using HeuristicLab.Parameters;
[16723]29using HEAL.Attic;
[13421]30
[14111]31namespace HeuristicLab.Problems.TestFunctions.MultiObjective {
[13421]32  /// <summary>
33  /// Base class for a test function evaluator.
34  /// </summary>
[13451]35  [Item("Multi-Objective Function", "Base class for multi objective functions.")]
[16723]36  [StorableType("6E9E9993-5B26-4D97-A58C-B4FD28308544")]
[13421]37  public abstract class MultiObjectiveTestFunction : ParameterizedNamedItem, IMultiObjectiveTestFunction {
38    /// <summary>
39    /// These operators should not change their name through the GUI
40    /// </summary>
41    public override bool CanChangeName {
42      get { return false; }
43    }
[14067]44
[13421]45    /// <summary>
46    /// Gets the minimum problem size.
47    /// </summary>
[14067]48    [Storable]
49    public int MinimumSolutionLength { get; private set; }
[13421]50    /// <summary>
51    /// Gets the maximum problem size.
52    /// </summary>
[14067]53    [Storable]
54    public int MaximumSolutionLength { get; private set; }
[13620]55
56
[13421]57    /// <summary>
[14067]58    /// Gets the minimum solution size.
[13421]59    /// </summary>
[13620]60    [Storable]
[14067]61    public int MinimumObjectives { get; private set; }
[13448]62    /// <summary>
[14067]63    /// Gets the maximum solution size.
[13448]64    /// </summary>
[14067]65    [Storable]
66    public int MaximumObjectives { get; private set; }
67
68
[13421]69    /// <summary>
[14067]70    /// Returns whether the actual function constitutes a maximization or minimization problem.
[13421]71    /// </summary>
[14068]72    public bool[] Maximization(int objectives) {
73      CheckObjectives(objectives);
74      return GetMaximization(objectives);
75    }
76    protected abstract bool[] GetMaximization(int objectives);
[14067]77    /// <summary>
78    /// Gets the lower and upper bound of the function.
79    /// </summary>
[14068]80    public double[,] Bounds(int objectives) {
81      CheckObjectives(objectives);
82      return GetBounds(objectives);
83    }
84    protected abstract double[,] GetBounds(int objectives);
[13421]85
[13515]86    /// <summary>
87    /// retrieves the optimal pareto front (if known from a file)
88    /// </summary>
[14068]89    public IEnumerable<double[]> OptimalParetoFront(int objectives) {
90      CheckObjectives(objectives);
91      return GetOptimalParetoFront(objectives);
92    }
93    protected abstract IEnumerable<double[]> GetOptimalParetoFront(int objectives);
[13515]94
[13562]95    /// <summary>
[14067]96    /// returns a Reference Point for Hypervolume calculation (default=(11|11))
[13562]97    /// </summary>
[14068]98    public double[] ReferencePoint(int objectives) {
99      CheckObjectives(objectives);
100      return GetReferencePoint(objectives);
101    }
102    protected abstract double[] GetReferencePoint(int objectives);
[13515]103
[13562]104    /// <summary>
[14067]105    /// returns the best known Hypervolume for this test function   (default=-1)
[14068]106    /// </summary>     
[14085]107    public virtual double OptimalHypervolume(int objectives) {
[14068]108      CheckObjectives(objectives);
109      return GetBestKnownHypervolume(objectives);
110    }
111
112    protected virtual double GetBestKnownHypervolume(int objectives) {
[13620]113      return -1;
114    }
[13515]115
[14068]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));
119    }
120
[13421]121    [StorableConstructor]
[16723]122    protected MultiObjectiveTestFunction(StorableConstructorFlag _) : base(_) { }
[14067]123
124    protected MultiObjectiveTestFunction(MultiObjectiveTestFunction original, Cloner cloner)
125      : base(original, cloner) {
126      MinimumObjectives = original.MinimumObjectives;
127      MaximumObjectives = original.MaximumObjectives;
128      MinimumSolutionLength = original.MinimumSolutionLength;
129      MaximumSolutionLength = original.MaximumSolutionLength;
[13725]130    }
[14067]131
132    protected MultiObjectiveTestFunction(int minimumObjectives, int maximumObjectives, int minimumSolutionLength, int maximumSolutionLength)
133      : base() {
134      Parameters.Add(new FixedValueParameter<IntValue>("Minimum Objectives",
135        "The dimensionality of the problem instance (number of variables in the function).",
136        (IntValue)new IntValue(minimumObjectives).AsReadOnly()) { GetsCollected = false });
137      Parameters.Add(new FixedValueParameter<IntValue>("Maximum Objectives", "The dimensionality of the problem instance (number of variables in the function).", (IntValue)new IntValue(maximumObjectives).AsReadOnly()) { GetsCollected = false });
138      Parameters.Add(new FixedValueParameter<IntValue>("Minimum SolutionLength", "The dimensionality of the problem instance (number of variables in the function).", (IntValue)new IntValue(minimumSolutionLength).AsReadOnly()) { GetsCollected = false });
139      Parameters.Add(new FixedValueParameter<IntValue>("Maximum SolutionLength", "The dimensionality of the problem instance (number of variables in the function).", (IntValue)new IntValue(maximumSolutionLength).AsReadOnly()) { GetsCollected = false });
140
141      MinimumObjectives = minimumObjectives;
142      MaximumObjectives = maximumObjectives;
143      MinimumSolutionLength = minimumSolutionLength;
144      MaximumSolutionLength = maximumSolutionLength;
[13620]145    }
[13421]146
147    /// <summary>
148    /// Evaluates the test function for a specific <paramref name="point"/>.
149    /// </summary>
150    /// <param name="point">N-dimensional point for which the test function should be evaluated.</param>
151    /// <returns>The result values of the function at the given point.</returns>
[13620]152    public abstract double[] Evaluate(RealVector point, int objectives);
[13421]153  }
154}
Note: See TracBrowser for help on using the repository browser.