Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2521: Added and modified encoding-specific abstract base classes

File size: 3.3 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.LinearLinkageEncoding {
33  [StorableType("ad8b6097-a26b-440c-bfd4-92e5ecf17894")]
34  public abstract class LinearLinkageMultiObjectiveProblem : MultiObjectiveProblem<LinearLinkageEncoding, LinearLinkage> {
35    public int Length {
36      get { return Encoding.Length; }
37      set { Encoding.Length = value; }
38    }
39
40    [StorableConstructor]
41    protected LinearLinkageMultiObjectiveProblem(StorableConstructorFlag _) : base(_) { }
42    [StorableHook(HookType.AfterDeserialization)]
43    private void AfterDeserialization() {
44      RegisterEventHandlers();
45    }
46
47    protected LinearLinkageMultiObjectiveProblem(LinearLinkageMultiObjectiveProblem original, Cloner cloner)
48      : base(original, cloner) {
49      RegisterEventHandlers();
50    }
51
52    protected LinearLinkageMultiObjectiveProblem() : this(new LinearLinkageEncoding() { Length = 10 }) { }
53    protected LinearLinkageMultiObjectiveProblem(LinearLinkageEncoding encoding) : base(new LinearLinkageEncoding()) {
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(LinearLinkage[] individuals, double[][] qualities, ResultCollection results, IRandom random) {
64      base.Analyze(individuals, qualities, results, random);
65
66      var result = DominationCalculator<LinearLinkage>.CalculateBestParetoFront(individuals, qualities, Maximization);
67      // TODO: Add results
68    }
69
70    protected override void OnEncodingChanged() {
71      base.OnEncodingChanged();
72      Parameterize();
73    }
74
75    private void Parameterize() {
76      foreach (var similarityCalculator in Operators.OfType<ISolutionSimilarityCalculator>()) {
77        similarityCalculator.SolutionVariableName = Encoding.Name;
78        similarityCalculator.QualityVariableName = Evaluator.QualitiesParameter.ActualName;
79      }
80    }
81
82    private void RegisterEventHandlers() {
83      Encoding.LengthParameter.Value.ValueChanged += LengthParameter_ValueChanged;
84    }
85
86    protected virtual void LengthParameter_ValueChanged(object sender, EventArgs e) { }
87  }
88}
Note: See TracBrowser for help on using the repository browser.