Changeset 6525
- Timestamp:
- 07/07/11 00:37:06 (13 years ago)
- Location:
- trunk/sources
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Core/3.3/Collections/ItemSet.cs
r5445 r6525 54 54 public ItemSet() : base() { } 55 55 public ItemSet(IEnumerable<T> collection) : base(collection) { } 56 public ItemSet(IEqualityComparer<T> comparer) : base(comparer) { } 57 public ItemSet(IEnumerable<T> collection, IEqualityComparer<T> comparer) : base(collection, comparer) { } 56 58 57 59 public object Clone() { -
trunk/sources/HeuristicLab.Problems.QuadraticAssignment/3.3/Analyzers/BestQAPSolutionAnalyzer.cs
r6342 r6525 61 61 get { return (LookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; } 62 62 } 63 public LookupParameter<Item List<Permutation>> BestKnownSolutionsParameter {64 get { return (LookupParameter<Item List<Permutation>>)Parameters["BestKnownSolutions"]; }63 public LookupParameter<ItemSet<Permutation>> BestKnownSolutionsParameter { 64 get { return (LookupParameter<ItemSet<Permutation>>)Parameters["BestKnownSolutions"]; } 65 65 } 66 66 public LookupParameter<Permutation> BestKnownSolutionParameter { … … 84 84 Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the best QAP solution should be stored.")); 85 85 Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this QAP instance.")); 86 Parameters.Add(new LookupParameter<Item List<Permutation>>("BestKnownSolutions", "The best known solutions (there may be multiple) of this QAP instance."));86 Parameters.Add(new LookupParameter<ItemSet<Permutation>>("BestKnownSolutions", "The best known solutions (there may be multiple) of this QAP instance.")); 87 87 Parameters.Add(new LookupParameter<Permutation>("BestKnownSolution", "The best known solution of this QAP instance.")); 88 88 } … … 117 117 BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[i].Value); 118 118 BestKnownSolutionParameter.ActualValue = (Permutation)permutations[i].Clone(); 119 BestKnownSolutionsParameter.ActualValue = new Item List<Permutation>();119 BestKnownSolutionsParameter.ActualValue = new ItemSet<Permutation>(new PermutationEqualityComparer()); 120 120 BestKnownSolutionsParameter.ActualValue.Add((Permutation)permutations[i].Clone()); 121 121 } else if (bestKnownQuality.Value == qualities[i].Value) { … … 125 125 BestKnownSolutionParameter.ActualValue = (Permutation)permutations[i].Clone(); 126 126 if (BestKnownSolutionsParameter.ActualValue == null) 127 BestKnownSolutionsParameter.ActualValue = new ItemList<Permutation>(); 128 PermutationEqualityComparer comparer = new PermutationEqualityComparer(); 127 BestKnownSolutionsParameter.ActualValue = new ItemSet<Permutation>(new PermutationEqualityComparer()); 129 128 foreach (var k in sorted) { // for each solution that we found check if it is in the pool of best-knowns 130 129 if (!max && k.Value > qualities[i].Value 131 130 || max && k.Value < qualities[i].Value) break; // stop when we reached a solution worse than the best-known quality 132 131 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) 132 if (!BestKnownSolutionsParameter.ActualValue.Contains(p)) 141 133 BestKnownSolutionsParameter.ActualValue.Add((Permutation)permutations[k.index].Clone()); 142 134 } -
trunk/sources/HeuristicLab.Problems.QuadraticAssignment/3.3/QuadraticAssignmentProblem.cs
r6342 r6525 49 49 50 50 #region Parameter Properties 51 public IValueParameter<Item List<Permutation>> BestKnownSolutionsParameter {52 get { return (IValueParameter<Item List<Permutation>>)Parameters["BestKnownSolutions"]; }51 public IValueParameter<ItemSet<Permutation>> BestKnownSolutionsParameter { 52 get { return (IValueParameter<ItemSet<Permutation>>)Parameters["BestKnownSolutions"]; } 53 53 } 54 54 public IValueParameter<Permutation> BestKnownSolutionParameter { … … 64 64 65 65 #region Properties 66 public Item List<Permutation> BestKnownSolutions {66 public ItemSet<Permutation> BestKnownSolutions { 67 67 get { return BestKnownSolutionsParameter.Value; } 68 68 set { BestKnownSolutionsParameter.Value = value; } … … 113 113 public QuadraticAssignmentProblem() 114 114 : base(new QAPEvaluator(), new RandomPermutationCreator()) { 115 Parameters.Add(new OptionalValueParameter<Item List<Permutation>>("BestKnownSolutions", "The list of best known solutions which is updated whenever a new better solution is found or may be the optimal solution if it is known beforehand.", null));115 Parameters.Add(new OptionalValueParameter<ItemSet<Permutation>>("BestKnownSolutions", "The list of best known solutions which is updated whenever a new better solution is found or may be the optimal solution if it is known beforehand.", null)); 116 116 Parameters.Add(new OptionalValueParameter<Permutation>("BestKnownSolution", "The best known solution which is updated whenever a new better solution is found or may be the optimal solution if it is known beforehand.", null)); 117 117 Parameters.Add(new ValueParameter<DoubleMatrix>("Weights", "The strength of the connection between the facilities.", new DoubleMatrix(5, 5))); … … 152 152 // BackwardsCompatibility3.3 153 153 #region Backwards compatible code, remove with 3.4 154 /*if (Parameters.ContainsKey("BestKnownSolution")) {155 Permutation solution = ((IValueParameter<Permutation>)Parameters["BestKnownSolution"]).Value;156 Parameters.Remove("BestKnownSolution");157 Parameters.Add(new OptionalValueParameter<ItemList<Permutation>>("BestKnownSolutions", "The list of best known solutions which is updated whenever a new better solution is found or may be the optimal solution if it is known beforehand.", null));158 if (solution != null) {159 BestKnownSolutions = new ItemList<Permutation>();160 BestKnownSolutions.Add(solution);161 }162 }*/163 154 if (!Parameters.ContainsKey("BestKnownSolutions")) { 164 Parameters.Add(new OptionalValueParameter<ItemList<Permutation>>("BestKnownSolutions", "The list of best known solutions which is updated whenever a new better solution is found or may be the optimal solution if it is known beforehand.", null)); 155 Parameters.Add(new OptionalValueParameter<ItemSet<Permutation>>("BestKnownSolutions", "The list of best known solutions which is updated whenever a new better solution is found or may be the optimal solution if it is known beforehand.", null)); 156 } else if (Parameters["BestKnownSolutions"].GetType().Equals(typeof(OptionalValueParameter<ItemList<Permutation>>))) { 157 ItemList<Permutation> list = ((OptionalValueParameter<ItemList<Permutation>>)Parameters["BestKnownSolutions"]).Value; 158 Parameters.Add(new OptionalValueParameter<ItemSet<Permutation>>("BestKnownSolutions", "The list of best known solutions which is updated whenever a new better solution is found or may be the optimal solution if it is known beforehand.", new ItemSet<Permutation>(list))); 165 159 } 166 160 if (Parameters.ContainsKey("DistanceMatrix")) { 167 DoubleMatrix bla= ((ValueParameter<DoubleMatrix>)Parameters["DistanceMatrix"]).Value;161 DoubleMatrix d = ((ValueParameter<DoubleMatrix>)Parameters["DistanceMatrix"]).Value; 168 162 Parameters.Remove("DistanceMatrix"); 169 Parameters.Add(new ValueParameter<DoubleMatrix>("Distances", " bla", bla));163 Parameters.Add(new ValueParameter<DoubleMatrix>("Distances", "The distance matrix which can either be specified directly without the coordinates, or can be calculated automatically from the coordinates.", d)); 170 164 } 171 165 AttachEventHandlers(); … … 411 405 if (solParser.Quality.IsAlmost(QAPEvaluator.Apply(new Permutation(PermutationTypes.Absolute, solParser.Assignment), Weights, Distances))) { 412 406 BestKnownQuality = new DoubleValue(solParser.Quality); 413 BestKnownSolutions = new Item List<Permutation>(new Permutation[] { new Permutation(PermutationTypes.Absolute, solParser.Assignment) });407 BestKnownSolutions = new ItemSet<Permutation>(new Permutation[] { new Permutation(PermutationTypes.Absolute, solParser.Assignment) }, new PermutationEqualityComparer()); 414 408 BestKnownSolution = new Permutation(PermutationTypes.Absolute, solParser.Assignment); 415 409 } else { … … 420 414 } else { 421 415 BestKnownQuality = new DoubleValue(solParser.Quality); 422 BestKnownSolutions = new Item List<Permutation>(new Permutation[] { new Permutation(PermutationTypes.Absolute, solParser.Assignment) });416 BestKnownSolutions = new ItemSet<Permutation>(new Permutation[] { new Permutation(PermutationTypes.Absolute, solParser.Assignment) }, new PermutationEqualityComparer()); 423 417 BestKnownSolution = new Permutation(PermutationTypes.Absolute, solParser.Assignment); 424 418 } … … 426 420 } else { 427 421 BestKnownQuality = null; 428 BestKnownSolutions = n ull;422 BestKnownSolutions = new ItemSet<Permutation>(new PermutationEqualityComparer()); 429 423 BestKnownSolution = null; 430 424 }
Note: See TracChangeset
for help on using the changeset viewer.