Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Optimization.Operators/3.3/MultiObjective/RankAndCrowdingSorter.cs @ 14186

Last change on this file since 14186 was 14186, checked in by swagner, 8 years ago

#2526: Updated year of copyrights in license headers

File size: 5.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 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  [StorableClass]
32  public class RankAndCrowdingSorter : AlgorithmOperator, IMultiObjectiveOperator {
33    #region Parameter properties
34    public ValueLookupParameter<BoolArray> MaximizationParameter {
35      get { return (ValueLookupParameter<BoolArray>)Parameters["Maximization"]; }
36    }
37    public ScopeTreeLookupParameter<DoubleArray> QualitiesParameter {
38      get { return (ScopeTreeLookupParameter<DoubleArray>)Parameters["Qualities"]; }
39    }
40    public ScopeTreeLookupParameter<IntValue> RankParameter {
41      get { return (ScopeTreeLookupParameter<IntValue>)Parameters["Rank"]; }
42    }
43    public ScopeTreeLookupParameter<DoubleValue> CrowdingDistanceParameter {
44      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["CrowdingDistance"]; }
45    }
46    public IValueLookupParameter<BoolValue> DominateOnEqualQualitiesParameter {
47      get { return (ValueLookupParameter<BoolValue>)Parameters["DominateOnEqualQualities"]; }
48    }
49    #endregion
50
51    [StorableConstructor]
52    protected RankAndCrowdingSorter(bool deserializing) : base(deserializing) { }
53    protected RankAndCrowdingSorter(RankAndCrowdingSorter original, Cloner cloner) : base(original, cloner) { }
54    public RankAndCrowdingSorter()
55      : base() {
56      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."));
57      Parameters.Add(new ValueLookupParameter<BoolValue>("DominateOnEqualQualities", "Flag which determines wether solutions with equal quality values should be treated as dominated."));
58      Parameters.Add(new ScopeTreeLookupParameter<DoubleArray>("Qualities", "The vector of quality values."));
59      Parameters.Add(new ScopeTreeLookupParameter<IntValue>("Rank", "The rank of a solution (to which front it belongs)."));
60      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("CrowdingDistance", "The crowding distance of a solution in a population."));
61
62      FastNonDominatedSort fastNonDominatedSort = new FastNonDominatedSort();
63      UniformSubScopesProcessor subScopesProcessor = new UniformSubScopesProcessor();
64      CrowdingDistanceAssignment crowdingDistanceAssignment = new CrowdingDistanceAssignment();
65      CrowdedComparisonSorter crowdedComparisonSorter = new CrowdedComparisonSorter();
66      MergingReducer mergingReducer = new MergingReducer();
67
68      fastNonDominatedSort.MaximizationParameter.ActualName = MaximizationParameter.Name;
69      fastNonDominatedSort.DominateOnEqualQualitiesParameter.ActualName = DominateOnEqualQualitiesParameter.Name;
70      fastNonDominatedSort.QualitiesParameter.ActualName = QualitiesParameter.Name;
71      fastNonDominatedSort.RankParameter.ActualName = RankParameter.Name;
72
73      crowdingDistanceAssignment.CrowdingDistanceParameter.ActualName = CrowdingDistanceParameter.Name;
74      crowdingDistanceAssignment.QualitiesParameter.ActualName = QualitiesParameter.Name;
75
76      crowdedComparisonSorter.CrowdingDistanceParameter.ActualName = CrowdingDistanceParameter.Name;
77      crowdedComparisonSorter.RankParameter.ActualName = RankParameter.Name;
78
79      OperatorGraph.InitialOperator = fastNonDominatedSort;
80      fastNonDominatedSort.Successor = subScopesProcessor;
81      subScopesProcessor.Operator = crowdingDistanceAssignment;
82      crowdingDistanceAssignment.Successor = crowdedComparisonSorter;
83      crowdedComparisonSorter.Successor = null;
84      subScopesProcessor.Successor = mergingReducer;
85      mergingReducer.Successor = null;
86    }
87
88    public override IDeepCloneable Clone(Cloner cloner) {
89      return new RankAndCrowdingSorter(this, cloner);
90    }
91
92    [StorableHook(HookType.AfterDeserialization)]
93    private void AfterDeserialization() {
94      // BackwardsCompatibility3.3
95      #region Backwards compatible code, remove with 3.4
96      if (!Parameters.ContainsKey("DominateOnEqualQualities"))
97        Parameters.Add(new ValueLookupParameter<BoolValue>("DominateOnEqualQualities", "Flag which determines wether solutions with equal quality values should be treated as dominated."));
98      #endregion
99    }
100  }
101}
Note: See TracBrowser for help on using the repository browser.