Changeset 12079
- Timestamp:
- 02/25/15 23:08:19 (10 years ago)
- Location:
- branches/VOSGA/HeuristicLab.Algorithms.VOffspringSelectionGeneticAlgorithm
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/VOSGA/HeuristicLab.Algorithms.VOffspringSelectionGeneticAlgorithm/Comparators/PopulationDiversityComparator.cs
r11845 r12079 36 36 [Item("PopulationDiversityComparator", "Structural comparison of child to population.")] 37 37 [StorableClass] 38 public class PopulationDiversityComparator : SingleSuccessorOperator, ISubScopesQualityComparatorOperator , ISimilarityBasedOperator{38 public class PopulationDiversityComparator : SingleSuccessorOperator, ISubScopesQualityComparatorOperator { 39 39 [Storable] 40 40 public ISolutionSimilarityCalculator SimilarityCalculator { get; set; } 41 public IValueLookupParameter<ISolutionSimilarityCalculator> SimilarityCalculatorParameter { 42 get { return (IValueLookupParameter<ISolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; } 43 } 41 44 public IValueLookupParameter<BoolValue> MaximizationParameter { 42 45 get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; } … … 126 129 Parameters.Add(new LookupParameter<IntValue>("Generations", "The current number of generations.")); 127 130 Parameters.Add(new ValueParameter<BoolValue>("EnableDivCriteria", "Use diversity as additional offspring selection criteria.", new BoolValue(true))); 131 Parameters.Add(new ValueLookupParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The similarity calculator that should be used to calculate solution similarity.")); 128 132 129 133 foreach (IDiscreteDoubleValueModifier modifier in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name)) … … 136 140 public override IDeepCloneable Clone(Cloner cloner) { 137 141 return new PopulationDiversityComparator(this, cloner); 142 } 143 144 [StorableHook(HookType.AfterDeserialization)] 145 private void AfterDeserialization() { 146 // BackwardsCompatibility3.3 147 #region Backwards compatible code, remove with 3.4 148 if (!Parameters.ContainsKey("SimilarityCalculator")) 149 Parameters.Add(new ValueLookupParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The similarity calculator that should be used to calculate solution similarity.")); 150 #endregion 138 151 } 139 152 … … 207 220 Scope fakeScope = new Scope(); 208 221 fakeScope.SubScopes.Add((IScope)ExecutionContext.Scope.Clone()); 209 var similarities = SimilarityCalculator .CalculateSolutionCrowdSimilarity(fakeScope, remainingScope);222 var similarities = SimilarityCalculatorParameter.ActualValue.CalculateSolutionCrowdSimilarity(fakeScope, remainingScope); 210 223 double averageSimilarity = similarities[0].Average(); 211 224 resultDiversity = averageSimilarity < diversityComFact; -
branches/VOSGA/HeuristicLab.Algorithms.VOffspringSelectionGeneticAlgorithm/Comparators/PopulationQualityComparator.cs
r11845 r12079 20 20 #endregion 21 21 22 using System;23 22 using System.Linq; 24 23 using HeuristicLab.Analysis; … … 36 35 [Item("PopulationQualityComparator", "Compares the quality of the child to the population.")] 37 36 [StorableClass] 38 public class PopulationQualityComparator : SingleSuccessorOperator, ISubScopesQualityComparatorOperator , ISimilarityBasedOperator{37 public class PopulationQualityComparator : SingleSuccessorOperator, ISubScopesQualityComparatorOperator { 39 38 [Storable] 40 39 public ISolutionSimilarityCalculator SimilarityCalculator { get; set; } 40 public IValueLookupParameter<ISolutionSimilarityCalculator> SimilarityCalculatorParameter { 41 get { return (IValueLookupParameter<ISolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; } 42 } 41 43 public IValueLookupParameter<BoolValue> MaximizationParameter { 42 44 get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; } … … 126 128 Parameters.Add(new LookupParameter<IntValue>("Generations", "The current number of generations.")); 127 129 Parameters.Add(new ValueParameter<BoolValue>("EnableDivCriteria", "Use diversity as additional offspring selection criteria.", new BoolValue(false))); 130 Parameters.Add(new ValueLookupParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The similarity calculator that should be used to calculate solution similarity.")); 128 131 129 132 foreach (IDiscreteDoubleValueModifier modifier in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name)) … … 136 139 public override IDeepCloneable Clone(Cloner cloner) { 137 140 return new PopulationQualityComparator(this, cloner); 141 } 142 143 [StorableHook(HookType.AfterDeserialization)] 144 private void AfterDeserialization() { 145 // BackwardsCompatibility3.3 146 #region Backwards compatible code, remove with 3.4 147 if (!Parameters.ContainsKey("SimilarityCalculator")) 148 Parameters.Add(new ValueLookupParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The similarity calculator that should be used to calculate solution similarity.")); 149 #endregion 138 150 } 139 151 -
branches/VOSGA/HeuristicLab.Algorithms.VOffspringSelectionGeneticAlgorithm/Comparators/UnwantedMutationsComparator.cs
r11884 r12079 37 37 [Item("UnwantedMutationsComparator", "Compares the similarity against that of its parents (assumes the parents are subscopes to the child scope). This operator works with any number of subscopes > 0.")] 38 38 [StorableClass] 39 public class UnwantedMutationsComparator : SingleSuccessorOperator, ISubScopesQualityComparatorOperator , ISimilarityBasedOperator{39 public class UnwantedMutationsComparator : SingleSuccessorOperator, ISubScopesQualityComparatorOperator { 40 40 [Storable] 41 41 public ISolutionSimilarityCalculator SimilarityCalculator { get; set; } 42 public IValueLookupParameter<ISolutionSimilarityCalculator> SimilarityCalculatorParameter { 43 get { return (IValueLookupParameter<ISolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; } 44 } 42 45 public IValueLookupParameter<BoolValue> MaximizationParameter { 43 46 get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; } … … 135 138 Parameters.Add(new ValueParameter<BoolValue>("EnableDivCriteria", "Use diversity as additional offspring selection criteria.", new BoolValue(true))); 136 139 Parameters.Add(new ValueParameter<BoolValue>("EnableQualityCriteria", "Use quality as additional offspring selection criteria.", new BoolValue(false))); 140 Parameters.Add(new ValueLookupParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The similarity calculator that should be used to calculate solution similarity.")); 137 141 138 142 foreach (IDiscreteDoubleValueModifier modifier in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name)) … … 145 149 public override IDeepCloneable Clone(Cloner cloner) { 146 150 return new UnwantedMutationsComparator(this, cloner); 151 } 152 153 [StorableHook(HookType.AfterDeserialization)] 154 private void AfterDeserialization() { 155 // BackwardsCompatibility3.3 156 #region Backwards compatible code, remove with 3.4 157 if (!Parameters.ContainsKey("SimilarityCalculator")) 158 Parameters.Add(new ValueLookupParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The similarity calculator that should be used to calculate solution similarity.")); 159 #endregion 147 160 } 148 161 … … 203 216 } 204 217 205 string solutionVariableName = ((ISingleObjectiveSolutionSimilarityCalculator)SimilarityCalculator ).SolutionVariableName;218 string solutionVariableName = ((ISingleObjectiveSolutionSimilarityCalculator)SimilarityCalculatorParameter.ActualValue).SolutionVariableName; 206 219 double resultVal = AnalyzeUnwantedMutations(ExecutionContext.Scope.SubScopes[0], 207 220 ExecutionContext.Scope.SubScopes[1], ExecutionContext.Scope, solutionVariableName); … … 237 250 if (EnableDivCriteriaParameter.Value.Value && !EnableQualityCriteriaParameter.Value.Value) { 238 251 result = resultDiversity; 239 } 252 } 240 253 //use diveristiy criteria or not 241 254 if (EnableDivCriteriaParameter.Value.Value && EnableQualityCriteriaParameter.Value.Value) { -
branches/VOSGA/HeuristicLab.Algorithms.VOffspringSelectionGeneticAlgorithm/Comparators/WeightedParentsDiversityComparator.cs
r11844 r12079 36 36 [Item("WeightedParentsDiversityComparator", "Compares the similarity against that of its parents (assumes the parents are subscopes to the child scope). This operator works with any number of subscopes > 0.")] 37 37 [StorableClass] 38 public class WeightedParentsDiversityComparator : SingleSuccessorOperator, ISubScopesQualityComparatorOperator , ISimilarityBasedOperator{38 public class WeightedParentsDiversityComparator : SingleSuccessorOperator, ISubScopesQualityComparatorOperator { 39 39 [Storable] 40 40 public ISolutionSimilarityCalculator SimilarityCalculator { get; set; } 41 public IValueLookupParameter<ISolutionSimilarityCalculator> SimilarityCalculatorParameter { 42 get { return (IValueLookupParameter<ISolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; } 43 } 41 44 public IValueLookupParameter<BoolValue> MaximizationParameter { 42 45 get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; } … … 126 129 Parameters.Add(new LookupParameter<IntValue>("Generations", "The current number of generations.")); 127 130 Parameters.Add(new ValueParameter<BoolValue>("EnableDivCriteria", "Use diversity as additional offspring selection criteria.", new BoolValue(true))); 131 Parameters.Add(new ValueLookupParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The similarity calculator that should be used to calculate solution similarity.")); 128 132 129 133 foreach (IDiscreteDoubleValueModifier modifier in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name)) … … 146 150 if (!Parameters.ContainsKey("EnableDivCriteria")) 147 151 Parameters.Add(new ValueParameter<BoolValue>("EnableDivCriteria", "Use diversity as additional offspring selection criteria.", new BoolValue(true))); 152 // BackwardsCompatibility3.3 153 #region Backwards compatible code, remove with 3.4 154 if (!Parameters.ContainsKey("SimilarityCalculator")) 155 Parameters.Add(new ValueLookupParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The similarity calculator that should be used to calculate solution similarity.")); 156 #endregion 148 157 } 149 158 … … 202 211 #region Calculate threshold 203 212 if (rightQualities.Length == 2) { 204 var sim1 = SimilarityCalculator .CalculateSolutionSimilarity(ExecutionContext.Scope, ExecutionContext.Scope.SubScopes[0]);205 var sim2 = SimilarityCalculator .CalculateSolutionSimilarity(ExecutionContext.Scope, ExecutionContext.Scope.SubScopes[1]);213 var sim1 = SimilarityCalculatorParameter.ActualValue.CalculateSolutionSimilarity(ExecutionContext.Scope, ExecutionContext.Scope.SubScopes[0]); 214 var sim2 = SimilarityCalculatorParameter.ActualValue.CalculateSolutionSimilarity(ExecutionContext.Scope, ExecutionContext.Scope.SubScopes[1]); 206 215 var simAvg = (sim1 + sim2) / 2.0; 207 216 -
branches/VOSGA/HeuristicLab.Algorithms.VOffspringSelectionGeneticAlgorithm/VOffspringSelectionGeneticAlgorithm.cs
r11516 r12079 444 444 Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); 445 445 } 446 SimilarityCalculatorParameter.ValueChanged += SimilarityCalculatorParameter_ValueChanged;447 }448 void SimilarityCalculatorParameter_ValueChanged(object sender, EventArgs e) {449 foreach (ISimilarityBasedOperator op in SubScopesQualityComparatorParameter.ValidValues.OfType<ISimilarityBasedOperator>())450 op.SimilarityCalculator = SimilarityCalculator;451 446 } 452 447 private void ParameterizeSolutionsCreator() {
Note: See TracChangeset
for help on using the changeset viewer.