1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 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.Linq;
|
---|
23 | using HEAL.Attic;
|
---|
24 | using HeuristicLab.Analysis;
|
---|
25 | using HeuristicLab.Common;
|
---|
26 | using HeuristicLab.Core;
|
---|
27 | using HeuristicLab.Data;
|
---|
28 | using HeuristicLab.Optimization;
|
---|
29 | using HeuristicLab.Parameters;
|
---|
30 |
|
---|
31 | namespace HeuristicLab.Encodings.BinaryVectorEncoding {
|
---|
32 | [StorableType("b64caac0-a23a-401a-bb7e-ffa3e22b80ea")]
|
---|
33 | public abstract class BinaryVectorMultiObjectiveProblem : MultiObjectiveProblem<BinaryVectorEncoding, BinaryVector> {
|
---|
34 | [Storable] protected IResultParameter<ParetoFrontScatterPlot<BinaryVector>> BestResultParameter { get; private set; }
|
---|
35 | [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; }
|
---|
36 |
|
---|
37 | public int Dimension {
|
---|
38 | get { return DimensionRefParameter.Value.Value; }
|
---|
39 | protected set { DimensionRefParameter.Value.Value = value; }
|
---|
40 | }
|
---|
41 |
|
---|
42 | [StorableConstructor]
|
---|
43 | protected BinaryVectorMultiObjectiveProblem(StorableConstructorFlag _) : base(_) { }
|
---|
44 | [StorableHook(HookType.AfterDeserialization)]
|
---|
45 | private void AfterDeserialization() {
|
---|
46 | RegisterEventHandlers();
|
---|
47 | }
|
---|
48 |
|
---|
49 | protected BinaryVectorMultiObjectiveProblem(BinaryVectorMultiObjectiveProblem original, Cloner cloner)
|
---|
50 | : base(original, cloner) {
|
---|
51 | BestResultParameter = cloner.Clone(original.BestResultParameter);
|
---|
52 | DimensionRefParameter = cloner.Clone(original.DimensionRefParameter);
|
---|
53 | RegisterEventHandlers();
|
---|
54 | }
|
---|
55 |
|
---|
56 | protected BinaryVectorMultiObjectiveProblem() : this(new BinaryVectorEncoding() { Length = 10 }) { }
|
---|
57 | protected BinaryVectorMultiObjectiveProblem(BinaryVectorEncoding encoding) : base(encoding) {
|
---|
58 | EncodingParameter.ReadOnly = true;
|
---|
59 | Parameters.Add(BestResultParameter = new ResultParameter<ParetoFrontScatterPlot<BinaryVector>>("Best Pareto Front", "The best Pareto front found."));
|
---|
60 | Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the binary vector problem.", Encoding.LengthParameter));
|
---|
61 |
|
---|
62 | Operators.Add(new HammingSimilarityCalculator());
|
---|
63 | Operators.Add(new PopulationSimilarityAnalyzer(Operators.OfType<ISolutionSimilarityCalculator>()));
|
---|
64 |
|
---|
65 | Parameterize();
|
---|
66 | RegisterEventHandlers();
|
---|
67 | }
|
---|
68 |
|
---|
69 | public override void Analyze(BinaryVector[] individuals, double[][] qualities, ResultCollection results, IRandom random) {
|
---|
70 | base.Analyze(individuals, qualities, results, random);
|
---|
71 |
|
---|
72 | var fronts = DominationCalculator.CalculateAllParetoFrontsIndices(individuals, qualities, Maximization);
|
---|
73 | var plot = new ParetoFrontScatterPlot<BinaryVector>(fronts, individuals, qualities, Objectives, BestKnownFront);
|
---|
74 |
|
---|
75 | BestResultParameter.ActualValue = plot;
|
---|
76 | }
|
---|
77 |
|
---|
78 | protected override void OnEncodingChanged() {
|
---|
79 | base.OnEncodingChanged();
|
---|
80 | Parameterize();
|
---|
81 | }
|
---|
82 |
|
---|
83 | private void Parameterize() {
|
---|
84 | foreach (var similarityCalculator in Operators.OfType<ISolutionSimilarityCalculator>()) {
|
---|
85 | similarityCalculator.SolutionVariableName = Encoding.Name;
|
---|
86 | similarityCalculator.QualityVariableName = Evaluator.QualitiesParameter.ActualName;
|
---|
87 | }
|
---|
88 | }
|
---|
89 |
|
---|
90 | private void RegisterEventHandlers() {
|
---|
91 | IntValueParameterChangeHandler.Create(DimensionRefParameter, DimensionOnChanged);
|
---|
92 | }
|
---|
93 |
|
---|
94 | protected virtual void DimensionOnChanged() { }
|
---|
95 | }
|
---|
96 | }
|
---|