- Timestamp:
- 05/30/11 18:07:32 (14 years ago)
- Location:
- trunk/sources
- Files:
-
- 2 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources
- Property svn:mergeinfo changed
/branches/histogram (added) merged: 5959,5961,5970,5994-5996,5999,6007,6010-6016,6020,6022,6027-6028,6032,6046,6055-6056,6081-6082,6086-6087,6089,6115,6176,6194-6195,6338-6341
- Property svn:mergeinfo changed
-
trunk/sources/HeuristicLab.Problems.QuadraticAssignment/3.3/Analyzers/BestQAPSolutionAnalyzer.cs
r5933 r6342 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 (there may be multiple) 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("BestKnownSolutions")) { 95 Parameters.Add(new LookupParameter<ItemList<Permutation>>("BestKnownSolutions", "The best known solutions of this QAP instance.")); 96 } 97 #endregion 84 98 } 85 99 … … 93 107 DoubleValue bestKnownQuality = BestKnownQualityParameter.ActualValue; 94 108 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; 109 var sorted = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).ToArray(); 110 if (max) sorted = sorted.Reverse().ToArray(); 111 int i = sorted.First().index; 99 112 100 if (bestKnownQuality == null || 101 max && qualities[i].Value > bestKnownQuality.Value || 102 !max && qualities[i].Value < bestKnownQuality.Value) { 113 if (bestKnownQuality == null 114 || max && qualities[i].Value > bestKnownQuality.Value 115 || !max && qualities[i].Value < bestKnownQuality.Value) { 116 // if there isn't a best-known quality or we improved the best-known quality we'll add the current solution as best-known 103 117 BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[i].Value); 104 118 BestKnownSolutionParameter.ActualValue = (Permutation)permutations[i].Clone(); 119 BestKnownSolutionsParameter.ActualValue = new ItemList<Permutation>(); 120 BestKnownSolutionsParameter.ActualValue.Add((Permutation)permutations[i].Clone()); 121 } else if (bestKnownQuality.Value == qualities[i].Value) { 122 // if we matched the best-known quality we'll try to set the best-known solution if it isn't null 123 // and try to add it to the pool of best solutions if it is different 124 if (BestKnownSolutionParameter.ActualValue == null) 125 BestKnownSolutionParameter.ActualValue = (Permutation)permutations[i].Clone(); 126 if (BestKnownSolutionsParameter.ActualValue == null) 127 BestKnownSolutionsParameter.ActualValue = new ItemList<Permutation>(); 128 PermutationEqualityComparer comparer = new PermutationEqualityComparer(); 129 foreach (var k in sorted) { // for each solution that we found check if it is in the pool of best-knowns 130 if (!max && k.Value > qualities[i].Value 131 || max && k.Value < qualities[i].Value) break; // stop when we reached a solution worse than the best-known quality 132 Permutation p = permutations[k.index]; 133 bool alreadyPresent = false; 134 foreach (Permutation p2 in BestKnownSolutionsParameter.ActualValue) { 135 if (comparer.Equals(p, p2)) { 136 alreadyPresent = true; 137 break; 138 } 139 } 140 if (!alreadyPresent) 141 BestKnownSolutionsParameter.ActualValue.Add((Permutation)permutations[k.index].Clone()); 142 } 105 143 } 106 144
Note: See TracChangeset
for help on using the changeset viewer.