Changeset 6342 for trunk/sources/HeuristicLab.Problems.QuadraticAssignment/3.3/QuadraticAssignmentProblem.cs
- Timestamp:
- 05/30/11 18:07:32 (13 years ago)
- Location:
- trunk/sources
- Files:
-
- 2 edited
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/QuadraticAssignmentProblem.cs
r6088 r6342 49 49 50 50 #region Parameter Properties 51 public IValueParameter<ItemList<Permutation>> BestKnownSolutionsParameter { 52 get { return (IValueParameter<ItemList<Permutation>>)Parameters["BestKnownSolutions"]; } 53 } 51 54 public IValueParameter<Permutation> BestKnownSolutionParameter { 52 55 get { return (IValueParameter<Permutation>)Parameters["BestKnownSolution"]; } … … 61 64 62 65 #region Properties 66 public ItemList<Permutation> BestKnownSolutions { 67 get { return BestKnownSolutionsParameter.Value; } 68 set { BestKnownSolutionsParameter.Value = value; } 69 } 63 70 public Permutation BestKnownSolution { 64 71 get { return BestKnownSolutionParameter.Value; } … … 88 95 get { return Operators.OfType<BestQAPSolutionAnalyzer>().FirstOrDefault(); } 89 96 } 97 98 private QAPAlleleFrequencyAnalyzer QAPAlleleFrequencyAnalyzer { 99 get { return Operators.OfType<QAPAlleleFrequencyAnalyzer>().FirstOrDefault(); } 100 } 101 102 private QAPPopulationDiversityAnalyzer QAPPopulationDiversityAnalyzer { 103 get { return Operators.OfType<QAPPopulationDiversityAnalyzer>().FirstOrDefault(); } 104 } 90 105 #endregion 91 106 … … 98 113 public QuadraticAssignmentProblem() 99 114 : base(new QAPEvaluator(), new RandomPermutationCreator()) { 115 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)); 100 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)); 101 117 Parameters.Add(new ValueParameter<DoubleMatrix>("Weights", "The strength of the connection between the facilities.", new DoubleMatrix(5, 5))); … … 130 146 public override IDeepCloneable Clone(Cloner cloner) { 131 147 return new QuadraticAssignmentProblem(this, cloner); 148 } 149 150 [StorableHook(HookType.AfterDeserialization)] 151 private void AfterDeserialization() { 152 // BackwardsCompatibility3.3 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 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)); 165 } 166 if (Parameters.ContainsKey("DistanceMatrix")) { 167 DoubleMatrix bla = ((ValueParameter<DoubleMatrix>)Parameters["DistanceMatrix"]).Value; 168 Parameters.Remove("DistanceMatrix"); 169 Parameters.Add(new ValueParameter<DoubleMatrix>("Distances", "bla", bla)); 170 } 171 AttachEventHandlers(); 172 #endregion 132 173 } 133 174 … … 217 258 218 259 #region Helpers 219 [StorableHook(HookType.AfterDeserialization)]220 private void AfterDeserializationHook() {221 AttachEventHandlers();222 }223 224 260 private void AttachEventHandlers() { 225 261 SolutionCreator.PermutationParameter.ActualNameChanged += new EventHandler(SolutionCreator_PermutationParameter_ActualNameChanged); … … 238 274 Operators.AddRange(ApplicationManager.Manager.GetInstances<IQAPMoveEvaluator>()); 239 275 Operators.Add(new BestQAPSolutionAnalyzer()); 276 Operators.Add(new QAPAlleleFrequencyAnalyzer()); 277 Operators.Add(new QAPPopulationDiversityAnalyzer()); 278 Operators.Add(new QAPExhaustiveSwap2LocalImprovement()); 240 279 ParameterizeAnalyzers(); 241 280 ParameterizeOperators(); … … 262 301 BestQAPSolutionAnalyzer.ResultsParameter.ActualName = "Results"; 263 302 BestQAPSolutionAnalyzer.BestKnownQualityParameter.ActualName = BestKnownQualityParameter.Name; 264 BestQAPSolutionAnalyzer.BestKnownSolution Parameter.ActualName = BestKnownSolutionParameter.Name;303 BestQAPSolutionAnalyzer.BestKnownSolutionsParameter.ActualName = BestKnownSolutionsParameter.Name; 265 304 BestQAPSolutionAnalyzer.MaximizationParameter.ActualName = MaximizationParameter.Name; 305 } 306 if (QAPAlleleFrequencyAnalyzer != null) { 307 QAPAlleleFrequencyAnalyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName; 308 QAPAlleleFrequencyAnalyzer.BestKnownSolutionParameter.ActualName = BestKnownSolutionParameter.Name; 309 QAPAlleleFrequencyAnalyzer.DistancesParameter.ActualName = DistancesParameter.Name; 310 QAPAlleleFrequencyAnalyzer.MaximizationParameter.ActualName = MaximizationParameter.Name; 311 QAPAlleleFrequencyAnalyzer.ResultsParameter.ActualName = "Results"; 312 QAPAlleleFrequencyAnalyzer.SolutionParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 313 QAPAlleleFrequencyAnalyzer.WeightsParameter.ActualName = WeightsParameter.Name; 314 } 315 if (QAPPopulationDiversityAnalyzer != null) { 316 QAPPopulationDiversityAnalyzer.MaximizationParameter.ActualName = MaximizationParameter.Name; 317 QAPPopulationDiversityAnalyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName; 318 QAPPopulationDiversityAnalyzer.ResultsParameter.ActualName = "Results"; 319 QAPPopulationDiversityAnalyzer.SolutionParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 266 320 } 267 321 } … … 291 345 foreach (var op in Operators.OfType<IPermutationMultiNeighborhoodShakingOperator>()) 292 346 op.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 347 348 QAPExhaustiveSwap2LocalImprovement localOpt = Operators.OfType<QAPExhaustiveSwap2LocalImprovement>().SingleOrDefault(); 349 if (localOpt != null) { 350 localOpt.AssignmentParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 351 localOpt.DistancesParameter.ActualName = DistancesParameter.Name; 352 localOpt.MaximizationParameter.ActualName = MaximizationParameter.Name; 353 localOpt.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName; 354 localOpt.WeightsParameter.ActualName = WeightsParameter.Name; 355 } 293 356 } 294 357 … … 315 378 Description = "Imported problem data using QAPLIBParser " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().FirstOrDefault().Version + "."; 316 379 BestKnownQuality = null; 317 BestKnownSolution = null;380 BestKnownSolutions = null; 318 381 OnReset(); 319 382 } … … 348 411 if (solParser.Quality.IsAlmost(QAPEvaluator.Apply(new Permutation(PermutationTypes.Absolute, solParser.Assignment), Weights, Distances))) { 349 412 BestKnownQuality = new DoubleValue(solParser.Quality); 413 BestKnownSolutions = new ItemList<Permutation>(new Permutation[] { new Permutation(PermutationTypes.Absolute, solParser.Assignment) }); 350 414 BestKnownSolution = new Permutation(PermutationTypes.Absolute, solParser.Assignment); 351 415 } else { 352 416 BestKnownQuality = new DoubleValue(solParser.Quality); 417 BestKnownSolutions = null; 353 418 BestKnownSolution = null; 354 419 } 355 420 } else { 356 421 BestKnownQuality = new DoubleValue(solParser.Quality); 422 BestKnownSolutions = new ItemList<Permutation>(new Permutation[] { new Permutation(PermutationTypes.Absolute, solParser.Assignment) }); 357 423 BestKnownSolution = new Permutation(PermutationTypes.Absolute, solParser.Assignment); 358 424 } … … 360 426 } else { 361 427 BestKnownQuality = null; 428 BestKnownSolutions = null; 362 429 BestKnownSolution = null; 363 430 }
Note: See TracChangeset
for help on using the changeset viewer.