Changeset 12276 for stable/HeuristicLab.Optimization.Operators/3.3/MultiObjective/FastNonDominatedSort.cs
- Timestamp:
- 04/01/15 15:44:13 (10 years ago)
- Location:
- stable
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/branches/NSGA-II Changes (added) merged: 12033-12034,12044 /trunk/sources merged: 12123,12144
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Optimization.Operators/3.3/MultiObjective/FastNonDominatedSort.cs
r12009 r12276 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Linq; 24 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Core; … … 40 41 private enum DominationResult { Dominates, IsDominated, IsNonDominated }; 41 42 43 #region Parameter properties 42 44 public IValueLookupParameter<BoolArray> MaximizationParameter { 43 45 get { return (IValueLookupParameter<BoolArray>)Parameters["Maximization"]; } 44 46 } 45 47 public IValueLookupParameter<BoolValue> DominateOnEqualQualitiesParameter { 48 get { return (ValueLookupParameter<BoolValue>)Parameters["DominateOnEqualQualities"]; } 49 } 46 50 public IScopeTreeLookupParameter<DoubleArray> QualitiesParameter { 47 51 get { return (IScopeTreeLookupParameter<DoubleArray>)Parameters["Qualities"]; } 48 52 } 49 50 53 public IScopeTreeLookupParameter<IntValue> RankParameter { 51 54 get { return (IScopeTreeLookupParameter<IntValue>)Parameters["Rank"]; } 52 55 } 56 #endregion 53 57 54 58 [StorableConstructor] … … 57 61 public FastNonDominatedSort() { 58 62 Parameters.Add(new ValueLookupParameter<BoolArray>("Maximization", "Whether each objective is maximization or minimization.")); 63 Parameters.Add(new ValueLookupParameter<BoolValue>("DominateOnEqualQualities", "Flag which determines wether solutions with equal quality values should be treated as dominated.")); 59 64 Parameters.Add(new ScopeTreeLookupParameter<DoubleArray>("Qualities", "The qualities of a solution.", 1)); 60 65 Parameters.Add(new ScopeTreeLookupParameter<IntValue>("Rank", "The rank of a solution.", 1)); … … 62 67 63 68 public override IOperation Apply() { 69 bool dominateOnEqualQualities = DominateOnEqualQualitiesParameter.ActualValue.Value; 64 70 BoolArray maximization = MaximizationParameter.ActualValue; 65 71 ItemArray<DoubleArray> qualities = QualitiesParameter.ActualValue; … … 79 85 dominatedScopes[p] = new List<int>(); 80 86 for (int qI = pI + 1; qI < populationSize; qI++) { 81 DominationResult test = Dominates(qualities[pI], qualities[qI], maximization );87 DominationResult test = Dominates(qualities[pI], qualities[qI], maximization, dominateOnEqualQualities); 82 88 if (test == DominationResult.Dominates) { 83 89 dominatedScopes[p].Add(qI); … … 134 140 } 135 141 136 private DominationResult Dominates(DoubleArray left, DoubleArray right, BoolArray maximizations) { 142 private static DominationResult Dominates(DoubleArray left, DoubleArray right, BoolArray maximizations, bool dominateOnEqualQualities) { 143 if (dominateOnEqualQualities && left.SequenceEqual(right)) return DominationResult.Dominates; 144 137 145 bool leftIsBetter = false, rightIsBetter = false; 138 146 for (int i = 0; i < left.Length; i++) { … … 141 149 if (leftIsBetter && rightIsBetter) break; 142 150 } 151 143 152 if (leftIsBetter && !rightIsBetter) return DominationResult.Dominates; 144 153 if (!leftIsBetter && rightIsBetter) return DominationResult.IsDominated; … … 146 155 } 147 156 148 private bool IsDominated(double left, double right, bool maximization) {157 private static bool IsDominated(double left, double right, bool maximization) { 149 158 return maximization && left < right 150 159 || !maximization && left > right; 151 160 } 152 161 153 private void AddToFront(IScope p, List<ScopeList> fronts, int i) {162 private static void AddToFront(IScope p, List<ScopeList> fronts, int i) { 154 163 if (i == fronts.Count) fronts.Add(new ScopeList()); 155 164 fronts[i].Add(p); … … 159 168 return new FastNonDominatedSort(this, cloner); 160 169 } 170 171 [StorableHook(HookType.AfterDeserialization)] 172 private void AfterDeserialization() { 173 // BackwardsCompatibility3.3 174 #region Backwards compatible code, remove with 3.4 175 if (!Parameters.ContainsKey("DominateOnEqualQualities")) 176 Parameters.Add(new ValueLookupParameter<BoolValue>("DominateOnEqualQualities", "Flag which determines wether solutions with equal quality values should be treated as dominated.")); 177 #endregion 178 } 161 179 } 162 180 }
Note: See TracChangeset
for help on using the changeset viewer.