Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2701_MemPRAlgorithm/HeuristicLab.Tests/HeuristicLab.Encodings.LinearLinkageEncoding-3.3/MoveTests.cs @ 16752

Last change on this file since 16752 was 14492, checked in by abeham, 8 years ago

#2701:

  • Updated LLE encoding
    • Made folder for version 3.4
    • Added conversion from and to LLE-b representation (back-links)
    • Updated moves and movegenerator to replace bidirectionaldictionary with LLE-b representation
  • Updated MemPR (linear linkage)
    • Updated tabu walk
  • Added test for conversion between LLE-e and LLE and LLE-b and LLE
  • Updated test for move apply/undo and added test for applying in sequence
File size: 2.1 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using HeuristicLab.Encodings.LinearLinkageEncoding;
5using HeuristicLab.Random;
6using Microsoft.VisualStudio.TestTools.UnitTesting;
7
8namespace HeuristicLab.Tests.HeuristicLab.Encodings.LinearLinkageEncoding {
9  [TestClass]
10  public class LinearLinkageMoveTests {
11    [TestMethod]
12    public void TestApplyUndo() {
13      var random = new MersenneTwister(42);
14      for (var p = 0; p < 7; p++) {
15        var lle = ExactGroupsLinearLinkageCreator.Apply(random, 64, (int)Math.Pow(2, p));
16        var before = (LinearLinkage)lle.Clone();
17        var beforeb = before.ToBackLinks();
18        var moves = 0;
19        foreach (var move in MoveGenerator.Generate(lle)) {
20          var lleb = lle.ToBackLinks();
21          move.Apply(lle);
22          move.ApplyToLLEb(lleb);
23          Assert.IsFalse(before.SequenceEqual(lle));
24          Assert.IsFalse(lleb.SequenceEqual(beforeb));
25          Assert.IsTrue(lleb.SequenceEqual(lle.ToBackLinks()));
26          Assert.IsTrue(lle.SequenceEqual(LinearLinkage.FromBackLinks(lleb)));
27          move.Undo(lle);
28          Assert.IsTrue(before.SequenceEqual(lle));
29          moves++;
30        }
31        Assert.IsTrue(moves > 0);
32      }
33    }
34
35    [TestMethod]
36    public void TestApply() {
37      var random = new MersenneTwister(42);
38      for (var p = 0; p < 7; p++) {
39        var lle = ExactGroupsLinearLinkageCreator.Apply(random, 64, (int)Math.Pow(2, p));
40        var lleb = lle.ToBackLinks();
41        var groupItems = new List<int>() { 0 };
42        var moves = 0;
43        for (var i = 1; i < lle.Length; i++) {
44          var move = MoveGenerator.GenerateForItem(i, groupItems, lle, lleb).SampleRandom(random);
45          move.Apply(lle);
46          move.ApplyToLLEb(lleb);
47          Assert.IsTrue(lleb.SequenceEqual(lle.ToBackLinks()));
48          Assert.IsTrue(lle.SequenceEqual(LinearLinkage.FromBackLinks(lleb)));
49
50          if (lleb[i] != i)
51            groupItems.Remove(lleb[i]);
52          groupItems.Add(i);
53
54          moves++;
55        }
56        Assert.IsTrue(moves == lle.Length - 1);
57      }
58    }
59  }
60}
Note: See TracBrowser for help on using the repository browser.