Free cookie consent management tool by TermsFeed Policy Generator

source: branches/RemoveBackwardsCompatibility/HeuristicLab.Optimization.Operators/3.3/MultiObjective/RankAndCrowdingSorter.cs @ 13365

Last change on this file since 13365 was 12144, checked in by mkommend, 10 years ago

#2321: Removed trailing white space in DominateOnEqualQualities parameter name.

File size: 5.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Data;
25using HeuristicLab.Operators;
26using HeuristicLab.Parameters;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28using HeuristicLab.Selection;
29
30namespace HeuristicLab.Optimization.Operators {
31  public class RankAndCrowdingSorter : AlgorithmOperator, IMultiObjectiveOperator {
32    #region Parameter properties
33    public ValueLookupParameter<BoolArray> MaximizationParameter {
34      get { return (ValueLookupParameter<BoolArray>)Parameters["Maximization"]; }
35    }
36    public ScopeTreeLookupParameter<DoubleArray> QualitiesParameter {
37      get { return (ScopeTreeLookupParameter<DoubleArray>)Parameters["Qualities"]; }
38    }
39    public ScopeTreeLookupParameter<IntValue> RankParameter {
40      get { return (ScopeTreeLookupParameter<IntValue>)Parameters["Rank"]; }
41    }
42    public ScopeTreeLookupParameter<DoubleValue> CrowdingDistanceParameter {
43      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["CrowdingDistance"]; }
44    }
45    public IValueLookupParameter<BoolValue> DominateOnEqualQualitiesParameter {
46      get { return (ValueLookupParameter<BoolValue>)Parameters["DominateOnEqualQualities"]; }
47    }
48    #endregion
49
50    [StorableConstructor]
51    protected RankAndCrowdingSorter(bool deserializing) : base(deserializing) { }
52    protected RankAndCrowdingSorter(RankAndCrowdingSorter original, Cloner cloner) : base(original, cloner) { }
53    public RankAndCrowdingSorter()
54      : base() {
55      Parameters.Add(new ValueLookupParameter<BoolArray>("Maximization", "For each objective a value that is true if that objective should be maximized, or false if it should be minimized."));
56      Parameters.Add(new ValueLookupParameter<BoolValue>("DominateOnEqualQualities", "Flag which determines wether solutions with equal quality values should be treated as dominated."));
57      Parameters.Add(new ScopeTreeLookupParameter<DoubleArray>("Qualities", "The vector of quality values."));
58      Parameters.Add(new ScopeTreeLookupParameter<IntValue>("Rank", "The rank of a solution (to which front it belongs)."));
59      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("CrowdingDistance", "The crowding distance of a solution in a population."));
60
61      FastNonDominatedSort fastNonDominatedSort = new FastNonDominatedSort();
62      UniformSubScopesProcessor subScopesProcessor = new UniformSubScopesProcessor();
63      CrowdingDistanceAssignment crowdingDistanceAssignment = new CrowdingDistanceAssignment();
64      CrowdedComparisonSorter crowdedComparisonSorter = new CrowdedComparisonSorter();
65      MergingReducer mergingReducer = new MergingReducer();
66
67      fastNonDominatedSort.MaximizationParameter.ActualName = MaximizationParameter.Name;
68      fastNonDominatedSort.DominateOnEqualQualitiesParameter.ActualName = DominateOnEqualQualitiesParameter.Name;
69      fastNonDominatedSort.QualitiesParameter.ActualName = QualitiesParameter.Name;
70      fastNonDominatedSort.RankParameter.ActualName = RankParameter.Name;
71
72      crowdingDistanceAssignment.CrowdingDistanceParameter.ActualName = CrowdingDistanceParameter.Name;
73      crowdingDistanceAssignment.QualitiesParameter.ActualName = QualitiesParameter.Name;
74
75      crowdedComparisonSorter.CrowdingDistanceParameter.ActualName = CrowdingDistanceParameter.Name;
76      crowdedComparisonSorter.RankParameter.ActualName = RankParameter.Name;
77
78      OperatorGraph.InitialOperator = fastNonDominatedSort;
79      fastNonDominatedSort.Successor = subScopesProcessor;
80      subScopesProcessor.Operator = crowdingDistanceAssignment;
81      crowdingDistanceAssignment.Successor = crowdedComparisonSorter;
82      crowdedComparisonSorter.Successor = null;
83      subScopesProcessor.Successor = mergingReducer;
84      mergingReducer.Successor = null;
85    }
86
87    public override IDeepCloneable Clone(Cloner cloner) {
88      return new RankAndCrowdingSorter(this, cloner);
89    }
90
91    [StorableHook(HookType.AfterDeserialization)]
92    private void AfterDeserialization() {
93      // BackwardsCompatibility3.3
94      #region Backwards compatible code, remove with 3.4
95      if (!Parameters.ContainsKey("DominateOnEqualQualities"))
96        Parameters.Add(new ValueLookupParameter<BoolValue>("DominateOnEqualQualities", "Flag which determines wether solutions with equal quality values should be treated as dominated."));
97      #endregion
98    }
99  }
100}
Note: See TracBrowser for help on using the repository browser.