source: branches/2521_ProblemRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeMultiObjectiveProblem.cs @ 17230

Last change on this file since 17230 was 17230, checked in by abeham, 11 months ago

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

File size: 2.8 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.Optimization;
30
31namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
32  [StorableType("f4819c68-b6fc-469f-bcb5-cb5b2a9d8aff")]
33  public abstract class SymbolicExpressionTreeMultiObjectiveProblem : MultiObjectiveProblem<SymbolicExpressionTreeEncoding, ISymbolicExpressionTree> {
34
35    // persistence
36    [StorableConstructor]
37    protected SymbolicExpressionTreeMultiObjectiveProblem(StorableConstructorFlag _) : base(_) { }
38    [StorableHook(HookType.AfterDeserialization)]
39    private void AfterDeserialization() { }
40
41
42    // cloning
43    protected SymbolicExpressionTreeMultiObjectiveProblem(SymbolicExpressionTreeMultiObjectiveProblem original, Cloner cloner)
44      : base(original, cloner) {
45    }
46
47    protected SymbolicExpressionTreeMultiObjectiveProblem(SymbolicExpressionTreeEncoding encoding)
48      : base(encoding) {
49      EncodingParameter.ReadOnly = true;
50    }
51
52    public override void Analyze(ISymbolicExpressionTree[] trees, double[][] qualities, ResultCollection results,
53      IRandom random) {
54      base.Analyze(trees, qualities, results, random);
55
56      var fronts = DominationCalculator.CalculateAllParetoFrontsIndices(trees, qualities, Maximization);
57      var plot = new ParetoFrontScatterPlot<ISymbolicExpressionTree>(fronts, trees, qualities, Objectives, BestKnownFront);
58      results.AddOrUpdateResult("Pareto Front Scatter Plot", plot);
59    }
60
61    protected override void OnEncodingChanged() {
62      base.OnEncodingChanged();
63      Parameterize();
64    }
65
66    private void Parameterize() {
67      foreach (var similarityCalculator in Operators.OfType<ISolutionSimilarityCalculator>()) {
68        similarityCalculator.SolutionVariableName = Encoding.Name;
69        similarityCalculator.QualityVariableName = Evaluator.QualitiesParameter.ActualName;
70      }
71    }
72  }
73}
Note: See TracBrowser for help on using the repository browser.