Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2521_ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding/3.3/PermutationMultiObjectiveProblem.cs @ 17620

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

#2521:

  • Fixed orienteering problem
  • Corrected ParameterizeOperators in all encoding-specific problem base classes
  • Added new interfaces and wiring code to IntegerVectorEncoding
File size: 4.5 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.PermutationEncoding {
34  [StorableType("7bc5215b-c181-40d0-a758-d7c19a356e18")]
35  public abstract class PermutationMultiObjectiveProblem : MultiObjectiveProblem<PermutationEncoding, Permutation> {
36    [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; }
37    [Storable] protected ReferenceParameter<EnumValue<PermutationTypes>> PermutationTypeRefParameter { get; private set; }
38
39    public int Dimension {
40      get { return DimensionRefParameter.Value.Value; }
41      set { DimensionRefParameter.Value.Value = value; }
42    }
43
44    public PermutationTypes Type {
45      get { return PermutationTypeRefParameter.Value.Value; }
46      set { PermutationTypeRefParameter.Value.Value = value; }
47    }
48
49    [StorableConstructor]
50    protected PermutationMultiObjectiveProblem(StorableConstructorFlag _) : base(_) { }
51    [StorableHook(HookType.AfterDeserialization)]
52    private void AfterDeserialization() {
53      RegisterEventHandlers();
54    }
55
56    protected PermutationMultiObjectiveProblem(PermutationMultiObjectiveProblem original, Cloner cloner)
57      : base(original, cloner) {
58      DimensionRefParameter = cloner.Clone(original.DimensionRefParameter);
59      PermutationTypeRefParameter = cloner.Clone(original.PermutationTypeRefParameter);
60      RegisterEventHandlers();
61    }
62
63    protected PermutationMultiObjectiveProblem() : this(new PermutationEncoding() { Length = 10, Type = PermutationTypes.Absolute }) { }
64    protected PermutationMultiObjectiveProblem(PermutationEncoding encoding) : base(encoding) {
65      EncodingParameter.ReadOnly = true;
66      Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the permutation problem.", Encoding.LengthParameter));
67      Parameters.Add(PermutationTypeRefParameter = new ReferenceParameter<EnumValue<PermutationTypes>>("Type", "The type of the permutation.", Encoding.PermutationTypeParameter));
68
69      Operators.Add(new HammingSimilarityCalculator());
70      Operators.Add(new PopulationSimilarityAnalyzer(Operators.OfType<ISolutionSimilarityCalculator>()));
71
72      Parameterize();
73      RegisterEventHandlers();
74    }
75
76    public override void Analyze(Permutation[] individuals, double[][] qualities, ResultCollection results, IRandom random) {
77      base.Analyze(individuals, qualities, results, random);
78
79      var fronts = DominationCalculator.CalculateAllParetoFrontsIndices(individuals, qualities, Maximization);
80      var plot = new ParetoFrontScatterPlot<Permutation>(fronts, individuals, qualities, Objectives, BestKnownFront);
81      results.AddOrUpdateResult("Pareto Front Scatter Plot", plot);
82    }
83
84    protected override void ParameterizeOperators() {
85      base.ParameterizeOperators();
86      Parameterize();
87    }
88
89    private void Parameterize() {
90      foreach (var similarityCalculator in Operators.OfType<ISolutionSimilarityCalculator>()) {
91        similarityCalculator.SolutionVariableName = Encoding.Name;
92        similarityCalculator.QualityVariableName = Evaluator.QualitiesParameter.ActualName;
93      }
94    }
95
96    private void RegisterEventHandlers() {
97      IntValueParameterChangeHandler.Create(DimensionRefParameter, DimensionOnChanged);
98      EnumValueParameterChangeHandler<PermutationTypes>.Create(PermutationTypeRefParameter, TypeOnChanged);
99    }
100
101    protected virtual void DimensionOnChanged() { }
102
103    protected virtual void TypeOnChanged() { }
104  }
105}
Note: See TracBrowser for help on using the repository browser.