Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Analysis.AlgorithmBehavior/AlgorithmBehaviorUnitTests/PermutationCacheTest.cs @ 10091

Last change on this file since 10091 was 10060, checked in by ascheibe, 11 years ago

#1886

  • added point calculation from distance matrices
  • added convex hull algorithm based on LP (work in progress)
  • added unit tests
File size: 2.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 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 System.Linq;
23using HeuristicLab.Analysis.SolutionCaching;
24using HeuristicLab.Analysis.SolutionCaching.PermutationEncoding;
25using HeuristicLab.Encodings.PermutationEncoding;
26using Microsoft.VisualStudio.TestTools.UnitTesting;
27
28namespace AlgorithmBehaviorUnitTests {
29  [TestClass]
30  public class PermutationCacheTest {
31    [TestMethod]
32    public void TestPermutationSolutionDictionary() {
33      var rand = new HeuristicLab.Random.FastRandom();
34      PermutationEqualityComparer comp = new PermutationEqualityComparer();
35      PermutationSolutionCache dict = new PermutationSolutionCache();
36      int realDuplicates = 0;
37      int noDuplicates = 0;
38
39      Permutation[] permutations = new Permutation[500];
40      for (int i = 0; i < permutations.Length; i += 2) {
41        var p = new Permutation(PermutationTypes.RelativeUndirected, 21, rand);
42        permutations[i] = p;
43        permutations[i + 1] = p;
44
45        PermutationSolutionInformation pi = new PermutationSolutionInformation();
46        pi.Generation = rand.Next(0, 100);
47        pi.ProducedBy = ProducedBy.Mutation;
48
49        dict.Add(p, pi);
50      }
51
52      for (int i = 0; i < permutations.Length; i++) {
53        for (int j = i + 1; j < permutations.Length; j++) {
54          if (comp.Equals(permutations[i], permutations[j])) {
55            realDuplicates++;
56            break;
57          }
58        }
59      }
60
61      for (int i = 0; i < dict.SolutionDictionary.Keys.Count; i++) {
62        for (int j = i + 1; j < dict.SolutionDictionary.Keys.Count; j++) {
63          if (comp.Equals(dict.SolutionDictionary.Keys.ElementAt(i), dict.SolutionDictionary.Keys.ElementAt(j))) {
64            noDuplicates++;
65            break;
66          }
67        }
68      }
69
70      Assert.AreNotEqual(0, realDuplicates);
71      Assert.AreEqual(0, noDuplicates);
72      Assert.AreEqual(250, dict.SolutionDictionary.Keys.Count);
73    }
74  }
75}
Note: See TracBrowser for help on using the repository browser.