Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking.Tests/GenealogyOperationsPerformanceTests.cs @ 15589

Last change on this file since 15589 was 11852, checked in by bburlacu, 9 years ago

#1772: Added some useful functionality to the GenealogyGraphView.

File size: 3.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2014 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;
23using System.Collections.Generic;
24using System.Diagnostics;
25using System.Linq;
26using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
27using HeuristicLab.Persistence.Default.Xml;
28using HeuristicLab.Problems.DataAnalysis.Symbolic;
29using Microsoft.VisualStudio.TestTools.UnitTesting;
30
31namespace HeuristicLab.EvolutionTracking.Tests {
32  [TestClass]
33  public class GenealogyOperationsPerformanceTests {
34    private readonly IGenealogyGraph<ISymbolicExpressionTree> graph;
35
36    public GenealogyOperationsPerformanceTests() {
37      graph = XmlParser.Deserialize<IGenealogyGraph<ISymbolicExpressionTree>>("genealogyGraph.hl");
38    }
39
40    [TestMethod]
41    public void TestTracingPerformance() {
42      var tc = new TraceCalculator();
43      //      var bestIndividual = (IGenealogyGraphNode<ISymbolicExpressionTree>)graph.Ranks.Last().Value.OrderBy(x => x.Quality).Last();
44      var sw = new Stopwatch();
45      sw.Start();
46      //      double s = graph.Ranks.Last().Value.Average(x => tc.Trace((IGenealogyGraphNode<ISymbolicExpressionTree>) x, 2)); 
47      double s = graph.Ranks.Last().Value.Aggregate<IGenealogyGraphNode, double>(0, (current, individual) => current + tc.Trace((IGenealogyGraphNode<ISymbolicExpressionTree>)individual, 2).Vertices.Count());
48      //      var trace = tc.Trace(bestIndividual, 2);
49      sw.Stop();
50      Console.WriteLine("Avg trace size: {0}", s / graph.Ranks.Last().Value.Count());
51      //      var ancestry = bestIndividual.Ancestors;
52      //      Console.WriteLine("Ancestry size: {0}", ancestry.Count());
53      //      Console.WriteLine("Trace size: {0}", trace.Vertices.Count());
54      Console.WriteLine("Elapsed time: {0}", sw.ElapsedMilliseconds / 1000.0);
55    }
56
57    [TestMethod]
58    public void TestAncestorsPerformance() {
59      var sw = new Stopwatch();
60      sw.Start();
61      List<IEnumerable<IGenealogyGraphNode>> ancestries = graph.Ranks.Last().Value.Select(x => x.Ancestors).ToList();
62      sw.Stop();
63      Console.WriteLine("Average ancestry size: {0}", ancestries.Average(x => x.Count()));
64      Console.WriteLine("Elapsed time: {0}", sw.ElapsedMilliseconds / 1000.0);
65
66      sw.Restart();
67      var overlap = ancestries[0].Intersect(ancestries[1]).Count();
68      sw.Stop();
69      Console.WriteLine("Overlap: {0}", overlap);
70      Console.WriteLine("Elapsed time: {0}", sw.ElapsedMilliseconds / 1000.0);
71    }
72  }
73}
Note: See TracBrowser for help on using the repository browser.