Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 5838 was 5838, checked in by abeham, 14 years ago

#1330

  • Renamed the DistanceMatrix parameter to Distances
  • Renamed the SwapMove to Swap2Move and renamed operators accordingly
  • Integrated changes in HeuristicLab.Analysis.Views regarding description text box
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.Distances);
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.