- Timestamp:
- 01/19/15 12:35:24 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/VOSGA/HeuristicLab.Algorithms.VOffspringSelectionGeneticAlgorithm/WeightedParentsDiversityComparator.cs
r11729 r11796 22 22 using System; 23 23 using System.Linq; 24 using HeuristicLab.Analysis; 24 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Core; … … 65 66 get { return (IConstrainedValueParameter<IDiscreteDoubleValueModifier>)Parameters["ComparisonFactorModifier"]; } 66 67 } 68 public ValueLookupParameter<ResultCollection> ResultsParameter { 69 get { return (ValueLookupParameter<ResultCollection>)Parameters["Results"]; } 70 } 71 public ILookupParameter<IntValue> GenerationsParameter { 72 get { return (LookupParameter<IntValue>)Parameters["Generations"]; } 73 } 74 75 private const string spDetailsParameterName = "SPDetails"; 76 private const string divDataRowName = "DiversitySuccessCount"; 77 private const string qualityDataRowName = "QualitySuccessCount"; 78 private const string overallCountDataRowName = "OverallCount"; 79 private const string successCountDataRowName = "SuccessCount"; 80 81 [Storable] 82 private int currentGeneration; 83 [Storable] 84 private int divCount; 85 [Storable] 86 private int qualityCount; 87 [Storable] 88 private int overallCount; 89 [Storable] 90 private int successCount; 67 91 68 92 [StorableConstructor] … … 71 95 : base(original, cloner) { 72 96 SimilarityCalculator = cloner.Clone(original.SimilarityCalculator); 97 currentGeneration = original.currentGeneration; 98 divCount = original.divCount; 99 qualityCount = original.qualityCount; 100 overallCount = original.overallCount; 101 successCount = original.successCount; 73 102 } 74 103 public WeightedParentsDiversityComparator() … … 83 112 Parameters.Add(new ValueLookupParameter<DoubleValue>("DiversityComparisonFactorUpperBound", "The upper bound of the comparison factor (end).", new DoubleValue(1.0))); 84 113 Parameters.Add(new OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>("ComparisonFactorModifier", "The operator used to modify the comparison factor.", new ItemSet<IDiscreteDoubleValueModifier>(new IDiscreteDoubleValueModifier[] { new LinearDiscreteDoubleValueModifier() }), new LinearDiscreteDoubleValueModifier())); 114 Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the population diversity analysis results should be stored.")); 115 Parameters.Add(new LookupParameter<IntValue>("Generations", "The current number of generations.")); 85 116 86 117 foreach (IDiscreteDoubleValueModifier modifier in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name)) … … 93 124 public override IDeepCloneable Clone(Cloner cloner) { 94 125 return new WeightedParentsDiversityComparator(this, cloner); 126 } 127 128 [StorableHook(HookType.AfterDeserialization)] 129 private void AfterDeserialization() { 130 if (!Parameters.ContainsKey("Generations")) 131 Parameters.Add(new LookupParameter<IntValue>("Generations", "The current number of generations.")); 132 if (!Parameters.ContainsKey("Results")) 133 Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the population diversity analysis results should be stored.")); 95 134 } 96 135 … … 115 154 double leftQuality = LeftSideParameter.ActualValue.Value; 116 155 bool resultDiversity; 117 118 156 double threshold = 0; 157 158 DataTable spDetailsTable; 159 if (ResultsParameter.ActualValue.ContainsKey(spDetailsParameterName)) { 160 spDetailsTable = (DataTable)ResultsParameter.ActualValue[spDetailsParameterName].Value; 161 } else { 162 spDetailsTable = new DataTable(spDetailsParameterName); 163 spDetailsTable.Rows.Add(new DataRow(divDataRowName)); 164 spDetailsTable.Rows.Add(new DataRow(qualityDataRowName)); 165 spDetailsTable.Rows.Add(new DataRow(overallCountDataRowName)); 166 spDetailsTable.Rows.Add(new DataRow(successCountDataRowName)); 167 ResultsParameter.ActualValue.Add(new Result(spDetailsParameterName, spDetailsTable)); 168 } 169 170 if (GenerationsParameter.ActualValue.Value != currentGeneration) { 171 spDetailsTable.Rows[divDataRowName].Values.Add(divCount); 172 divCount = 0; 173 spDetailsTable.Rows[qualityDataRowName].Values.Add(qualityCount); 174 qualityCount = 0; 175 spDetailsTable.Rows[overallCountDataRowName].Values.Add(overallCount); 176 overallCount = 0; 177 spDetailsTable.Rows[successCountDataRowName].Values.Add(successCount); 178 successCount = 0; 179 currentGeneration = GenerationsParameter.ActualValue.Value; 180 } 119 181 120 182 #region Calculate threshold … … 140 202 141 203 bool result = maximization && leftQuality > threshold || !maximization && leftQuality < threshold; 204 205 if (result) { 206 qualityCount++; 207 } 208 142 209 result = result && resultDiversity; 210 211 if (resultDiversity) { 212 divCount++; 213 } 214 if (result) { 215 successCount++; 216 } 217 overallCount++; 218 143 219 BoolValue resultValue = ResultParameter.ActualValue; 144 220 if (resultValue == null) {
Note: See TracChangeset
for help on using the changeset viewer.