[16876] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[17226] | 3 | * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[16876] | 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 |
|
---|
[17695] | 22 | using System;
|
---|
[16876] | 23 | using System.Linq;
|
---|
| 24 | using HEAL.Attic;
|
---|
| 25 | using HeuristicLab.Analysis;
|
---|
| 26 | using HeuristicLab.Common;
|
---|
| 27 | using HeuristicLab.Core;
|
---|
[17544] | 28 | using HeuristicLab.Data;
|
---|
[16876] | 29 | using HeuristicLab.Optimization;
|
---|
[17544] | 30 | using HeuristicLab.Parameters;
|
---|
[16876] | 31 |
|
---|
| 32 | namespace HeuristicLab.Encodings.BinaryVectorEncoding {
|
---|
| 33 | [StorableType("b64caac0-a23a-401a-bb7e-ffa3e22b80ea")]
|
---|
| 34 | public abstract class BinaryVectorMultiObjectiveProblem : MultiObjectiveProblem<BinaryVectorEncoding, BinaryVector> {
|
---|
[17544] | 35 | [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; }
|
---|
[17747] | 36 | [Storable] public IResult<ParetoFrontScatterPlot<BinaryVector>> BestParetoFrontResult { get; private set; }
|
---|
[17522] | 37 |
|
---|
[17544] | 38 | public int Dimension {
|
---|
[17567] | 39 | get { return DimensionRefParameter.Value.Value; }
|
---|
[17570] | 40 | protected set { DimensionRefParameter.Value.Value = value; }
|
---|
[16876] | 41 | }
|
---|
| 42 |
|
---|
[17747] | 43 | protected ParetoFrontScatterPlot<BinaryVector> BestParetoFront {
|
---|
| 44 | get => BestParetoFrontResult.Value;
|
---|
| 45 | set => BestParetoFrontResult.Value = value;
|
---|
| 46 | }
|
---|
| 47 |
|
---|
[16876] | 48 | [StorableConstructor]
|
---|
| 49 | protected BinaryVectorMultiObjectiveProblem(StorableConstructorFlag _) : base(_) { }
|
---|
| 50 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 51 | private void AfterDeserialization() {
|
---|
| 52 | RegisterEventHandlers();
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | protected BinaryVectorMultiObjectiveProblem(BinaryVectorMultiObjectiveProblem original, Cloner cloner)
|
---|
| 56 | : base(original, cloner) {
|
---|
[17544] | 57 | DimensionRefParameter = cloner.Clone(original.DimensionRefParameter);
|
---|
[17747] | 58 | BestParetoFrontResult = cloner.Clone(original.BestParetoFrontResult);
|
---|
| 59 |
|
---|
[16876] | 60 | RegisterEventHandlers();
|
---|
| 61 | }
|
---|
| 62 |
|
---|
[16948] | 63 | protected BinaryVectorMultiObjectiveProblem() : this(new BinaryVectorEncoding() { Length = 10 }) { }
|
---|
| 64 | protected BinaryVectorMultiObjectiveProblem(BinaryVectorEncoding encoding) : base(encoding) {
|
---|
| 65 | EncodingParameter.ReadOnly = true;
|
---|
[17695] | 66 | EvaluatorParameter.ReadOnly = true;
|
---|
[17544] | 67 | Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the binary vector problem.", Encoding.LengthParameter));
|
---|
[17747] | 68 | Results.Add(BestParetoFrontResult = new Result<ParetoFrontScatterPlot<BinaryVector>>("Best Pareto Front", "The best Pareto front found so far."));
|
---|
[16876] | 69 |
|
---|
| 70 | Operators.Add(new HammingSimilarityCalculator());
|
---|
| 71 | Operators.Add(new PopulationSimilarityAnalyzer(Operators.OfType<ISolutionSimilarityCalculator>()));
|
---|
| 72 |
|
---|
| 73 | Parameterize();
|
---|
| 74 | RegisterEventHandlers();
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | public override void Analyze(BinaryVector[] individuals, double[][] qualities, ResultCollection results, IRandom random) {
|
---|
| 78 | base.Analyze(individuals, qualities, results, random);
|
---|
[17230] | 79 |
|
---|
| 80 | var fronts = DominationCalculator.CalculateAllParetoFrontsIndices(individuals, qualities, Maximization);
|
---|
| 81 | var plot = new ParetoFrontScatterPlot<BinaryVector>(fronts, individuals, qualities, Objectives, BestKnownFront);
|
---|
[17594] | 82 |
|
---|
[17747] | 83 | BestParetoFront = plot;
|
---|
[16876] | 84 | }
|
---|
| 85 |
|
---|
[17695] | 86 | protected override sealed void OnEvaluatorChanged() {
|
---|
| 87 | throw new InvalidOperationException("Evaluator may not change!");
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | protected override sealed void OnEncodingChanged() {
|
---|
| 91 | throw new InvalidOperationException("Encoding may not change!");
|
---|
| 92 | }
|
---|
| 93 |
|
---|
[17620] | 94 | protected override void ParameterizeOperators() {
|
---|
| 95 | base.ParameterizeOperators();
|
---|
[16876] | 96 | Parameterize();
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | private void Parameterize() {
|
---|
| 100 | foreach (var similarityCalculator in Operators.OfType<ISolutionSimilarityCalculator>()) {
|
---|
| 101 | similarityCalculator.SolutionVariableName = Encoding.Name;
|
---|
| 102 | similarityCalculator.QualityVariableName = Evaluator.QualitiesParameter.ActualName;
|
---|
| 103 | }
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | private void RegisterEventHandlers() {
|
---|
[17567] | 107 | IntValueParameterChangeHandler.Create(DimensionRefParameter, DimensionOnChanged);
|
---|
[16876] | 108 | }
|
---|
| 109 |
|
---|
[17544] | 110 | protected virtual void DimensionOnChanged() { }
|
---|
[16876] | 111 | }
|
---|
| 112 | }
|
---|