- Timestamp:
- 04/30/11 15:40:40 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/histogram/HeuristicLab.Problems.QuadraticAssignment/3.3/Analyzers/BestQAPSolutionAnalyzer.cs
r5933 r6086 61 61 get { return (LookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; } 62 62 } 63 public LookupParameter<ItemList<Permutation>> BestKnownSolutionsParameter { 64 get { return (LookupParameter<ItemList<Permutation>>)Parameters["BestKnownSolutions"]; } 65 } 63 66 public LookupParameter<Permutation> BestKnownSolutionParameter { 64 67 get { return (LookupParameter<Permutation>)Parameters["BestKnownSolution"]; } … … 81 84 Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the best QAP solution should be stored.")); 82 85 Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this QAP instance.")); 86 Parameters.Add(new LookupParameter<ItemList<Permutation>>("BestKnownSolutions", "The best known solutions of this QAP instance.")); 83 87 Parameters.Add(new LookupParameter<Permutation>("BestKnownSolution", "The best known solution of this QAP instance.")); 88 } 89 90 [StorableHook(HookType.AfterDeserialization)] 91 private void AfterDeserialization() { 92 // BackwardsCompatibility3.3 93 #region Backwards compatible code, remove with 3.4 94 /*if (Parameters.ContainsKey("BestKnownSolution")) { 95 Parameters.Remove("BestKnownSolution"); 96 Parameters.Add(new LookupParameter<ItemList<Permutation>>("BestKnownSolutions", "The best known solutions of this QAP instance.")); 97 }*/ 98 if (!Parameters.ContainsKey("BestKnownSolutions")) { 99 Parameters.Add(new LookupParameter<ItemList<Permutation>>("BestKnownSolutions", "The best known solutions of this QAP instance.")); 100 } 101 #endregion 84 102 } 85 103 … … 93 111 DoubleValue bestKnownQuality = BestKnownQualityParameter.ActualValue; 94 112 95 int i = -1; 96 if (!max) 97 i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index; 98 else i = qualities.Select((x, index) => new { index, x.Value }).OrderByDescending(x => x.Value).First().index; 113 var sorted = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).ToArray(); 114 if (max) sorted = sorted.Reverse().ToArray(); 115 int i = sorted.First().index; 99 116 100 if (bestKnownQuality == null || 101 max && qualities[i].Value > bestKnownQuality.Value || 102 !max && qualities[i].Value < bestKnownQuality.Value) { 117 if (bestKnownQuality == null 118 || max && qualities[i].Value > bestKnownQuality.Value 119 || !max && qualities[i].Value < bestKnownQuality.Value 120 || bestKnownQuality.Value == qualities[i].Value 121 && (BestKnownSolutionsParameter.ActualValue == null || BestKnownSolutionsParameter.ActualValue.Count == 0)) { 103 122 BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[i].Value); 104 123 BestKnownSolutionParameter.ActualValue = (Permutation)permutations[i].Clone(); 124 BestKnownSolutionsParameter.ActualValue = new ItemList<Permutation>(); 125 BestKnownSolutionsParameter.ActualValue.Add((Permutation)permutations[i].Clone()); 126 } else if (bestKnownQuality != null && qualities[i].Value == bestKnownQuality.Value) { 127 PermutationEqualityComparer comparer = new PermutationEqualityComparer(); 128 foreach (var k in sorted) { 129 if (!max && k.Value > qualities[i].Value 130 || max && k.Value < qualities[i].Value) break; 131 Permutation p = permutations[k.index]; 132 bool alreadyPresent = false; 133 foreach (Permutation p2 in BestKnownSolutionsParameter.ActualValue) { 134 if (comparer.Equals(p, p2)) { 135 alreadyPresent = true; 136 break; 137 } 138 } 139 if (!alreadyPresent) 140 BestKnownSolutionsParameter.ActualValue.Add((Permutation)permutations[k.index].Clone()); 141 } 105 142 } 106 143
Note: See TracChangeset
for help on using the changeset viewer.