Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/SymbolicExpressionTreeMaxCommonSubtreeSimilarityCalculatorTest.cs @ 13689

Last change on this file since 13689 was 11916, checked in by bburlacu, 10 years ago

#2215: Merged unit tests into the trunk.

File size: 2.7 KB
Line 
1using System;
2using System.Diagnostics;
3using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
4using HeuristicLab.Problems.DataAnalysis.Symbolic;
5using HeuristicLab.Problems.DataAnalysis.Symbolic.Tests;
6using HeuristicLab.Random;
7using Microsoft.VisualStudio.TestTools.UnitTesting;
8
9namespace HeuristicLab.Tests {
10  /// <summary>
11  /// Summary description for MaxCommonSubtreeSimilarityCalculatorTest
12  /// </summary>
13  [TestClass]
14  public class SymbolicExpressionTreeMaxCommonSubtreeSimilarityCalculatorTest {
15    private readonly ISymbolicExpressionTreeNodeSimilarityComparer comparer;
16
17    private const int N = 100;
18    private const int Rows = 1;
19    private const int Columns = 10;
20
21    public SymbolicExpressionTreeMaxCommonSubtreeSimilarityCalculatorTest() {
22      comparer = new SymbolicExpressionTreeNodeEqualityComparer();
23    }
24
25    #region Additional test attributes
26    //
27    // You can use the following additional attributes as you write your tests:
28    //
29    // Use ClassInitialize to run code before running the first test in the class
30    // [ClassInitialize()]
31    // public static void MyClassInitialize(TestContext testContext) { }
32    //
33    // Use ClassCleanup to run code after all tests in a class have run
34    // [ClassCleanup()]
35    // public static void MyClassCleanup() { }
36    //
37    // Use TestInitialize to run code before running each test
38    // [TestInitialize()]
39    // public void MyTestInitialize() { }
40    //
41    // Use TestCleanup to run code after each test has run
42    // [TestCleanup()]
43    // public void MyTestCleanup() { }
44    //
45    #endregion
46
47    [TestMethod]
48    [TestCategory("Problems.DataAnalysis.Symbolic")]
49    [TestProperty("Time", "long")]
50    public void MaxCommonSubtreeSimilarityCalculatorTestPerformance() {
51      var grammar = new TypeCoherentExpressionGrammar();
52      grammar.ConfigureAsDefaultRegressionGrammar();
53      var twister = new MersenneTwister(31415);
54      var ds = Util.CreateRandomDataset(twister, Rows, Columns);
55      var trees = Util.CreateRandomTrees(twister, ds, grammar, N, 1, 100, 0, 0);
56
57      double s = 0;
58      var sw = new Stopwatch();
59
60      sw.Start();
61      for (int i = 0; i < trees.Length - 1; ++i) {
62        for (int j = i + 1; j < trees.Length; ++j) {
63          s += SymbolicExpressionTreeMaxCommonSubtreeSimilarityCalculator.MaxCommonSubtreeSimilarity(trees[i], trees[j], comparer);
64        }
65      }
66      sw.Stop();
67      Console.WriteLine("Elapsed time: " + sw.ElapsedMilliseconds / 1000.0 + ", Avg. similarity: " + s / (N * (N - 1) / 2));
68      Console.WriteLine(N * (N + 1) / (2 * sw.ElapsedMilliseconds / 1000.0) + " similarity calculations per second.");
69    }
70  }
71}
Note: See TracBrowser for help on using the repository browser.