Changeset 7000 for branches/Benchmarking/sources/HeuristicLab.Problems.QuadraticAssignment/3.3/QuadraticAssignmentProblem.cs
- Timestamp:
- 11/16/11 15:07:36 (12 years ago)
- Location:
- branches/Benchmarking
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Benchmarking
- Property svn:mergeinfo changed
/trunk (added) merged: 6918-6919,6921-6923,6928-6930,6933,6935,6938-6939,6942,6944,6949-6954,6959,6961-6964,6974-6983,6985-6986,6993-6995,6997-6999
- Property svn:mergeinfo changed
-
branches/Benchmarking/sources
- Property svn:mergeinfo changed
/trunk/sources (added) merged: 6918-6919,6921-6923,6928-6930,6935,6938-6939,6942,6944,6949-6954,6959,6961-6964,6974-6983,6986,6993-6995,6997-6999
- Property svn:mergeinfo changed
-
branches/Benchmarking/sources/HeuristicLab.Problems.QuadraticAssignment
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Problems.QuadraticAssignment (added) merged: 6939,6952
- Property svn:mergeinfo changed
-
branches/Benchmarking/sources/HeuristicLab.Problems.QuadraticAssignment/3.3/QuadraticAssignmentProblem.cs
r6891 r7000 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using System.Drawing; 24 25 using System.IO; 25 26 using System.Linq; 26 27 using System.Reflection; 27 using HeuristicLab.Collections;28 28 using HeuristicLab.Common; 29 29 using HeuristicLab.Core; … … 93 93 } 94 94 95 private ObservableList<string> instances = new ObservableList<string>(); 96 public ObservableList<string> Instances { 97 get { return instances; } 95 public IEnumerable<string> Instances { 96 get { 97 return Assembly.GetExecutingAssembly() 98 .GetManifestResourceNames() 99 .Where(x => x.EndsWith(".dat")) 100 .OrderBy(x => x) 101 .Select(x => x.Replace(".dat", String.Empty)) 102 .Select(x => x.Replace(InstancePrefix, String.Empty)); 103 } 98 104 } 99 105 #endregion … … 103 109 private QuadraticAssignmentProblem(QuadraticAssignmentProblem original, Cloner cloner) 104 110 : base(original, cloner) { 105 instances = new ObservableList<string>(original.instances);106 111 AttachEventHandlers(); 107 112 } … … 113 118 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.", new DoubleMatrix(5, 5))); 114 119 115 Maximization = new BoolValue(false); 120 Maximization.Value = false; 121 MaximizationParameter.Hidden = true; 116 122 117 123 Weights = new DoubleMatrix(new double[,] { … … 411 417 OnReset(); 412 418 } 419 420 public void LoadInstanceFromEmbeddedResource(string instance) { 421 using (Stream stream = Assembly.GetExecutingAssembly() 422 .GetManifestResourceStream(InstancePrefix + instance + ".dat")) { 423 QAPLIBParser datParser = new QAPLIBParser(); 424 datParser.Parse(stream); 425 if (datParser.Error != null) throw datParser.Error; 426 Distances = new DoubleMatrix(datParser.Distances); 427 Weights = new DoubleMatrix(datParser.Weights); 428 Name = instance; 429 Description = "Loaded embedded instance " + instance + " of plugin version " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().FirstOrDefault().Version + "."; 430 431 bool solutionExists = Assembly.GetExecutingAssembly() 432 .GetManifestResourceNames() 433 .Where(x => x.EndsWith(instance + ".sln")) 434 .Any(); 435 436 if (solutionExists) { 437 using (Stream solStream = Assembly.GetExecutingAssembly() 438 .GetManifestResourceStream(InstancePrefix + instance + ".sln")) { 439 QAPLIBSolutionParser slnParser = new QAPLIBSolutionParser(); 440 slnParser.Parse(solStream, true); 441 if (slnParser.Error != null) throw slnParser.Error; 442 443 BestKnownQuality = new DoubleValue(slnParser.Quality); 444 BestKnownSolution = new Permutation(PermutationTypes.Absolute, slnParser.Assignment); 445 BestKnownSolutions = new ItemSet<Permutation>(new PermutationEqualityComparer()); 446 BestKnownSolutions.Add((Permutation)BestKnownSolution.Clone()); 447 448 if (!BestKnownQuality.Value.IsAlmost(QAPEvaluator.Apply(BestKnownSolution, Weights, Distances))) { 449 // the solution doesn't result in the given quality, maybe indices and values are inverted 450 // try parsing again, this time inverting them 451 solStream.Seek(0, SeekOrigin.Begin); 452 slnParser.Reset(); 453 slnParser.Parse(solStream, false); 454 if (slnParser.Error != null) throw slnParser.Error; 455 456 BestKnownQuality = new DoubleValue(slnParser.Quality); 457 BestKnownSolution = new Permutation(PermutationTypes.Absolute, slnParser.Assignment); 458 BestKnownSolutions = new ItemSet<Permutation>(new PermutationEqualityComparer()); 459 BestKnownSolutions.Add((Permutation)BestKnownSolution.Clone()); 460 461 if (!BestKnownQuality.Value.IsAlmost(QAPEvaluator.Apply(BestKnownSolution, Weights, Distances))) { 462 // if the solution still doesn't result in the given quality, remove it and only take the quality 463 BestKnownSolution = null; 464 BestKnownSolutions = new ItemSet<Permutation>(new PermutationEqualityComparer()); 465 } 466 } 467 } 468 } 469 } 470 OnReset(); 471 } 413 472 } 414 473 }
Note: See TracChangeset
for help on using the changeset viewer.