Changeset 6760 for branches/PersistenceSpeedUp/HeuristicLab.Problems.QuadraticAssignment/3.3/Analyzers
- Timestamp:
- 09/14/11 13:59:25 (13 years ago)
- Location:
- branches/PersistenceSpeedUp
- Files:
-
- 2 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/PersistenceSpeedUp
- Property svn:ignore
-
old new 12 12 *.psess 13 13 *.vsp 14 *.docstates
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/PersistenceSpeedUp/HeuristicLab.Problems.QuadraticAssignment/3.3/Analyzers/BestQAPSolutionAnalyzer.cs
r5933 r6760 61 61 get { return (LookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; } 62 62 } 63 public LookupParameter<ItemSet<Permutation>> BestKnownSolutionsParameter { 64 get { return (LookupParameter<ItemSet<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<ItemSet<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<ItemSet<Permutation>>("BestKnownSolutions", "The best known solutions of this QAP instance.")); 96 } else if (Parameters["BestKnownSolutions"].GetType().Equals(typeof(LookupParameter<ItemList<Permutation>>))) { 97 string actualName = (Parameters["BestKnownSolutions"] as LookupParameter<ItemList<Permutation>>).ActualName; 98 Parameters.Remove("BestKnownSolutions"); 99 Parameters.Add(new LookupParameter<ItemSet<Permutation>>("BestKnownSolutions", "The best known solutions of this QAP instance.", actualName)); 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 // 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 121 BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[i].Value); 104 122 BestKnownSolutionParameter.ActualValue = (Permutation)permutations[i].Clone(); 123 BestKnownSolutionsParameter.ActualValue = new ItemSet<Permutation>(new PermutationEqualityComparer()); 124 BestKnownSolutionsParameter.ActualValue.Add((Permutation)permutations[i].Clone()); 125 } else if (bestKnownQuality.Value == qualities[i].Value) { 126 // if we matched the best-known quality we'll try to set the best-known solution if it isn't null 127 // and try to add it to the pool of best solutions if it is different 128 if (BestKnownSolutionParameter.ActualValue == null) 129 BestKnownSolutionParameter.ActualValue = (Permutation)permutations[i].Clone(); 130 if (BestKnownSolutionsParameter.ActualValue == null) 131 BestKnownSolutionsParameter.ActualValue = new ItemSet<Permutation>(new PermutationEqualityComparer()); 132 foreach (var k in sorted) { // for each solution that we found check if it is in the pool of best-knowns 133 if (!max && k.Value > qualities[i].Value 134 || max && k.Value < qualities[i].Value) break; // stop when we reached a solution worse than the best-known quality 135 Permutation p = permutations[k.index]; 136 if (!BestKnownSolutionsParameter.ActualValue.Contains(p)) 137 BestKnownSolutionsParameter.ActualValue.Add((Permutation)permutations[k.index].Clone()); 138 } 105 139 } 106 140
Note: See TracChangeset
for help on using the changeset viewer.