Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/LinearLinkageMultiObjectiveProblem.cs @ 17587

Last change on this file since 17587 was 17587, checked in by abeham, 4 years ago

#2521: refactoring in progress

File size: 3.9 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.Linq;
25using HEAL.Attic;
26using HeuristicLab.Analysis;
27using HeuristicLab.Common;
28using HeuristicLab.Core;
29using HeuristicLab.Data;
30using HeuristicLab.Optimization;
31using HeuristicLab.Parameters;
32
33namespace HeuristicLab.Encodings.LinearLinkageEncoding {
34  [StorableType("ad8b6097-a26b-440c-bfd4-92e5ecf17894")]
35  public abstract class LinearLinkageMultiObjectiveProblem : MultiObjectiveProblem<LinearLinkageEncoding, LinearLinkage> {
36    [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; }
37    public IValueParameter<IntValue> DimensionParameter => DimensionRefParameter;
38
39    public int Dimension {
40      get { return DimensionRefParameter.Value.Value; }
41      set { DimensionRefParameter.Value.Value = value; }
42    }
43
44    [StorableConstructor]
45    protected LinearLinkageMultiObjectiveProblem(StorableConstructorFlag _) : base(_) { }
46    [StorableHook(HookType.AfterDeserialization)]
47    private void AfterDeserialization() {
48      RegisterEventHandlers();
49    }
50
51    protected LinearLinkageMultiObjectiveProblem(LinearLinkageMultiObjectiveProblem original, Cloner cloner)
52      : base(original, cloner) {
53      DimensionRefParameter = cloner.Clone(original.DimensionRefParameter);
54      RegisterEventHandlers();
55    }
56
57    protected LinearLinkageMultiObjectiveProblem() : this(new LinearLinkageEncoding() { Length = 10 }) { }
58    protected LinearLinkageMultiObjectiveProblem(LinearLinkageEncoding encoding) : base(new LinearLinkageEncoding()) {
59      EncodingParameter.ReadOnly = true;
60      Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the linear linkage problem.", Encoding.LengthParameter));
61
62
63      Operators.Add(new HammingSimilarityCalculator());
64      Operators.Add(new PopulationSimilarityAnalyzer(Operators.OfType<ISolutionSimilarityCalculator>()));
65
66      Parameterize();
67      RegisterEventHandlers();
68    }
69
70    public override void Analyze(LinearLinkage[] individuals, double[][] qualities, ResultCollection results, IRandom random) {
71      base.Analyze(individuals, qualities, results, random);
72
73      var fronts = DominationCalculator.CalculateAllParetoFrontsIndices(individuals, qualities, Maximization);
74      var plot = new ParetoFrontScatterPlot<LinearLinkage>(fronts, individuals, qualities, Objectives, BestKnownFront);
75      results.AddOrUpdateResult("Pareto Front Scatter Plot", 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}
Note: See TracBrowser for help on using the repository browser.