- Timestamp:
- 02/18/15 11:45:29 (10 years ago)
- Location:
- branches/NSGA-II Changes/HeuristicLab.Optimization.Operators/3.3/MultiObjective
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/NSGA-II Changes/HeuristicLab.Optimization.Operators/3.3/MultiObjective/FastNonDominatedSort.cs
r12012 r12034 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Drawing; 25 using System.Linq; 24 26 using HeuristicLab.Common; 25 27 using HeuristicLab.Core; … … 40 42 private enum DominationResult { Dominates, IsDominated, IsNonDominated }; 41 43 44 #region Parameter properties 42 45 public IValueLookupParameter<BoolArray> MaximizationParameter { 43 46 get { return (IValueLookupParameter<BoolArray>)Parameters["Maximization"]; } 44 47 } 45 48 public IValueLookupParameter<BoolValue> TreatSolutionsWithEqualQualityAsDominatedParameter { 49 get { return (ValueLookupParameter<BoolValue>)Parameters["TreatSolutionsWithEqualQualityAsDominated"]; } 50 } 46 51 public IScopeTreeLookupParameter<DoubleArray> QualitiesParameter { 47 52 get { return (IScopeTreeLookupParameter<DoubleArray>)Parameters["Qualities"]; } 48 53 } 49 50 54 public IScopeTreeLookupParameter<IntValue> RankParameter { 51 55 get { return (IScopeTreeLookupParameter<IntValue>)Parameters["Rank"]; } 52 56 } 57 #endregion 53 58 54 59 [StorableConstructor] … … 57 62 public FastNonDominatedSort() { 58 63 Parameters.Add(new ValueLookupParameter<BoolArray>("Maximization", "Whether each objective is maximization or minimization.")); 64 Parameters.Add(new ValueLookupParameter<BoolValue>("TreatSolutionsWithEqualQualityAsDominated", "Flag which determines wether solutions with equal quality values should be treated as dominated.")); 59 65 Parameters.Add(new ScopeTreeLookupParameter<DoubleArray>("Qualities", "The qualities of a solution.", 1)); 60 66 Parameters.Add(new ScopeTreeLookupParameter<IntValue>("Rank", "The rank of a solution.", 1)); … … 62 68 63 69 public override IOperation Apply() { 70 bool treatSolutionsWithEqualQualityAsDominated = TreatSolutionsWithEqualQualityAsDominatedParameter.ActualValue.Value; 64 71 BoolArray maximization = MaximizationParameter.ActualValue; 65 72 ItemArray<DoubleArray> qualities = QualitiesParameter.ActualValue; … … 79 86 dominatedScopes[p] = new List<int>(); 80 87 for (int qI = pI + 1; qI < populationSize; qI++) { 81 DominationResult test = Dominates(qualities[pI], qualities[qI], maximization );88 DominationResult test = Dominates(qualities[pI], qualities[qI], maximization, treatSolutionsWithEqualQualityAsDominated); 82 89 if (test == DominationResult.Dominates) { 83 90 dominatedScopes[p].Add(qI); … … 134 141 } 135 142 136 private DominationResult Dominates(DoubleArray left, DoubleArray right, BoolArray maximizations) { 143 private static DominationResult Dominates(DoubleArray left, DoubleArray right, BoolArray maximizations, bool treatSolutionsWithEqualQualityAsDominated) { 144 if (treatSolutionsWithEqualQualityAsDominated && left.SequenceEqual(right)) return DominationResult.Dominates; 145 137 146 bool leftIsBetter = false, rightIsBetter = false; 138 147 for (int i = 0; i < left.Length; i++) { … … 141 150 if (leftIsBetter && rightIsBetter) break; 142 151 } 152 143 153 if (leftIsBetter && !rightIsBetter) return DominationResult.Dominates; 144 154 if (!leftIsBetter && rightIsBetter) return DominationResult.IsDominated; … … 146 156 } 147 157 148 private bool IsDominated(double left, double right, bool maximization) {158 private static bool IsDominated(double left, double right, bool maximization) { 149 159 return maximization && left < right 150 160 || !maximization && left > right; 151 161 } 152 162 153 private void AddToFront(IScope p, List<ScopeList> fronts, int i) {163 private static void AddToFront(IScope p, List<ScopeList> fronts, int i) { 154 164 if (i == fronts.Count) fronts.Add(new ScopeList()); 155 165 fronts[i].Add(p); … … 159 169 return new FastNonDominatedSort(this, cloner); 160 170 } 171 172 [StorableHook(HookType.AfterDeserialization)] 173 private void AfterDeserialization() { 174 // BackwardsCompatibility3.3 175 #region Backwards compatible code, remove with 3.4 176 if (!Parameters.ContainsKey("TreatSolutionsWithEqualQualityAsDominated")) 177 Parameters.Add(new ValueLookupParameter<BoolValue>("TreatSolutionsWithEqualQualityAsDominated", "Flag which determines wether solutions with equal quality values should be treated as dominated.")); 178 #endregion 179 } 161 180 } 162 181 } -
branches/NSGA-II Changes/HeuristicLab.Optimization.Operators/3.3/MultiObjective/RankAndCrowdingSorter.cs
r12012 r12034 30 30 namespace HeuristicLab.Optimization.Operators { 31 31 public class RankAndCrowdingSorter : AlgorithmOperator, IMultiObjectiveOperator { 32 #region Parameter properties 32 33 public ValueLookupParameter<BoolArray> MaximizationParameter { 33 34 get { return (ValueLookupParameter<BoolArray>)Parameters["Maximization"]; } … … 42 43 get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["CrowdingDistance"]; } 43 44 } 45 public IValueLookupParameter<BoolValue> TreatSolutionsWithEqualQualityAsDominatedParameter { 46 get { return (ValueLookupParameter<BoolValue>)Parameters["TreatSolutionsWithEqualQualityAsDominated"]; } 47 } 48 #endregion 44 49 45 50 [StorableConstructor] … … 49 54 : base() { 50 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>("TreatSolutionsWithEqualQualityAsDominated", "Flag which determines wether solutions with equal quality values should be treated as dominated.")); 51 57 Parameters.Add(new ScopeTreeLookupParameter<DoubleArray>("Qualities", "The vector of quality values.")); 52 58 Parameters.Add(new ScopeTreeLookupParameter<IntValue>("Rank", "The rank of a solution (to which front it belongs).")); … … 60 66 61 67 fastNonDominatedSort.MaximizationParameter.ActualName = MaximizationParameter.Name; 68 fastNonDominatedSort.TreatSolutionsWithEqualQualityAsDominatedParameter.ActualName = TreatSolutionsWithEqualQualityAsDominatedParameter.Name; 62 69 fastNonDominatedSort.QualitiesParameter.ActualName = QualitiesParameter.Name; 63 70 fastNonDominatedSort.RankParameter.ActualName = RankParameter.Name; … … 81 88 return new RankAndCrowdingSorter(this, cloner); 82 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("TreatSolutionsWithEqualQualityAsDominated")) 96 Parameters.Add(new ValueLookupParameter<BoolValue>("TreatSolutionsWithEqualQualityAsDominated", "Flag which determines wether solutions with equal quality values should be treated as dominated.")); 97 #endregion 98 } 83 99 } 84 100 }
Note: See TracChangeset
for help on using the changeset viewer.