Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2521_ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding/3.3/PermutationMultiObjectiveProblem.cs @ 17230

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

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

File size: 3.7 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.PermutationEncoding {
33  [StorableType("7bc5215b-c181-40d0-a758-d7c19a356e18")]
34  public abstract class PermutationMultiObjectiveProblem : MultiObjectiveProblem<PermutationEncoding, Permutation> {
35    public int Length {
36      get { return Encoding.Length; }
37      set { Encoding.Length = value; }
38    }
39
40    public PermutationTypes Type {
41      get { return Encoding.Type; }
42      set { Encoding.Type = value; }
43    }
44
45    [StorableConstructor]
46    protected PermutationMultiObjectiveProblem(StorableConstructorFlag _) : base(_) { }
47    [StorableHook(HookType.AfterDeserialization)]
48    private void AfterDeserialization() {
49      RegisterEventHandlers();
50    }
51
52    protected PermutationMultiObjectiveProblem(PermutationMultiObjectiveProblem original, Cloner cloner)
53      : base(original, cloner) {
54      RegisterEventHandlers();
55    }
56
57    protected PermutationMultiObjectiveProblem() : this(new PermutationEncoding() { Length = 10, Type = PermutationTypes.Absolute }) { }
58    protected PermutationMultiObjectiveProblem(PermutationEncoding encoding) : base(encoding) {
59      EncodingParameter.ReadOnly = true;
60
61      Operators.Add(new HammingSimilarityCalculator());
62      Operators.Add(new PopulationSimilarityAnalyzer(Operators.OfType<ISolutionSimilarityCalculator>()));
63
64      Parameterize();
65      RegisterEventHandlers();
66    }
67
68    public override void Analyze(Permutation[] individuals, double[][] qualities, ResultCollection results, IRandom random) {
69      base.Analyze(individuals, qualities, results, random);
70
71      var fronts = DominationCalculator.CalculateAllParetoFrontsIndices(individuals, qualities, Maximization);
72      var plot = new ParetoFrontScatterPlot<Permutation>(fronts, individuals, qualities, Objectives, BestKnownFront);
73      results.AddOrUpdateResult("Pareto Front Scatter Plot", plot);
74    }
75
76    protected override void OnEncodingChanged() {
77      base.OnEncodingChanged();
78      Parameterize();
79    }
80
81    private void Parameterize() {
82      foreach (var similarityCalculator in Operators.OfType<ISolutionSimilarityCalculator>()) {
83        similarityCalculator.SolutionVariableName = Encoding.Name;
84        similarityCalculator.QualityVariableName = Evaluator.QualitiesParameter.ActualName;
85      }
86    }
87
88    private void RegisterEventHandlers() {
89      Encoding.LengthParameter.Value.ValueChanged += LengthParameter_ValueChanged;
90      Encoding.PermutationTypeParameter.Value.ValueChanged += TypeParameter_ValueChanged;
91    }
92
93    protected virtual void LengthParameter_ValueChanged(object sender, EventArgs e) { }
94    protected virtual void TypeParameter_ValueChanged(object sender, EventArgs e) { }
95  }
96}
Note: See TracBrowser for help on using the repository browser.