Changeset 6760 for branches/PersistenceSpeedUp/HeuristicLab.Problems.QuadraticAssignment/3.3/QuadraticAssignmentProblem.cs
- Timestamp:
- 09/14/11 13:59:25 (13 years ago)
- Location:
- branches/PersistenceSpeedUp
- Files:
-
- 2 edited
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/QuadraticAssignmentProblem.cs
r6088 r6760 49 49 50 50 #region Parameter Properties 51 public IValueParameter<ItemSet<Permutation>> BestKnownSolutionsParameter { 52 get { return (IValueParameter<ItemSet<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 ItemSet<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<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)); 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("BestKnownSolutions")) { 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.Remove("BestKnownSolutions"); 159 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.", (list != null ? new ItemSet<Permutation>(list) : null))); 160 } 161 if (Parameters.ContainsKey("DistanceMatrix")) { 162 DoubleMatrix d = ((ValueParameter<DoubleMatrix>)Parameters["DistanceMatrix"]).Value; 163 Parameters.Remove("DistanceMatrix"); 164 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)); 165 } 166 AttachEventHandlers(); 167 #endregion 132 168 } 133 169 … … 217 253 218 254 #region Helpers 219 [StorableHook(HookType.AfterDeserialization)]220 private void AfterDeserializationHook() {221 AttachEventHandlers();222 }223 224 255 private void AttachEventHandlers() { 225 256 SolutionCreator.PermutationParameter.ActualNameChanged += new EventHandler(SolutionCreator_PermutationParameter_ActualNameChanged); … … 238 269 Operators.AddRange(ApplicationManager.Manager.GetInstances<IQAPMoveEvaluator>()); 239 270 Operators.Add(new BestQAPSolutionAnalyzer()); 271 Operators.Add(new QAPAlleleFrequencyAnalyzer()); 272 Operators.Add(new QAPPopulationDiversityAnalyzer()); 273 Operators.Add(new QAPExhaustiveSwap2LocalImprovement()); 240 274 ParameterizeAnalyzers(); 241 275 ParameterizeOperators(); … … 262 296 BestQAPSolutionAnalyzer.ResultsParameter.ActualName = "Results"; 263 297 BestQAPSolutionAnalyzer.BestKnownQualityParameter.ActualName = BestKnownQualityParameter.Name; 264 BestQAPSolutionAnalyzer.BestKnownSolution Parameter.ActualName = BestKnownSolutionParameter.Name;298 BestQAPSolutionAnalyzer.BestKnownSolutionsParameter.ActualName = BestKnownSolutionsParameter.Name; 265 299 BestQAPSolutionAnalyzer.MaximizationParameter.ActualName = MaximizationParameter.Name; 300 } 301 if (QAPAlleleFrequencyAnalyzer != null) { 302 QAPAlleleFrequencyAnalyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName; 303 QAPAlleleFrequencyAnalyzer.BestKnownSolutionParameter.ActualName = BestKnownSolutionParameter.Name; 304 QAPAlleleFrequencyAnalyzer.DistancesParameter.ActualName = DistancesParameter.Name; 305 QAPAlleleFrequencyAnalyzer.MaximizationParameter.ActualName = MaximizationParameter.Name; 306 QAPAlleleFrequencyAnalyzer.ResultsParameter.ActualName = "Results"; 307 QAPAlleleFrequencyAnalyzer.SolutionParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 308 QAPAlleleFrequencyAnalyzer.WeightsParameter.ActualName = WeightsParameter.Name; 309 } 310 if (QAPPopulationDiversityAnalyzer != null) { 311 QAPPopulationDiversityAnalyzer.MaximizationParameter.ActualName = MaximizationParameter.Name; 312 QAPPopulationDiversityAnalyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName; 313 QAPPopulationDiversityAnalyzer.ResultsParameter.ActualName = "Results"; 314 QAPPopulationDiversityAnalyzer.SolutionParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 266 315 } 267 316 } … … 291 340 foreach (var op in Operators.OfType<IPermutationMultiNeighborhoodShakingOperator>()) 292 341 op.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 342 343 QAPExhaustiveSwap2LocalImprovement localOpt = Operators.OfType<QAPExhaustiveSwap2LocalImprovement>().SingleOrDefault(); 344 if (localOpt != null) { 345 localOpt.AssignmentParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 346 localOpt.DistancesParameter.ActualName = DistancesParameter.Name; 347 localOpt.MaximizationParameter.ActualName = MaximizationParameter.Name; 348 localOpt.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName; 349 localOpt.WeightsParameter.ActualName = WeightsParameter.Name; 350 } 293 351 } 294 352 … … 315 373 Description = "Imported problem data using QAPLIBParser " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().FirstOrDefault().Version + "."; 316 374 BestKnownQuality = null; 317 BestKnownSolution = null;375 BestKnownSolutions = null; 318 376 OnReset(); 319 377 } … … 327 385 Distances = new DoubleMatrix(parser.Distances); 328 386 Weights = new DoubleMatrix(parser.Weights); 329 Name = "Quadratic Assignment Problem (loaded instance " + instance + ")";330 Description = "Loaded embedded problem data of instance " + instance + ".";387 Name = instance; 388 Description = "Loaded embedded QAPLIB problem data of instance " + instance + "."; 331 389 OnReset(); 332 390 } … … 348 406 if (solParser.Quality.IsAlmost(QAPEvaluator.Apply(new Permutation(PermutationTypes.Absolute, solParser.Assignment), Weights, Distances))) { 349 407 BestKnownQuality = new DoubleValue(solParser.Quality); 408 BestKnownSolutions = new ItemSet<Permutation>(new Permutation[] { new Permutation(PermutationTypes.Absolute, solParser.Assignment) }, new PermutationEqualityComparer()); 350 409 BestKnownSolution = new Permutation(PermutationTypes.Absolute, solParser.Assignment); 351 410 } else { 352 411 BestKnownQuality = new DoubleValue(solParser.Quality); 412 BestKnownSolutions = null; 353 413 BestKnownSolution = null; 354 414 } 355 415 } else { 356 416 BestKnownQuality = new DoubleValue(solParser.Quality); 417 BestKnownSolutions = new ItemSet<Permutation>(new Permutation[] { new Permutation(PermutationTypes.Absolute, solParser.Assignment) }, new PermutationEqualityComparer()); 357 418 BestKnownSolution = new Permutation(PermutationTypes.Absolute, solParser.Assignment); 358 419 } … … 360 421 } else { 361 422 BestKnownQuality = null; 423 BestKnownSolutions = new ItemSet<Permutation>(new PermutationEqualityComparer()); 362 424 BestKnownSolution = null; 363 425 }
Note: See TracChangeset
for help on using the changeset viewer.