Changeset 11916
- Timestamp:
- 02/05/15 17:04:30 (10 years ago)
- 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 1 1 using System; 2 using System.Collections.Generic;3 2 using 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;10 3 using HeuristicLab.Random; 11 4 using Microsoft.VisualStudio.TestTools.UnitTesting; … … 29 22 [TestCategory("Problems.DataAnalysis.Symbolic")] 30 23 [TestProperty("Time", "short")] 31 public void TestBottomUpMatching() {24 public void BottomUpTreeSimilarityCalculatorTestMapping() { 32 25 TestMatchedNodes("(+ 1 2)", "(+ 2 1)", 5); 33 26 TestMatchedNodes("(- 2 1)", "(- 1 2)", 2); … … 72 65 [TestCategory("Problems.DataAnalysis.Symbolic")] 73 66 [TestProperty("Time", "long")] 74 public void TestBottomUpSimilarityCalculatorPerformance() {67 public void BottomUpTreeSimilarityCalculatorTestPerformance() { 75 68 var grammar = new TypeCoherentExpressionGrammar(); 76 69 grammar.ConfigureAsDefaultRegressionGrammar(); … … 93 86 Console.WriteLine(N * (N + 1) / (2 * sw.ElapsedMilliseconds / 1000.0) + " similarity calculations per second."); 94 87 } 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 }175 88 } 176 89 } -
trunk/sources/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/SymbolicExpressionTreeMaxCommonSubtreeSimilarityCalculatorTest.cs
r11910 r11916 48 48 [TestCategory("Problems.DataAnalysis.Symbolic")] 49 49 [TestProperty("Time", "long")] 50 public void TestMaxCommonSubtreeSimilarityCalculatorPerformance() {50 public void MaxCommonSubtreeSimilarityCalculatorTestPerformance() { 51 51 var grammar = new TypeCoherentExpressionGrammar(); 52 52 grammar.ConfigureAsDefaultRegressionGrammar(); -
trunk/sources/HeuristicLab.Tests/HeuristicLab.Tests.csproj
r11789 r11916 492 492 <Compile Include="HeuristicLab.Problems.DataAnalysis-3.4\OnlineCalculatorPerformanceTest.cs" /> 493 493 <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" /> 494 496 <Compile Include="HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis-3.4\SymbolicDataAnalysisExpressionTreeInterpreterTest.cs" /> 495 497 <Compile Include="HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis-3.4\Util.cs" />
Note: See TracChangeset
for help on using the changeset viewer.