Changeset 6952 for trunk/sources/HeuristicLab.Problems.QuadraticAssignment/3.3/QuadraticAssignmentProblem.cs
- Timestamp:
- 11/06/11 20:47:56 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.QuadraticAssignment/3.3/QuadraticAssignmentProblem.cs
r6939 r6952 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 } … … 412 417 OnReset(); 413 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 } 414 472 } 415 473 }
Note: See TracChangeset
for help on using the changeset viewer.