[16949] | 1 | #region License Information
|
---|
| 2 |
|
---|
| 3 | /* HeuristicLab
|
---|
| 4 | * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 5 | *
|
---|
| 6 | * This file is part of HeuristicLab.
|
---|
| 7 | *
|
---|
| 8 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 9 | * it under the terms of the GNU General Public License as published by
|
---|
| 10 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 11 | * (at your option) any later version.
|
---|
| 12 | *
|
---|
| 13 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 16 | * GNU General Public License for more details.
|
---|
| 17 | *
|
---|
| 18 | * You should have received a copy of the GNU General Public License
|
---|
| 19 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 20 | */
|
---|
| 21 |
|
---|
| 22 | #endregion
|
---|
| 23 |
|
---|
[17695] | 24 | using System;
|
---|
[16949] | 25 | using System.Linq;
|
---|
| 26 | using HEAL.Attic;
|
---|
| 27 | using HeuristicLab.Analysis;
|
---|
| 28 | using HeuristicLab.Common;
|
---|
| 29 | using HeuristicLab.Core;
|
---|
[17544] | 30 | using HeuristicLab.Data;
|
---|
[16949] | 31 | using HeuristicLab.Optimization;
|
---|
[17544] | 32 | using HeuristicLab.Parameters;
|
---|
[16949] | 33 |
|
---|
| 34 | namespace HeuristicLab.Encodings.RealVectorEncoding {
|
---|
| 35 | [StorableType("135697c1-1b2b-46b6-a518-1c6efae09475")]
|
---|
| 36 | public abstract class RealVectorMultiObjectiveProblem : MultiObjectiveProblem<RealVectorEncoding, RealVector> {
|
---|
[17544] | 37 | [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; }
|
---|
| 38 | [Storable] protected ReferenceParameter<DoubleMatrix> BoundsRefParameter { get; private set; }
|
---|
[17747] | 39 | [Storable] public IResult<ParetoFrontScatterPlot<RealVector>> BestParetoFrontResult { get; private set; }
|
---|
[17544] | 40 |
|
---|
| 41 | public int Dimension {
|
---|
| 42 | get { return DimensionRefParameter.Value.Value; }
|
---|
| 43 | set { DimensionRefParameter.Value.Value = value; }
|
---|
[16949] | 44 | }
|
---|
| 45 |
|
---|
[17544] | 46 | public DoubleMatrix Bounds {
|
---|
| 47 | get { return BoundsRefParameter.Value; }
|
---|
[17587] | 48 | set { BoundsRefParameter.Value = value; }
|
---|
[17544] | 49 | }
|
---|
| 50 |
|
---|
[17747] | 51 | protected ParetoFrontScatterPlot<RealVector> BestParetoFront {
|
---|
| 52 | get => BestParetoFrontResult.Value;
|
---|
| 53 | set => BestParetoFrontResult.Value = value;
|
---|
| 54 | }
|
---|
| 55 |
|
---|
[16949] | 56 | [StorableConstructor]
|
---|
| 57 | protected RealVectorMultiObjectiveProblem(StorableConstructorFlag _) : base(_) { }
|
---|
| 58 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 59 | private void AfterDeserialization() {
|
---|
| 60 | RegisterEventHandlers();
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | protected RealVectorMultiObjectiveProblem(RealVectorMultiObjectiveProblem original, Cloner cloner)
|
---|
| 64 | : base(original, cloner) {
|
---|
[17544] | 65 | DimensionRefParameter = cloner.Clone(original.DimensionRefParameter);
|
---|
| 66 | BoundsRefParameter = cloner.Clone(original.BoundsRefParameter);
|
---|
[17747] | 67 | BestParetoFrontResult = cloner.Clone(original.BestParetoFrontResult);
|
---|
[16949] | 68 | RegisterEventHandlers();
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | protected RealVectorMultiObjectiveProblem() : this(new RealVectorEncoding() { Length = 10 }) { }
|
---|
| 72 | protected RealVectorMultiObjectiveProblem(RealVectorEncoding encoding) : base(encoding) {
|
---|
| 73 | EncodingParameter.ReadOnly = true;
|
---|
[17695] | 74 | EvaluatorParameter.ReadOnly = true;
|
---|
[17544] | 75 | Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the real vector problem.", Encoding.LengthParameter));
|
---|
| 76 | Parameters.Add(BoundsRefParameter = new ReferenceParameter<DoubleMatrix>("Bounds", "The bounding box of the values.", Encoding.BoundsParameter));
|
---|
[17747] | 77 | Results.Add(BestParetoFrontResult = new Result<ParetoFrontScatterPlot<RealVector>>("Best Pareto Front", "The best Pareto front found so far."));
|
---|
[16949] | 78 |
|
---|
| 79 | Operators.Add(new HammingSimilarityCalculator());
|
---|
| 80 | Operators.Add(new PopulationSimilarityAnalyzer(Operators.OfType<ISolutionSimilarityCalculator>()));
|
---|
| 81 |
|
---|
| 82 | Parameterize();
|
---|
| 83 | RegisterEventHandlers();
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | public override void Analyze(RealVector[] individuals, double[][] qualities, ResultCollection results, IRandom random) {
|
---|
| 87 | base.Analyze(individuals, qualities, results, random);
|
---|
[17230] | 88 |
|
---|
| 89 | var fronts = DominationCalculator.CalculateAllParetoFrontsIndices(individuals, qualities, Maximization);
|
---|
| 90 | var plot = new ParetoFrontScatterPlot<RealVector>(fronts, individuals, qualities, Objectives, BestKnownFront);
|
---|
[17747] | 91 |
|
---|
| 92 | BestParetoFront = plot;
|
---|
[16949] | 93 | }
|
---|
| 94 |
|
---|
[17695] | 95 | protected override sealed void OnEvaluatorChanged() {
|
---|
| 96 | throw new InvalidOperationException("Evaluator may not change!");
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | protected override sealed void OnEncodingChanged() {
|
---|
| 100 | throw new InvalidOperationException("Encoding may not change!");
|
---|
| 101 | }
|
---|
| 102 |
|
---|
[17620] | 103 | protected override void ParameterizeOperators() {
|
---|
| 104 | base.ParameterizeOperators();
|
---|
[16949] | 105 | Parameterize();
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | private void Parameterize() {
|
---|
| 109 | foreach (var similarityCalculator in Operators.OfType<ISolutionSimilarityCalculator>()) {
|
---|
| 110 | similarityCalculator.SolutionVariableName = Encoding.Name;
|
---|
| 111 | similarityCalculator.QualityVariableName = Evaluator.QualitiesParameter.ActualName;
|
---|
| 112 | }
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | private void RegisterEventHandlers() {
|
---|
[17587] | 116 | IntValueParameterChangeHandler.Create(DimensionRefParameter, DimensionOnChanged);
|
---|
| 117 | DoubleMatrixParameterChangeHandler.Create(BoundsRefParameter, BoundsOnChanged);
|
---|
[16949] | 118 | }
|
---|
| 119 |
|
---|
[17544] | 120 | protected virtual void DimensionOnChanged() { }
|
---|
| 121 |
|
---|
| 122 | protected virtual void BoundsOnChanged() { }
|
---|
[16949] | 123 | }
|
---|
| 124 | }
|
---|