Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2521_ProblemRefactoring/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVectorMultiObjectiveProblem.cs @ 17383

Last change on this file since 17383 was 17230, checked in by abeham, 5 years ago

#2521: add multi-objective analysis to all multi-objective encoding-base problems

File size: 3.4 KB
Line 
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
24using System;
25using System.Linq;
26using HEAL.Attic;
27using HeuristicLab.Analysis;
28using HeuristicLab.Common;
29using HeuristicLab.Core;
30using HeuristicLab.Optimization;
31
32namespace 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}
Note: See TracBrowser for help on using the repository browser.