[11694] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Diagnostics;
|
---|
| 25 | using System.Linq;
|
---|
| 26 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
| 27 | using HeuristicLab.Persistence.Default.Xml;
|
---|
| 28 | using HeuristicLab.Problems.DataAnalysis.Symbolic;
|
---|
| 29 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
| 30 |
|
---|
| 31 | namespace 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();
|
---|
[11852] | 50 | Console.WriteLine("Avg trace size: {0}", s / graph.Ranks.Last().Value.Count());
|
---|
[11694] | 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 | }
|
---|