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;
|
---|
30 | using HeuristicLab.Optimization;
|
---|
31 |
|
---|
32 | namespace HeuristicLab.Encodings.IntegerVectorEncoding {
|
---|
33 | [StorableType("11916b0f-4c34-4ece-acae-e28d11211b43")]
|
---|
34 | public abstract class IntegerVectorMultiObjectiveProblem : MultiObjectiveProblem<IntegerVectorEncoding, IntegerVector> {
|
---|
35 | public int Length {
|
---|
36 | get { return Encoding.Length; }
|
---|
37 | set { Encoding.Length = value; }
|
---|
38 | }
|
---|
39 |
|
---|
40 | [StorableConstructor]
|
---|
41 | protected IntegerVectorMultiObjectiveProblem(StorableConstructorFlag _) : base(_) { }
|
---|
42 | [StorableHook(HookType.AfterDeserialization)]
|
---|
43 | private void AfterDeserialization() {
|
---|
44 | RegisterEventHandlers();
|
---|
45 | }
|
---|
46 |
|
---|
47 | protected IntegerVectorMultiObjectiveProblem(IntegerVectorMultiObjectiveProblem original, Cloner cloner)
|
---|
48 | : base(original, cloner) {
|
---|
49 | RegisterEventHandlers();
|
---|
50 | }
|
---|
51 |
|
---|
52 | protected IntegerVectorMultiObjectiveProblem() : this(new IntegerVectorEncoding() { Length = 10 }) { }
|
---|
53 | protected IntegerVectorMultiObjectiveProblem(IntegerVectorEncoding encoding) : base(encoding) {
|
---|
54 | EncodingParameter.ReadOnly = true;
|
---|
55 |
|
---|
56 | Operators.Add(new HammingSimilarityCalculator());
|
---|
57 | Operators.Add(new PopulationSimilarityAnalyzer(Operators.OfType<ISolutionSimilarityCalculator>()));
|
---|
58 |
|
---|
59 | Parameterize();
|
---|
60 | RegisterEventHandlers();
|
---|
61 | }
|
---|
62 |
|
---|
63 | public override void Analyze(IntegerVector[] individuals, double[][] qualities, ResultCollection results, IRandom random) {
|
---|
64 | base.Analyze(individuals, qualities, results, random);
|
---|
65 |
|
---|
66 | var fronts = DominationCalculator.CalculateAllParetoFrontsIndices(individuals, qualities, Maximization);
|
---|
67 | var plot = new ParetoFrontScatterPlot<IntegerVector>(fronts, individuals, qualities, Objectives, BestKnownFront);
|
---|
68 | results.AddOrUpdateResult("Pareto Front Scatter Plot", plot);
|
---|
69 | }
|
---|
70 |
|
---|
71 | protected override void OnEncodingChanged() {
|
---|
72 | base.OnEncodingChanged();
|
---|
73 | Parameterize();
|
---|
74 | }
|
---|
75 |
|
---|
76 | private void Parameterize() {
|
---|
77 | foreach (var similarityCalculator in Operators.OfType<ISolutionSimilarityCalculator>()) {
|
---|
78 | similarityCalculator.SolutionVariableName = Encoding.Name;
|
---|
79 | similarityCalculator.QualityVariableName = Evaluator.QualitiesParameter.ActualName;
|
---|
80 | }
|
---|
81 | }
|
---|
82 |
|
---|
83 | private void RegisterEventHandlers() {
|
---|
84 | Encoding.LengthParameter.Value.ValueChanged += LengthParameter_ValueChanged;
|
---|
85 | }
|
---|
86 |
|
---|
87 | protected virtual void LengthParameter_ValueChanged(object sender, EventArgs e) { }
|
---|
88 | }
|
---|
89 | }
|
---|