#region License Information /* HeuristicLab * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; using HeuristicLab.Persistence.Default.Xml; using HeuristicLab.Problems.DataAnalysis.Symbolic; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace HeuristicLab.EvolutionTracking.Tests { [TestClass] public class GenealogyOperationsPerformanceTests { private readonly IGenealogyGraph graph; public GenealogyOperationsPerformanceTests() { graph = XmlParser.Deserialize>("genealogyGraph.hl"); } [TestMethod] public void TestTracingPerformance() { var tc = new TraceCalculator(); // var bestIndividual = (IGenealogyGraphNode)graph.Ranks.Last().Value.OrderBy(x => x.Quality).Last(); var sw = new Stopwatch(); sw.Start(); // double s = graph.Ranks.Last().Value.Average(x => tc.Trace((IGenealogyGraphNode) x, 2)); double s = graph.Ranks.Last().Value.Aggregate(0, (current, individual) => current + tc.Trace((IGenealogyGraphNode)individual, 2).Vertices.Count()); // var trace = tc.Trace(bestIndividual, 2); sw.Stop(); Console.WriteLine("Avg trace size: {0}", s / graph.Ranks.Last().Value.Count()); // var ancestry = bestIndividual.Ancestors; // Console.WriteLine("Ancestry size: {0}", ancestry.Count()); // Console.WriteLine("Trace size: {0}", trace.Vertices.Count()); Console.WriteLine("Elapsed time: {0}", sw.ElapsedMilliseconds / 1000.0); } [TestMethod] public void TestAncestorsPerformance() { var sw = new Stopwatch(); sw.Start(); List> ancestries = graph.Ranks.Last().Value.Select(x => x.Ancestors).ToList(); sw.Stop(); Console.WriteLine("Average ancestry size: {0}", ancestries.Average(x => x.Count())); Console.WriteLine("Elapsed time: {0}", sw.ElapsedMilliseconds / 1000.0); sw.Restart(); var overlap = ancestries[0].Intersect(ancestries[1]).Count(); sw.Stop(); Console.WriteLine("Overlap: {0}", overlap); Console.WriteLine("Elapsed time: {0}", sw.ElapsedMilliseconds / 1000.0); } } }