[16876] | 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 |
|
---|
| 24 | using System;
|
---|
| 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;
|
---|
[16876] | 31 | using HeuristicLab.Optimization;
|
---|
[17544] | 32 | using HeuristicLab.Parameters;
|
---|
[16876] | 33 |
|
---|
| 34 | namespace HeuristicLab.Encodings.IntegerVectorEncoding {
|
---|
| 35 | [StorableType("11916b0f-4c34-4ece-acae-e28d11211b43")]
|
---|
| 36 | public abstract class IntegerVectorMultiObjectiveProblem : MultiObjectiveProblem<IntegerVectorEncoding, IntegerVector> {
|
---|
[17522] | 37 | [Storable] protected IResultParameter<ParetoFrontScatterPlot<IntegerVector>> BestResultParameter { get; private set; }
|
---|
| 38 | public IResultDefinition<ParetoFrontScatterPlot<IntegerVector>> BestResult { get { return BestResultParameter; } }
|
---|
[17544] | 39 | [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; }
|
---|
| 40 | public IValueParameter<IntValue> DimensionParameter => DimensionRefParameter;
|
---|
[17522] | 41 |
|
---|
[17544] | 42 | public int Dimension {
|
---|
| 43 | get { return DimensionRefParameter.Value.Value; }
|
---|
| 44 | set { DimensionRefParameter.Value.Value = value; }
|
---|
[16876] | 45 | }
|
---|
| 46 |
|
---|
| 47 | [StorableConstructor]
|
---|
| 48 | protected IntegerVectorMultiObjectiveProblem(StorableConstructorFlag _) : base(_) { }
|
---|
| 49 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 50 | private void AfterDeserialization() {
|
---|
| 51 | RegisterEventHandlers();
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | protected IntegerVectorMultiObjectiveProblem(IntegerVectorMultiObjectiveProblem original, Cloner cloner)
|
---|
| 55 | : base(original, cloner) {
|
---|
[17522] | 56 | BestResultParameter = cloner.Clone(original.BestResultParameter);
|
---|
[17544] | 57 | DimensionRefParameter = cloner.Clone(original.DimensionRefParameter);
|
---|
[16876] | 58 | RegisterEventHandlers();
|
---|
| 59 | }
|
---|
| 60 |
|
---|
[16948] | 61 | protected IntegerVectorMultiObjectiveProblem() : this(new IntegerVectorEncoding() { Length = 10 }) { }
|
---|
| 62 | protected IntegerVectorMultiObjectiveProblem(IntegerVectorEncoding encoding) : base(encoding) {
|
---|
| 63 | EncodingParameter.ReadOnly = true;
|
---|
[17522] | 64 | Parameters.Add(BestResultParameter = new ResultParameter<ParetoFrontScatterPlot<IntegerVector>>("Best Pareto Front", "The best Pareto front found."));
|
---|
[17544] | 65 | Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the integer vector problem.", Encoding.LengthParameter));
|
---|
[16876] | 66 |
|
---|
| 67 | Operators.Add(new HammingSimilarityCalculator());
|
---|
| 68 | Operators.Add(new PopulationSimilarityAnalyzer(Operators.OfType<ISolutionSimilarityCalculator>()));
|
---|
| 69 |
|
---|
| 70 | Parameterize();
|
---|
| 71 | RegisterEventHandlers();
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | public override void Analyze(IntegerVector[] individuals, double[][] qualities, ResultCollection results, IRandom random) {
|
---|
| 75 | base.Analyze(individuals, qualities, results, random);
|
---|
[17230] | 76 |
|
---|
| 77 | var fronts = DominationCalculator.CalculateAllParetoFrontsIndices(individuals, qualities, Maximization);
|
---|
| 78 | var plot = new ParetoFrontScatterPlot<IntegerVector>(fronts, individuals, qualities, Objectives, BestKnownFront);
|
---|
[17522] | 79 |
|
---|
| 80 | BestResultParameter.ActualValue = plot;
|
---|
[16876] | 81 | }
|
---|
| 82 |
|
---|
| 83 | protected override void OnEncodingChanged() {
|
---|
| 84 | base.OnEncodingChanged();
|
---|
| 85 | Parameterize();
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | private void Parameterize() {
|
---|
| 89 | foreach (var similarityCalculator in Operators.OfType<ISolutionSimilarityCalculator>()) {
|
---|
| 90 | similarityCalculator.SolutionVariableName = Encoding.Name;
|
---|
| 91 | similarityCalculator.QualityVariableName = Evaluator.QualitiesParameter.ActualName;
|
---|
| 92 | }
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | private void RegisterEventHandlers() {
|
---|
[17544] | 96 | DimensionRefParameter.Value.ValueChanged += DimensionParameter_Value_ValueChanged;
|
---|
[16876] | 97 | }
|
---|
| 98 |
|
---|
[17544] | 99 | private void DimensionParameter_Value_ValueChanged(object sender, EventArgs e) {
|
---|
| 100 | DimensionOnChanged();
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | protected virtual void DimensionOnChanged() { }
|
---|
[16876] | 104 | }
|
---|
| 105 | }
|
---|