Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OaaS/HeuristicLab.Tests/HeuristicLab.Problems.LinearAssignment-3.3/LinearAssignmentProblemSolverTest.cs @ 11290

Last change on this file since 11290 was 7873, checked in by abeham, 13 years ago

#1855:

  • Added linear assignment problem (LAP)
  • Added solver (+unit test)
  • Added dependencies in HeuristicLab-3.3 project
File size: 2.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using HeuristicLab.Data;
23using HeuristicLab.Encodings.PermutationEncoding;
24using Microsoft.VisualStudio.TestTools.UnitTesting;
25
26namespace HeuristicLab.Problems.LinearAssignment.Tests_33 {
27  /// <summary>
28  ///This is a test class for LinearAssignmentProblemSolverTest and is intended
29  ///to contain all LinearAssignmentProblemSolverTest Unit Tests
30  ///</summary>
31  [TestClass()]
32  public class LinearAssignmentProblemSolverTest {
33
34    private TestContext testContextInstance;
35
36    /// <summary>
37    ///Gets or sets the test context which provides
38    ///information about and functionality for the current test run.
39    ///</summary>
40    public TestContext TestContext {
41      get { return testContextInstance; }
42      set { testContextInstance = value; }
43    }
44
45
46    /// <summary>
47    ///A test for Solve
48    ///</summary>
49    [TestMethod()]
50    public void SolveTest() {
51      double[,] costs = new double[,] {
52        {  5,  9,  3,  6 },
53        {  8,  7,  8,  2 },
54        {  6, 10, 12,  7 },
55        {  3, 10,  8,  6 }};
56      double quality;
57      Permutation p;
58      p = new Permutation(PermutationTypes.Absolute, LinearAssignmentProblemSolver.Solve(new DoubleMatrix(costs), out quality));
59      Assert.AreEqual(18, quality);
60      Assert.IsTrue(p.Validate());
61
62      costs = new double[,] {
63        { 11,  7, 10, 17, 10 },
64        { 13, 21,  7, 11, 13 },
65        { 13, 13, 15, 13, 14 },
66        { 18, 10, 13, 16, 14 },
67        { 12,  8, 16, 19, 10 }};
68
69      p = new Permutation(PermutationTypes.Absolute, LinearAssignmentProblemSolver.Solve(new DoubleMatrix(costs), out quality));
70      Assert.AreEqual(51, quality);
71      Assert.IsTrue(p.Validate());
72
73      costs = new double[,] {
74        {  3,  1,  1,  4 },
75        {  4,  2,  2,  5 },
76        {  5,  3,  4,  8 },
77        {  4,  2,  5,  9 }};
78
79      p = new Permutation(PermutationTypes.Absolute, LinearAssignmentProblemSolver.Solve(new DoubleMatrix(costs), out quality));
80      Assert.AreEqual(13, quality);
81      Assert.IsTrue(p.Validate());
82    }
83  }
84}
Note: See TracBrowser for help on using the repository browser.