Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11916


Ignore:
Timestamp:
02/05/15 17:04:30 (10 years ago)
Author:
bburlacu
Message:

#2215: Merged unit tests into the trunk.

Location:
trunk/sources/HeuristicLab.Tests
Files:
1 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/SymbolicExpressionTreeBottomUpSimilarityCalculatorTest.cs

    r11910 r11916  
    11using System;
    2 using System.Collections.Generic;
    32using System.Diagnostics;
    4 using System.Drawing;
    5 using System.Globalization;
    6 using System.Linq;
    7 using System.Text;
    8 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    9 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views;
    103using HeuristicLab.Random;
    114using Microsoft.VisualStudio.TestTools.UnitTesting;
     
    2922    [TestCategory("Problems.DataAnalysis.Symbolic")]
    3023    [TestProperty("Time", "short")]
    31     public void TestBottomUpMatching() {
     24    public void BottomUpTreeSimilarityCalculatorTestMapping() {
    3225      TestMatchedNodes("(+ 1 2)", "(+ 2 1)", 5);
    3326      TestMatchedNodes("(- 2 1)", "(- 1 2)", 2);
     
    7265    [TestCategory("Problems.DataAnalysis.Symbolic")]
    7366    [TestProperty("Time", "long")]
    74     public void TestBottomUpSimilarityCalculatorPerformance() {
     67    public void BottomUpTreeSimilarityCalculatorTestPerformance() {
    7568      var grammar = new TypeCoherentExpressionGrammar();
    7669      grammar.ConfigureAsDefaultRegressionGrammar();
     
    9386      Console.WriteLine(N * (N + 1) / (2 * sw.ElapsedMilliseconds / 1000.0) + " similarity calculations per second.");
    9487    }
    95 
    96     private static string FormatMapping(ISymbolicExpressionTree t1, ISymbolicExpressionTree t2, Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode> map) {
    97       var symbolNameMap = new Dictionary<string, string>
    98     {
    99       {"ProgramRootSymbol", "Prog"},
    100       {"StartSymbol","RPB"},
    101       {"Multiplication", "$\\times$"},
    102       {"Division", "$\\div$"},
    103       {"Addition", "$+$"},
    104       {"Subtraction", "$-$"},
    105       {"Exponential", "$\\exp$"},
    106       {"Logarithm", "$\\log$"}
    107     };
    108 
    109       var sb = new StringBuilder();
    110       var nodeIds = new Dictionary<ISymbolicExpressionTreeNode, string>();
    111       int offset = 0;
    112       var layoutEngine = new ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode>(x => x.Subtrees);
    113       var nodeCoordinates = layoutEngine.CalculateLayout(t1.Root).ToDictionary(n => n.Content, n => new PointF(n.X, n.Y));
    114 
    115       double ws = 0.5;
    116       double hs = 0.5;
    117 
    118       var nl = Environment.NewLine;
    119       sb.Append("\\documentclass[class=minimal,border=0pt]{standalone}" + nl +
    120                  "\\usepackage{tikz}" + nl +
    121                  "\\begin{document}" + nl +
    122                  "\\begin{tikzpicture}" + nl +
    123                  "\\def\\ws{1}" + nl +
    124                  "\\def\\hs{0.7}" + nl +
    125                  "\\def\\offs{" + offset + "}" + nl);
    126 
    127       foreach (var node in t1.IterateNodesBreadth()) {
    128         var id = Guid.NewGuid().ToString();
    129         nodeIds[node] = id;
    130         var coord = nodeCoordinates[node];
    131         var nodeName = symbolNameMap.ContainsKey(node.Symbol.Name) ? symbolNameMap[node.Symbol.Name] : node.ToString();
    132         sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "\\node ({0}) at (\\ws*{1} + \\offs,\\hs*{2}) {{{3}}};", nodeIds[node], ws * coord.X, -hs * coord.Y, EscapeLatexString(nodeName)));
    133       }
    134 
    135       foreach (ISymbolicExpressionTreeNode t in t1.IterateNodesBreadth()) {
    136         var n = t;
    137         foreach (var s in t.Subtrees) {
    138           sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "\\draw ({0}) -- ({1});", nodeIds[n], nodeIds[s]));
    139         }
    140       }
    141 
    142       nodeCoordinates = layoutEngine.CalculateLayout(t2.Root).ToDictionary(n => n.Content, n => new PointF(n.X, n.Y));
    143 
    144       offset = 20;
    145       sb.Append("\\def\\offs{" + offset + "}" + nl);
    146       foreach (var node in t2.IterateNodesBreadth()) {
    147         var id = Guid.NewGuid().ToString();
    148         nodeIds[node] = id;
    149         var coord = nodeCoordinates[node];
    150         var nodeName = symbolNameMap.ContainsKey(node.Symbol.Name) ? symbolNameMap[node.Symbol.Name] : node.ToString();
    151         sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "\\node ({0}) at (\\ws*{1} + \\offs,\\hs*{2}) {{{3}}};", nodeIds[node], ws * coord.X, -hs * coord.Y, EscapeLatexString(nodeName)));
    152       }
    153 
    154       foreach (ISymbolicExpressionTreeNode t in t2.IterateNodesBreadth()) {
    155         var n = t;
    156         foreach (var s in t.Subtrees) {
    157           sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "\\draw ({0}) -- ({1});", nodeIds[n], nodeIds[s]));
    158         }
    159       }
    160 
    161       foreach (var p in map) {
    162         var id1 = nodeIds[p.Key];
    163         var id2 = nodeIds[p.Value];
    164 
    165         sb.Append(string.Format(CultureInfo.InvariantCulture, "\\path[draw,->,color=gray] ({0}) edge[bend left,dashed] ({1});" + Environment.NewLine, id1, id2));
    166       }
    167       sb.Append("\\end{tikzpicture}" + nl +
    168                 "\\end{document}" + nl);
    169       return sb.ToString();
    170     }
    171 
    172     private static string EscapeLatexString(string s) {
    173       return s.Replace("\\", "\\\\").Replace("{", "\\{").Replace("}", "\\}").Replace("_", "\\_");
    174     }
    17588  }
    17689}
  • trunk/sources/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/SymbolicExpressionTreeMaxCommonSubtreeSimilarityCalculatorTest.cs

    r11910 r11916  
    4848    [TestCategory("Problems.DataAnalysis.Symbolic")]
    4949    [TestProperty("Time", "long")]
    50     public void TestMaxCommonSubtreeSimilarityCalculatorPerformance() {
     50    public void MaxCommonSubtreeSimilarityCalculatorTestPerformance() {
    5151      var grammar = new TypeCoherentExpressionGrammar();
    5252      grammar.ConfigureAsDefaultRegressionGrammar();
  • trunk/sources/HeuristicLab.Tests/HeuristicLab.Tests.csproj

    r11789 r11916  
    492492    <Compile Include="HeuristicLab.Problems.DataAnalysis-3.4\OnlineCalculatorPerformanceTest.cs" />
    493493    <Compile Include="HeuristicLab.Problems.DataAnalysis-3.4\StatisticCalculatorsTest.cs" />
     494    <Compile Include="HeuristicLab.Problems.DataAnalysis.Symbolic-3.4\SymbolicExpressionTreeBottomUpSimilarityCalculatorTest.cs" />
     495    <Compile Include="HeuristicLab.Problems.DataAnalysis.Symbolic-3.4\SymbolicExpressionTreeMaxCommonSubtreeSimilarityCalculatorTest.cs" />
    494496    <Compile Include="HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis-3.4\SymbolicDataAnalysisExpressionTreeInterpreterTest.cs" />
    495497    <Compile Include="HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis-3.4\Util.cs" />
Note: See TracChangeset for help on using the changeset viewer.