Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 17612 was 17612, checked in by mkommend, 4 years ago

#2521: Added first version of problem results.

File size: 4.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.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.IntegerVectorEncoding {
34  [StorableType("11916b0f-4c34-4ece-acae-e28d11211b43")]
35  public abstract class IntegerVectorMultiObjectiveProblem : MultiObjectiveProblem<IntegerVectorEncoding, IntegerVector> {
36    [Storable] protected IResultParameter<ParetoFrontScatterPlot<IntegerVector>> BestResultParameter { get; private set; }
37    [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; }
38    [Storable] protected ReferenceParameter<IntMatrix> BoundsRefParameter { get; private set; }
39
40    public int Dimension {
41      get { return DimensionRefParameter.Value.Value; }
42      set { DimensionRefParameter.Value.Value = value; }
43    }
44
45    public IntMatrix Bounds {
46      get { return BoundsRefParameter.Value; }
47      set { BoundsRefParameter.Value = value; }
48    }
49
50    [StorableConstructor]
51    protected IntegerVectorMultiObjectiveProblem(StorableConstructorFlag _) : base(_) { }
52    [StorableHook(HookType.AfterDeserialization)]
53    private void AfterDeserialization() {
54      RegisterEventHandlers();
55    }
56
57    protected IntegerVectorMultiObjectiveProblem(IntegerVectorMultiObjectiveProblem original, Cloner cloner)
58      : base(original, cloner) {
59      BestResultParameter = cloner.Clone(original.BestResultParameter);
60      DimensionRefParameter = cloner.Clone(original.DimensionRefParameter);
61      BoundsRefParameter = cloner.Clone(original.BoundsRefParameter);
62      RegisterEventHandlers();
63    }
64
65    protected IntegerVectorMultiObjectiveProblem() : this(new IntegerVectorEncoding() { Length = 10 }) { }
66    protected IntegerVectorMultiObjectiveProblem(IntegerVectorEncoding encoding) : base(encoding) {
67      EncodingParameter.ReadOnly = true;
68      Parameters.Add(BestResultParameter = new ResultParameter<ParetoFrontScatterPlot<IntegerVector>>("Best Pareto Front", "The best Pareto front found."));
69      Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the integer vector problem.", Encoding.LengthParameter));
70      Parameters.Add(BoundsRefParameter = new ReferenceParameter<IntMatrix>("Bounds", "The bounds of the integer vector problem.", Encoding.BoundsParameter));
71
72      Operators.Add(new HammingSimilarityCalculator());
73      Operators.Add(new PopulationSimilarityAnalyzer(Operators.OfType<ISolutionSimilarityCalculator>()));
74
75      Parameterize();
76      RegisterEventHandlers();
77    }
78
79    public override void Analyze(IntegerVector[] individuals, double[][] qualities, ResultCollection results, IRandom random) {
80      base.Analyze(individuals, qualities, results, random);
81
82      var fronts = DominationCalculator.CalculateAllParetoFrontsIndices(individuals, qualities, Maximization);
83      var plot = new ParetoFrontScatterPlot<IntegerVector>(fronts, individuals, qualities, Objectives, BestKnownFront);
84
85      BestResultParameter.ActualValue = plot;
86    }
87
88    protected override void OnEncodingChanged() {
89      base.OnEncodingChanged();
90      Parameterize();
91    }
92
93    private void Parameterize() {
94      foreach (var similarityCalculator in Operators.OfType<ISolutionSimilarityCalculator>()) {
95        similarityCalculator.SolutionVariableName = Encoding.Name;
96        similarityCalculator.QualityVariableName = Evaluator.QualitiesParameter.ActualName;
97      }
98    }
99
100    private void RegisterEventHandlers() {
101      IntValueParameterChangeHandler.Create(DimensionRefParameter, DimensionOnChanged);
102      IntMatrixParameterChangeHandler.Create(BoundsRefParameter, BoundsOnChanged);
103    }
104
105    protected virtual void DimensionOnChanged() { }
106
107    protected virtual void BoundsOnChanged() { }
108  }
109}
Note: See TracBrowser for help on using the repository browser.