Changeset 12123
- Timestamp:
- 03/04/15 14:26:35 (10 years ago)
- Location:
- trunk/sources
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources
- Property svn:mergeinfo changed
/branches/NSGA-II Changes (added) merged: 12033-12034,12044
- Property svn:mergeinfo changed
-
trunk/sources/HeuristicLab.Algorithms.NSGA2/3.3/NSGA2.cs
r12012 r12123 88 88 get { return (ValueParameter<IntValue>)Parameters["SelectedParents"]; } 89 89 } 90 91 private IFixedValueParameter<BoolValue> DominateOnEqualQualitiesParameter { 92 get { return (IFixedValueParameter<BoolValue>)Parameters["DominateOnEqualQualities"]; } 93 } 90 94 #endregion 91 95 … … 135 139 set { SelectedParentsParameter.Value = value; } 136 140 } 141 public bool DominateOnEqualQualities { 142 get { return DominateOnEqualQualitiesParameter.Value.Value; } 143 set { DominateOnEqualQualitiesParameter.Value.Value = value; } 144 } 145 137 146 private RandomCreator RandomCreator { 138 147 get { return (RandomCreator)OperatorGraph.InitialOperator; } … … 171 180 Parameters.Add(new ValueParameter<IntValue>("MaximumGenerations", "The maximum number of generations which should be processed.", new IntValue(1000))); 172 181 Parameters.Add(new ValueParameter<IntValue>("SelectedParents", "Each two parents form a new child, typically this value should be twice the population size, but because the NSGA-II is maximally elitist it can be any multiple of 2 greater than 0.", new IntValue(200))); 182 Parameters.Add(new FixedValueParameter<BoolValue>("DominateOnEqualQualities", "Flag which determines wether solutions with equal quality values should be treated as dominated.", new BoolValue(false))); 173 183 174 184 RandomCreator randomCreator = new RandomCreator(); … … 195 205 subScopesCounter.Successor = rankAndCrowdingSorter; 196 206 207 rankAndCrowdingSorter.DominateOnEqualQualitiesParameter.ActualName = DominateOnEqualQualitiesParameter.Name; 197 208 rankAndCrowdingSorter.CrowdingDistanceParameter.ActualName = "CrowdingDistance"; 198 209 rankAndCrowdingSorter.RankParameter.ActualName = "Rank"; … … 311 322 [StorableHook(HookType.AfterDeserialization)] 312 323 private void AfterDeserialization() { 324 // BackwardsCompatibility3.3 325 #region Backwards compatible code, remove with 3.4 326 if (!Parameters.ContainsKey("DominateOnEqualQualities")) 327 Parameters.Add(new FixedValueParameter<BoolValue>("DominateOnEqualQualities", "Flag which determines wether solutions with equal quality values should be treated as dominated.", new BoolValue(false))); 328 #endregion 329 313 330 PopulationSizeParameter.ValueChanged += new EventHandler(PopulationSizeParameter_ValueChanged); 314 331 PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged); -
trunk/sources/HeuristicLab.Algorithms.NSGA2/3.3/NSGA2MainLoop.cs
r12012 r12123 79 79 get { return (LookupParameter<IntValue>)Parameters["EvaluatedSolutions"]; } 80 80 } 81 public IValueLookupParameter<BoolValue> DominateOnEqualQualitiesParameter { 82 get { return (ValueLookupParameter<BoolValue>)Parameters["DominateOnEqualQualities"]; } 83 } 81 84 #endregion 82 85 83 86 [StorableConstructor] 84 87 protected NSGA2MainLoop(bool deserializing) : base(deserializing) { } 88 [StorableHook(HookType.AfterDeserialization)] 89 private void AfterDeserialization() { 90 // BackwardsCompatibility3.3 91 #region Backwards compatible code, remove with 3.4 92 if (!Parameters.ContainsKey("DominateOnEqualQualities")) 93 Parameters.Add(new ValueLookupParameter<BoolValue>("DominateOnEqualQualities", "Flag which determines wether solutions with equal quality values should be treated as dominated.")); 94 #endregion 95 } 96 85 97 protected NSGA2MainLoop(NSGA2MainLoop original, Cloner cloner) : base(original, cloner) { } 86 98 public NSGA2MainLoop() … … 105 117 Parameters.Add(new ValueLookupParameter<IOperator>("Analyzer", "The operator used to analyze each generation.")); 106 118 Parameters.Add(new LookupParameter<IntValue>("EvaluatedSolutions", "The number of times solutions have been evaluated.")); 119 Parameters.Add(new ValueLookupParameter<BoolValue>("DominateOnEqualQualities", "Flag which determines wether solutions with equal quality values should be treated as dominated.")); 107 120 #endregion 108 121 … … 171 184 subScopesCounter.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name; 172 185 186 rankAndCrowdingSorter.DominateOnEqualQualitiesParameter.ActualName = DominateOnEqualQualitiesParameter.Name; 173 187 rankAndCrowdingSorter.CrowdingDistanceParameter.ActualName = "CrowdingDistance"; 174 188 rankAndCrowdingSorter.RankParameter.ActualName = "Rank"; -
trunk/sources/HeuristicLab.Optimization.Operators/3.3/MultiObjective/FastNonDominatedSort.cs
r12012 r12123 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 } -
trunk/sources/HeuristicLab.Optimization.Operators/3.3/MultiObjective/RankAndCrowdingSorter.cs
r12012 r12123 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> DominateOnEqualQualitiesParameter { 46 get { return (ValueLookupParameter<BoolValue>)Parameters["DominateOnEqualQualities "]; } 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>("DominateOnEqualQualities ", "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.DominateOnEqualQualitiesParameter.ActualName = DominateOnEqualQualitiesParameter.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("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 } 83 99 } 84 100 }
Note: See TracChangeset
for help on using the changeset viewer.