Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2839_HiveProjectManagement/HeuristicLab.Tests/HeuristicLab.Problems.LinearAssignment-3.3/LinearAssignmentProblemSolverTest.cs @ 17277

Last change on this file since 17277 was 16057, checked in by jkarder, 6 years ago

#2839:

File size: 2.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 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 {
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    /// <summary>
34    ///A test for Solve
35    ///</summary>
36    [TestMethod]
37    [TestCategory("Problems.Assignment")]
38    [TestProperty("Time", "short")]
39    public void SolveTest() {
40      double[,] costs = new double[,] {
41        {  5,  9,  3,  6 },
42        {  8,  7,  8,  2 },
43        {  6, 10, 12,  7 },
44        {  3, 10,  8,  6 }};
45      double quality;
46      Permutation p;
47      p = new Permutation(PermutationTypes.Absolute, LinearAssignmentProblemSolver.Solve(new DoubleMatrix(costs), out quality));
48      Assert.AreEqual(18, quality);
49      Assert.IsTrue(p.Validate());
50
51      costs = new double[,] {
52        { 11,  7, 10, 17, 10 },
53        { 13, 21,  7, 11, 13 },
54        { 13, 13, 15, 13, 14 },
55        { 18, 10, 13, 16, 14 },
56        { 12,  8, 16, 19, 10 }};
57
58      p = new Permutation(PermutationTypes.Absolute, LinearAssignmentProblemSolver.Solve(new DoubleMatrix(costs), out quality));
59      Assert.AreEqual(51, quality);
60      Assert.IsTrue(p.Validate());
61
62      costs = new double[,] {
63        {  3,  1,  1,  4 },
64        {  4,  2,  2,  5 },
65        {  5,  3,  4,  8 },
66        {  4,  2,  5,  9 }};
67
68      p = new Permutation(PermutationTypes.Absolute, LinearAssignmentProblemSolver.Solve(new DoubleMatrix(costs), out quality));
69      Assert.AreEqual(13, quality);
70      Assert.IsTrue(p.Validate());
71    }
72  }
73}
Note: See TracBrowser for help on using the repository browser.