Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2521_ProblemRefactoring/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/BinaryVectorMultiObjectiveProblem.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.1 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.BinaryVectorEncoding {
33  [StorableType("b64caac0-a23a-401a-bb7e-ffa3e22b80ea")]
34  public abstract class BinaryVectorMultiObjectiveProblem : MultiObjectiveProblem<BinaryVectorEncoding, BinaryVector> {
35    public int Length {
36      get { return Encoding.Length; }
37      set { Encoding.Length = value; }
38    }
39
40    [StorableConstructor]
41    protected BinaryVectorMultiObjectiveProblem(StorableConstructorFlag _) : base(_) { }
42    [StorableHook(HookType.AfterDeserialization)]
43    private void AfterDeserialization() {
44      RegisterEventHandlers();
45    }
46
47    protected BinaryVectorMultiObjectiveProblem(BinaryVectorMultiObjectiveProblem original, Cloner cloner)
48      : base(original, cloner) {
49      RegisterEventHandlers();
50    }
51
52    protected BinaryVectorMultiObjectiveProblem() : this(new BinaryVectorEncoding() { Length = 10 }) { }
53    protected BinaryVectorMultiObjectiveProblem(BinaryVectorEncoding 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(BinaryVector[] individuals, double[][] qualities, ResultCollection results, IRandom random) {
64      base.Analyze(individuals, qualities, results, random);
65      // TODO: Calculate Pareto front and add to results
66    }
67
68    protected override void OnEncodingChanged() {
69      base.OnEncodingChanged();
70      Parameterize();
71    }
72
73    private void Parameterize() {
74      foreach (var similarityCalculator in Operators.OfType<ISolutionSimilarityCalculator>()) {
75        similarityCalculator.SolutionVariableName = Encoding.Name;
76        similarityCalculator.QualityVariableName = Evaluator.QualitiesParameter.ActualName;
77      }
78    }
79
80    private void RegisterEventHandlers() {
81      Encoding.LengthParameter.Value.ValueChanged += LengthParameter_ValueChanged;
82    }
83
84    protected virtual void LengthParameter_ValueChanged(object sender, EventArgs e) { }
85  }
86}
Note: See TracBrowser for help on using the repository browser.