1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using HeuristicLab.Common;
|
---|
25 | using HeuristicLab.Core;
|
---|
26 | using HeuristicLab.Data;
|
---|
27 | using HeuristicLab.Encodings.RealVectorEncoding;
|
---|
28 | using HeuristicLab.Parameters;
|
---|
29 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
30 |
|
---|
31 | namespace HeuristicLab.Problems.TestFunctions.MultiObjective {
|
---|
32 | /// <summary>
|
---|
33 | /// Base class for a test function evaluator.
|
---|
34 | /// </summary>
|
---|
35 | [Item("Multi-Objective Function", "Base class for multi objective functions.")]
|
---|
36 | [StorableClass]
|
---|
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 | }
|
---|
44 |
|
---|
45 | /// <summary>
|
---|
46 | /// Gets the minimum problem size.
|
---|
47 | /// </summary>
|
---|
48 | [Storable]
|
---|
49 | public int MinimumSolutionLength { get; private set; }
|
---|
50 | /// <summary>
|
---|
51 | /// Gets the maximum problem size.
|
---|
52 | /// </summary>
|
---|
53 | [Storable]
|
---|
54 | public int MaximumSolutionLength { get; private set; }
|
---|
55 |
|
---|
56 |
|
---|
57 | /// <summary>
|
---|
58 | /// Gets the minimum solution size.
|
---|
59 | /// </summary>
|
---|
60 | [Storable]
|
---|
61 | public int MinimumObjectives { get; private set; }
|
---|
62 | /// <summary>
|
---|
63 | /// Gets the maximum solution size.
|
---|
64 | /// </summary>
|
---|
65 | [Storable]
|
---|
66 | public int MaximumObjectives { get; private set; }
|
---|
67 |
|
---|
68 |
|
---|
69 | /// <summary>
|
---|
70 | /// Returns whether the actual function constitutes a maximization or minimization problem.
|
---|
71 | /// </summary>
|
---|
72 | public bool[] Maximization(int objectives) {
|
---|
73 | CheckObjectives(objectives);
|
---|
74 | return GetMaximization(objectives);
|
---|
75 | }
|
---|
76 | protected abstract bool[] GetMaximization(int objectives);
|
---|
77 | /// <summary>
|
---|
78 | /// Gets the lower and upper bound of the function.
|
---|
79 | /// </summary>
|
---|
80 | public double[,] Bounds(int objectives) {
|
---|
81 | CheckObjectives(objectives);
|
---|
82 | return GetBounds(objectives);
|
---|
83 | }
|
---|
84 | protected abstract double[,] GetBounds(int objectives);
|
---|
85 |
|
---|
86 | /// <summary>
|
---|
87 | /// retrieves the optimal pareto front (if known from a file)
|
---|
88 | /// </summary>
|
---|
89 | public IEnumerable<double[]> OptimalParetoFront(int objectives) {
|
---|
90 | CheckObjectives(objectives);
|
---|
91 | return GetOptimalParetoFront(objectives);
|
---|
92 | }
|
---|
93 | protected abstract IEnumerable<double[]> GetOptimalParetoFront(int objectives);
|
---|
94 |
|
---|
95 | /// <summary>
|
---|
96 | /// returns a Reference Point for Hypervolume calculation (default=(11|11))
|
---|
97 | /// </summary>
|
---|
98 | public double[] ReferencePoint(int objectives) {
|
---|
99 | CheckObjectives(objectives);
|
---|
100 | return GetReferencePoint(objectives);
|
---|
101 | }
|
---|
102 | protected abstract double[] GetReferencePoint(int objectives);
|
---|
103 |
|
---|
104 | /// <summary>
|
---|
105 | /// returns the best known Hypervolume for this test function (default=-1)
|
---|
106 | /// </summary>
|
---|
107 | public virtual double OptimalHypervolume(int objectives) {
|
---|
108 | CheckObjectives(objectives);
|
---|
109 | return GetBestKnownHypervolume(objectives);
|
---|
110 | }
|
---|
111 |
|
---|
112 | protected virtual double GetBestKnownHypervolume(int objectives) {
|
---|
113 | 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));
|
---|
119 | }
|
---|
120 |
|
---|
121 | [StorableConstructor]
|
---|
122 | protected MultiObjectiveTestFunction(bool deserializing) : base(deserializing) { }
|
---|
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;
|
---|
130 | }
|
---|
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;
|
---|
145 | }
|
---|
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>
|
---|
152 | public abstract double[] Evaluate(RealVector point, int objectives);
|
---|
153 | }
|
---|
154 | }
|
---|