Free cookie consent management tool by TermsFeed Policy Generator

source: branches/QAP/HeuristicLab.Problems.QuadraticAssignment/3.3/Tests/QAPLIBInstancesTest.cs @ 5814

Last change on this file since 5814 was 5814, checked in by abeham, 12 years ago

#1330

  • Added a test if the reported quality of the solution instances is similar to the evaluated qualities of these solutions
  • Adapted parsing of the solution file and added another parameter whether the permutation should be treated as facility->location (HeuristicLab default) or location->facility.
  • Adapted QuadraticAssignmentProblem to use that method that corresponds with the reported quality since there is no consistent encoding over all files
  • Improved API documentation of the parsing methods
File size: 2.0 KB
Line 
1using System;
2using System.Text;
3using HeuristicLab.Common;
4using HeuristicLab.Problems.QuadraticAssignment;
5using Microsoft.VisualStudio.TestTools.UnitTesting;
6
7namespace Tests {
8  [TestClass]
9  public class QAPLIBInstancesTest {
10    [TestMethod]
11    public void LoadAllEmbeddedInstances() {
12      QuadraticAssignmentProblem qap = new QuadraticAssignmentProblem();
13      StringBuilder failedInstances = new StringBuilder();
14      foreach (string instance in qap.EmbeddedInstances) {
15        try {
16          qap.LoadEmbeddedInstance(instance);
17        } catch (Exception ex) {
18          failedInstances.AppendLine(instance + ": " + ex.Message);
19        }
20      }
21      Assert.IsTrue(failedInstances.Length == 0, "Following instances failed to load: " + Environment.NewLine + failedInstances.ToString());
22    }
23
24    [TestMethod]
25    public void TestReportedSolutionQuality() {
26      StringBuilder failedInstances = new StringBuilder();
27      QuadraticAssignmentProblem qap = new QuadraticAssignmentProblem();
28      foreach (string instance in qap.EmbeddedInstances) {
29        try {
30          qap.LoadEmbeddedInstance(instance);
31        } catch {
32          Assert.Fail("Not all instances load correctly");
33        }
34        if (qap.BestKnownSolution != null) {
35          double quality = double.NaN;
36          try {
37            quality = QAPEvaluator.Apply(qap.BestKnownSolution, qap.Weights, qap.DistanceMatrix);
38          } catch (Exception ex) {
39            failedInstances.AppendLine("An unknown problem occurred evaluating solution of instance " + instance + ": " + ex.Message);
40          }
41          if (!quality.IsAlmost(qap.BestKnownQuality.Value)) {
42            failedInstances.AppendLine(instance + ": Reported quality: " + qap.BestKnownQuality.Value.ToString() + ", evaluated fitness: " + quality.ToString() + ".");
43          }
44        }
45
46      }
47      Assert.IsTrue(failedInstances.Length == 0, "Following instances report divergent fitness values: " + Environment.NewLine + failedInstances.ToString());
48    }
49  }
50}
Note: See TracBrowser for help on using the repository browser.