Changeset 3868
- Timestamp:
- 05/28/10 15:12:21 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Optimization.Operators/3.3/WeightedParentsQualityComparator.cs
r3659 r3868 62 62 if (rightQualities.Length < 1) throw new InvalidOperationException(Name + ": No subscopes found."); 63 63 double compFact = ComparisonFactorParameter.ActualValue.Value; 64 if (compFact < 0 || compFact > 1) throw new InvalidOperationException(Name + ": Comparison Factor is outside the range [0;1]");65 64 bool maximization = MaximizationParameter.ActualValue.Value; 66 65 double leftQuality = LeftSideParameter.ActualValue.Value; … … 70 69 #region Calculate threshold 71 70 if (rightQualities.Length == 2) { // this case will probably be used most often 72 threshold = (maximization ? 73 (Math.Max(rightQualities[0].Value, rightQualities[1].Value) * compFact + Math.Min(rightQualities[0].Value, rightQualities[1].Value) * (1 - compFact)) : 74 (Math.Min(rightQualities[0].Value, rightQualities[1].Value) * compFact + Math.Max(rightQualities[0].Value, rightQualities[1].Value) * (1 - compFact))); 71 double minQuality = Math.Min(rightQualities[0].Value, rightQualities[1].Value); 72 double maxQuality = Math.Max(rightQualities[0].Value, rightQualities[1].Value); 73 if (maximization) 74 threshold = minQuality + (maxQuality - minQuality) * compFact; 75 else 76 threshold = maxQuality - (maxQuality - minQuality) * compFact; 75 77 } else if (rightQualities.Length == 1) { // case for just one parent 76 78 threshold = rightQualities[0].Value; … … 78 80 List<double> sortedQualities = rightQualities.Select(x => x.Value).ToList(); 79 81 sortedQualities.Sort(); 80 double min = sortedQualities.First() * -1; // min is used to pull the qualities to the 0 line82 double minimumQuality = sortedQualities.First(); 81 83 82 double sum = min * sortedQualities.Count;84 double integral = 0; 83 85 for (int i = 0; i < sortedQualities.Count - 1; i++) { 84 sum+= (sortedQualities[i] + sortedQualities[i + 1]) / 2.0; // sum of the trapezoid86 integral += (sortedQualities[i] + sortedQualities[i + 1]) / 2.0; // sum of the trapezoid 85 87 } 86 if (sum == 0) threshold = sortedQualities[0]; // all qualities are equal 88 integral -= minimumQuality * sortedQualities.Count; 89 if (integral == 0) threshold = sortedQualities[0]; // all qualities are equal 87 90 else { 88 double area = sum * (maximization ? compFact : (1 - compFact)); // the qualities are sorted ascending so in minimization a high comp factor (close to 1) means small area89 sum= 0;91 double selectedArea = integral * (maximization ? compFact : (1 - compFact)); 92 integral = 0; 90 93 for (int i = 0; i < sortedQualities.Count - 1; i++) { 91 double currentArea = (sortedQualities[i] + sortedQualities[i + 1]) / 2.0; 92 if (min + currentArea == 0) continue; // skip the first few consecutive 0s 93 sum += min + currentArea; 94 if (sum >= area) { 95 double factor = 1 - ((sum - area) / (min + currentArea)); 94 double currentSliceArea = (sortedQualities[i] + sortedQualities[i + 1]) / 2.0; 95 double windowedSliceArea = currentSliceArea - minimumQuality; 96 if (windowedSliceArea == 0) continue; 97 integral += windowedSliceArea; 98 if (integral >= selectedArea) { 99 double factor = 1 - ((integral - selectedArea) / (windowedSliceArea)); 96 100 threshold = sortedQualities[i] + (sortedQualities[i + 1] - sortedQualities[i]) * factor; 97 101 break;
Note: See TracChangeset
for help on using the changeset viewer.